Skip to content

Add test for Path.contains_path #25730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down