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

Ignore non-draw codes when calculating path extent#19216

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

Merged
brunobeltran merged 1 commit intomatplotlib:masterfromdstansby:path-extent
Jan 6, 2021

Conversation

dstansby
Copy link
Member

@dstansbydstansby commentedJan 2, 2021
edited
Loading

When calculating the extents of a path, anyMOVETO, CLOESPOLY, or STOP codes shouldn't be taken into account. This is a follow up to#16832.

@dstansby
Copy link
MemberAuthor

🤔 looking at the failing tests it looks like any MOVETO codes are deliberately included in the path extents. This should probably just ignore CLOSEPOLY and STOP.

timhoffm reacted with thumbs up emoji

Comment on lines 628 to 634
draw_idxs = np.in1d(self.codes, Path.LINETO)
# Include the start and end point of each line
draw_idxs = draw_idxs | np.roll(draw_idxs, -1)
# Add in commands that aren't ignored
# (in the straight line case here this is only MOVETO)
draw_idxs = draw_idxs | ~np.in1d(self.codes, Path.IGNORED_CODES)
xys = self.vertices[draw_idxs]
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this way of writing is more concise:

Suggested change
draw_idxs=np.in1d(self.codes,Path.LINETO)
# Include the start and end point of each line
draw_idxs=draw_idxs|np.roll(draw_idxs,-1)
# Add in commands that aren't ignored
# (in the straight line case here this is only MOVETO)
draw_idxs=draw_idxs|~np.in1d(self.codes,Path.IGNORED_CODES)
xys=self.vertices[draw_idxs]
# we have only straight lines:
# consider line starts, line ends and points moved to
line_end_mask=np.isin(self.codes,Path.LINETO)
line_start_mask=np.roll(line_end_mask,-1)
moveto_mask=np.isin(self.codes,Path.MOVETO)
xys=self.vertices[line_start_mask|line_end_mask|moveto_mask]

Note also that I've usednp.isin() instead ofnp.in1d() becauseself.codes are 1D.

Edit: I'm wondering if

xys = self.vertices[np.isin(self.codes, [Path.LINETO, Path.MOVETO])]

would be sufficient. Here, the codes of points at line starts cannot be STOP, CURVE3, CURVE4. The only grey area would be CLOSEPOLY followed by LINETO, in which case the line start would be a CLOSEPOLY node. IMHO that's not quite well defined CLOSEPOLY should always be followed by MOVETO.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think they can be CURVE{3,4}, as there will always be a final control point for those curves (the curve endpoint) which one can then draw a straight line from.

Copy link
Member

Choose a reason for hiding this comment

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

But theelif conditions explicitly excludes CURVE{3,4} here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the lag. A couple of things:

The only grey area would be CLOSEPOLY followed by LINETO, in which case the line start would be a CLOSEPOLY node. IMHO that's not quite well defined CLOSEPOLY should always be followed by MOVETO.

While "undefined" is a reasonable guess, AFAICT, all backends currently handle this behavior consistently. That is, CLOSEPOLY's vertex is ignored and it is treated as "(start_point, LINETO)" plus adding the extra cap.

Which means that CLOSEPOLY followed by LINETO is well-defined, and does the natural thing:

importmatplotlib.pyplotaspltfrommatplotlib.pathimportPathfrommatplotlib.patchesimportPathPatchp=Path(    [[0,0], [0,1], [1,1], [5,5], [1,0], [0,-1], [-5,5]],     [Path.MOVETO,Path.LINETO,Path.LINETO,Path.CLOSEPOLY,Path.LINETO,Path.LINETO,Path.CLOSEPOLY])fig,ax=plt.subplots()ax.add_patch(PathPatch(p))ax.set_xlim([-0.5,1.5])ax.set_ylim([-1.5,1.5])

image

And, unless I'm missing something, then

I'm wondering if

xys = self.vertices[np.isin(self.codes, [Path.LINETO, Path.MOVETO])]

would be sufficient.

tl;dr: yes. We should just be doing this.

@dstansby
Copy link
MemberAuthor

👍 thanks for the suggestions, agreed that they make the code read much better

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.

Should the ignored code list be integrated into#19088?

Copy link
Contributor

@brunobeltranbrunobeltran left a comment

Choose a reason for hiding this comment

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

Thanks for this catch@dstansby!

Not sure why this wasn't justxys = self.vertices[np.isin(self.codes, [Path.MOVETO, Path.LINETO])] right from the start.

@dstansby
Copy link
MemberAuthor

dstansby commentedJan 5, 2021
edited
Loading

Thanks for the reviews. There were enough changes that I've just amended the commit and force pushed a new version.

Copy link
Contributor

@brunobeltranbrunobeltran left a comment

Choose a reason for hiding this comment

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

LGTM.

@brunobeltranbrunobeltran merged commite904fa3 intomatplotlib:masterJan 6, 2021
@QuLogicQuLogic added this to thev3.4.0 milestoneJan 6, 2021
@dstansbydstansby deleted the path-extent branchJanuary 6, 2021 10:14
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@brunobeltranbrunobeltranbrunobeltran approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

4 participants
@dstansby@QuLogic@brunobeltran@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp