2026-07-25 04:07:24 +00:00
|
|
|
#include "vde/brep/tolerance.h"
|
|
|
|
|
#include "vde/brep/brep.h"
|
|
|
|
|
|
|
|
|
|
namespace vde::brep {
|
|
|
|
|
|
|
|
|
|
// Global tolerance config
|
|
|
|
|
static ToleranceConfig g_global_tolerance;
|
|
|
|
|
|
|
|
|
|
const ToleranceConfig& ToleranceConfig::global() {
|
|
|
|
|
return g_global_tolerance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToleranceConfig::set_global(const ToleranceConfig& cfg) {
|
|
|
|
|
g_global_tolerance = cfg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double model_tolerance(const BrepModel& body) {
|
|
|
|
|
auto bb = body.bounds();
|
|
|
|
|
if (bb.min().x() > bb.max().x()) return 1e-6;
|
|
|
|
|
|
|
|
|
|
double extent = bb.extent().norm();
|
|
|
|
|
return adaptive_tolerance(extent);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 16:42:55 +08:00
|
|
|
// ── ToleranceChain ──
|
|
|
|
|
|
|
|
|
|
void ToleranceChain::push(const std::string& op_name, double tol) {
|
|
|
|
|
steps_.emplace_back(op_name, tol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double ToleranceChain::cumulative() const {
|
|
|
|
|
double sum_sq = 0.0;
|
|
|
|
|
for (auto& [_, tol] : steps_) {
|
|
|
|
|
sum_sq += tol * tol;
|
|
|
|
|
}
|
|
|
|
|
return std::sqrt(sum_sq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double ToleranceChain::max_step() const {
|
|
|
|
|
double m = 0.0;
|
|
|
|
|
for (auto& [_, tol] : steps_) {
|
|
|
|
|
m = std::max(m, tol);
|
|
|
|
|
}
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 04:07:24 +00:00
|
|
|
} // namespace vde::brep
|