@@ -273,81 +273,78 @@ def test_path_deepcopy():
273273 copy .deepcopy (path2 )
274274
275275
276- def test_path_intersect_path ():
276+ @pytest .mark .parametrize ('phi' , np .concatenate ([
277+ np .array ([0 , 15 , 30 , 45 , 60 , 75 , 90 , 105 , 120 , 135 ]) + delta
278+ for delta in [- 1 , 0 , 1 ]]))
279+ def test_path_intersect_path (phi ):
277280 # test for the range of intersection angles
278- base_angles = np .array ([0 , 15 , 30 , 45 , 60 , 75 , 90 , 105 , 120 , 135 ])
279- angles = np .concatenate ([base_angles , base_angles + 1 , base_angles - 1 ])
280281 eps_array = [1e-5 , 1e-8 , 1e-10 , 1e-12 ]
281282
282- for phi in angles :
283+ transform = transforms . Affine2D (). rotate ( np . deg2rad ( phi ))
283284
284- transform = transforms .Affine2D ().rotate (np .deg2rad (phi ))
285+ # a and b intersect at angle phi
286+ a = Path ([(- 2 , 0 ), (2 , 0 )])
287+ b = transform .transform_path (a )
288+ assert a .intersects_path (b ) and b .intersects_path (a )
285289
286- # a and b intersect at angle phi
287- a = Path ([(- 2 , 0 ), (2 , 0 )])
288- b = transform .transform_path (a )
289- assert a .intersects_path (b ) and b .intersects_path (a )
290+ # a and b touch at angle phi at (0, 0)
291+ a = Path ([(0 , 0 ), (2 , 0 )])
292+ b = transform .transform_path (a )
293+ assert a .intersects_path (b ) and b .intersects_path (a )
290294
291- # a and b touch at angle phi at (0, 0 )
292- a = Path ([(0 , 0 ), (2 , 0 )] )
293- b = transform .transform_path (a )
294- assert a .intersects_path (b ) and b .intersects_path (a )
295+ # a and b are orthogonal and intersect at (0, 3 )
296+ a = transform . transform_path ( Path ([(0 , 1 ), (0 , 3 )]) )
297+ b = transform .transform_path (Path ([( 1 , 3 ), ( 0 , 3 )]) )
298+ assert a .intersects_path (b ) and b .intersects_path (a )
295299
296- # a and b are orthogonal and intersect at (0, 3)
297- a = transform .transform_path (Path ([(0 , 1 ), (0 , 3 )]))
298- b = transform .transform_path (Path ([(1 , 3 ), (0 , 3 )]))
299- assert a .intersects_path (b ) and b .intersects_path (a )
300+ # a and b are collinear and intersect at (0, 3)
301+ a = transform .transform_path (Path ([(0 , 1 ), (0 , 3 )]))
302+ b = transform .transform_path (Path ([(0 , 5 ), (0 , 3 )]))
303+ assert a .intersects_path (b ) and b .intersects_path (a )
300304
301- # a and b are collinear and intersect at (0, 3)
302- a = transform .transform_path (Path ([(0 , 1 ), (0 , 3 )]))
303- b = transform .transform_path (Path ([(0 , 5 ), (0 , 3 )]))
304- assert a .intersects_path (b ) and b .intersects_path (a )
305+ # self-intersect
306+ assert a .intersects_path (a )
305307
306- # self-intersect
307- assert a .intersects_path (a )
308+ # a contains b
309+ a = transform .transform_path (Path ([(0 , 0 ), (5 , 5 )]))
310+ b = transform .transform_path (Path ([(1 , 1 ), (3 , 3 )]))
311+ assert a .intersects_path (b ) and b .intersects_path (a )
308312
309- # a contains b
310- a = transform .transform_path (Path ([(0 , 0 ), (5 , 5 )]))
311- b = transform .transform_path (Path ([(1 , 1 ), (3 , 3 )]))
312- assert a .intersects_path (b ) and b .intersects_path (a )
313+ # a and b are collinear but do not intersect
314+ a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
315+ b = transform .transform_path (Path ([(3 , 0 ), (3 , 3 )]))
316+ assert not a .intersects_path (b ) and not b .intersects_path (a )
317+
318+ # a and b are on the same line but do not intersect
319+ a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
320+ b = transform .transform_path (Path ([(0 , 6 ), (0 , 7 )]))
321+ assert not a .intersects_path (b ) and not b .intersects_path (a )
322+
323+ # Note: 1e-13 is the absolute tolerance error used for
324+ # `isclose` function from src/_path.h
313325
314- # a and b are collinear but do not intersect
326+ # a and b are parallel but do not touch
327+ for eps in eps_array :
315328 a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
316- b = transform .transform_path (Path ([(3 , 0 ), (3 , 3 )]))
329+ b = transform .transform_path (Path ([(0 + eps , 1 ), (0 + eps , 5 )]))
317330 assert not a .intersects_path (b ) and not b .intersects_path (a )
318331
319- # a and b are on the same line but do not intersect
332+ # a and b are on the same line but do not intersect (really close)
333+ for eps in eps_array :
320334 a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
321- b = transform .transform_path (Path ([(0 , 6 ), (0 , 7 )]))
335+ b = transform .transform_path (Path ([(0 , 5 + eps ), (0 , 7 )]))
322336 assert not a .intersects_path (b ) and not b .intersects_path (a )
323337
324- # Note: 1e-13 is the absolute tolerance error used for
325- # `isclose` function from src/_path.h
326-
327- # a and b are parallel but do not touch
328- for eps in eps_array :
329- a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
330- b = transform .transform_path (Path ([(0 + eps , 1 ), (0 + eps , 5 )]))
331- assert not a .intersects_path (b ) and not b .intersects_path (a )
332-
333- # a and b are on the same line but do not intersect (really close)
334- for eps in eps_array :
335- a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
336- b = transform .transform_path (Path ([(0 , 5 + eps ), (0 , 7 )]))
337- assert not a .intersects_path (b ) and not b .intersects_path (a )
338-
339- # a and b are on the same line and intersect (really close)
340- for eps in eps_array :
341- a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
342- b = transform .transform_path (Path ([(0 , 5 - eps ), (0 , 7 )]))
343- assert a .intersects_path (b ) and b .intersects_path (a )
344-
345- # b is the same as a but with an extra point
338+ # a and b are on the same line and intersect (really close)
339+ for eps in eps_array :
346340 a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
347- b = transform .transform_path (Path ([(0 , 1 ), ( 0 , 2 ), (0 , 5 )]))
341+ b = transform .transform_path (Path ([(0 , 5 - eps ), (0 , 7 )]))
348342 assert a .intersects_path (b ) and b .intersects_path (a )
349343
350- return
344+ # b is the same as a but with an extra point
345+ a = transform .transform_path (Path ([(0 , 1 ), (0 , 5 )]))
346+ b = transform .transform_path (Path ([(0 , 1 ), (0 , 2 ), (0 , 5 )]))
347+ assert a .intersects_path (b ) and b .intersects_path (a )
351348
352349
353350@pytest .mark .parametrize ('offset' , range (- 720 , 361 , 45 ))
@@ -360,3 +357,46 @@ def test_full_arc(offset):
360357 maxs = np .max (path .vertices , axis = 0 )
361358 np .testing .assert_allclose (mins , - 1 )
362359 assert np .allclose (maxs , 1 )
360+
361+
362+ def test_disjoint_zero_length_segment ():
363+ this_path = Path (
364+ np .array ([
365+ [824.85064295 , 2056.26489203 ],
366+ [861.69033931 , 2041.00539016 ],
367+ [868.57864109 , 2057.63522175 ],
368+ [831.73894473 , 2072.89472361 ],
369+ [824.85064295 , 2056.26489203 ]]),
370+ np .array ([1 , 2 , 2 , 2 , 79 ], dtype = Path .code_type ))
371+
372+ outline_path = Path (
373+ np .array ([
374+ [859.91051028 , 2165.38461538 ],
375+ [859.06772495 , 2149.30331334 ],
376+ [859.06772495 , 2181.46591743 ],
377+ [859.91051028 , 2165.38461538 ],
378+ [859.91051028 , 2165.38461538 ]]),
379+ np .array ([1 , 2 , 2 , 2 , 2 ],
380+ dtype = Path .code_type ))
381+
382+ assert not outline_path .intersects_path (this_path )
383+ assert not this_path .intersects_path (outline_path )
384+
385+
386+ def test_intersect_zero_length_segment ():
387+ this_path = Path (
388+ np .array ([
389+ [0 , 0 ],
390+ [1 , 1 ],
391+ ]))
392+
393+ outline_path = Path (
394+ np .array ([
395+ [1 , 0 ],
396+ [.5 , .5 ],
397+ [.5 , .5 ],
398+ [0 , 1 ],
399+ ]))
400+
401+ assert outline_path .intersects_path (this_path )
402+ assert this_path .intersects_path (outline_path )
0 commit comments