Skip to content
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

Fix clip_path_to_rect, add convenience method on Path object for it #1778

Merged
merged 3 commits into from Feb 25, 2013

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Feb 22, 2013

Aternative to #1777. Properly closes the paths returned by clip_to_rect and adds a new clip_to_bbox method to Path that returns a Path object. Adds a test that tests clipping compound paths and multiple subsegments.

…clip_to_rect and adds a new clip_to_bbox method to Path that returns a Path object. Adds a test that tests clipping compound paths and multiple subsegments.
lengths = [len(x) for x in args]
total_length = sum(lengths)

vertices = np.vstack([x.vertices for x in args])
vertices.reshape((total_length, 2))

codes = cls.LINETO * np.ones(total_length)
codes = np.ones(total_length, dtype=cls.code_type)
Copy link
Member

Choose a reason for hiding this comment

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

Would this be better as np.repeat(cls.LINETO, total_length)? (Though I'm not sure you can specify the dtype that way)

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise, it may as well be np.empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. I think np.empty is the best here.

@pelson
Copy link
Member

pelson commented Feb 23, 2013

Looks good to me. Just a couple of comments, but I'd be happy enough to merge this early next week.
FWIW, you've pretty much implemented the Sutherland-Hodgman algorithm here, except it has been reduced to a path-bbox clip - I'm pretty sure it wouldn't be too much work to do a path-path clip as I have done in https://github.com/SciTools/cartopy/pull/230/files#L1R39. I don't propose we do that here (or in v1.2.x) but it is something we could bear in mind if anybody else finds this functionality useful.

Good stuff @mdboom!

pelson added a commit that referenced this pull request Feb 25, 2013
Fix clip_path_to_rect, add convenience method on Path object for it
@pelson pelson merged commit 41fcfd2 into matplotlib:v1.2.x Feb 25, 2013
@mdboom mdboom deleted the clip_path_to_rect branch August 7, 2014 13:54
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.

None yet

2 participants