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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Core configuration, error types, and numeric constants for geometry repair.
//!
//! Provides [`MakeValidConfig`] for fine-grained control over the repair
//! strategy, [`PolyMethod`] to select the polygon repair algorithm, and
//! [`MakeValidError`] as the crate's unified error type for repair,
//! validation, WKB parsing, and I/O operations.
//!
//! Also defines internal numeric constants used across the crate for
//! epsilon comparisons, grid thresholds, and snap scaling.
use FillRule;
use Error;
use crateCrs;
// ---------------------------------------------------------------------------
// Numeric constants
// ---------------------------------------------------------------------------
/// Default geometric epsilon for robust equality / zero checks.
pub const EPS: f64 = 1e-12;
/// Epsilon for parametric (t/u) intersection comparisons.
pub const EPS_PARAM: f64 = 1e-14;
/// Vertex count threshold above which grid-based spatial indexing is used
/// instead of brute-force O(n²) checks for self-intersection detection
/// and edge splitting. At n=2000 the brute-force 2M pair checks completes
/// in ~5ms for most geometries, well below the cost of grid construction.
pub const GRID_THRESHOLD_N: usize = 2000;
/// Maximum total vertices for the fast-path validity check in fix_polygon.
/// Larger polygons fall through to the full repair pipeline.
pub const FAST_PATH_MAX_VERTS: usize = 50000;
/// Snap scale factor for integer-keyed graph construction.
pub const SNAP_SCALE: f64 = 1e8;
// ---------------------------------------------------------------------------
// Config
// ---------------------------------------------------------------------------
/// Configuration for geometry repair operations.
///
/// Controls which polygon repair strategy to use, whether collapsed
/// geometries should be kept, and CRS-aware tolerance settings.
///
/// # Default
///
/// ```rust
/// use geo_repair::MakeValidConfig;
///
/// let config = MakeValidConfig::default();
/// // Equivalent to:
/// // poly_method: PolyMethod::Auto,
/// // keep_collapsed: false,
/// // fill_rule: FillRule::EvenOdd,
/// // crs: None,
/// // target_crs: None,
/// ```
/// Polygon repair strategy selector.
///
/// Controls which algorithm is used for polygon repair.
///
/// - [`Auto`](PolyMethod::Auto): Try Structure first (fast path), fall back
/// to Arrange for complex topology
/// - [`Structure`](PolyMethod::Structure): Planar graph fast path only
/// - [`Arrange`](PolyMethod::Arrange): CDT triangulation only
///
/// See the [`structure`](crate::structure) and [`arrange`](crate::arrange)
/// module docs for algorithm details.
// ---------------------------------------------------------------------------
// Errors
// ---------------------------------------------------------------------------
/// Errors that can occur during geometry repair, validation, or I/O.
///
/// This is the crate's unified error type, used by repair, validation,
/// WKB parsing, and all I/O backends.
///
/// # Feature gating
///
/// The `std::error::Error` impl is only available when the `std` feature
/// is enabled. In no_std mode, only `Display` is available.