8000 Fix path simplification of closed loops by QuLogic · Pull Request #21387 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Oct 28, 2021

Conversation

QuLogic
Copy link
Member
@QuLogic QuLogic commented Oct 20, 2021

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

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [n/a] New features are documented, with examples if plot related.
  • [n/a] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [n/a] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [n/a] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic QuLogic added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: path handling labels Oct 20, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Oct 20, 2021
@QuLogic QuLogic linked an issue Oct 20, 2021 that may be closed by this pull request
@QuLogic
Copy link
Member Author
QuLogic commented Oct 20, 2021

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
@QuLogic QuLogic force-pushed the clipped-closed-path branch from b43fb0d to 8adf493 Compare October 23, 2021 03:54
@QuLogic QuLogic changed the title Revert "Don't disable path clipping on paths with codes." Fix path simplification of closed loops Oct 23, 2021
@QuLogic
Copy link
Member Author
QuLogic commented Oct 23, 2021

I've repurposed this to instead be fixing closed loops the right way. The original description has been updated with further details.

Copy link
Member
@jklymak jklymak left a 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.

@jklymak jklymak merged commit 7eaf90b into matplotlib:main Oct 28, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Oct 28, 2021
@QuLogic QuLogic deleted the clipped-closed-path branch October 28, 2021 19:24
QuLogic added a commit that referenced this pull request Oct 30, 2021
…387-on-v3.5.x

Backport PR #21387 on branch v3.5.x (Fix path simplification of closed loops)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: path handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: zooming in on contour plot gives false extra contour lines
3 participants
0