feat: v0.6.0 精度提升 — Shewchuk Level C + 分层容差 + 业内方案调研
精确谓词: 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 精度提升路线图
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
#include <Eigen/Core>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace vde::foundation {
|
||||
|
||||
/// 分层容差:支持全局 + 局部覆盖
|
||||
class Tolerance {
|
||||
public:
|
||||
Tolerance(double absolute = 1e-6, double relative = 1e-8,
|
||||
@@ -12,6 +14,7 @@ public:
|
||||
: 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_;
|
||||
}
|
||||
@@ -31,12 +34,33 @@ public:
|
||||
double angular() const { return angular_; }
|
||||
double snapping() const { return snapping_; }
|
||||
|
||||
void set_absolute(double v) { absolute_ = v; }
|
||||
void set_relative(double v) { relative_ = v; }
|
||||
// ── 分层容差:继承并收紧 ──
|
||||
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_;
|
||||
@@ -45,4 +69,15 @@ private:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user