-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Circle approximation can freeze host application for extended time #91
Comments
Could you provide some academic references on what this loop is attempting to achieve? I'd like to read up on this so I could possibly contribute. |
Hey @kastolars, thank you for your interest! That method creates a regular polygon to approximate a circle. The That loop in particular determines how many-sided the polygon needs to be. It starts with a triangle, determines how far that triangle deviates from the ideal circle. If it's too much, it does a As per the comment in the code, the ideal circle is the circumscribed circle of the approximated polygon (meaning the polygon's vertices are on the circle, the rest of the polygon is in it). The points on the polygon that are farthest from the circle are the center points of the edges. Since that is where the polygon's incircle (([1], [2], [3]) touches the polygon, we can compute the maximum deviation between polygon and circle by subtracting the incircle radius from the circumscribed circle radius. So the problem boils down to this:
That loop solves this problem using the brute-force method, and I hope we can come up with an equation that we can just plug the circle radius and the Does that help? |
The circle approximation code contains a loop that can become long-running, if the
tolerance
parameter is unreasonably low. This happened once before, due to a bug in calculatingtolerance
.I think that we can do away with that loop completely by being a bit more clever about calculating
n
, which would solve the problem. I haven't actually sat down and done the math though, so I'm not 100% sure.If it turns out this is not possible, then an alternative solution would be to create some system that can monitor and abort long-running algorithms. We might need something like that anyway, long-term, but that one loop is not a good enough reason to work on that now.
Labeling as
good first issue
, as this is basically a math problem, and the affected code is fully contained within a reasonable method.The text was updated successfully, but these errors were encountered: