-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BF: for degenerate polygons, add CLOSEPOLY vertex #17982
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
BF: for degenerate polygons, add CLOSEPOLY vertex #17982
Conversation
33cc440
to
787bf03
Compare
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.
Add a test?
787bf03
to
e551a27
Compare
Couldn't decide what to test initially. Settled on testing that for a single point (x, y), the extents of a degenerate polygon with only that point as its vertices has the extents |
I'm sure this was covered in the other PR, but what happens if x=np.Nan? |
tl;dr: NaN works. The So |
CI fail is due to "error allocating resources" on our Mac box? |
... the mac CI on azure seems to have issues |
lib/matplotlib/patches.py
Outdated
if self._closed: | ||
if len(xy) and (xy[0] != xy[-1]).any(): | ||
if N == 1 or N > 1 and (xy[0] != xy[-1]).any(): |
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.
Could you add a quick comment about the if
statements you've changed just to say what they're doing? And maybe nverts
is a better variable name than just N
?
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 was reticent to add these comments, because technically the checks here are very brittle as-written, so I didn't want to give people the impression this is something which is okay to do in other code.
The checks are bad because we don't guarantee anything about the coordinates of a CLOSEPOLY vertex, but this code uses the assumption that these vertices will "correctly" match the start point of the curve.
In particular, both Python (e.g. Path.iter_bezier
) and C++ code (i.e. handlers for agg:path_flags_close
) actively ignore this vertex's value, because it's known to hold "trash" sometimes, especially after cleaning NaN arrays, etc (weird stuff like #17885 and #17914).
But, I added comments that make it more clear what the if statements are nominally doing, since you think it's a good idea. I personally like N
since it matches what all the Polygon
docstrings use, but I agree that nverts
is easier to read if you're skimming the code only.
e551a27
to
1a1c288
Compare
1a1c288
to
0d5c018
Compare
…982-on-v3.3.x Backport PR #17982 on branch v3.3.x (BF: for degenerate polygons, add CLOSEPOLY vertex)
PR Summary
Fixes #17975. New
iter_bezier
code exposed an existing bug inpatches.Polygon.set_xy
.The check
xy[0] != xy[-1]
was meant to check if the user had already included an extraCLOSEPOLY
vertex for us in the list of vertices (shape(xy) = (N, 2)
). But for single-vertex (degenerate)Polygon
s, it produced a false positive (sincexy[0] == xy[-1]
by definition), leading to malformedPath
s that look like:PR Checklist