Skip to content

Commit

Permalink
better checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Dec 9, 2024
1 parent fe3c59b commit 91dd727
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,7 @@ std::shared_ptr<CsgLeafNode> ImplToLeaf(Manifold::Impl &&impl) {
std::shared_ptr<CsgLeafNode> SimpleBoolean(const Manifold::Impl &a,
const Manifold::Impl &b, OpType op) {
#ifdef MANIFOLD_DEBUG
try {
Boolean3 boolean(a, b, op);
auto impl = boolean.Result(op);
if (ManifoldParams().intermediateChecks && impl.IsSelfIntersecting()) {
dump_lock.lock();
std::cout << "self-intersection detected" << std::endl;
dump_lock.unlock();
throw logicErr("self intersection detected");
}
return ImplToLeaf(std::move(impl));
} catch (logicErr &err) {
auto dump = [&]() {
if (ManifoldParams().verbose) {
dump_lock.lock();
if (op == OpType::Add)
Expand All @@ -139,6 +129,19 @@ std::shared_ptr<CsgLeafNode> SimpleBoolean(const Manifold::Impl &a,
std::cout << b;
dump_lock.unlock();
}
};
try {
Boolean3 boolean(a, b, op);
auto impl = boolean.Result(op);
if (ManifoldParams().intermediateChecks && impl.IsSelfIntersecting()) {
throw logicErr("self intersection detected");
}
return ImplToLeaf(std::move(impl));
} catch (logicErr &err) {
dump();
throw err;
} catch (geometryErr &err) {
dump();
throw err;
}
#else
Expand Down
19 changes: 19 additions & 0 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ bool Manifold::Impl::IsSelfIntersecting() const {
if (distance2(tri_x[i], tri_y[j]) <= epsilonSq) return true;

if (DistanceTriangleTriangleSquared(tri_x, tri_y) == 0.0) {
// try to move the triangles around the normal of the other face
std::array<vec3, 3> tmp_x, tmp_y;
for (int i : {0, 1, 2})
tmp_x[i] = tri_x[i] + epsilon_ * faceNormal_[y];
if (DistanceTriangleTriangleSquared(tmp_x, tri_y) > 0.0)
return true;
for (int i : {0, 1, 2})
tmp_x[i] = tri_x[i] - epsilon_ * faceNormal_[y];
if (DistanceTriangleTriangleSquared(tmp_x, tri_y) > 0.0)
return true;
for (int i : {0, 1, 2})
tmp_y[i] = tri_y[i] + epsilon_ * faceNormal_[x];
if (DistanceTriangleTriangleSquared(tri_x, tmp_y) > 0.0)
return true;
for (int i : {0, 1, 2})
tmp_y[i] = tri_y[i] - epsilon_ * faceNormal_[x];
if (DistanceTriangleTriangleSquared(tri_x, tmp_y) > 0.0)
return true;

#ifdef MANIFOLD_DEBUG
if (verbose) {
dump_lock.lock();
Expand Down

0 comments on commit 91dd727

Please sign in to comment.