52 |
"""Return the distance between p1 and p2 (AWT points)""" |
"""Return the distance between p1 and p2 (AWT points)""" |
53 |
return math.sqrt((p1.x-p2.x)**2 + (p1.y-p2.y)**2) |
return math.sqrt((p1.x-p2.x)**2 + (p1.y-p2.y)**2) |
54 |
|
|
55 |
|
def angle(p1, p2): |
56 |
|
""" |
57 |
|
If p1 is the origin, return the angle between a |
58 |
|
line from p1 to p2 and the x axis. |
59 |
|
""" |
60 |
|
x, y = (p2.x-p1.x) * 1.0, (p2.y-p1.y) * 1.0 |
61 |
|
if x == 0: return math.pi/2 |
62 |
|
return math.asin(y/x) |
63 |
|
|
64 |
|
|
65 |
def testWheel(): |
def testWheel(): |
66 |
r.addProperty(p, s) |
r.addProperty(p, s) |
92 |
for px in (pt, pu, pv, pw): |
for px in (pt, pu, pv, pw): |
93 |
assert abs(distance(pr,ps) - distance(pr,px)) < 1 |
assert abs(distance(pr,ps) - distance(pr,px)) < 1 |
94 |
|
|
95 |
|
# Check the angles XXX |
96 |
|
# This code doesn't seem to work right? XXX |
97 |
|
|
98 |
|
assert angle(pr, ps) == 0 |
99 |
|
assert angle(pr, pw) == 0 |
100 |
|
print angle(pr, pt), angle(pr, pu), angle(pr, pv) |
101 |
|
|
102 |
# Test that WheelView calls its NodeView |
# Test that WheelView calls its NodeView |
103 |
# with all the correct parameters. |
# with all the correct parameters. |
104 |
|
|