MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_path_intersect_path

Function test_path_intersect_path

lib/matplotlib/tests/test_path.py:421–499  ·  view source on GitHub ↗
(phi)

Source from the content-addressed store, hash-verified

419 np.array([0, 15, 30, 45, 60, 75, 90, 105, 120, 135]) + delta
420 for delta in [-1, 0, 1]]))
421def test_path_intersect_path(phi):
422 # test for the range of intersection angles
423 eps_array = [1e-5, 1e-8, 1e-10, 1e-12]
424
425 transform = transforms.Affine2D().rotate(np.deg2rad(phi))
426
427 # a and b intersect at angle phi
428 a = Path([(-2, 0), (2, 0)])
429 b = transform.transform_path(a)
430 assert a.intersects_path(b) and b.intersects_path(a)
431
432 # a and b touch at angle phi at (0, 0)
433 a = Path([(0, 0), (2, 0)])
434 b = transform.transform_path(a)
435 assert a.intersects_path(b) and b.intersects_path(a)
436
437 # a and b are orthogonal and intersect at (0, 3)
438 a = transform.transform_path(Path([(0, 1), (0, 3)]))
439 b = transform.transform_path(Path([(1, 3), (0, 3)]))
440 assert a.intersects_path(b) and b.intersects_path(a)
441
442 # a and b are collinear and intersect at (0, 3)
443 a = transform.transform_path(Path([(0, 1), (0, 3)]))
444 b = transform.transform_path(Path([(0, 5), (0, 3)]))
445 assert a.intersects_path(b) and b.intersects_path(a)
446
447 # self-intersect
448 assert a.intersects_path(a)
449
450 # a contains b
451 a = transform.transform_path(Path([(0, 0), (5, 5)]))
452 b = transform.transform_path(Path([(1, 1), (3, 3)]))
453 assert a.intersects_path(b) and b.intersects_path(a)
454
455 # a and b are collinear but do not intersect
456 a = transform.transform_path(Path([(0, 1), (0, 5)]))
457 b = transform.transform_path(Path([(3, 0), (3, 3)]))
458 assert not a.intersects_path(b) and not b.intersects_path(a)
459
460 # a and b are on the same line but do not intersect
461 a = transform.transform_path(Path([(0, 1), (0, 5)]))
462 b = transform.transform_path(Path([(0, 6), (0, 7)]))
463 assert not a.intersects_path(b) and not b.intersects_path(a)
464
465 # Note: 1e-13 is the absolute tolerance error used for
466 # `isclose` function from src/_path.h
467
468 # a and b are parallel but do not touch
469 for eps in eps_array:
470 a = transform.transform_path(Path([(0, 1), (0, 5)]))
471 b = transform.transform_path(Path([(0 + eps, 1), (0 + eps, 5)]))
472 assert not a.intersects_path(b) and not b.intersects_path(a)
473
474 # a and b are on the same line but do not intersect (really close)
475 for eps in eps_array:
476 a = transform.transform_path(Path([(0, 1), (0, 5)]))
477 b = transform.transform_path(Path([(0, 5 + eps), (0, 7)]))
478 assert not a.intersects_path(b) and not b.intersects_path(a)

Callers

nothing calls this directly

Calls 4

intersects_pathMethod · 0.95
PathClass · 0.90
rotateMethod · 0.45
transform_pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…