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

Improve isPointInsidePath() robustness #1130

Open
samhocevar opened this issue Mar 3, 2021 · 0 comments · May be fixed by #1131
Open

Improve isPointInsidePath() robustness #1130

samhocevar opened this issue Mar 3, 2021 · 0 comments · May be fixed by #1131

Comments

@samhocevar
Copy link

samhocevar commented Mar 3, 2021

The current isPointInsidePath() implementation launches an horizontal ray and counts how many times it intersects the path. However it relies on interHelper() which has trouble finding intersections lying exactly at path vertex coordinates. This causes the issue reported in #563 that #594 attempted to fix.

Here is an example of an obvious failure:

var shape = paper.path("M0,80 L80,0 L160,80 L80,160 Z");
Raphael.isPointInsidePath(shape.getPath(), 80, 80);
>>> false

Obviously interHelper() needs fixing, but because that is a complex task I suggest instead to add some jitter to the ray destination in isPointInsidePath(), which is trivial and harmless. Instead of:

interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;

Use:

interPathHelper(path, [["M", x, y], ["l", bbox.width + 10, Math.random()]], 1) % 2 == 1;
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 a pull request may close this issue.

1 participant