Skip to content

Implement PolygonSelector #837

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Implement PolygonSelector #837

wants to merge 14 commits into from

Conversation

almarklein
Copy link
Collaborator

@almarklein almarklein commented May 26, 2025

  • Get it to draw a polygon.
  • Triangulation.
  • Selection.
  • Decide on interaction model.
image

@ivoflipse
Copy link

Next up, add morphing 😎

@almarklein
Copy link
Collaborator Author

add morphing

That's worthy of a separate lib :)

@ivoflipse
Copy link

You already have gfxmorph 🤣

@almarklein
Copy link
Collaborator Author

This is nearly done, but the ux needs some thought and work. I'm thinking something like this:

  • User clicks points to create the polygon. Optionally start with existing polygon.
  • Once created, vertices can be dragged.
  • Clicking on an edge will split it in two, creating an extra vertex.
  • Double-clicking on inside the polygon will delete and let the user create a new polygon.

@kushalkolar
Copy link
Member

kushalkolar commented Jun 29, 2025

This is nearly done, but the ux needs some thought and work. I'm thinking something like this:

  • User clicks points to create the polygon. Optionally start with existing polygon.
  • Once created, vertices can be dragged.
  • Clicking on an edge will split it in two, creating an extra vertex.

All this sounds good to me!

  • Double-clicking on inside the polygon will delete and let the user create a new polygon.

I think this should be explicitly called, or via imgui right click menu. Or clicking on the fill area selects the polygon and presing the "Del" key deletes it.

@almarklein
Copy link
Collaborator Author

almarklein commented Jul 4, 2025

Interaction done! Slightly different than I said earlier:

  • Can initialize the tool with an initial selection.
  • If the initial selection is empty, enter polygon creation mode.
  • Can also call start_new_polygon() to clear the current polygon and draw a new one.
  • When creating a new polygon, clicking adds a vertex. Clicking on the first vertex again will finish the polygon.
  • When created, the vertices can be dragged. When dragged on top of a neighbouring polygon, it will be deleted.
  • When clicking/dragging on a line, a new vertex is inserted.

edit: in the above, a snapping visualization is applied to help the user understand that the vertex will be "merged" with the vertex under the mouse.

@almarklein almarklein marked this pull request as ready for review July 4, 2025 12:41
@almarklein
Copy link
Collaborator Author

I just learned about bermuda, a triangulation lib implemented in Rust, a spin-off of the Napari project. We could try and see if it helps here. It would mean an extra dependency, so maybe not use it unless we need it. But we can at least do some quick benchmarks and add a note, so that in case we do need more speed, we know how to get it.

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.

3 participants