Sparse spatially-indexed layer ordering #57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "worktree-spatial-layers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Replaces
Fold_state's denserel array arraylayer-ordering matrix with a sparse structure built by an exact sweep-and-prune broad phase, so distributed fold patterns (tessellations) evaluate sub-quadratically per fold. Output is byte-identical.A scaling probe this session measured the dense build at O(faces²) per fold — ~0.37s at 256 faces, 1.5s at 512, 6s at 1024, 24s at 2048 — capping practical folded programs at ~1–2k faces. The matrix stored
n²entries andbuild_orderranGeom.convex_overlapon everyi<jpair, even though a tessellation's faces overlap only locally.New
lib/layer_order.mlstores only overlapping pairs (absent = not overlapping; present-with-Apart= the tortilla-tortilla case) and builds them with a sweep-and-prune over exactNumbounding boxes: sort by bboxxmin, sweep an active set, and run the exactGeom.convex_overlaponly on bbox-overlapping candidates. The spatial index only culls candidates — no float in the decision, and it can never drop a real overlap — so the relation, and every.foldoutput, is unchanged.Fold_state.orderbecomes aLayer_order.t;validity_error,subdivide,fold_with_records,flip,topmost_preimageandfold_emit's faceOrders migrate to the sparse API.For distributed patterns this drops the per-fold order build from O(faces²) to O(faces log faces), lifting the practical ceiling from ~2k toward tens of thousands of faces. A fully-overlapping stack (repeated in-place folding) genuinely has O(faces²) relations and is unchanged — inherent, and rare in real origami.
Byte-identical is not just the goldens passing (23/23): both build paths call
rel_ofon the same canonicali<jpairs, andfold_emitkeeps its nested loop reading viaLayer_order.get, so every relation and the faceOrders emission order are reproduced by construction.New:
Layer_orderunit tests (sweep-and-prune vs an O(n²) reference; the absent-vs-Apartinvariant) and aSlowscaling guard that separates the new sparse build (~4.3× on doubling N) from the old dense scan (~8×).Also drops the committed
scratch/directory (first commit): the #56 squash force-added it, and itsscratch/dunereferenced gitignored files that never landed, breakingdune buildon a fresh checkout.scratch/is gitignored throwaway; the spike findings live innotes/.Full suite green, goldens byte-identical.
https://claude.ai/code/session_01TinroyhVWz1RBZtXMZoLdd