Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

brunobeltran
Copy link
Contributor

@brunobeltranbrunobeltran commentedJul 20, 2020
edited
Loading

PR Summary

Fixes#17975. Newiter_bezier code exposed an existing bug inpatches.Polygon.set_xy.

The checkxy[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)Polygons, it produced a false positive (sincexy[0] == xy[-1] by definition), leading to malformedPaths that look like:

In [1]:frommatplotlib.patchesimportPolygonIn [2]:pp=Polygon([[0,0]])In [3]:pp.get_path()Out[3]:Path(array([[0.,0.]]),array([79],dtype=uint8))

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

@brunobeltranbrunobeltran added topic: path handling Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labelsJul 20, 2020
@brunobeltranbrunobeltranforce-pushed theclosepoly-clobbers-poly-vertex branch from33cc440 to787bf03CompareJuly 20, 2020 23:00
Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Add a test?

@QuLogicQuLogic added this to thev3.3.1 milestoneJul 20, 2020
@brunobeltranbrunobeltranforce-pushed theclosepoly-clobbers-poly-vertex branch from787bf03 toe551a27CompareJuly 20, 2020 23:13
@brunobeltran
Copy link
ContributorAuthor

Add a test?

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 extentsBbox([[x, y], [x, y]]), which is the behavior where we actually differ from the (buggy) 3.2 behavior.

@jklymak
Copy link
Member

I'm sure this was covered in the other PR, but what happens if x=np.Nan?

@brunobeltran
Copy link
ContributorAuthor

tl;dr: NaN works.

ThePolygon class doesn't complain about NaN's or clean them explicitly (currently. You might argue that it should).

SoPolygon([[np.nan, 0]]) creates a path thatwould be correct if there were no NaN's there:Path([[np.nan, 0], [np.nan, 0]], [MOVETO, CLOSEPOLY]). The newPath.get_extents blindly adds all possible extremal values to aBbox.null() (which in this case are all NaN). Adding a NaN to a Bbox is a no-op, (the call chain ends in_path.update_path_extents, which works on aPathNaNRemover<agg:conv_transform<PathIterator>>), so theBbox stays null, correctly indicating there are no non-NaN points in the polygon.

@brunobeltran
Copy link
ContributorAuthor

CI fail is due to "error allocating resources" on our Mac box?

@jklymak
Copy link
Member

... the mac CI on azure seems to have issues

if self._closed:
iflen(xy) and (xy[0] != xy[-1]).any():
ifN == 1 or N > 1 and (xy[0] != xy[-1]).any():
Copy link
Member

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 theif statements you've changed just to say what they're doing? And maybenverts is a better variable name than justN?

Copy link
ContributorAuthor

@brunobeltranbrunobeltranJul 21, 2020
edited
Loading

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 foragg: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 arenominally doing, since you think it's a good idea. I personally likeN since it matches what all thePolygon docstrings use, but I agree thatnverts is easier to read if you're skimming the code only.

@brunobeltranbrunobeltranforce-pushed theclosepoly-clobbers-poly-vertex branch frome551a27 to1a1c288CompareJuly 21, 2020 14:51
@brunobeltranbrunobeltranforce-pushed theclosepoly-clobbers-poly-vertex branch from1a1c288 to0d5c018CompareJuly 21, 2020 15:02
@QuLogicQuLogic merged commit21c3e3f intomatplotlib:masterJul 22, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestJul 22, 2020
QuLogic added a commit that referenced this pull requestJul 22, 2020
…982-on-v3.3.xBackport PR#17982 on branch v3.3.x (BF: for degenerate polygons, add CLOSEPOLY vertex)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: path handling
Projects
None yet
Milestone
v3.3.1
Development

Successfully merging this pull request may close these issues.

Computing the bounding box of a degenerate polygon throws an error
4 participants
@brunobeltran@jklymak@QuLogic@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp