From c20fad0479d5121f790f03b56629dccc7ebdeeb2 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Mon, 21 Oct 2024 16:07:09 +0800 Subject: [PATCH] remove SetTolerance Tolerance value is set before the mesh is created, when SimplfiyTopology cannot be called. --- src/impl.cpp | 14 +------------- src/impl.h | 1 - src/manifold.cpp | 11 ++++++++++- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/impl.cpp b/src/impl.cpp index 9e6c9894e..69fee504d 100644 --- a/src/impl.cpp +++ b/src/impl.cpp @@ -569,19 +569,7 @@ Manifold::Impl Manifold::Impl::Transform(const mat3x4& transform_) const { */ void Manifold::Impl::SetEpsilon(double minEpsilon) { epsilon_ = MaxEpsilon(minEpsilon, bBox_); - SetTolerance(std::max(tolerance_, epsilon_)); -} - -void Manifold::Impl::SetTolerance(double newTolerance) { - if (newTolerance > tolerance_) { - // increased tolerance -> simplify opportunity - tolerance_ = newTolerance; - SimplifyTopology(); - } else { - // for reducing tolerance, we need to make sure it is still at least - // equal to epsilon. - tolerance_ = std::max(epsilon_, newTolerance); - } + tolerance_ = std::max(tolerance_, epsilon_); } /** diff --git a/src/impl.h b/src/impl.h index 579751608..19d4ba7bc 100644 --- a/src/impl.h +++ b/src/impl.h @@ -277,7 +277,6 @@ struct Manifold::Impl { bool IsFinite() const; bool IsIndexInBounds(VecView triVerts) const; void SetEpsilon(double minEpsilon = -1); - void SetTolerance(double minTolerance); bool IsManifold() const; bool Is2Manifold() const; bool MatchesTriNormals() const; diff --git a/src/manifold.cpp b/src/manifold.cpp index a25bc656f..064c2b67b 100644 --- a/src/manifold.cpp +++ b/src/manifold.cpp @@ -382,7 +382,9 @@ double Manifold::GetEpsilon() const { Manifold Manifold::SetEpsilon(double epsilon) const { auto impl = std::make_shared(*GetCsgLeafNode().GetImpl()); + auto oldTolerance = impl->tolerance_; impl->SetEpsilon(epsilon); + if (impl->tolerance_ > oldTolerance) impl->SimplifyTopology(); return Manifold(impl); } @@ -400,7 +402,14 @@ double Manifold::GetTolerance() const { */ Manifold Manifold::SetTolerance(double tolerance) const { auto impl = std::make_shared(*GetCsgLeafNode().GetImpl()); - impl->SetTolerance(tolerance); + if (tolerance > impl->tolerance_) { + impl->tolerance_ = tolerance; + impl->SimplifyTopology(); + } else { + // for reducing tolerance, we need to make sure it is still at least + // equal to epsilon. + impl->tolerance_ = std::max(impl->epsilon_, tolerance); + } return Manifold(impl); }