029dd6b75a
精确谓词: Shewchuk Level B → Level C (expansion arithmetic) - Dekker split + Two-Product + Two-Sum + Expansion 4-component - orient_2d/3d 自适应精度,支持大坐标(>1e14) - in_circle 扩展精度 容差系统: 单级 → 分层 - Tolerance::tighten/relax 继承 - Tolerance::min 合并取更严格 - ToleranceScope 作用域临时容差 - 预设容差级别: Modeling/Fitting/Intersection/Snapping 文档: 新增 06-精度提升方案调研 (252行) - 6种主流精度方案对比 - Parasolid/ACIS/OCCT/CGAL 商业内核解密 - VDE v0.6-v2.0 精度提升路线图
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
#pragma once
|
|
#include <Eigen/Core>
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
namespace vde::foundation {
|
|
|
|
/// 分层容差:支持全局 + 局部覆盖
|
|
class Tolerance {
|
|
public:
|
|
Tolerance(double absolute = 1e-6, double relative = 1e-8,
|
|
double angular = 1e-8, double snapping = 1e-4)
|
|
: absolute_(absolute), relative_(relative),
|
|
angular_(angular), snapping_(snapping) {}
|
|
|
|
// ── 判定 ──
|
|
bool points_equal(const Eigen::MatrixXd& a, const Eigen::MatrixXd& b) const {
|
|
return (a - b).norm() < absolute_;
|
|
}
|
|
|
|
template <typename T>
|
|
bool is_zero(T value) const {
|
|
return std::abs(value) < absolute_;
|
|
}
|
|
|
|
template <typename T>
|
|
bool equals(T a, T b) const {
|
|
return std::abs(a - b) < absolute_ + relative_ * std::max(std::abs(a), std::abs(b));
|
|
}
|
|
|
|
double absolute() const { return absolute_; }
|
|
double relative() const { return relative_; }
|
|
double angular() const { return angular_; }
|
|
double snapping() const { return snapping_; }
|
|
|
|
// ── 分层容差:继承并收紧 ──
|
|
Tolerance tighten(double factor = 0.1) const {
|
|
return Tolerance(absolute_ * factor, relative_ * factor, angular_ * factor, snapping_ * factor);
|
|
}
|
|
|
|
Tolerance relax(double factor = 10.0) const {
|
|
return Tolerance(absolute_ * factor, relative_ * factor, angular_ * factor, snapping_ * factor);
|
|
}
|
|
|
|
// ── 合并:取更严格的那个 ──
|
|
static Tolerance min(const Tolerance& a, const Tolerance& b) {
|
|
return Tolerance(std::min(a.absolute_, b.absolute_),
|
|
std::min(a.relative_, b.relative_),
|
|
std::min(a.angular_, b.angular_),
|
|
std::min(a.snapping_, b.snapping_));
|
|
}
|
|
|
|
// ── 全局实例 ──
|
|
static Tolerance& global() { return global_; }
|
|
static void set_global(const Tolerance& tol) { global_ = tol; }
|
|
|
|
// ── 默认建模容差等级 ──
|
|
static constexpr double Modeling() { return 1e-6; } // 建模级
|
|
static constexpr double Fitting() { return 1e-3; } // 拟合级
|
|
static constexpr double Intersection() { return 1e-8; } // 求交级
|
|
static constexpr double Snapping() { return 1e-4; } // 吸附级
|
|
|
|
private:
|
|
double absolute_;
|
|
double relative_;
|
|
double angular_;
|
|
double snapping_;
|
|
static Tolerance global_;
|
|
};
|
|
|
|
/// 局部容差堆栈:支持作用域内的临时容差
|
|
class ToleranceScope {
|
|
public:
|
|
explicit ToleranceScope(const Tolerance& tol) : previous_(Tolerance::global()) {
|
|
Tolerance::set_global(tol);
|
|
}
|
|
~ToleranceScope() { Tolerance::set_global(previous_); }
|
|
private:
|
|
Tolerance previous_;
|
|
};
|
|
|
|
} // namespace vde::foundation
|