Skip to content

Return an error instead of panicking on edges shared by more than two faces - #16

Merged
komietty merged 1 commit into
komietty:mainfrom
joseph-x-li:fix-nonmanifold-edge-panic
Oct 22, 2026
Merged

komietty merged 1 commit into
komietty:mainfrom
joseph-x-li:fix-nonmanifold-edge-panic

Conversation

@joseph-x-li

Copy link
Copy Markdown
Contributor

Fixes #14.

edge_topology now checks the sorted half-edge list for any vertex pair that occurs
three or more times and returns
Err("Input mesh has an edge shared by more than two faces."), before the counting and
pairing loops that assume at most two. Valid (2-manifold or bordered) input takes the
same path as before; this only turns a panic into an error.

Adds edge_shared_by_four_faces_is_an_error_not_a_panic to src/tests.rs (two
tetrahedra sharing an edge), which panics on main and passes with this change.

Diff (src/manifold/hmesh.rs):

    ett.sort();

+   // An edge shared by more than two faces cannot be paired into halfedges; the
+   // counting and pairing below assume at most two and would index past the end.
+   if ett.windows(3).any(|w| w[0][..2] == w[1][..2] && w[1][..2] == w[2][..2]) {
+       return Err("Input mesh has an edge shared by more than two faces.".into());
+   }
+
    let mut ne = 1;

🤖 Generated with Claude Code

… faces

edge_topology counted edges as distinct vertex pairs but paired sorted
entries two at a time, so a pair occurring three or more times overran
e2v (index out of bounds). It now returns an error for such input, like
the other malformed-input checks. Adds a test with two tetrahedra
sharing an edge.

Fixes komietty#14

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@komietty

Copy link
Copy Markdown
Owner

Thank you for your PR. LGTM.

@komietty
komietty merged commit 4977ace into komietty:main Oct 22, 2026
4 checks 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.

Manifold::new panics (index out of bounds) on a mesh with an edge shared by more than two faces

2 participants