From a74f8645703ee3bcf25f105dd77cf1e54a6ce55c Mon Sep 17 00:00:00 2001 From: Emmett Lalish Date: Tue, 3 Dec 2024 14:07:49 -0800 Subject: [PATCH 1/3] added test --- test/manifold_test.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/manifold_test.cpp b/test/manifold_test.cpp index 3d561a1c8..f40d8b6c3 100644 --- a/test/manifold_test.cpp +++ b/test/manifold_test.cpp @@ -555,6 +555,53 @@ TEST(Manifold, Merge) { CheckCube(cubeSTL); } +TEST(Manifold, Crash) { + MeshGL shape; + shape.numProp = 7; + shape.triVerts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}; + shape.vertProperties = {0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 1.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + 0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 0.0, + 0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + -0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0, + 0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0, + 0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0, + 0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + -0.0, 0.5, 0.434500008821487, 0.0, 0.0, 1.0, 0.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0, + -0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0, + -0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + -0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0, + -0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 1.0, + -0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0, + 0.0, -0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0, + -0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0}; + EXPECT_TRUE(shape.Merge()); + Manifold man(shape); + EXPECT_NEAR(man.Volume(), 1, 0.01); +} + TEST(Manifold, PinchedVert) { MeshGL shape; shape.numProp = 3; From 01d489dede41dd2b202738fad6a2992c9d6b8959 Mon Sep 17 00:00:00 2001 From: Emmett Lalish Date: Tue, 3 Dec 2024 14:55:13 -0800 Subject: [PATCH 2/3] fixed dedupePropVerts --- src/impl.cpp | 11 +++++++---- test/manifold_test.cpp | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/impl.cpp b/src/impl.cpp index 9582b2c12..40c5f11d4 100644 --- a/src/impl.cpp +++ b/src/impl.cpp @@ -194,13 +194,14 @@ int GetLabels(std::vector& components, } void DedupePropVerts(manifold::Vec& triProp, - const Vec>& vert2vert) { + const Vec>& vert2vert, + int numPropVert) { ZoneScoped; std::vector vertLabels; - const int numLabels = GetLabels(vertLabels, vert2vert, vert2vert.size()); + const int numLabels = GetLabels(vertLabels, vert2vert, numPropVert); std::vector label2vert(numLabels); - for (size_t v = 0; v < vert2vert.size(); ++v) label2vert[vertLabels[v]] = v; + for (size_t v = 0; v < numPropVert; ++v) label2vert[vertLabels[v]] = v; for (auto& prop : triProp) for (int i : {0, 1, 2}) prop[i] = label2vert[vertLabels[prop[i]]]; } @@ -343,6 +344,8 @@ void Manifold::Impl::CreateFaces() { const int prop1 = meshRelation_ .triProperties[pairFace][jointNum == 2 ? 0 : jointNum + 1]; + if (prop0 == prop1) return; + bool propEqual = true; for (size_t p = 0; p < numProp; ++p) { if (meshRelation_.properties[numProp * prop0 + p] != @@ -355,7 +358,7 @@ void Manifold::Impl::CreateFaces() { vert2vert[edgeIdx] = std::make_pair(prop0, prop1); } }); - DedupePropVerts(meshRelation_.triProperties, vert2vert); + DedupePropVerts(meshRelation_.triProperties, vert2vert, NumPropVert()); } for_each_n(autoPolicy(halfedge_.size(), 1e4), countAt(0), halfedge_.size(), diff --git a/test/manifold_test.cpp b/test/manifold_test.cpp index f40d8b6c3..ddaefd2bb 100644 --- a/test/manifold_test.cpp +++ b/test/manifold_test.cpp @@ -555,7 +555,7 @@ TEST(Manifold, Merge) { CheckCube(cubeSTL); } -TEST(Manifold, Crash) { +TEST(Manifold, MergeEmpty) { MeshGL shape; shape.numProp = 7; shape.triVerts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, @@ -599,7 +599,8 @@ TEST(Manifold, Crash) { -0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0}; EXPECT_TRUE(shape.Merge()); Manifold man(shape); - EXPECT_NEAR(man.Volume(), 1, 0.01); + EXPECT_EQ(man.Status(), Manifold::Error::NoError); + EXPECT_TRUE(man.IsEmpty()); } TEST(Manifold, PinchedVert) { From 3e8161b2b5686f1fd8ca5928e82bc99067abd8b7 Mon Sep 17 00:00:00 2001 From: Emmett Lalish Date: Tue, 3 Dec 2024 15:05:49 -0800 Subject: [PATCH 3/3] size_t --- src/impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl.cpp b/src/impl.cpp index 40c5f11d4..59cc0293d 100644 --- a/src/impl.cpp +++ b/src/impl.cpp @@ -195,7 +195,7 @@ int GetLabels(std::vector& components, void DedupePropVerts(manifold::Vec& triProp, const Vec>& vert2vert, - int numPropVert) { + size_t numPropVert) { ZoneScoped; std::vector vertLabels; const int numLabels = GetLabels(vertLabels, vert2vert, numPropVert);