pub struct Tolerance {
pub linear: f64,
pub angular: f64,
pub relative: f64,
}Expand description
Tolerance thresholds for geometric comparisons.
Fields§
§linear: f64Absolute tolerance for linear (distance) comparisons.
angular: f64Absolute tolerance for angular (radian) comparisons.
relative: f64Relative tolerance as a fraction of the larger operand.
Used by approx_eq to scale comparisons:
|a - b| <= max(linear, relative * max(|a|, |b|)).
Implementations§
Source§impl Tolerance
impl Tolerance
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Sensible defaults for CAD geometry.
Linear: 1e-7, angular: 1e-12, relative: 1e-10.
Sourcepub const fn loose() -> Self
pub const fn loose() -> Self
A looser tolerance for visualization or rough checks.
Linear: 1e-4, angular: 1e-8, relative: 1e-6.
Sourcepub const fn tight() -> Self
pub const fn tight() -> Self
A tighter tolerance for high-precision operations.
Linear: 1e-10, angular: 1e-15, relative: 1e-14.
Sourcepub fn approx_eq(self, a: f64, b: f64) -> bool
pub fn approx_eq(self, a: f64, b: f64) -> bool
Scale-aware approximate equality.
Returns true when |a - b| <= max(linear, relative * max(|a|, |b|)).
This ensures comparisons remain meaningful at any coordinate magnitude.
Sourcepub fn approx_eq_abs(self, a: f64, b: f64) -> bool
pub fn approx_eq_abs(self, a: f64, b: f64) -> bool
Purely absolute approximate equality (ignores relative).
Use this when comparing values that are not coordinates, e.g.
parameter-space values in [0, 1] where relative scaling is wrong.
Sourcepub fn parametric(self, derivative_mag: f64) -> f64
pub fn parametric(self, derivative_mag: f64) -> f64
Convert the linear tolerance to parameter space given the magnitude of a surface derivative (or curve tangent).
The parametric tolerance is linear / derivative_magnitude, so a
surface with ||∂S/∂u|| = 1000 and linear tolerance 1e-7 gives
parametric tolerance 1e-10.
Clamps to [1e-15, 0.1] to prevent degeneracy.