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

Eliminate recursion with a fixed-size stack #35

Merged
merged 1 commit into from
Oct 1, 2018
Merged

Conversation

mourner
Copy link
Member

@mourner mourner commented Oct 1, 2018

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

@delfrrr
Copy link

delfrrr commented Oct 1, 2018

Need to spend time on it to understand why it will produce the same result 😯

@mourner mourner merged commit bd6160c into master Oct 1, 2018
@mourner mourner deleted the eliminate-recursion branch October 1, 2018 14:42
@mourner
Copy link
Member Author

mourner commented Oct 1, 2018

@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 a value).


this._legalize(a);
return this._legalize(br);
if (i < EDGE_STACK.length) {
Copy link

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?

Copy link
Member Author

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;
}
Copy link

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?

Copy link
Member Author

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.

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 this pull request may close these issues.

2 participants