Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clipping filled paths in vector outputs #9488

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

Open
anntzer opened this issue Oct 20, 2017 · 5 comments
Open

Clipping filled paths in vector outputs #9488

anntzer opened this issue Oct 20, 2017 · 5 comments
Labels
backend: pdf backend: svg keep Items to be ignored by the “Stale” Github Action

Comments

@anntzer
Copy link
Contributor

anntzer commented Oct 20, 2017

The svg spec says that renderers should support values within the range of a C float (https://www.w3.org/TR/SVG/types.html#Precision). However, in practice, inkscape appears to be limited to overflow around 2**24, probably due to the fact that it relies on cairo (which has the same limitation) for rendering. Chromium's svg renderer also appears to hit an overflow somewhere (not sure about the exact value). Agg also has this limitation (see comment at the top of _path_converters.h:

PathClipper: Clips line segments to a given rectangle. This is
helpful for data reduction, and also to avoid a limitation in
Agg where coordinates can not be larger than 24-bit signed
integers.

and it is explicitly tested that this is worked around for Agg (test_simplification.test_overflow).

Currently, the svg backend clips output paths to the actually drawn canvas, but does not clip filled areas. So, with

from pylab import *
fill_between([0, 1e10], [1, 1], color="b")
plot([0, 1e10], [.5, .5], "r")
gca().set(xlim=(0, 1))  # force very large x-coordinates in pixels
gca().set_axis_off()
savefig("/tmp/foo.png")
savefig("/tmp/foo.svg")

we get:

png:

foo

svg, converted to png by inkscape (can't attach a svg in a gh comment) -- but chromium renders the same way:

foosvg

(the red line is drawn accurately because it is clipped in the SVG output; the blue box disappears because it is not clipped and overflows inkscape's renderer)

There are similar overflow issues with pdf output (via ghostscript -- the relevant renderer, as we use it for the test suite), which are in fact the factor limiting the clip value in #9477 (that's how I found out about this issue), although I can't point to anything in the pdf spec right now.

Now one may argue that "this is the fault of the noncompliant renderer", but given that we are already clipping unfilled paths, and also fully working around this for raster output, I think it makes sense to clip filled paths as well in svg (and pdf). (Of course, this will still fail when someone tries to make a svg image with a dimension exceeding 2**24. Honestly I don't care about that case :-))

Related to #8901 (clipping in eps).

@tacaswell tacaswell added this to the v2.2 milestone Oct 21, 2017
@tacaswell
Copy link
Member

iirc the reason that we do not clip filled regions is to avoid having to do the computational geometry required.

@anntzer anntzer modified the milestones: needs sorting, v3.0 Feb 14, 2018
@anntzer
Copy link
Contributor Author

anntzer commented Feb 14, 2018

https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm doesn't look too bad to implement.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 21, 2023
@anntzer
Copy link
Contributor Author

anntzer commented Apr 21, 2023

Would still be nice to have, I think.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Apr 22, 2023
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label May 29, 2024
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: pdf backend: svg keep Items to be ignored by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

2 participants