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

Speed up the pointInPolygon function. #1052

Merged
merged 1 commit into from
Jun 3, 2020
Merged

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Apr 16, 2020

This relies on the distanceToPolygon2D function, but we don't actually care about the distance, so skip some calculations.

@@ -693,14 +695,14 @@ var util = {
if (((p0.y > pt.y) !== (p1.y > pt.y)) && (pt.x < (p1.x - p0.x) * (pt.y - p0.y) / (p1.y - p0.y) + p0.x)) {
inside = !inside;
}
distSq = util.distance2dToLineSquared(pt, p0, p1);
distSq = onlySign ? 1 : util.distance2dToLineSquared(pt, p0, p1);
Copy link
Member

Choose a reason for hiding this comment

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

so if onlySign is true, the function will return distSq == 1? I did not look at the entire block, just the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

distSq will be 1 (because we don't care about the actual value of the distance), but the returned result will be -1 or +1 depending on the value of the inside flag.

Copy link
Member

Choose a reason for hiding this comment

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

thanks makes sense.

This relies on the distanceToPolygon2D function, but we don't actually
care about the distance, so skip some calculations.
@manthey manthey force-pushed the speed-up-point-in-polygon branch from 47230f6 to cd7dd47 Compare June 2, 2020 11:56
@manthey manthey merged commit 6d1f99b into master Jun 3, 2020
@manthey manthey deleted the speed-up-point-in-polygon branch June 3, 2020 11: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.

2 participants