Repository navigation
Commit 3d236b1
authored
Internal cleanup + numerical robustness fixes (#4)
* refactor: tolerance policy, dedupe numerics, rustdoc
Internal cleanup; no behavior or API change (cross-validation against the
Python reference and an A/B benchmark against main confirm identical
results and equal-or-better performance).
- Add src/tolerances.rs: every fuzzy comparison now goes through a named,
documented constant (BARYCENTRIC_EPS, CIRCUMCIRCLE_RTOL,
DEGENERATE_VOLUME_EPS, VOLUME_CONSERVATION_ATOL/RTOL,
ORIENTATION_LOG_DET_CUTOFF) stating whether it is scale-invariant and
why. Replaces the multi-purpose DEFAULT_EPS and scattered literals.
- Dedupe the barycentric solve (was written three times) into
geometry::barycentric_coordinates, generic over AsRef<[f64]> so the
triangulation passes vertex references without cloning.
- Dedupe the reduced-simplex threshold logic shared by the core and the
signed-index Python wrapper into reduced_simplex_positions.
- Dedupe face-multiplicity counting (bowyer_watson / extend_hull / hull)
into Triangulation::face_multiplicities.
- Reuse triangulation::numpy_linalg_error in lib.rs instead of a copy.
- Recover the last_simplex location cache from RwLock poisoning instead
of panicking across the FFI boundary; collapse redundant into_pyerr
match arms; drop an unnecessary coords clone in the constructor.
- Rustdoc for the crate, both modules, and all public items
(cargo doc builds warning-free).
* fix: scale-aware degeneracy filter and orphan-free insertion in 2D+
Two deliberate behavior divergences from the Python reference, in regimes
where the reference corrupts its own state. Cross-validation on
well-conditioned inputs is unaffected (all parity tests still pass).
- simplex_is_numerically_degenerate: drop a Bowyer-Watson candidate only
when its volume is negligible BOTH absolutely (the reference's
criterion, which keeps volume conservation safe) AND as scale-invariant
flatness. The absolute test alone silently emptied finely refined or
small-coordinate meshes (inserting into a [0, 1e-4]^2 mesh deleted
every simplex and orphaned all vertices); the flatness test alone
(briefly used here for 1D) deletes large-but-flat simplices the cavity
needs. The conjunction also subsumes the previous 1D special case.
- bowyer_watson now collects the cavity without mutating, and rejects the
insertion as 'Point already in triangulation.' when it would strand a
cavity vertex (a point within the circumcircle slack of every simplex
around an existing vertex - previously this silently orphaned the
vertex). add_point rolls back the pushed vertex/hull extension on these
pre-mutation rejections.
- New regression tests for both, plus a parametrized 2D/3D off-origin
small-scale insertion sweep (the class of test whose absence hid the
PR #3 bugs).
Known limitation, now documented in tolerances.rs: point sets mixing
widely separated coordinate scales in one triangulation create ~1e7
aspect-ratio slivers whose circumsphere tests are unreliable; the volume
conservation assertion catches this loudly. The Python reference fails
the same stress more often (41/50 runs vs 33/50 here); a real fix needs
exact geometric predicates.1 parent cf1b37d commit 3d236b1
5 files changed
Lines changed: 535 additions & 169 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
4 | 14 | | |
5 | 15 | | |
| 16 | + | |
6 | 17 | | |
7 | 18 | | |
| 19 | + | |
8 | 20 | | |
9 | 21 | | |
| 22 | + | |
10 | 23 | | |
11 | 24 | | |
12 | 25 | | |
13 | 26 | | |
| 27 | + | |
14 | 28 | | |
15 | 29 | | |
16 | 30 | | |
| |||
113 | 127 | | |
114 | 128 | | |
115 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
116 | 133 | | |
117 | 134 | | |
118 | 135 | | |
| |||
139 | 156 | | |
140 | 157 | | |
141 | 158 | | |
| 159 | + | |
142 | 160 | | |
143 | 161 | | |
144 | 162 | | |
145 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
146 | 191 | | |
147 | 192 | | |
148 | 193 | | |
| |||
165 | 210 | | |
166 | 211 | | |
167 | 212 | | |
| 213 | + | |
| 214 | + | |
168 | 215 | | |
169 | 216 | | |
170 | 217 | | |
| |||
191 | 238 | | |
192 | 239 | | |
193 | 240 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 241 | + | |
207 | 242 | | |
208 | 243 | | |
209 | 244 | | |
| 245 | + | |
| 246 | + | |
210 | 247 | | |
211 | 248 | | |
212 | 249 | | |
| |||
228 | 265 | | |
229 | 266 | | |
230 | 267 | | |
| 268 | + | |
| 269 | + | |
231 | 270 | | |
232 | 271 | | |
233 | 272 | | |
| |||
258 | 297 | | |
259 | 298 | | |
260 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
261 | 305 | | |
262 | 306 | | |
263 | 307 | | |
| |||
371 | 415 | | |
372 | 416 | | |
373 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
374 | 422 | | |
375 | 423 | | |
376 | 424 | | |
| |||
384 | 432 | | |
385 | 433 | | |
386 | 434 | | |
387 | | - | |
| 435 | + | |
388 | 436 | | |
389 | 437 | | |
390 | 438 | | |
| |||
393 | 441 | | |
394 | 442 | | |
395 | 443 | | |
| 444 | + | |
| 445 | + | |
396 | 446 | | |
397 | 447 | | |
398 | 448 | | |
| |||
413 | 463 | | |
414 | 464 | | |
415 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
416 | 470 | | |
417 | 471 | | |
418 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
| 7 | + | |
2 | 8 | | |
3 | 9 | | |
4 | 10 | | |
| |||
7 | 13 | | |
8 | 14 | | |
9 | 15 | | |
10 | | - | |
11 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
12 | 19 | | |
13 | 20 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 21 | | |
26 | 22 | | |
27 | 23 | | |
| |||
126 | 122 | | |
127 | 123 | | |
128 | 124 | | |
129 | | - | |
| 125 | + | |
130 | 126 | | |
131 | 127 | | |
132 | 128 | | |
| |||
152 | 148 | | |
153 | 149 | | |
154 | 150 | | |
155 | | - | |
| 151 | + | |
156 | 152 | | |
157 | 153 | | |
158 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments