1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Centralized epsilon and tolerance constants for numeric stability.
//!
//! This module defines all epsilon and tolerance values used throughout the library
//! to ensure consistent handling of floating-point precision across geometric algorithms.
//!
//! # Epsilon Hierarchy
//!
//! - `DIVISION_EPSILON` (1e-12): Guards near-zero denominators in degenerate geometry
//! - `GEOMETRIC_EPSILON` (1e-10): Threshold for geometric predicates and tolerance tests
//!
//! For reference, f64::EPSILON (~2.22e-16) is the machine precision limit but is not
//! directly used since geometric operations require much larger tolerances.
/// Geometric epsilon for tolerance in geometric predicates and comparisons.
/// Used for detecting collinearity, near-tangency, coincident points, and similar conditions.
/// This is larger than machine epsilon to account for accumulated floating-point errors
/// in geometric computations.
pub const GEOMETRIC_EPSILON: f64 = 1e-10;
/// Epsilon for guarding division operations to prevent division by near-zero values.
/// Used before dividing by computed values that might be near zero due to degenerate geometry
/// (e.g., line directions with very small magnitude, perpendicular distances near zero).
///
/// This is smaller than GEOMETRIC_EPSILON because we want to allow divisions by values
/// slightly smaller than geometric tolerance, but still guard against truly degenerate cases.
pub const DIVISION_EPSILON: f64 = 1e-12;
/// Tolerance for collinearity detection in segment-segment and point-line tests.
/// Points or lines that are collinear within this tolerance are treated as collinear.
pub const COLLINEARITY_TOLERANCE: f64 = GEOMETRIC_EPSILON; // 1e-10
/// Tolerance for detecting nearly identical circles (same center and radius within tolerance).
/// Used to handle degenerate cases where two circles are effectively the same.
pub const CIRCLE_TOLERANCE: f64 = GEOMETRIC_EPSILON; // 1e-10
/// Tolerance for detecting coincident or nearly identical points.
/// Used when checking if two points are effectively the same location.
pub const POINT_TOLERANCE: f64 = GEOMETRIC_EPSILON; // 1e-10