-
Notifications
You must be signed in to change notification settings - Fork 62
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 looping for /* Pass the sweep line over those endpoints */ loop in operation.js #95
Comments
Not sure if this is a related bug but the end result is the same (infinite looping in the same while loop) when performing union operation. Differences are:
See attached file for the set of polygons. |
I made a simple script to generate smallish random polygons. It creates between 2 and 3 polygons, each with between 1 and 3 rings, each with between 3 and 10 points each. The coordinates are integers in the range [0, 100]. The coordinates are random; most polygons will not be simple, but these meet the input specifications for this library so I guess that shouldn't be a problem. I got it to reproduce the infinite looping issue:
I'm not sure how to add this to the tests. I went to add a new case in the end-to-end folder but then realised that that requires knowing what the output should be... 🤣 The script created lots of examples that triggered these other errors: "Unable to complete output ring", "Maximum call stack size exceeded", "Unable to find segment". Let me know if it would be useful to create a PR that includes such a script (perhaps with floating point variants as well). I added it to package.json for my own ease of use so could include this in the PR. The script is:
|
yeah gotcha! haha 😂 This, and the other bugs your script have generate are probably related to floating-point math round-off errors. As the test suite in this project has grown and grown it is increasingly hard to fix new issues without breaking some of the existing tests. If you (or anyone else) is able to put together a PR that fixes behavior a new set of failing coordinates without breaking any of the existing tests, I'll happily accept it. |
I'd be happy to give it a go, but in the meantime can you accept this PR (for which it's maybe not even possible to write a sensible test)? #97 It seems like it's at least possible for this to be an on-going issue no matter how many tests there are or fixes are applied for them. Being able to catch and gracefully handle an infinite-loop is far better than crashing the node process... |
Using version 0.14.3.
I found a way to make the while loop commented with
Pass the sweep line over those endpoints
in operation.js (around line 62) run infinitely. Or at least until the memory heap is full...Using my new novel technique (patent pending) it looks like it continuously adds segments to the
sweepLine
until it falls over. I could get it up to about 1,000,000 segments before it fell over with the default heap size. I'm guessing a million segments is more than expected for the below inputs...To reproduce perform a union operation over the polygons below.
Additional info: the coordinates were already rounded to a precision of 1 decimal place (because that helped a lot with general stability, as noted previously in a different issue). Rounding them to integers makes the issue noted here go away for the below inputs.
The text was updated successfully, but these errors were encountered: