BF: for degenerate polygons, add CLOSEPOLY vertex#17982
BF: for degenerate polygons, add CLOSEPOLY vertex#17982QuLogic merged 1 commit intomatplotlib:masterfrom
Conversation
33cc440 to
787bf03
Compare
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 |
| N, _ = xy.shape | ||
| 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.
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.
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_beziercode 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 extraCLOSEPOLYvertex for us in the list of vertices (shape(xy) = (N, 2)). But for single-vertex (degenerate)Polygons, it produced a false positive (sincexy[0] == xy[-1]by definition), leading to malformedPaths that look like:PR Checklist