Skip to content

Commit

Permalink
Update to latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
zalo committed Jan 27, 2025
1 parent 8040506 commit 5d18521
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/edge_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,15 +711,15 @@ bool Manifold::Impl::IsConvex(float tolerance) const {
Halfedge edge = pImpl->halfedge_[idx];
if (!edge.IsForward()) return;

const vec3 normal0 = pImpl->faceNormal_[edge.face];
const vec3 normal1 =
pImpl->faceNormal_[pImpl->halfedge_[edge.pairedHalfedge].face];
if (glm::all(glm::equal(normal0, normal1))) return;
const vec3 normal0 = pImpl->faceNormal_[idx / 3];
const vec3 normal1 = pImpl->faceNormal_[edge.pairedHalfedge / 3];

if (linalg::all(linalg::equal(normal0, normal1))) return;

const vec3 edgeVec =
pImpl->vertPos_[edge.endVert] - pImpl->vertPos_[edge.startVert];
const bool convex =
glm::dot(edgeVec, glm::cross(normal0, normal1)) > tolerance;
linalg::dot(edgeVec, linalg::cross(normal0, normal1)) > tolerance;
if (!convex) anyConcave = true;
});

Expand Down
5 changes: 3 additions & 2 deletions src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,10 @@ Manifold Manifold::Minkowski(const Manifold& other, bool inset) const {
} else if (!aConvex && !bConvex) {
for (size_t aFace = 0; aFace < aImpl->NumTri(); aFace++) {
for (size_t bFace = 0; bFace < bImpl->NumTri(); bFace++) {
const bool coplanar = glm::all(glm::equal(aImpl->faceNormal_[aFace],
const bool coplanar =
linalg::all(linalg::equal(aImpl->faceNormal_[aFace],
bImpl->faceNormal_[bFace])) ||
glm::all(glm::equal(aImpl->faceNormal_[aFace],
linalg::all(linalg::equal(aImpl->faceNormal_[aFace],
-bImpl->faceNormal_[bFace]));
if (coplanar) continue; // Skip Coplanar Triangles

Expand Down
34 changes: 17 additions & 17 deletions test/boolean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ TEST(Boolean, ConvexConvexMinkowski) {
Manifold sphere = Manifold::Sphere(offsetRadius, 20);
Manifold cube = Manifold::Cube({cubeWidth, cubeWidth, cubeWidth});
Manifold sum = cube.MinkowskiSum(sphere);
EXPECT_NEAR(sum.GetProperties().volume, 10.589364051818848f, 1e-5);
EXPECT_NEAR(sum.Volume(), 10.589364051818848f, 1e-5);
EXPECT_EQ(sum.Genus(), 0);
Manifold difference = Manifold::Cube({cubeWidth, cubeWidth, cubeWidth})
.MinkowskiDifference(sphere);
EXPECT_NEAR(difference.GetProperties().volume, 5.8319993019104004f, 1e-5);
EXPECT_NEAR(difference.GetProperties().surfaceArea, 19.439998626708984, 1e-5);
EXPECT_NEAR(difference.Volume(), 5.8319993019104004f, 1e-5);
EXPECT_NEAR(difference.SurfaceArea(), 19.439998626708984, 1e-5);
EXPECT_EQ(difference.Genus(), 0);

#ifdef MANIFOLD_EXPORT
Expand All @@ -365,57 +365,57 @@ TEST(Boolean, ConvexConvexMinkowski) {
}

TEST(Boolean, NonConvexConvexMinkowski) {
bool oldDeterministic = ManifoldParams().deterministic;
ManifoldParams().deterministic = true;
//bool oldDeterministic = ManifoldParams().deterministic;
//ManifoldParams().deterministic = true;
ManifoldParams().processOverlaps = true;

Manifold sphere = Manifold::Sphere(1.2, 20);
Manifold cube = Manifold::Cube({2.0, 2.0, 2.0}, true);
Manifold nonConvex = cube - sphere;
Manifold sum = nonConvex.MinkowskiSum(Manifold::Sphere(0.1, 20));
EXPECT_NEAR(sum.GetProperties().volume, 4.8406339f, 1e-5);
EXPECT_NEAR(sum.GetProperties().surfaceArea, 34.063014984130859f, 1e-5);
EXPECT_NEAR(sum.Volume(), 4.8406339f, 1e-5);
EXPECT_NEAR(sum.SurfaceArea(), 34.063014984130859f, 1e-5);
EXPECT_EQ(sum.Genus(), 5);
Manifold difference =
nonConvex.MinkowskiDifference(Manifold::Sphere(0.05, 20));
EXPECT_NEAR(difference.GetProperties().volume, 0.77841246128082275f, 1e-5);
EXPECT_NEAR(difference.GetProperties().surfaceArea, 16.703740785913258, 1e-5);
EXPECT_NEAR(difference.Volume(), 0.77841246128082275f, 1e-5);
EXPECT_NEAR(difference.SurfaceArea(), 16.703740785913258, 1e-5);
EXPECT_EQ(difference.Genus(), 5);

#ifdef MANIFOLD_EXPORT
if (options.exportModels)
ExportMesh("minkowski-nonconvex-convex.glb", sum.GetMeshGL(), {});
#endif

ManifoldParams().deterministic = oldDeterministic;
//ManifoldParams().deterministic = oldDeterministic;
ManifoldParams().processOverlaps = false;
}

TEST(Boolean, NonConvexNonConvexMinkowski) {
bool oldDeterministic = ManifoldParams().deterministic;
ManifoldParams().deterministic = true;
//bool oldDeterministic = ManifoldParams().deterministic;
//ManifoldParams().deterministic = true;
ManifoldParams().processOverlaps = true;

Manifold tet = Manifold::Tetrahedron();
Manifold nonConvex = tet - tet.Rotate(0, 0, 90).Translate(vec3(1));

Manifold sum = nonConvex.MinkowskiSum(nonConvex.Scale(vec3(0.5)));
EXPECT_NEAR(sum.GetProperties().volume, 8.65625f, 1e-5);
EXPECT_NEAR(sum.GetProperties().surfaceArea, 31.176914f, 1e-5);
EXPECT_NEAR(sum.Volume(), 8.65625f, 1e-5);
EXPECT_NEAR(sum.SurfaceArea(), 31.176914f, 1e-5);
EXPECT_EQ(sum.Genus(), 0);

Manifold difference =
nonConvex.MinkowskiDifference(nonConvex.Scale(vec3(0.1)));
EXPECT_NEAR(difference.GetProperties().volume, 0.81554f, 1e-5);
EXPECT_NEAR(difference.GetProperties().surfaceArea, 6.95045f, 1e-5);
EXPECT_NEAR(difference.Volume(), 0.81554f, 1e-5);
EXPECT_NEAR(difference.SurfaceArea(), 6.95045f, 1e-5);
EXPECT_EQ(difference.Genus(), 0);

#ifdef MANIFOLD_EXPORT
if (options.exportModels)
ExportMesh("minkowski-nonconvex-nonconvex.glb", sum.GetMeshGL(), {});
#endif

ManifoldParams().deterministic = oldDeterministic;
//ManifoldParams().deterministic = oldDeterministic;
ManifoldParams().processOverlaps = false;
}

Expand Down

0 comments on commit 5d18521

Please sign in to comment.