comparison python/tests/moving.txt @ 614:5e09583275a4

Merged Nicolas/trafficintelligence into default
author Mohamed Gomaa <eng.m.gom3a@gmail.com>
date Fri, 05 Dec 2014 12:13:53 -0500
parents 6ebfb43e938e
children 17b02c8054d0
comparison
equal deleted inserted replaced
598:11f96bd08552 614:5e09583275a4
40 >>> unionIntervals([TimeInterval(3,6), TimeInterval(8,10),TimeInterval(11,15)]) 40 >>> unionIntervals([TimeInterval(3,6), TimeInterval(8,10),TimeInterval(11,15)])
41 [3, 15] 41 [3, 15]
42 42
43 >>> Point(3,4)-Point(1,7) 43 >>> Point(3,4)-Point(1,7)
44 (2.000000,-3.000000) 44 (2.000000,-3.000000)
45 >>> -Point(1,2)
46 (-1.000000,-2.000000)
47 >>> Point(1,2).multiply(0.5)
48 (0.500000,1.000000)
45 49
46 >>> Point(3,2).norm2Squared() 50 >>> Point(3,2).norm2Squared()
47 13 51 13
48 52
49 >>> Point.distanceNorm2(Point(3,4),Point(1,7)) 53 >>> Point.distanceNorm2(Point(3,4),Point(1,7))
50 3.605551275463989 54 3.605551275463989
51 55
52 >>> Point(3,2).inPolygon([Point(0,0),Point(1,0),Point(1,1),Point(0,1)]) 56 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[1,0],[1,1],[0,1]]))
53 False 57 False
54 >>> Point(3,2).inPolygon([Point(0,0),Point(4,0),Point(4,3),Point(0,3)]) 58 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
55 True 59 True
56 60
57 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS 61 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS
58 ((1.0...,1.0...), (10.0...,10.0...)) 62 ((1.0...,1.0...), (10.0...,10.0...))
59 63
60 >>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2)) 64 >>> segmentIntersection(Point(0,0), Point(0,1), Point(1,1), Point(2,3))
61 >>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1)) 65 >>> segmentIntersection(Point(0,1), Point(0,3), Point(1,0), Point(3,1))
62 >>> segmentIntersection(Point(0,0),Point(2,0), Point(1,-1),Point(1,1)) 66 >>> segmentIntersection(Point(0.,0.), Point(2.,2.), Point(0.,2.), Point(2.,0.))
63 (1.000000,0.000000) 67 (1.000000,1.000000)
64 >>> segmentIntersection(Point(0,1),Point(2,0),Point(1,1),Point(1,2)) 68 >>> segmentIntersection(Point(0,1), Point(1,2), Point(2,0), Point(3,2))
69
70 >>> left = Trajectory.fromPointList([(92.291666666666686, 102.99239033124439), (56.774193548387103, 69.688898836168306)])
71 >>> middle = Trajectory.fromPointList([(87.211021505376351, 93.390778871978512), (59.032258064516128, 67.540286481647257)])
72 >>> right = Trajectory.fromPointList([(118.82392473118281, 115.68263205013426), (63.172043010752688, 66.600268576544309)])
73 >>> alignments = [left, middle, right]
74 >>> for a in alignments: a.computeCumulativeDistances()
75 >>> getSYfromXY(Point(73, 82), alignments)
76 [1, 0, (73.819977,81.106170), 18.172277808821125, 18.172277808821125, 1.2129694042343868]
77 >>> getSYfromXY(Point(78, 83), alignments, 0.5)
78 [1, 0, (77.033188,84.053889), 13.811799123113715, 13.811799123113715, -1.4301775140225983]
65 79
66 >>> Trajectory().length() 80 >>> Trajectory().length()
67 0 81 0
68 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) 82 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
69 >>> t1.length() == 3. 83 >>> t1.length() == 3.
70 True 84 True
71 >>> t1[1] 85 >>> t1[1]
72 (1.500000,3.500000) 86 (1.500000,3.500000)
73 >>> t1.getTrajectoryInPolygon(np.array([[0,0],[4,0],[4,3],[0,3]])) 87 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
74 (0.500000,0.500000) 88 (0.500000,0.500000)
75 >>> t1.getTrajectoryInPolygon(np.array([[10,10],[14,10],[14,13],[10,13]])).length() 89 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[10,10],[14,10],[14,13],[10,13]])).length()
76 0 90 0
77 91
78 >>> Trajectory.norm2LCSS(t1, t1, 0.1) 92 >>> t1.differentiate()
93 (1.000000,3.000000) (1.000000,3.000000)
94 >>> t1.differentiate(True)
95 (1.000000,3.000000) (1.000000,3.000000) (1.000000,3.000000)
96 >>> t1 = Trajectory([[0.5,1.5,3.5],[0.5,2.5,7.5]])
97 >>> t1.differentiate()
98 (1.000000,2.000000) (2.000000,5.000000)
99
100 >>> t1.computeCumulativeDistances()
101 >>> t1.getDistance(0)
102 2.23606797749979
103 >>> t1.getDistance(1)
104 5.385164807134504
105 >>> t1.getDistance(2)
106 Index 2 beyond trajectory length 3-1
107 >>> t1.getCumulativeDistance(0)
108 0.0
109 >>> t1.getCumulativeDistance(1)
110 2.23606797749979
111 >>> t1.getCumulativeDistance(2)
112 7.6212327846342935
113 >>> t1.getCumulativeDistance(3)
114 Index 3 beyond trajectory length 3
115
116
117 >>> from utils import LCSS
118 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1)
119 >>> Trajectory.lcss(t1, t1, lcss)
79 3 120 3
80 >>> Trajectory.normMaxLCSS(t1, t1, 0.1) 121 >>> lcss = LCSS(lambda p1, p2: (p1-p2).normMax() <= 0.1)
122 >>> Trajectory.lcss(t1, t1, lcss)
81 3 123 3
124
125 >>> p1=Point(0,0)
126 >>> p2=Point(1,0)
127 >>> v1 = Point(0.1,0.1)
128 >>> v2 = Point(-0.1, 0.1)
129 >>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.)-5.0) < 0.00001
130 True
131 >>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.1)-4.5) < 0.00001
132 True
133 >>> p1=Point(0,1)
134 >>> p2=Point(1,0)
135 >>> v1 = Point(0,0.1)
136 >>> v2 = Point(0.1, 0)
137 >>> Point.timeToCollision(p1, p2, v1, v2, 0.) == None
138 True
139 >>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None
140 True
141 >>> Point.midPoint(p1, p2)
142 (0.500000,0.500000)
143
144 >>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4)
145 >>> t.differentiate() # doctest:+ELLIPSIS
146 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1']
147 >>> t.differentiate(True) # doctest:+ELLIPSIS
148 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] [2.0, 0.099..., '1']
149 >>> t = CurvilinearTrajectory(S = [1.], Y = [0.5], lanes = ['1'])
150 >>> t.differentiate().empty()
151 True
152
153 >>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3]))
154 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)
155 >>> userTypeNames[o1.getUserType()]
156 'car'
157 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.mean)
158 >>> userTypeNames[o1.getUserType()]
159 'car'
160 >>> o1.classifyUserTypeSpeedMotorized(1.5, np.median)
161 >>> userTypeNames[o1.getUserType()]
162 'pedestrian'