Skip to content

Commit

Permalink
remove SetTolerance
Browse files Browse the repository at this point in the history
Tolerance value is set before the mesh is created, when SimplfiyTopology
cannot be called.
  • Loading branch information
pca006132 committed Oct 21, 2024
1 parent ce0938f commit c20fad0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
14 changes: 1 addition & 13 deletions src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ struct Manifold::Impl {
bool IsFinite() const;
bool IsIndexInBounds(VecView<const ivec3> triVerts) const;
void SetEpsilon(double minEpsilon = -1);
void SetTolerance(double minTolerance);
bool IsManifold() const;
bool Is2Manifold() const;
bool MatchesTriNormals() const;
Expand Down
11 changes: 10 additions & 1 deletion src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ double Manifold::GetEpsilon() const {

Manifold Manifold::SetEpsilon(double epsilon) const {
auto impl = std::make_shared<Impl>(*GetCsgLeafNode().GetImpl());
auto oldTolerance = impl->tolerance_;
impl->SetEpsilon(epsilon);
if (impl->tolerance_ > oldTolerance) impl->SimplifyTopology();
return Manifold(impl);
}

Expand All @@ -400,7 +402,14 @@ double Manifold::GetTolerance() const {
*/
Manifold Manifold::SetTolerance(double tolerance) const {
auto impl = std::make_shared<Impl>(*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);
}

Expand Down

0 comments on commit c20fad0

Please sign in to comment.