-
Notifications
You must be signed in to change notification settings - Fork 141
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
Eliminate recursion with a fixed-size stack #35
Conversation
Need to spend time on it to understand why it will produce the same result 😯 |
@delfrrr basically, it "recurses" (increases stack) only in one direction, while the other one just runs as the next iteration of the loop (while keeping |
|
||
this._legalize(a); | ||
return this._legalize(br); | ||
if (i < EDGE_STACK.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you want here i + 1 < EDGE_STACK.length
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter much I think
return this._legalize(br); | ||
if (i < EDGE_STACK.length) { | ||
EDGE_STACK[i++] = br; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw exception in else
statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so — I'd prefer the algorithm to finish triangulation even if it has minor (e.g. floating-point-error-induced) errors in extremely degenerate cases.
Managed to get a perf win with recursion elimination here too — but in a simpler/faster way, by only increasing the stack once on each illegal edge. cc @delfrrr