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

web: reimplement new line tool state with stack instead of nested ifs #83

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

av8ta
Copy link
Collaborator

@av8ta av8ta commented Jun 2, 2024

I find the ui state code when using the modeling tools confusing. Rather than a bunch of nested ifs and else ifs it's simpler implemented as a stack.

switch (stack.length) {
case 0: // nothing to do, the stack is empty
break
case 1: // can't create a line with only one point!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow that's so much clearer! great approach!

Copy link
Collaborator Author

@av8ta av8ta Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just had to write something my grug brain could understand haha

@MattFerraro
Copy link
Collaborator

Can you rename to a clearer title and give a quick description?

Also there's one piece of functionality that seems to have unintentionally changed: When you close a polyline by clicking on a point that already exists, the line tool should reset to its initial state of having nothing in the stack. As written, the last point stays selected

@av8ta av8ta changed the title web: make my grug brain less confused https://grugbrain.dev/ web: reimplement new line tool state with stack instead of nested ifs Jun 3, 2024
@av8ta
Copy link
Collaborator Author

av8ta commented Jun 3, 2024

Thanks for spotting that bug @MattFerraro - I thought I had wrapped my head around the old code well enough to make it simpler but clearly not! Fixed by clearing the stack when it's a point we've seen before a67b516

@av8ta av8ta merged commit 87a1fab into CADmium-Co:main Jun 3, 2024
1 check passed
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