Mercurial Hosting > traffic-intelligence
diff python/utils.py @ 152:74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 06 Sep 2011 18:44:23 -0400 |
parents | 2bf5b76320c0 |
children | f03fe3d6d0c8 |
line wrap: on
line diff
--- a/python/utils.py Tue Sep 06 17:55:06 2011 -0400 +++ b/python/utils.py Tue Sep 06 18:44:23 2011 -0400 @@ -4,8 +4,6 @@ #from numpy import * #from pylab import * -import moving - __metaclass__ = type commentChar = '#' @@ -119,30 +117,8 @@ 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 - from numpy.linalg import linalg, det - - dp1 = p2-p1#[s1[0][1]-s1[0][0], s1[1][1]-s1[1][0]] - dp2 = p4-p3#[s2[0][1]-s2[0][0], s2[1][1]-s2[1][0]] - - A = matrix([[dp1.y, -dp1.x], - [dp2.y, -dp2.x]]) - B = matrix([[dp1.y*p1.x-dp1.x*p1.y], - [dp2.y*p3.x-dp2.x*p3.y]]) - - if linalg.det(A) == 0:#crossProduct(ds1, ds2) == 0: - return None - else: - intersection = linalg.solve(A,B) - if (moving.Interval(p1.x, p2.x, True).contains(intersection[0,0]) - and moving.Interval(p3.x, p4.x, True).contains(intersection[0,0]) - and moving.Interval(p1.y, p2.y, True).contains(intersection[1,0]) - and moving.Interval(p3.y, p4.y, True).contains(intersection[1,0])): - return moving.Point(intersection[0,0], intersection[1,0]) - else: - return None +def inBetween(bound1, bound2, x): + return bound1 <= x <= bound2 or bound2 <= x<= bound1 def crossProduct(l1, l2): return l1[0]*l2[1]-l1[1]*l2[0]