# HG changeset patch # User Nicolas Saunier # Date 1270940323 14400 # Node ID 48e56179c39e141999777646eb14b80541ae4b0b # Parent c000f37c316d0be4f141411063ef3c77ec36ffb7 added ceil function diff -r c000f37c316d -r 48e56179c39e python/tests/utils.txt --- a/python/tests/utils.txt Sat Feb 13 19:46:33 2010 -0500 +++ b/python/tests/utils.txt Sat Apr 10 18:58:43 2010 -0400 @@ -8,6 +8,11 @@ >>> computeChi2(range(1,9),range(1,10)) 0.0 +>>> ceilDecimals(1.23, 0) +2.0 +>>> ceilDecimals(1.23, 1) +1.3 + >>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2)) >>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1)) >>> segmentIntersection(Point(0,0),Point(2,0), Point(1,-1),Point(1,1)) diff -r c000f37c316d -r 48e56179c39e python/utils.py --- a/python/utils.py Sat Feb 13 19:46:33 2010 -0500 +++ b/python/utils.py Sat Apr 10 18:58:43 2010 -0400 @@ -31,6 +31,13 @@ # maths section ######################### +def ceilDecimals(v, nDecimals): + '''Rounds the number at the nth decimal + eg 1.23 at 0 decimal is 2, at 1 decimal is 1.3''' + from math import ceil,pow + tens = pow(10,nDecimals) + return ceil(v*tens)/tens + def segmentIntersection(p1, p2, p3, p4): '''Returns the intersecting point of the segments [p1, p2] and [p3, p4], None otherwise''' from numpy import matrix