55 |
def angle(p1, p2): |
def angle(p1, p2): |
56 |
""" |
""" |
57 |
If p1 is the origin, return the angle between a |
If p1 is the origin, return the angle between a |
58 |
line from p1 to p2 and the x axis. |
line from p1 to p2 and the x axis. The zero angle is |
59 |
|
at the clock three and expands clockwise. |
60 |
""" |
""" |
61 |
x, y = (p2.x-p1.x) * 1.0, (p2.y-p1.y) * 1.0 |
x, y = (p2.x-p1.x) * 1.0, (p2.y-p1.y) * 1.0 |
62 |
if x == 0: return math.pi/2 |
if x == 0 and y < 0: return math.pi * 1.5 |
63 |
return math.asin(y/x) |
elif x == 0 and y == 0: return 0.0 |
64 |
|
elif x == 0 and y > 0: return math.pi/2 |
65 |
|
elif x > 0 and y < 0: return math.pi * 1.5 + math.atan(-y/x) |
66 |
|
elif x > 0 and y == 0: return 0.0 |
67 |
|
elif x > 0 and y > 0: return math.atan(y/x) |
68 |
|
elif x < 0 and y < 0: return math.pi + math.atan(-y/-x) |
69 |
|
elif x < 0 and y == 0: return math.pi |
70 |
|
elif x < 0 and y > 0: return math.pi/2 + math.atan(y/-x) |
71 |
|
|
72 |
def testWheel(): |
def testWheel(): |
73 |
r.addProperty(p, s) |
r.addProperty(p, s) |
89 |
[vs.coords.transformPoint(cs, 0, 0, None) |
[vs.coords.transformPoint(cs, 0, 0, None) |
90 |
for cs in [cs_r, cs_s, cs_t, cs_u, cs_v, cs_w]] |
for cs in [cs_r, cs_s, cs_t, cs_u, cs_v, cs_w]] |
91 |
|
|
92 |
|
# Check that selected nodes are drawn on same level |
93 |
|
|
94 |
assert pw.y == pr.y == ps.y |
assert pw.y == pr.y == ps.y |
95 |
|
|
96 |
|
# Check that the positive side of the wheel seem to turn right |
97 |
|
|
98 |
assert pt.y < ps.y < pv.y |
assert pt.y < ps.y < pv.y |
99 |
assert pt.x < ps.x > pv.x |
assert pt.x < ps.x > pv.x |
100 |
|
|
104 |
for px in (pt, pu, pv, pw): |
for px in (pt, pu, pv, pw): |
105 |
assert abs(distance(pr,ps) - distance(pr,px)) < 1 |
assert abs(distance(pr,ps) - distance(pr,px)) < 1 |
106 |
|
|
107 |
# Check the angles XXX |
# Check the angles |
|
# This code doesn't seem to work right? XXX |
|
108 |
|
|
109 |
assert angle(pr, ps) == 0 |
assert angle(pr, ps) == 0 |
110 |
assert angle(pr, pw) == 0 |
assert angle(pr, pv) == 2*math.pi/8 |
111 |
print angle(pr, pt), angle(pr, pu), angle(pr, pv) |
assert angle(pr, pu) == 2*math.pi/8*2 |
112 |
|
assert angle(pr, pw) == math.pi |
113 |
|
assert angle(pr, pt) == 2*math.pi - angle(pr, pv) |
114 |
|
|
115 |
# Test that WheelView calls its NodeView |
# Test that WheelView calls its NodeView |
116 |
# with all the correct parameters. |
# with all the correct parameters. |