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

Fix clipping of markers in PDF backend.#17163

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
QuLogic merged 1 commit intomatplotlib:masterfromQuLogic:pdf-marker-clip
Jun 10, 2020

Conversation

QuLogic
Copy link
Member

@QuLogicQuLogic commentedApr 17, 2020
edited
Loading

The bbox only contains the points of the marker, but the line will extend outside by half the line width. This was handled before, except when the line is at an angle to the edge, as then the line outside is wider than half a line width. The maximum is at 45°, or √2.

This fixes corners on 'v', '^', '<', '>', 'p', 'h', 'H', 'D', 'd', 'X'.

Fixes#9829.

PR Summary

PR Checklist

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

@brunobeltran
Copy link
Contributor

brunobeltran commentedApr 17, 2020
edited
Loading

Can check carefully in a second, but doesn't the maximum amount of extra clipping box needed depend on the miter limit?

I would believe that it happens to occur at 45 degrees, but maybe documenting it that way is misleading?

Edit: default PDF miter limit appears to be 10 (https://help.adobe.com/pdfl_sdk/18/PDFL_SDK_HTMLHelp/PDFL_SDK_HTMLHelp/API_References/PDFL_API_Reference/PDFEdit_Layer/General.html), which means the longest possible miter will occur for an angle of around 11.5 degrees (https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-miterlimit).

@brunobeltran
Copy link
Contributor

P.S. Once#16832 gets merged, I'll be able to clean up#16607 to compute the "exact" Bbox for an arbitrary path given the stroke width and miter limit. Just dropping this reference here so I remember to also fix this code to set an exact clipping path once this is possible.

@QuLogic
Copy link
MemberAuthor

I don't believe so, because all markers have cap style of 'butt'.

@QuLogic
Copy link
MemberAuthor

Oh, default joinstyle is 'round', but some are 'miter'. I was a bit worried about that, but no markers in our tests or examples seem to have extended passed the sqrt(2) limit.

@brunobeltran
Copy link
Contributor

Yeah the only ones which are miter are e.g.X and other 90 degree angle-heavy guys.Since this code is marker-specific (and isn't called for general paths, where we might have much more acute angles), I'd say it's good to go as-is, but would still recommend rewording the comment to clarify that the only reason this works is because the built-in markers never have angles more acute than 90 degrees.

Nix what I said up there. We now allow custom markers and this will fail for those. I would recommend using an extra buffer of size "10/2" instead of "sqrt(2)/2" to account for the miter limit of 10 (your code worked because "sqrt(2)/2" is the miter limit that starts beveling after 90 degrees).

@brunobeltran
Copy link
Contributor

brunobeltran commentedApr 17, 2020
edited
Loading

Actually, I guessMarkerStyle._joinstyle is private, so 45 degrees should work for now. Although we will have to be careful to fix this in the future if we go down a path like suggested in#16773.

@QuLogic
Copy link
MemberAuthor

Actually, I had focused on X initially, and that one is definitely 90° so 45° makes sense, but looking at triangles again, they are slightly clipped. You have to zoom in about 8x, but since PDF is vector, it's definitely there.

@QuLogic
Copy link
MemberAuthor

QuLogic commentedApr 17, 2020
edited
Loading

I updated the scaling to 5 as you said, to match the miter limit, and threw in some spec references. This fixes the triangles, 'v', '^', '<', '>', and diamond 'd', which are all markers with sharper corners.

I don't think my test triggers it, but I think we'd have to use huge markers to really see it. I'm a bit confused as to why, but I can confirm there's a difference when using the marker reference example.

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.

Test seems to check what we want. The fix and comments seem readable. LGTM.

I think making the image tests larger so that it's more precise (to catch 'd', '<', etc.) is getting to be diminishing returns, I'd merge as-is.

@anntzer
Copy link
Contributor

Why did you need to change the baseline image? Here tests seem to pass without changing it.

@QuLogic
Copy link
MemberAuthor

TBH, I'm not sure, but I think it has to do with Ghostscript rasterization. If I run diffpdf on it, it sees no difference, nor if I just look at the two in a PDF viewer.

@anntzer
Copy link
Contributor

The tests fail with the old baselines for you?

@QuLogic
Copy link
MemberAuthor

They do, with ghostscript 9.27, if that's the problem.

@QuLogicQuLogic added this to thev3.3.0 milestoneMay 26, 2020
@anntzer
Copy link
Contributor

I guess I would rather have this go on top of#17603 to avoid having to add a new baseline image.

The bbox only contains the points of the marker, but the line willextend outside by half the line width, unless it's mitered. The PDFmiter limit is 10, so pad by 5*line width (half the miter length).This fixes corners on 'v', '^', '<', '>', 'p', 'h', 'H', 'D', 'd', 'X'.Fixesmatplotlib#9829.
Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

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

Postci.

@QuLogicQuLogic merged commit21c3acb intomatplotlib:masterJun 10, 2020
@QuLogicQuLogic deleted the pdf-marker-clip branchJune 10, 2020 20:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@anntzeranntzeranntzer approved these changes

@brunobeltranbrunobeltranbrunobeltran approved these changes

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

Successfully merging this pull request may close these issues.

Vertices clipped for certain markers when plotting more than two points and saving as pdf
4 participants
@QuLogic@brunobeltran@anntzer@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp