From 5233b32ebc0fe32bfb35ee57dfe6d753ff80acbc Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 20 Apr 2023 13:05:08 +0200 Subject: [PATCH] Add test for Path.contains_path --- lib/matplotlib/tests/test_path.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 34a450847c01..0a1d6c6b5e52 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -60,6 +60,25 @@ def test_point_in_path(): np.testing.assert_equal(ret, [True, False]) +@pytest.mark.parametrize( + "other_path, inside, inverted_inside", + [(Path([(0.25, 0.25), (0.25, 0.75), (0.75, 0.75), (0.75, 0.25), (0.25, 0.25)], + closed=True), True, False), + (Path([(-0.25, -0.25), (-0.25, 1.75), (1.75, 1.75), (1.75, -0.25), (-0.25, -0.25)], + closed=True), False, True), + (Path([(-0.25, -0.25), (-0.25, 1.75), (0.5, 0.5), + (1.75, 1.75), (1.75, -0.25), (-0.25, -0.25)], + closed=True), False, False), + (Path([(0.25, 0.25), (0.25, 1.25), (1.25, 1.25), (1.25, 0.25), (0.25, 0.25)], + closed=True), False, False), + (Path([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)], closed=True), False, False), + (Path([(2, 2), (2, 3), (3, 3), (3, 2), (2, 2)], closed=True), False, False)]) +def test_contains_path(other_path, inside, inverted_inside): + path = Path([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)], closed=True) + assert path.contains_path(other_path) is inside + assert other_path.contains_path(path) is inverted_inside + + def test_contains_points_negative_radius(): path = Path.unit_circle()