diff options
author | Russell <rcoh@rcoh.(none)> | 2011-01-10 12:21:19 -0500 |
---|---|---|
committer | Russell <rcoh@rcoh.(none)> | 2011-01-10 12:21:19 -0500 |
commit | cbdc42af021f898e82d3e78ce7c636d3fb5eece0 (patch) | |
tree | f36ca72463702c104dd02f026e9fbcd6de3f0da8 /util/Geo.py | |
parent | 1679719e7ca8ce433c5714474a32c926161dc5b8 (diff) |
Some performance improvements. Faster evaluation of range-based queries with
lambda expressions. Faster exp with approximated fastexp. Some changes to the
component registry.
Diffstat (limited to 'util/Geo.py')
-rw-r--r-- | util/Geo.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/util/Geo.py b/util/Geo.py index a9243de..be3e93e 100644 --- a/util/Geo.py +++ b/util/Geo.py @@ -4,7 +4,6 @@ from bisect import * import random 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): @@ -13,9 +12,12 @@ def gaussian(x,height,center,width): 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))])) + return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) + #return math.sqrt(sum([(l1[i]-l2[i])**2 for i in range(len(l1))])) def randomLoc(boundingBox): #TODO: make less shitty loc = [] loc.append(random.randint(0, boundingBox[0])) loc.append(random.randint(0, boundingBox[1])) return tuple(loc) +def approxexp(x): + return 1+x+x**2/2+x**3/6 |