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

getCrossings() returns touching paths which do not cross each other #1409

Closed
richnicholls404 opened this issue Nov 9, 2017 · 4 comments
Closed

Comments

@richnicholls404
Copy link

In the documentation, Path.getCrossings() says

Crossings are intersections where the paths actually are crossing each other, as opposed to simply touching.

However, with the following code, these non-intersecting but touching paths are reported as crossing:

var path = new Path({
    segments: [[20, 20], [20, 80], [80, 80], [80, 20]],
    fillColor: 'blue',
    closed: true
});

var secondPath = new Path({
    segments: [[80, 20], [80, 80], [140, 80], [140, 20]],
    fillColor: 'green',
    closed: true
});

var crossings = path.getCrossings(secondPath);
console.log('crossings', crossings);
for (var i = 0; i < crossings.length; i++) {
	new Path.Circle({
		center: crossings[i].point,
		radius: 4,
		fillColor: 'red'
	});
}

Loving paper.js! It's absolutely amazing and I am very thankful for such a great library! Thank you!!

@lehni
Copy link
Member

lehni commented Nov 9, 2017

Yes there are a ton of edge cases where this doesn't work as it should. Unfortunately I have very little time available to further improve anything on paper.js : /

@richnicholls404
Copy link
Author

I can completely understand. It's a very complex area of the library too. In case it helps you or anyone else who has this issue, I'll detail my fix.

In order to find out if a path overlapped another path (but without returning as an overlap if it happened to be touching), I ended up using something like this:

const intersectingPath = PathItem.intersect(secondPath);
If (intersectingPath.segments.length === 0) console.log('does not overlap');

Thanks for your speedy feedback!

@renschler
Copy link

I'm not sure if this should be logged as a separate issue.

But if you take two identical simple paths, and run getCrossings, should this return empty? Today it does not.

For example, see this sketch

@lehni
Copy link
Member

lehni commented Jun 23, 2019

@renschler yeah this is a a bit of a workaround that was included for the boolean operations to work correctly, but it shouldn't affect the public API like this. See the TODO here:

// TODO: Only return overlaps that are actually crossings! For this
// we need proper overlap range detection / merging first...
// But as we call #resolveCrossings() first in boolean operations,
// removing all self-touching areas in paths, this currently works
// as it should in the known use cases.
// The ideal implementation would deal with it in a way outlined in:
// https://github.com/paperjs/paper.js/issues/874#issuecomment-168332391

You can work around this for now by doing this instead:

const crossings = path1.getIntersections(path2, inter => inter.isCrossing());

Updated Sketch

@lehni lehni closed this as completed in bba7090 Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants