diff options
author | rcoh <rcoh@mit.edu> | 2010-12-20 14:50:08 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2010-12-20 14:50:08 -0500 |
commit | 2736307c1d6d67868ca54a3df951f9e959efedd0 (patch) | |
tree | 50a61c798d52987f8fe575f678aaff5b5b9455b9 /util | |
parent | 7386cbc7ce48e3996d92d84cff3d1a4dab8f538d (diff) |
Util cleanup is done! Util.py is now refactored into the util module. Woo! RCOH
Diffstat (limited to 'util')
-rw-r--r-- | util/Geo.py | 15 | ||||
-rw-r--r-- | util/Search.py | 8 | ||||
-rw-r--r-- | util/Strings.py | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/util/Geo.py b/util/Geo.py new file mode 100644 index 0000000..885c585 --- /dev/null +++ b/util/Geo.py @@ -0,0 +1,15 @@ +#Geometry code +import math +from bisect import * +def pointWithinBoundingBox(point, bb): #this could be in 4 lines, but I'm lazy. + return sum([(point[i % 2] <= bb[i]) == (i>1) for i in range(4)]) == 4 +print pointWithinBoundingBox((118,21), (10,8,298,42)) +def addLocations(l1,l2): + return tuple([l1[i]+l2[i] for i in range(len(l1))]) +def gaussian(x,height,center,width): + a=height + b=center + c=width + return a*math.exp(-((x-b)**2)/(2*c**2)) +def dist(l1, l2): + return math.sqrt(sum([(l1[i]-l2[i])**2 for i in range(len(l1))])) diff --git a/util/Search.py b/util/Search.py new file mode 100644 index 0000000..25882da --- /dev/null +++ b/util/Search.py @@ -0,0 +1,8 @@ +from bisect import * +def find_le(a, x): + 'Find rightmost value less than or equal to x' + return bisect_right(a, x)-1 + +def find_ge(a, x): + 'Find leftmost value greater than x' + return bisect_left(a, x) diff --git a/util/Strings.py b/util/Strings.py new file mode 100644 index 0000000..1331db4 --- /dev/null +++ b/util/Strings.py @@ -0,0 +1 @@ +LOCATION = 'Location' |