-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix path simplification of closed loops #21387
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
Conversation
Ah, I forgot there was a reason for enabling the clipping. It (along with adding a clip box) fixes an overflow in PGF, #4482. That's a long standing bug that we could revert, but as we are still waiting for NumPy wheels, I'll try again to see if I can convince Agg to draw the way we want. |
Because that is really what it checks and is for.
All the other path converters do an early return if they're disabled, which can be done here as well to drop one extra indent level.
If we ever break a path due to a NaN, then it can never be closed, as Agg will try to close it back to the last MOVETO. This would not be the initial point of the loop, but the first point after the break. So we need to emulate a CLOSEPOLY by adding a LINETO the original initial point in the path.
Otherwise, a random spurious line connecting the last clipped point with the initial point is drawn unintentionally. Fixes matplotlib#21300
b43fb0d
to
8adf493
Compare
I've repurposed this to instead be fixing closed loops the right way. The original description has been updated with further details. |
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 checked that this fixes the original issue. Tests etc look good. Did not thoroughly review the c code.
…387-on-v3.5.x Backport PR #21387 on branch v3.5.x (Fix path simplification of closed loops)
PR Summary
When paths are closed, if we emit a closing code, Agg will attempt to actually close the path, if it was split due to NaN removal or clipping. We do not want that to occur, since that would make phantom lines appear on any paths that are larger than the figure or have NaNs.
This fixes both NaN removal and clipping, so that if any segments are removed, the close no longer occurs and is replaced by a
LINETO
instead.There should be tests that cover all cases. The
test_simplify_curve
tolerance change is because of an included NaN that caused a closed path that shouldn't have been there.Note, the first three commits are some cleanup, so this PR is a little larger looking that the fix really is. I can split that out if people prefer.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).