spade icon indicating copy to clipboard operation
spade copied to clipboard

Vertex handle usage after vertex removal

Open weigangd opened this issue 5 years ago • 1 comments

Hello,

first of all thank you for sharing this library!

For my usecase I need to remove vertices often. But I also need to store some vertex handles for later. Like written in your documentation the removal function will invalidate all Handles. Do you have a workaround for this like should i store points instead of the vertex handles.

If I were to try try alter the implementation, so that removal doesn't invalidate all handles, where should I start to look at. Do you have any hints for me?

Thanks

weigangd avatar Jan 13 '20 13:01 weigangd

Those are good points that you raise there. That use case certainly crossed my mind before (although I didn't need it myself yet).

Like written in your documentation the removal function will invalidate all Handles.

Well, there are a few more details that the docs (purposefully) don't mention:

  • All (fixed) handles (vertex, edge, faces) are usize values behind the scenes
  • The first inserted vertex has the handle value 0, the second 1... and so on. Inserting into a triangulation with n points will return a new handle with value n. (Exception: A vertex with the same position already exists, then the existing handle is returned)
  • Removing a vertex will swap remove the vertex. That means: Only the vertex with the highest value is being invalidated and gets re-assigned the handle of the removed vertex. The vertex with the highest handle value is always triangulation.num_vertices() - 1 (prior to removal). This information may already be enough to track and update any stored vertex handle.
  • Removing a vertex will also remove edges and faces. Their handles are swap removed as well. This is harder to track as multiple edges and faces get removed.

The reason why all of this is glossed over in the docs is to keep it as an implementation secret. However, there is no chance at the moment that that will change. Depending on your use case, tracking which vertex handles really get invalidated may already be enough.

Is this already sufficient? Or do you need a solution that does not invalidate any vertex handle (there are some)?

Let me know if you have any further questions!

Stoeoef avatar Jan 15 '20 19:01 Stoeoef