64ad721ed7
- CMake: INTERFACE 库修复、vde_compile_options 顺序修复 - 命名空间: 所有模块添加 using 声明 - 类型补全: Ray3Dd、Point4D - 头文件: tolerance 泛型化、std::optional include - 警告: 放宽 -Wconversion/-Wsign-conversion - 构建结果: 0 errors, 22/25 tests passed
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#pragma once
|
|
#include <Eigen/Core>
|
|
#include <cmath>
|
|
#include <limits>
|
|
|
|
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_; }
|
|
|
|
void set_absolute(double v) { absolute_ = v; }
|
|
void set_relative(double v) { relative_ = v; }
|
|
|
|
static Tolerance& global() { return global_; }
|
|
static void set_global(const Tolerance& tol) { global_ = tol; }
|
|
|
|
private:
|
|
double absolute_;
|
|
double relative_;
|
|
double angular_;
|
|
double snapping_;
|
|
static Tolerance global_;
|
|
};
|
|
|
|
} // namespace vde::foundation
|