add UnicodeEngine (MultiEngineText and axis texters returning MultiEngineText), texte...
[PyX.git] / test / unit / test_path.py
bloba6d1aa60faa45c6255e38ca1d0bf436124e0f5b5
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 assertAlmostEqualNormsubpathitem(self, nspi1, nspi2):
16 if isinstance(nspi1, normline_pt):
17 assert isinstance(nspi2, normline_pt), "%s != %s" % (nspi1, nspi2)
18 self.assertAlmostEqual(nspi1.x0_pt, nspi2.x0_pt)
19 self.assertAlmostEqual(nspi1.y0_pt, nspi2.y0_pt)
20 self.assertAlmostEqual(nspi1.x1_pt, nspi2.x1_pt)
21 self.assertAlmostEqual(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.assertAlmostEqual(nspi1.x0_pt, nspi2.x0_pt)
26 self.assertAlmostEqual(nspi1.y0_pt, nspi2.y0_pt)
27 self.assertAlmostEqual(nspi1.x1_pt, nspi2.x1_pt)
28 self.assertAlmostEqual(nspi1.y1_pt, nspi2.y1_pt)
29 self.assertAlmostEqual(nspi1.x2_pt, nspi2.x2_pt)
30 self.assertAlmostEqual(nspi1.y2_pt, nspi2.y2_pt)
31 self.assertAlmostEqual(nspi1.x3_pt, nspi2.x3_pt)
32 self.assertAlmostEqual(nspi1.y3_pt, nspi2.y3_pt)
34 def assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpathitem(nspi1, nspi2)
40 def assertAlmostEqualNormpath(self, np1, np2):
41 assert len(np1) == len(np2), "%s != %s" % (np1, np2)
42 for nsp1, nsp2 in zip(np1, np2):
43 self.assertAlmostEqualNormsubpath(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.assertEqual(param.normsubpathindex, 0)
56 self.assertAlmostEqual(param.normsubpathparam, 1.5)
57 param = param + 15 * unit.t_pt
58 self.assertEqual(param.normsubpathindex, 0)
59 self.assertAlmostEqual(param.normsubpathparam, 2.5)
60 param += 24.9 * unit.t_pt
61 self.assertEqual(param.normsubpathindex, 0)
62 self.assertAlmostEqual(param.normsubpathparam, 3.995)
63 param = 0.1 * unit.t_pt + param
64 self.assertEqual(param.normsubpathindex, 1)
65 self.assertAlmostEqual(param.normsubpathparam, 0)
66 param = param + 0.5*circle_pt(0, 0, 10).arclen()
67 circlerange = len(p.normsubpaths[1])
68 self.assertEqual(param.normsubpathindex, 1)
69 self.assertAlmostEqual(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.assertEqual(param.normsubpathindex, 2)
73 self.assertAlmostEqual(param.normsubpathparam, 1, 4)
74 param = param + 1 * unit.t_pt
75 self.assertEqual(param.normsubpathindex, 2)
76 self.assertAlmostEqual(param.normsubpathparam, 1.5, 4)
78 param = normpathparam(p, 0, 1.5)
79 param = param - 15 * unit.t_pt
80 self.assertEqual(param.normsubpathindex, 0)
81 self.assertAlmostEqual(param.normsubpathparam, 0.5)
82 param -= 10 * unit.t_pt
83 self.assertEqual(param.normsubpathindex, 0)
84 self.assertAlmostEqual(param.normsubpathparam, -0.5)
86 param = normpathparam(p, 0, 1.2)
87 param2 = 2*param
88 param += param
89 self.assertEqual(param.normsubpathindex, param2.normsubpathindex)
90 self.assertEqual(param.normsubpathparam, param2.normsubpathparam)
92 param = normpathparam(p, 0, 1.2)
93 self.assertTrue(param < 15 * unit.t_pt)
94 self.assertTrue(15 * unit.t_pt > param)
95 self.assertTrue(param > 12 * unit.t_pt)
96 self.assertTrue(12 * unit.t_pt < param)
97 self.assertTrue(param < 1)
98 self.assertTrue(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.assertAlmostEqual(p.at_pt(param)[0], at_x)
109 self.assertAlmostEqual(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.assertAlmostEqual(at_x, at2_x)
112 self.assertAlmostEqual(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.assertAlmostEqual(p.at_pt(6)[0], 3)
118 self.assertAlmostEqual(p.at_pt(6)[1], 3)
119 self.assertAlmostEqual(p.at_pt(4.5)[0], 3)
120 self.assertAlmostEqual(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.assertAlmostEqual(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.assertAlmostEqual(unit.tom(arclen), unit.tom(arclen2), 4)
138 def testsplit(self):
139 p = normline_pt(0, 0, 10, 0)
140 self.assertRaises(ValueError, p.segments, [])
141 self.assertRaises(ValueError, p.segments, [0.2])
142 s = p.segments([0.2, 0.8])
143 self.assertEqual(len(s), 1)
144 self.assertAlmostEqualNormsubpathitem(s[0], normline_pt(2, 0, 8, 0))
145 s = p.segments([-0.2, 1.8])
146 self.assertEqual(len(s), 1)
147 self.assertAlmostEqualNormsubpathitem(s[0], normline_pt(-2, 0, 18, 0))
149 p = normcurve_pt(0, 0, 10, 0, 20, 0, 30, 0)
150 self.assertRaises(ValueError, p.segments, [])
151 self.assertRaises(ValueError, p.segments, [0.2])
152 s = p.segments([0.2, 0.8])
153 self.assertEqual(len(s), 1)
154 self.assertAlmostEqualNormsubpathitem(s[0], normcurve_pt(6, 0, 12, 0, 18, 0, 24, 0))
155 s = p.segments([-0.2, 1.8])
156 self.assertEqual(len(s), 1)
157 self.assertAlmostEqualNormsubpathitem(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.assertRaises(ValueError, p.segments, [])
164 self.assertRaises(ValueError, p.segments, [0.2])
165 s = p.segments([0.5, 2.5])
166 self.assertEqual(len(s), 1)
167 self.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 1)
170 self.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 6)
173 self.assertAlmostEqualNormsubpath(s[0], normsubpath([normline_pt(0, 0, 0.1, 0)]))
174 self.assertAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
175 self.assertAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
176 self.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(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.assertRaises(ValueError, p.segments, [])
184 self.assertRaises(ValueError, p.segments, [0.5])
185 s = p.segments([0.5, 2.5])
186 self.assertEqual(len(s), 1)
187 self.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 1)
190 self.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 5)
193 self.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
195 self.assertAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
196 self.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 5)
200 self.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(s[1], normsubpath([normline_pt(0.1, 0, 1, 0), normline_pt(1, 0, 1, 0.2)]))
202 self.assertAlmostEqualNormsubpath(s[2], normsubpath([normline_pt(1, 0.2, 1, 0.3)]))
203 self.assertAlmostEqualNormsubpath(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.assertAlmostEqualNormsubpath(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.assertEqual(len(s), 6)
217 self.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(s[4], normpath([normsubpath([normline_pt(3.4, 0, 4, 0)]),
230 normsubpath([normline_pt(0, 1, 0.5, 1)])]))
231 self.assertAlmostEqualNormpath(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.assertEqual(len(s), 1)
241 self.assertAlmostEqualNormpath(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.assertEqual(len(s), 5)
253 self.assertAlmostEqualNormpath(s[0], normpath([normsubpath([normline_pt(0, -5, 0.5, -5)])]))
254 self.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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.assertAlmostEqualNormpath(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, 4.4, 2.7, 5.3, 5.7, 1.4, 1.8))
279 self.assertAlmostEqualNormsubpath(sp, normsubpath([normline_pt(0, 0, 1.5, 0), normline_pt(1.5, 0, 1.5, 1.2), normcurve_pt(1.5, 1.2, 4.4, 2.7, 5.3, 5.7, 1.4, 1.8)]))
281 def testcuspremoval(self):
282 self.assertAlmostEqualNormsubpath(normsubpath([normcurve_pt(0, 0, 5, 5, 0, 5, 5, 0)], epsilon=1),
283 normsubpath([normcurve_pt(0, 0, 2.5, 2.5, 2.5, 3.405172413793103, 2.5, 3.75), normcurve_pt(2.5, 3.75, 2.5, 3.405172413793103, 2.5, 2.5, 5, 0)], epsilon=None))
285 def testintersectnormsubpath(self):
286 smallposy = 0.09
287 smallnegy = -0.01
288 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
289 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
290 normline_pt(0, smallnegy, 0, 1+smallnegy),
291 normline_pt(0, 1+smallnegy, 0, smallnegy),
292 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
293 p1.epsilon = p2.epsilon = 0.05
294 intersect = p2.intersect(p1)
295 self.assertEqual(len(intersect[0]), 2)
296 self.assertAlmostEqual(intersect[0][0], 0.9)
297 self.assertAlmostEqual(intersect[0][1], 2.99)
299 smallposy = 0.09
300 smallnegy = -0.01
301 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
302 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
303 normline_pt(0, smallnegy, 0, 1+smallnegy),
304 normline_pt(0, 1+smallnegy, 0, smallnegy),
305 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
306 p1.epsilon = p2.epsilon = 0.05
307 intersect = p2.intersect(p1)
308 self.assertEqual(len(intersect[0]), 2)
309 self.assertAlmostEqual(intersect[0][0], 0.9)
310 self.assertAlmostEqual(intersect[0][1], 2.99)
312 smallposy = 0.01
313 smallnegy = -0.09
314 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
315 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
316 normline_pt(0, smallnegy, 0, 1+smallnegy),
317 normline_pt(0, 1+smallnegy, 0, smallnegy),
318 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
319 p1.epsilon = p2.epsilon = 0.05
320 intersect = p2.intersect(p1)
321 self.assertEqual(len(intersect[0]), 4)
322 self.assertAlmostEqual(intersect[0][0], 0.1)
323 self.assertAlmostEqual(intersect[0][1], 1.09)
324 self.assertAlmostEqual(intersect[0][2], 2.91)
325 self.assertAlmostEqual(intersect[0][3], 3.9)
327 smallposy = 0.01
328 smallnegy = -0.09
329 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
330 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
331 normline_pt(0, smallnegy, 0, 1+smallnegy),
332 normline_pt(0, 1+smallnegy, 0, smallnegy),
333 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
334 p1.epsilon = p2.epsilon = 0.05
335 intersect = p2.intersect(p1)
336 self.assertEqual(len(intersect[0]), 3)
337 self.assertAlmostEqual(intersect[0][0], 0.1)
338 self.assertAlmostEqual(intersect[0][1], 1.09)
339 self.assertAlmostEqual(intersect[0][2], 2.91)
341 smallposy = 0.01
342 smallnegy = -0.01
343 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
344 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
345 normline_pt(0, smallnegy, 0, 1+smallnegy),
346 normline_pt(0, 1+smallnegy, 0, smallnegy),
347 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
348 p1.epsilon = p2.epsilon = 0.05
349 intersect = p2.intersect(p1)
350 self.assertEqual(len(intersect[0]), 2)
351 self.assertAlmostEqual(intersect[0][0], 0.5)
352 self.assertAlmostEqual(intersect[0][1], 2.99)
354 smallposy = 0.01
355 smallnegy = -0.01
356 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
357 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
358 normline_pt(0, smallnegy, 0, 1+smallnegy),
359 normline_pt(0, 1+smallnegy, 0, smallnegy),
360 normline_pt(0, smallnegy, 0, smallposy)], closed=1)
361 p1.epsilon = p2.epsilon = 0.05
362 intersect = p2.intersect(p1)
363 self.assertEqual(len(intersect[0]), 1)
364 self.assertAlmostEqual(intersect[0][0], 0.5)
366 smallposy = 0.1
367 smallnegy = -0.1
368 p1 = normsubpath([normline_pt(-1, 0, 1, 0)])
369 p2 = normsubpath([normline_pt(0, smallposy, 0, smallnegy),
370 normline_pt(0, smallnegy, 0, 1+smallnegy),
371 normline_pt(0, 1+smallnegy, 0, smallnegy),
372 normline_pt(0, smallnegy, 0, smallposy)], closed=0)
373 p1.epsilon = p2.epsilon = 0.05
374 intersect = p2.intersect(p1)
375 self.assertEqual(len(intersect[0]), 4)
376 self.assertAlmostEqual(intersect[0][0], 0.5)
377 self.assertAlmostEqual(intersect[0][1], 1.1)
378 self.assertAlmostEqual(intersect[0][2], 2.9)
379 self.assertAlmostEqual(intersect[0][3], 3.5)
382 if __name__ == "__main__":
383 unittest.main()