-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Handle MOVETO's, CLOSEPOLY's and empty paths in Path.interpolated #29919
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,3 +541,84 @@ def test_cleanup_closepoly(): | |
cleaned = p.cleaned(remove_nans=True) | ||
assert len(cleaned) == 1 | ||
assert cleaned.codes[0] == Path.STOP | ||
|
||
|
||
def test_interpolated_moveto(): | ||
# Initial path has two subpaths with two LINETOs each | ||
vertices = np.array([[0, 0], | ||
[0, 1], | ||
[1, 2], | ||
[4, 4], | ||
[4, 5], | ||
[5, 5]]) | ||
codes = [Path.MOVETO, Path.LINETO, Path.LINETO] * 2 | ||
|
||
path = Path(vertices, codes) | ||
result = path.interpolated(3) | ||
|
||
# Result should have two subpaths with six LINETOs each | ||
expected_subpath_codes = [Path.MOVETO] + [Path.LINETO] * 6 | ||
np.testing.assert_array_equal(result.codes, expected_subpath_codes * 2) | ||
|
||
|
||
def test_interpolated_closepoly(): | ||
codes = [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test a compound path with multiple closepolys by doubling this again similar to your above test to make sure the implementation handles multiple MOVETOs and CLOSEPOLYS together? |
||
vertices = [(4, 3), (5, 4), (5, 3), (0, 0)] | ||
|
||
path = Path(vertices, codes) | ||
result = path.interpolated(2) | ||
|
||
expected_vertices = np.array([[4, 3], | ||
[4.5, 3.5], | ||
[5, 4], | ||
[5, 3.5], | ||
[5, 3], | ||
[4.5, 3], | ||
[4, 3]]) | ||
expected_codes = [Path.MOVETO] + [Path.LINETO]*5 + [Path.CLOSEPOLY] | ||
|
||
np.testing.assert_allclose(result.vertices, expected_vertices) | ||
np.testing.assert_array_equal(result.codes, expected_codes) | ||
|
||
# Usually closepoly is the last vertex but does not have to be. | ||
codes += [Path.LINETO] | ||
vertices += [(2, 1)] | ||
|
||
path = Path(vertices, codes) | ||
result = path.interpolated(2) | ||
|
||
extra_expected_vertices = np.array([[3, 2], | ||
[2, 1]]) | ||
expected_vertices = np.concatenate([expected_vertices, extra_expected_vertices]) | ||
|
||
expected_codes += [Path.LINETO] * 2 | ||
|
||
np.testing.assert_allclose(result.vertices, expected_vertices) | ||
np.testing.assert_array_equal(result.codes, expected_codes) | ||
|
||
|
||
def test_interpolated_moveto_closepoly(): | ||
# Initial path has two closed subpaths | ||
codes = ([Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]) * 2 | ||
vertices = [(4, 3), (5, 4), (5, 3), (0, 0), (8, 6), (10, 8), (10, 6), (0, 0)] | ||
|
||
path = Path(vertices, codes) | ||
result = path.interpolated(2) | ||
|
||
expected_vertices1 = np.array([[4, 3], | ||
[4.5, 3.5], | ||
[5, 4], | ||
[5, 3.5], | ||
[5, 3], | ||
[4.5, 3], | ||
[4, 3]]) | ||
expected_vertices = np.concatenate([expected_vertices1, expected_vertices1 * 2]) | ||
expected_codes = ([Path.MOVETO] + [Path.LINETO]*5 + [Path.CLOSEPOLY]) * 2 | ||
|
||
np.testing.assert_allclose(result.vertices, expected_vertices) | ||
np.testing.assert_array_equal(result.codes, expected_codes) | ||
|
||
|
||
def test_interpolated_empty_path(): | ||
path = Path(np.zeros((0, 2))) | ||
assert path.interpolated(42) is path |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this patch is not sufficient if you have a path with mixtures of CLOSEPOLY AND MOVETO. The MOVETO creates a new separate separate component with a starting point that is generally different from
vertices[0]
.Maybe a variation of
_iter_connected_components
is the way to go?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we got to here, we have no internal
MOVETO
's because we already split on them and called the function again on the subpath. I think this case is covered by the newtest_interpolated_moveto_closepoly
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.