create py3k branch
[PyX.git] / test / unit / test_path.py
blob1443eae1ab2a6f5db754f7399139b8db04c6a67b
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest
7 from pyx import *
8 from pyx.path import *
9 from pyx.normpath import normpathparam
10 import math
11 set(epsilon=1e-7)
13 class NormpathTestCase(unittest.TestCase):
15 def failUnlessAlmostEqualNormsubpathitem(self, nspi1, nspi2):
16 if isinstance(nspi1, normline_pt):
17 assert isinstance(nspi2, normline_pt), "%s != %s" % (nspi1, nspi2)
18 self.failUnlessAlmostEqual(nspi1.x0_pt, nspi2.x0_pt)
19 self.failUnlessAlmostEqual(nspi1.y0_pt, nspi2.y0_pt)
20 self.failUnlessAlmostEqual(nspi1.x1_pt, nspi2.x1_pt)
21 self.failUnlessAlmostEqual(nspi1.y1_pt, nspi2.y1_pt)
22 else:
23 assert isinstance(nspi1, normcurve_pt), "%s != %s" % (nspi1, nspi2)
24 assert isinstance(nspi2, normcurve_pt), "%s != %s" % (nspi1, nspi2)
25 self.failUnlessAlmostEqual(nspi1.x0_pt, nspi2.x0_pt)
26 self.failUnlessAlmostEqual(nspi1.y0_pt, nspi2.y0_pt)
27 self.failUnlessAlmostEqual(nspi1.x1_pt, nspi2.x1_pt)
28 self.failUnlessAlmostEqual(nspi1.y1_pt, nspi2.y1_pt)
29 self.failUnlessAlmostEqual(nspi1.x2_pt, nspi2.x2_pt)
30 self.failUnlessAlmostEqual(nspi1.y2_pt, nspi2.y2_pt)
31 self.failUnlessAlmostEqual(nspi1.x3_pt, nspi2.x3_pt)
32 self.failUnlessAlmostEqual(nspi1.y3_pt, nspi2.y3_pt)
34 def failUnlessAlmostEqualNormsubpath(self, nsp1, nsp2):
35 assert len(nsp1) == len(nsp2), "%s != %s" % (nsp1, nsp2)
36 assert nsp1.closed == nsp2.closed, "%s != %s" % (nsp1, nsp2)
37 for nspi1, nspi2 in zip(nsp1, nsp2):
38 self.failUnlessAlmostEqualNormsubpathitem(nspi1, nspi2)
40 def failUnlessAlmostEqualNormpath(self, np1, np2):
41 assert len(np1) == len(np2), "%s != %s" % (np1, np2)
42 for nsp1, nsp2 in zip(np1, np2):
43 self.failUnlessAlmostEqualNormsubpath(nsp1, nsp2)
45 def testparam(self):
46 p = ( normpath([normsubpath([normline_pt(0, 0, 10, 0),
47 normline_pt(10, 0, 10, 20),
48 normline_pt(10, 20, 0, 20),
49 normline_pt(0, 20, 0, 0)], closed=1)]) +
50 circle_pt(0, 0, 10) +
51 line_pt(0, 0, 2, 0))
53 param = normpathparam(p, 0, 1.5)
54 param = param + 0
55 self.failUnlessEqual(param.normsubpathindex, 0)
56 self.failUnlessAlmostEqual(param.normsubpathparam, 1.5)
57 param = param + 15 * unit.t_pt
58 self.failUnlessEqual(param.normsubpathindex, 0)
59 self.failUnlessAlmostEqual(param.normsubpathparam, 2.5)
60 param += 24.9 * unit.t_pt
61 self.failUnlessEqual(param.normsubpathindex, 0)
62 self.failUnlessAlmostEqual(param.normsubpathparam, 3.995)
63 param = 0.1 * unit.t_pt + param
64 self.failUnlessEqual(param.normsubpathindex, 1)
65 self.failUnlessAlmostEqual(param.normsubpathparam, 0)
66 param = param + 0.5*circle_pt(0, 0, 10).arclen()
67 circlerange = len(p.normsubpaths[1])
68 self.failUnlessEqual(param.normsubpathindex, 1)
69 self.failUnlessAlmostEqual(param.normsubpathparam, 0.5*circlerange, 4)
70 param = param + 0.5*circle_pt(0, 0, 10).arclen()
71 param = param + 2 * unit.t_pt
72 self.failUnlessEqual(param.normsubpathindex, 2)
73 self.failUnlessAlmostEqual(param.normsubpathparam, 1, 4)
74 param = param + 1 * unit.t_pt
75 self.failUnlessEqual(param.normsubpathindex, 2)
76 self.failUnlessAlmostEqual(param.normsubpathparam, 1.5, 4)
78 param = normpathparam(p, 0, 1.5)
79 param = param - 15 * unit.t_pt
80 self.failUnlessEqual(param.normsubpathindex, 0)
81 self.failUnlessAlmostEqual(param.normsubpathparam, 0.5)
82 param -= 10 * unit.t_pt
83 self.failUnlessEqual(param.normsubpathindex, 0)
84 self.failUnlessAlmostEqual(param.normsubpathparam, -0.5)
86 param = normpathparam(p, 0, 1.2)
87 param2 = 2*param
88 param += param
89 self.failUnlessEqual(param.normsubpathindex, param2.normsubpathindex)
90 self.failUnlessEqual(param.normsubpathparam, param2.normsubpathparam)
92 param = normpathparam(p, 0, 1.2)
93 self.failUnless(param < 15 * unit.t_pt)
94 self.failUnless(15 * unit.t_pt > param)
95 self.failUnless(param > 12 * unit.t_pt)
96 self.failUnless(12 * unit.t_pt < param)
97 self.failUnless(param < 1)
98 self.failUnless(1 > param)
100 def testat(self):
101 p = normpath([normsubpath([normline_pt(0, 0, 10, 0),
102 normline_pt(10, 0, 10, 20),
103 normline_pt(10, 20, 0, 20),
104 normline_pt(0, 20, 0, 0)], closed=1)])
105 params = [-5, 0, 5, 10, 20, 30, 35, 40, 50, 60, 70]
106 ats = (-5, 0), (0, 0), (5, 0), (10, 0), (10, 10), (10, 20), (5, 20), (0, 20), (0, 10), (0, 0), (0, -10)
107 for param, (at_x, at_y) in zip(params, ats):
108 self.failUnlessAlmostEqual(p.at_pt(param)[0], at_x)
109 self.failUnlessAlmostEqual(p.at_pt(param)[1], at_y)
110 for (at_x, at_y), (at2_x, at2_y) in zip(p.at_pt(params), ats):
111 self.failUnlessAlmostEqual(at_x, at2_x)
112 self.failUnlessAlmostEqual(at_y, at2_y)
113 p = normpath([normsubpath([normline_pt(0, 0, 3, 0),
114 normcurve_pt(3, 0, 3, 2, 3, 4, 3, 6),
115 normcurve_pt(3, 6, 2, 6, 1, 6, 0, 6),
116 normline_pt(0, 6, 0, 0)], closed=1)])
117 self.failUnlessAlmostEqual(p.at_pt(6)[0], 3)
118 self.failUnlessAlmostEqual(p.at_pt(6)[1], 3)
119 self.failUnlessAlmostEqual(p.at_pt(4.5)[0], 3)
120 self.failUnlessAlmostEqual(p.at_pt(4.5)[1], 1.5)
122 def testarclentoparam(self):
123 p = ( normpath([normsubpath([normline_pt(0, 0, 10, 0),
124 normline_pt(10, 0, 10, 20),
125 normline_pt(10, 20, 0, 20),
126 normline_pt(0, 20, 0, 0)], closed=1)]) +
127 circle_pt(0, 0, 10) +
128 line_pt(0, 0, 2, 0))
130 arclens_pt = [20, 30, -2, 61, 100, 200, -30, 1000]
131 for arclen_pt, arclen2_pt in zip(arclens_pt, p.paramtoarclen_pt(p.arclentoparam_pt(arclens_pt))):
132 self.failUnlessAlmostEqual(arclen_pt, arclen2_pt, 4)
134 arclens = [x*unit.t_pt for x in [20, 30, -2, 61, 100, 200, -30, 1000]]
135 for arclen, arclen2 in zip(arclens, p.paramtoarclen(p.arclentoparam(arclens))):
136 self.failUnlessAlmostEqual(unit.tom(arclen), unit.tom(arclen2), 4)
138 def testsplit(self):
139 p = normline_pt(0, 0, 10, 0)
140 self.failUnlessRaises(ValueError, p.segments, [])
141 self.failUnlessRaises(ValueError, p.segments, [0.2])
142 s = p.segments([0.2, 0.8])
143 self.failUnlessEqual(len(s), 1)
144 self.failUnlessAlmostEqualNormsubpathitem(s[0], normline_pt(2, 0, 8, 0))
145 s = p.segments([-0.2, 1.8])
146 self.failUnlessEqual(len(s), 1)
147 self.failUnlessAlmostEqualNormsubpathitem(s[0], normline_pt(-2, 0, 18, 0))
149 p = normcurve_pt(0, 0, 10, 0, 20, 0, 30, 0)
150 self.failUnlessRaises(ValueError, p.segments, [])
151 self.failUnlessRaises(ValueError, p.segments, [0.2])
152 s = p.segments([0.2, 0.8])
153 self.failUnlessEqual(len(s), 1)
154 self.failUnlessAlmostEqualNormsubpathitem(s[0], normcurve_pt(6, 0, 12, 0, 18, 0, 24, 0))
155 s = p.segments([-0.2, 1.8])
156 self.failUnlessEqual(len(s), 1)
157 self.failUnlessAlmostEqualNormsubpathitem(s[0], normcurve_pt(-6, 0, 14, 0, 34, 0, 54, 0))
159 p = normsubpath([normline_pt(0, 0, 1, 0),
160 normline_pt(1, 0, 1, 1),
161 normline_pt(1, 1, 0, 1),
162 normline_pt(0, 1, 0, 0)])
163 self.failUnlessRaises(ValueError, p.segments, [])
164 self.failUnlessRaises(ValueError, p.segments, [0.2])
165 s = p.segments([0.5, 2.5])
166 self.failUnlessEqual(len(s), 1)
167 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0.5, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0.5, 1)]))
168 s = p.segments([4.5, -1])
169 self.failUnlessEqual(len(s), 1)
170 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0, -0.5, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, -1, 0)]))
171 s = p.segments([0, 0.1, 1.2, 1.3, 3.4, 0.5, 4])
172 self.failUnlessEqual(len(s), 6)
173 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0, 0, 0.1, 0)]))
174 self.failUnlessAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
175 self.failUnlessAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
176 self.failUnlessAlmostEqualNormsubpath(s[3], normsubpath([normline_pt(1, 0.3, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.6)]))
177 self.failUnlessAlmostEqualNormsubpath(s[4], normsubpath([normline_pt(0, 0.6, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, 0.5, 0)]))
178 self.failUnlessAlmostEqualNormsubpath(s[5], normsubpath([normline_pt(0.5, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0)]))
180 p = normsubpath([normline_pt(0, 0, 1, 0),
181 normline_pt(1, 0, 1, 1),
182 normline_pt(1, 1, 0, 1)], closed=1)
183 self.failUnlessRaises(ValueError, p.segments, [])
184 self.failUnlessRaises(ValueError, p.segments, [0.5])
185 s = p.segments([0.5, 2.5])
186 self.failUnlessEqual(len(s), 1)
187 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0.5, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0.5, 1)]))
188 s = p.segments([4.5, -1])
189 self.failUnlessEqual(len(s), 1)
190 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0, -0.5, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, -1, 0)]))
191 s = p.segments([0, 0.1, 1.2, 1.3, 3.4, 0.5, 4])
192 self.failUnlessEqual(len(s), 5)
193 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0.5, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0), normline_pt(0, 0, 0.1, 0)]))
194 self.failUnlessAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
195 self.failUnlessAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
196 self.failUnlessAlmostEqualNormsubpath(s[3], normsubpath([normline_pt(1, 0.3, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.6)]))
197 self.failUnlessAlmostEqualNormsubpath(s[4], normsubpath([normline_pt(0, 0.6, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, 0.5, 0)]))
198 s = p.segments([4, 0.1, 1.2, 1.3, 3.4, 0.5, 0])
199 self.failUnlessEqual(len(s), 5)
200 self.failUnlessAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0.5, 0, 0, 0), normline_pt(0, 0, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, 0.1, 0)]))
201 self.failUnlessAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
202 self.failUnlessAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
203 self.failUnlessAlmostEqualNormsubpath(s[3], normsubpath([normline_pt(1, 0.3, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.6)]))
204 self.failUnlessAlmostEqualNormsubpath(s[4], normsubpath([normline_pt(0, 0.6, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, 0.5, 0)]))
206 p = normpath([normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 2, 0), normline_pt(2, 0, 3, 0), normline_pt(3, 0, 4, 0)]),
207 normsubpath([normline_pt(0, 1, 1, 1), normline_pt(1, 1, 2, 1), normline_pt(2, 1, 3, 1), normline_pt(3, 1, 4, 1)]),
208 normsubpath([normline_pt(0, 2, 1, 2), normline_pt(1, 2, 2, 2), normline_pt(2, 2, 3, 2), normline_pt(3, 2, 4, 2)]),
209 normsubpath([normline_pt(0, 3, 1, 3), normline_pt(1, 3, 2, 3), normline_pt(2, 3, 3, 3), normline_pt(3, 3, 4, 3)]),
210 normsubpath([normline_pt(0, 4, 1, 4), normline_pt(1, 4, 2, 4), normline_pt(2, 4, 3, 4), normline_pt(3, 4, 4, 4)])])
211 s = p.split([normpathparam(p, 3, 0.1),
212 normpathparam(p, 4, 1.2),
213 normpathparam(p, 2, 2.3),
214 normpathparam(p, 0, 3.4),
215 normpathparam(p, 1, 0.5)])
216 self.failUnlessEqual(len(s), 6)
217 self.failUnlessAlmostEqualNormpath(s[0], normpath([normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 2, 0), normline_pt(2, 0, 3, 0), normline_pt(3, 0, 4, 0)]),
218 normsubpath([normline_pt(0, 1, 1, 1), normline_pt(1, 1, 2, 1), normline_pt(2, 1, 3, 1), normline_pt(3, 1, 4, 1)]),
219 normsubpath([normline_pt(0, 2, 1, 2), normline_pt(1, 2, 2, 2), normline_pt(2, 2, 3, 2), normline_pt(3, 2, 4, 2)]),
220 normsubpath([normline_pt(0, 3, 0.1, 3)])]))
221 self.failUnlessAlmostEqualNormpath(s[1], normpath([normsubpath([normline_pt(0.1, 3, 1, 3), normline_pt(1, 3, 2, 3), normline_pt(2, 3, 3, 3), normline_pt(3, 3, 4, 3)]),
222 normsubpath([normline_pt(0, 4, 1, 4), normline_pt(1, 4, 1.2, 4)])]))
223 self.failUnlessAlmostEqualNormpath(s[2], normpath([normsubpath([normline_pt(1.2, 4, 1, 4), normline_pt(1, 4, 0, 4)]),
224 normsubpath([normline_pt(4, 3, 3, 3), normline_pt(3, 3, 2, 3), normline_pt(2, 3, 1, 3), normline_pt(1, 3, 0, 3)]),
225 normsubpath([normline_pt(4, 2, 3, 2), normline_pt(3, 2, 2.3, 2)])]))
226 self.failUnlessAlmostEqualNormpath(s[3], normpath([normsubpath([normline_pt(2.3, 2, 2, 2), normline_pt(2, 2, 1, 2), normline_pt(1, 2, 0, 2)]),
227 normsubpath([normline_pt(4, 1, 3, 1), normline_pt(3, 1, 2, 1), normline_pt(2, 1, 1, 1), normline_pt(1, 1, 0, 1)]),
228 normsubpath([normline_pt(4, 0, 3.4, 0)])]))
229 self.failUnlessAlmostEqualNormpath(s[4], normpath([normsubpath([normline_pt(3.4, 0, 4, 0)]),
230 normsubpath([normline_pt(0, 1, 0.5, 1)])]))
231 self.failUnlessAlmostEqualNormpath(s[5], normpath([normsubpath([normline_pt(0.5, 1, 1, 1), normline_pt(1, 1, 2, 1), normline_pt(2, 1, 3, 1), normline_pt(3, 1, 4, 1)]),
232 normsubpath([normline_pt(0, 2, 1, 2), normline_pt(1, 2, 2, 2), normline_pt(2, 2, 3, 2), normline_pt(3, 2, 4, 2)]),
233 normsubpath([normline_pt(0, 3, 1, 3), normline_pt(1, 3, 2, 3), normline_pt(2, 3, 3, 3), normline_pt(3, 3, 4, 3)]),
234 normsubpath([normline_pt(0, 4, 1, 4), normline_pt(1, 4, 2, 4), normline_pt(2, 4, 3, 4), normline_pt(3, 4, 4, 4)])]))
236 p = normpath([normsubpath([normline_pt(0, -5, 1, -5)]),
237 normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1)], closed=1),
238 normsubpath([normline_pt(0, 5, 1, 5)])])
239 s = p.split([normpathparam(p, 1, 3.5)])
240 self.failUnlessEqual(len(s), 1)
241 self.failUnlessAlmostEqualNormpath(s[0], normpath([normsubpath([normline_pt(0, -5, 1, -5)]),
242 normsubpath([normline_pt(0, 0.5, 0, 0), normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.5)]),
243 normsubpath([normline_pt(0, 5, 1, 5)])]))
245 p = normpath([normsubpath([normline_pt(0, -5, 1, -5)]),
246 normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1)], closed=1),
247 normsubpath([normline_pt(0, 5, 1, 5)])])
248 s = p.split([normpathparam(p, 0, 0.5),
249 normpathparam(p, 1, 3.5),
250 normpathparam(p, 0, 0.5),
251 normpathparam(p, 2, 0.5)])
252 self.failUnlessEqual(len(s), 5)
253 self.failUnlessAlmostEqualNormpath(s[0], normpath([normsubpath([normline_pt(0, -5, 0.5, -5)])]))
254 self.failUnlessAlmostEqualNormpath(s[1], normpath([normsubpath([normline_pt(0.5, -5, 1, -5)]),
255 normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.5)])]))
256 # XXX should we do ???: normsubpath([normline_pt(0, 0.5, 0, 0), normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0.5)])]))
257 # same question in the next line ...
258 self.failUnlessAlmostEqualNormpath(s[2], normpath([normsubpath([normline_pt(0, 0.5, 0, 1), normline_pt(0, 1, 1, 1), normline_pt(1, 1, 1, 0), normline_pt(1, 0, 0, 0)]),
259 normsubpath([normline_pt(1, -5, 0.5, -5)])]))
260 self.failUnlessAlmostEqualNormpath(s[3], normpath([normsubpath([normline_pt(0.5, -5, 1, -5)]),
261 normsubpath([normline_pt(0, 0, 1, 0), normline_pt(1, 0, 1, 1), normline_pt(1, 1, 0, 1), normline_pt(0, 1, 0, 0)], closed=1),
262 normsubpath([normline_pt(0, 5, 0.5, 5)])]))
263 self.failUnlessAlmostEqualNormpath(s[4], normpath([normsubpath([normline_pt(0.5, 5, 1, 5)])]))
265 def testshortnormsubpath(self):
266 sp = normsubpath(epsilon=1)
267 sp.append(normline_pt(0, 0, 0.5, 0))
268 sp.append(normline_pt(0.5, 0, 1.5, 0))
270 sp.append(normline_pt(1.5, 0, 1.5, 0.3))
271 sp.append(normline_pt(1.5, 0.3, 1.5, 0.6))
272 sp.append(normline_pt(1.5, 0.6, 1.5, 0.9))
273 sp.append(normline_pt(1.5, 0.9, 1.5, 1.2))
275 sp.append(normline_pt(1.5, 1.2, 1.3, 1.6))
276 sp.append(normcurve_pt(1.3, 1.6, 1.4, 1.7, 1.3, 1.7, 1.3, 1.8))
277 sp.append(normcurve_pt(1.3, 1.8, 2.4, 2.7, 3.3, 3.7, 1.4, 1.8))
279 self.failUnlessAlmostEqualNormsubpath(sp, normsubpath([normline_pt(0, 0, 1.5, 0), normline_pt(1.5, 0, 1.5, 1.2), normcurve_pt(1.5, 1.2, 2.4, 2.7, 3.3, 3.7, 1.4, 1.8)]))
281 def testintersectnormsubpath(self):
282 smallposy = 0.09
283 smallnegy = -0.01
284 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
285 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
286 normline_pt(0, smallnegy, 0, 1+smallnegy),
287 normline_pt(0, 1+smallnegy, 0, smallnegy),
288 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
289 p1.epsilon = p2.epsilon = 0.05
290 intersect = p2.intersect(p1)
291 self.failUnlessEqual(len(intersect[0]), 2)
292 self.failUnlessAlmostEqual(intersect[0][0], 0.9)
293 self.failUnlessAlmostEqual(intersect[0][1], 2.99)
295 smallposy = 0.09
296 smallnegy = -0.01
297 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
298 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
299 normline_pt(0, smallnegy, 0, 1+smallnegy),
300 normline_pt(0, 1+smallnegy, 0, smallnegy),
301 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
302 p1.epsilon = p2.epsilon = 0.05
303 intersect = p2.intersect(p1)
304 self.failUnlessEqual(len(intersect[0]), 2)
305 self.failUnlessAlmostEqual(intersect[0][0], 0.9)
306 self.failUnlessAlmostEqual(intersect[0][1], 2.99)
308 smallposy = 0.01
309 smallnegy = -0.09
310 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
311 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
312 normline_pt(0, smallnegy, 0, 1+smallnegy),
313 normline_pt(0, 1+smallnegy, 0, smallnegy),
314 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
315 p1.epsilon = p2.epsilon = 0.05
316 intersect = p2.intersect(p1)
317 self.failUnlessEqual(len(intersect[0]), 4)
318 self.failUnlessAlmostEqual(intersect[0][0], 0.1)
319 self.failUnlessAlmostEqual(intersect[0][1], 1.09)
320 self.failUnlessAlmostEqual(intersect[0][2], 2.91)
321 self.failUnlessAlmostEqual(intersect[0][3], 3.9)
323 smallposy = 0.01
324 smallnegy = -0.09
325 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
326 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
327 normline_pt(0, smallnegy, 0, 1+smallnegy),
328 normline_pt(0, 1+smallnegy, 0, smallnegy),
329 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
330 p1.epsilon = p2.epsilon = 0.05
331 intersect = p2.intersect(p1)
332 self.failUnlessEqual(len(intersect[0]), 3)
333 self.failUnlessAlmostEqual(intersect[0][0], 0.1)
334 self.failUnlessAlmostEqual(intersect[0][1], 1.09)
335 self.failUnlessAlmostEqual(intersect[0][2], 2.91)
337 smallposy = 0.01
338 smallnegy = -0.01
339 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
340 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
341 normline_pt(0, smallnegy, 0, 1+smallnegy),
342 normline_pt(0, 1+smallnegy, 0, smallnegy),
343 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
344 p1.epsilon = p2.epsilon = 0.05
345 intersect = p2.intersect(p1)
346 self.failUnlessEqual(len(intersect[0]), 2)
347 self.failUnlessAlmostEqual(intersect[0][0], 0.5)
348 self.failUnlessAlmostEqual(intersect[0][1], 2.99)
350 smallposy = 0.01
351 smallnegy = -0.01
352 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
353 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
354 normline_pt(0, smallnegy, 0, 1+smallnegy),
355 normline_pt(0, 1+smallnegy, 0, smallnegy),
356 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
357 p1.epsilon = p2.epsilon = 0.05
358 intersect = p2.intersect(p1)
359 self.failUnlessEqual(len(intersect[0]), 1)
360 self.failUnlessAlmostEqual(intersect[0][0], 0.5)
362 smallposy = 0.1
363 smallnegy = -0.1
364 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
365 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
366 normline_pt(0, smallnegy, 0, 1+smallnegy),
367 normline_pt(0, 1+smallnegy, 0, smallnegy),
368 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
369 p1.epsilon = p2.epsilon = 0.05
370 intersect = p2.intersect(p1)
371 self.failUnlessEqual(len(intersect[0]), 4)
372 self.failUnlessAlmostEqual(intersect[0][0], 0.5)
373 self.failUnlessAlmostEqual(intersect[0][1], 1.1)
374 self.failUnlessAlmostEqual(intersect[0][2], 2.9)
375 self.failUnlessAlmostEqual(intersect[0][3], 3.5)
378 if __name__ == "__main__":
379 unittest.main()