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