Skip to content

Fix #5948: Don't clip closed paths #5955

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

Merged
merged 2 commits into from
Feb 22, 2016
Merged

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Feb 1, 2016

The issue is that the clipping algorithm may create a moveto command if the polygon is clipped outside of the image. A subsequent "close poly" command will then close the polygon to that last moveto command, rather than the original moveto location.

I'm not sure there's a good solution to this: One needs the closepoly command to actually close the poly (if you just to a lineto to the original point, the line isn't "joined" at the corner properly... not getting that detail right has been the source of other bugs in the past.) The only correct solution I can think of is to "rotate" the order of the vertices so that the closepoly always ends up outside of the clipping box. But that just sounds hard to do efficiently.

In the meantime, I think the best fix is to just turn off clipping for all paths that have a closepoly on the grounds that large polygons are less likely to require clipping anyway vs. the many-vertex line plots that are quite common.

@mdboom mdboom added this to the 1.5.2 (Critical bug fix release) milestone Feb 1, 2016
@WeatherGod
Copy link
Member

How does this relate (if at all) with #5911?

On Mon, Feb 1, 2016 at 4:28 PM, Michael Droettboom <notifications@github.com

wrote:

The issue is that the clipping algorithm may create a moveto command if
the polygon is clipped outside of the image. A subsequent "close poly"
command will then close the polygon to that last moveto command, rather
than the original moveto location.

I'm not sure there's a good solution to this: One needs the closepoly
command to actually close the poly (if you just to a lineto to the original
point, the line isn't "joined" at the corner properly... not getting that
detail right has been the source of other bugs in the past.) The only
correct solution I can think of is to "rotate" the order of the vertices so
that the closepoly always ends up outside of the clipping box. But that
just sounds hard to do efficiently.

In the meantime, I think the best fix is to just turn off clipping for all
paths that have a closepoly on the grounds that large polygons are less
likely to require clipping anyway vs. the many-vertex line plots that are

quite common.

You can view, comment on, or merge this pull request online at:

#5955
Commit Summary

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#5955.

@tacaswell
Copy link
Member

Failures look like

======================================================================
ERROR: matplotlib.tests.test_transforms.test_clipping_of_log
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/matplotlib-1.5.1+40.ga952891-py3.5-linux-x86_64.egg/matplotlib/tests/test_transforms.py", line 214, in test_clipping_of_log
    assert np.allclose(tcodes, [M, M, L, L, L, C])
  File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/numpy/core/numeric.py", line 2278, in allclose
    res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
  File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/numpy/core/numeric.py", line 2359, in isclose
    return within_tol(x, y, atol, rtol)
  File "/home/travis/build/matplotlib/matplotlib/venv/lib/python3.5/site-packages/numpy/core/numeric.py", line 2342, in within_tol
    result = less_equal(abs(x-y), atol + rtol * abs(y))
ValueError: operands could not be broadcast together with shapes (5,) (6,) 
----------------------------------------------------------------------

@mdboom
Copy link
Member Author

mdboom commented Feb 1, 2016

In this case, I think we update the test...

@WeatherGod
Copy link
Member

Isn't that test also modified in #5911?

On Mon, Feb 1, 2016 at 5:44 PM, Michael Droettboom <notifications@github.com

wrote:

In this case, I think we update the test...


Reply to this email directly or view it on GitHub
#5955 (comment)
.

@mdboom
Copy link
Member Author

mdboom commented Feb 1, 2016

How does this relate (if at all) with #5911?

#5911 fixes the problem that there was always a MOVETO command emitted at the beginning, even if that MOVETO command was out of bounds. This deals with not inserting MOVETO commands in the middle of a closed shape -- by bluntly just turning off clipping for closed paths.

The test changed to be more correct (coincidentally) in both cases. One by not having two MOVETO commands at the beginning, and the other by not running clipping at all on the path. So, in a sense, the broken test is now testing something really easy (copying values from one place to another), but it's probably worth keeping anyway.

@@ -488,7 +488,7 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,

transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, path.has_curves());
clipped_t clipped(nan_removed, clip, width, height);
Copy link
Member

Choose a reason for hiding this comment

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

Don't we only want to skip this if the path has a close command, not just any code points.

@andnovar
Copy link

@tacaswell is definitely related I'll pull your latest code and check later on. Thanks for the reference.

tacaswell added a commit that referenced this pull request Feb 22, 2016
@tacaswell tacaswell merged commit 1c690ee into matplotlib:v1.5.x Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants