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

Feature request: difference and intersection operations for Path2 vs Region2 #2

Open
edwinRNDR opened this issue Sep 13, 2020 · 8 comments

Comments

@edwinRNDR
Copy link

Would it be possible to add difference and intersection operations for open shapes (Path2) versus closes ones (Region2)?

@ztellman
Copy link
Member

ztellman commented Sep 14, 2020 via email

@edwinRNDR
Copy link
Author

Screenshot 2020-09-14 at 09 30 32

Here you see the intersection and difference operators for Path2 (pink) vs Region2 (cyan-ish) and the result in black. They are still operators that work on a set, but in this case the set is not one of polygon area.

@ztellman
Copy link
Member

Ah, I see, I was thinking (Path, Path) => Path, not (Path, Region) => Path. Yes, that should be pretty straightforward, it's just the initial steps of the (Region, Region) => Region logic. Some of the consistency checks we use for the region operations (see https://ideolalia.com/2018/08/28/artifex.html) won't be possible here, so there may be more artifacts for pathological inputs, but that's difficult to quantify.

I'll update once I have some code thrown together for this.

@edwinRNDR
Copy link
Author

Yes, this is what I had in mind! Thank you, looking forward to seeing that code.

@hamoid
Copy link

hamoid commented Sep 21, 2020

Would be very nice to have also have splitting on intersections (closed-closed, closed-open and open-open contours).

Here an animation showing one of the cases: https://openrndr.discourse.group/t/doodles-wall-c/51/73?u=abe

The result is always a list of open contours, no matter if the sources are closed or open. In my code I have two arguments, a target shape and a cutter shape.

When a open contour crosses or touches a closed contour in a single point the only change that takes place on the target closed contour is that the first vertex becomes the intersection point (so the points are sorted). This is useful for animation (if I want to grow the contour starting at the cutting point) or effects like in this doodle, where I cut a series of parallel lines or concentric circles and then apply some forces to the resulting lines.
cut

@ztellman
Copy link
Member

I think the general form of this would be a Path2.split(Curve2[] splitters) => Iterable<Path2> method, which would return the original path split wherever it intersects the provided curves. For the intersection/difference method, you can just test a point within each of the resulting paths against the region.

Does that seem reasonable?

@edwinRNDR
Copy link
Author

That sounds fair. I see there is a Region2.test(), that would make figuring out if a path is inside or outside simple enough.

@ztellman
Copy link
Member

I'd probably still have explicit intersection/difference methods, because empirically I've found it's best to do the test somewhere other than the midpoint of a curve, because that often will be near the edge of the other intersecting shape (I use 1/e instead), and that's not something I'd expect a user of the library to have to know or worry about.

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

No branches or pull requests

3 participants