Repository navigation
Commit ce43abf
authored
Core data-structure overhaul: interned simplices, facet adjacency, incremental hull (#5)
* refactor: split PyO3 surface out of triangulation.rs into src/py.rs
Pure mechanical move, no logic changes: the pure-Rust Triangulation core
stays in src/triangulation.rs; argument parsing, result conversion,
TriangulationError::into_pyerr, the proxy/iterator views, and the
PyTriangulation class move to the new src/py.rs. Prepares for reworking
the core data structures without PyO3 noise in the diff.
* perf: intern simplices, maintain facet adjacency and hull incrementally
Replace the FxHashSet<Vec<usize>>-everywhere layout (which cloned and
re-hashed whole simplices in every hot path) with interned storage:
- a slab assigns each simplex a small integer SimplexId; the sorted
vertex list is stored once and referenced by id everywhere else
- vertex_to_simplices becomes vertex -> FxHashSet<SimplexId> (integer
sets instead of sets of cloned Vecs)
- a new facet index maps every (dim-1)-face to the ids of its incident
simplices, maintained by the single link/unlink pair of mutation
primitives, together with the derived boundary-facet set (hull) and
an overfull-facet count (corruption detector)
This turns the hot paths from set intersections over cloned vectors
into single hash lookups:
- locate_point walk steps and containing() facet queries are one
facet-map lookup
- the bowyer_watson cascade finds neighbours via dim+1 facet lookups
instead of unioning and scanning every simplex around all vertices
- extend_hull reads the maintained boundary set instead of recounting
every face of every simplex per outside-hull insertion (was the
O(n^2) bottleneck for hull-heavy workloads), and hull() is O(hull)
- reference_invariant() now also cross-checks the facet index,
boundary set, and overfull count against a recount
Behavior is unchanged: the full pytest cross-validation suite against
the Python reference passes, and stress sweeps (mixed-scale,
off-origin, near-duplicate, random) show the same pass/fail profile
as main. A/B benchmark (best of 3, same machine, incremental
insertion): 2D 5000 pts 0.296s -> 0.143s, 3D 2000 pts 0.540s ->
0.163s, 4D 500 pts 1.959s -> 0.241s, hull-heavy 2D 3000 pts 3.271s ->
1.058s, hull-heavy 3D 1500 pts 3.395s -> 0.698s.1 parent 3d236b1 commit ce43abf
6 files changed
Lines changed: 1377 additions & 1035 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | | - | |
76 | | - | |
77 | | - | |
| 74 | + | |
78 | 75 | | |
79 | 76 | | |
80 | 77 | | |
| |||
101 | 98 | | |
102 | 99 | | |
103 | 100 | | |
104 | | - | |
| 101 | + | |
105 | 102 | | |
106 | 103 | | |
107 | 104 | | |
| |||
130 | 127 | | |
131 | 128 | | |
132 | 129 | | |
133 | | - | |
| 130 | + | |
134 | 131 | | |
135 | 132 | | |
136 | 133 | | |
| |||
191 | 188 | | |
192 | 189 | | |
193 | 190 | | |
194 | | - | |
| 191 | + | |
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
0 commit comments