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

infinite loop during intersection #98

Open
levskaya opened this issue Jan 31, 2019 · 6 comments
Open

infinite loop during intersection #98

levskaya opened this issue Jan 31, 2019 · 6 comments
Assignees

Comments

@levskaya
Copy link

martinez.intersection([[-24.820450799231946, 81.60424965743837],[-66.98439939287994, 65.9251157774066],[-67.17837257682962, 65.5743714314538],[-23.564139586577383, 84.46172863817043],[-35.3782801119441, 162.91715665949576],[-37.42674770001716, 159.79423125392117], [-24.820450799231946, 81.60424965743837]], [[-23.564139586577383, 84.46172863817043],[-67.17837257682962, 65.5743714314538],[-24.85941638876879, 26.87535085545798],[-23.564139586577383, 84.46172863817043]])

causes an infinite loop inside 'subdivide' function due to possibleIntersection not handling the case of a self-intersecting polygon. There's even a commented-out line that when reactivated seems to solve this issue.

// that disallows self-intersecting polygons,
// did cost us half a day, so I'll leave it
// out of respect
//if (se1.isSubject === se2.isSubject) return;

This loop badly hangs the browser when it's hit.

@w8r w8r self-assigned this Jan 31, 2019
@levskaya
Copy link
Author

Hmm, even with that uncommented I'm still getting infinite loops on other geometry. e.g.

martinez.intersection([[-36.24781525291243, 28.240373566184424],[-5.276960407892941, 69.94177839542625],[-10.689741059141994, 70.14384722952903],[10.59203885271558, 26.42123891266195],[9.619931709858415, 41.63423842491253],[-61.1981865514771, 44.346933376701756], [-36.24781525291243, 28.240373566184424]], [[-5.276960407892941, 69.94177839542625],[-36.24781525291243, 28.240373566184424],[-28.04892431686142, 27.43688541864268],[-5.276960407892941, 69.94177839542625]])

@w8r
Copy link
Owner

w8r commented Jan 31, 2019

that line doesn't have much to do with it. As the comment suggests, it just stops at the first self-intersection

@Wotuu
Copy link

Wotuu commented Apr 14, 2019

I don't know why or how, but I came here from w8r/polygon-offset#14 since the infinite loop seems to be originating from this library, but commenting that line out seems to fix the issue. For what I use this library it's okay that some results may be wonky so I'll take any side effects in stride. Still, if there's some sort of proper fix for this I'd be happy to know. For now I'll fork and apply the above fix as that seemed to work.

@catalintatuta
Copy link

I found another case of infinite loop when intersecting, in my case it's stuck in connect_edges > orderEvents.
Taking a look at the actual polygons it seems they share a pretty big chunk of a border, and I suspect this is why it's having issues sorting them.
Screenshot 2022-09-30 at 13 59 11
I'm also attaching a file with the 2 polygons
test.js.zip

@w8r
Copy link
Owner

w8r commented Sep 30, 2022 via email

@crabmusket
Copy link

crabmusket commented Sep 12, 2023

I seem to be seeing the same issue when unioning shapes with some overlapping edges - though in my case, intersection works fine! Here's a reproduction: https://codepen.io/crabmusket/pen/VwqbWXW
image

I wonder if I could patch this issue for my use case by randomly jiggling the vertices a little bit. But I'd prefer to dig into the cause and fix it if possible. I'm not sure why this would be such a problem 🤔

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

5 participants