Commit 17857e94f2

17857e94f27f4275beebfe1b36d975ee4fc86a32

parent: 6793c5e4d7

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-19 20:20 UTC

Decide option A: axis tree for rigid steps, flagged non-rigid steps

Records the decision, measures how densely solved curves must be sampled,
adds Task 0b and batch A2, and amends Tasks 1, 3, 4, 6, 7, 8 and 15 and
the design doc's interpolation section.

Ref #1

Layout: unified · split

docs/decisions/0001-interpolation-model.md +47 −18
@@ -1,8 +1,11 @@
1# 0001 — Interpolation model 1# 0001 — Interpolation model
2 2
3**Status:** measured. Task 0's stop condition is met (the crane's reverse 3**Status:** decided 2026-10-19 — **option A**. Rigid steps use M2 with
4folds have no rigid model that matches the fold), so the choice below is the 4per-axis windows on *t*. Reverse folds, sinks and inversions are flagged
5author's. Task 1 does not start until it is made. 5non-rigid and animated by a model Task 0b chooses, which also settles the
6petal fold, the sampan's inversion and the masu's wall-raising. Task 0's stop
7condition was met (the crane's reverse folds have no rigid model that matches
8the fold); this choice resolves it.
6 9
7## Question 10## Question
8 11
@@ -38,10 +41,27 @@ contact.
38|---|---|---|---| 41|---|---|---|---|
39| 1. Letter fold, both thirds valley, one step | exact (gap 9e-16) | — | flaps meet at 120.2°. Staggered (one flap on *t* 0–0.5, the other on 0.5–1): none | 42| 1. Letter fold, both thirds valley, one step | exact (gap 9e-16) | — | flaps meet at 120.2°. Staggered (one flap on *t* 0–0.5, the other on 0.5–1): none |
40| 2. Letter fold, one valley, one mountain | exact | — | none | 43| 2. Letter fold, one valley, one mountain | exact | — | none |
41| 3. Flat-foldable degree-4 vertex (60°, 80°, 120°, 100°) | tears: gap 1.08–1.38 on a sheet of side 2 | M2 exact (4e-12). Opposite creases pair up; the pairs follow tan(ρ₁/2) = 0.347·tan(ρ₂/2): at the driven crease's 45°, 90°, 135° the other pair is at 16.4°, 38.3°, 80.0° | — | 44| 3. Flat-foldable degree-4 vertex (60°, 80°, 120°, 100°) | tears: gap 1.08–1.38 on a sheet of side 2 | M2 exact (4e-12). Opposite creases pair up; the pairs follow tan(ρ₁/2) = k·tan(ρ₂/2) with k = cos((α+β)/2) / cos((α−β)/2) = 0.3473: at the driven crease's 45°, 90°, 135° the other pair is at 16.4°, 38.3°, 80.0° | — |
42| 4. Inside reverse fold, two-layer flap, rest of the flap held | — | no rigid motion reaches it with the flap closed (below) | — | 45| 4. Inside reverse fold, two-layer flap, rest of the flap held | — | no rigid motion reaches it with the flap closed (below) | — |
43| 5. Petal fold of a preliminary base | inconclusive (below) | inconclusive | — | 46| 5. Petal fold of a preliminary base | inconclusive (below) | inconclusive | — |
44 47
48### Sampling a solved curve
49
50`foldc` writes a solved curve as samples. Rebuilding case 3's curves from
51N + 1 samples and measuring the tear between them (sheet of side 2):
52
53| N | linear | cubic Hermite, central-difference tangents |
54|---|---|---|
55| 16 | 1.0e-2 | 1.1e-3 |
56| 32 | 2.5e-3 | 1.2e-4 |
57| 64 | 6.3e-4 | 1.5e-5 |
58| 128 | 1.6e-4 | 1.8e-6 |
59| 256 | 3.9e-5 | 2.3e-7 |
60
61Cubic converges about eight times per halving. 257 samples keep the tear
62under 1e-6 on this sheet; `foldc` checks each curve at four times its sample
63density and refines a curve that does not.
64
45### Case 4 in detail 65### Case 4 in detail
46 66
47Sheet 4×2 folded on its spine y = 1; reverse-fold creases from (2, 1) to 67Sheet 4×2 folded on its spine y = 1; reverse-fold creases from (2, 1) to
@@ -159,27 +179,34 @@ the anti-goal "a fold that snaps".
159folds or sinks. Most traditional animals use reverse folds; the crane is the 179folds or sinks. Most traditional animals use reverse folds; the crane is the
160model most people will open the app for. 180model most people will open the app for.
161 181
162## If A is chosen: plan changes 182## Plan changes made for option A
163 183
164- **Task 0b** (new, before Task 1): bending model for reverse folds; verified 184- **Task 0b** (new, before Task 1, batch A2): a model for non-rigid steps and
165 bird base; sampan inversion; masu raise. Its decision record sets the 185 its strain bound, a verified bird base for the petal fold, the sampan's
166 strain bound. 186 inversion and the masu's wall-raising. Record 0002.
167- **Task 1:** `AxisRecord` gains `parent: Int?` (the axis whose motion carries 187- **Task 1:** `AxisRecord` gains `parent: Int?` (the axis whose motion carries
168 it), `window: [Double]?` (its span of *t*, default `[0, 1]`) and 188 it), `window: [Double]?` (its span of *t*, default `[0, 1]`) and
169 `angles: [Double]?` (a solved curve sampled on its window; absent means 189 `angles: [Double]?` (a solved curve, 257 samples over its window; absent
170 linear). `StepRecord` gains `nonRigid: Bool`. 190 means linear). `StepRecord` gains `nonRigid: Bool`; Task 0b adds what a
171- **Task 3:** `FoldAxis` carries the same; `readSteps` builds the tree. 191 non-rigid step needs beyond the flag.
192- **Task 3:** `FoldAxis` carries the same; `readSteps` builds the tree and
193 rejects a parent cycle or a window outside 0…1.
172- **Task 4:** `positions(at:)` composes rotations down the tree, using each 194- **Task 4:** `positions(at:)` composes rotations down the tree, using each
173 axis's curve. Add case 3 as a fixture to the isometry sweep, and a 195 axis's window and curve (cubic Hermite between samples). The isometry
174 staggered letter fold to the interpenetration tests. 196 sweep adds case 3's vertex, built in code with curves from the closed form.
175- **Task 7:** `foldc` solves each coupled step's curves by the same method as 197- **Task 6:** a staggered letter fold is clean where the simultaneous one
176 the spike and writes them; the script names a step's driving crease. 198 collides.
177- **Task 2:** the overlapping-moving-sets rule is removed, if the author 199- **Task 7:** `foldc` solves each coupled step's curves by the spike's method
178 agrees. 200 and writes them; the script may name a step's driving crease and give
201 creases windows.
202- **Task 8:** the catalogue's isometry sweep exempts flagged steps, which are
203 held to Task 0b's bound instead.
204- **Task 2:** unchanged. Removing the overlapping-moving-sets rule (point 5
205 above) is a separate decision, still open.
179 206
180## Appendix: spike output 207## Appendix: spike output
181 208
182See `spikes/interpolation`; the run that produced the numbers above: 209`swift run -c release --package-path spikes/interpolation`:
183 210
184``` 211```
185## Case 1 — letter fold, both flaps valley 212## Case 1 — letter fold, both flaps valley
@@ -193,6 +220,8 @@ See `spikes/interpolation`; the run that produced the numbers above:
193- M1, all four angles linear to the assignment with the odd crease at 60°: max gap 1.08e0 on a sheet of side 2 220- M1, all four angles linear to the assignment with the odd crease at 60°: max gap 1.08e0 on a sheet of side 2
194- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: −): max gap 4.19e-12; angles (0°, 60°, 140°, 260°) at t = 0.25: 45.0, -16.4, 45.0, 16.4; 0.5: 90.0, -38.3, 90.0, 38.3; 0.75: 135.0, -80.0, 135.0, 80.0; 1: 180.0, -180.0, 180.0, 180.0 221- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: −): max gap 4.19e-12; angles (0°, 60°, 140°, 260°) at t = 0.25: 45.0, -16.4, 45.0, 16.4; 0.5: 90.0, -38.3, 90.0, 38.3; 0.75: 135.0, -80.0, 135.0, 80.0; 1: 180.0, -180.0, 180.0, 180.0
195- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: +): max gap 4.19e-12; angles (0°, 60°, 140°, 260°) at t = 0.25: 45.0, -16.4, 45.0, 16.4; 0.5: 90.0, -38.3, 90.0, 38.3; 0.75: 135.0, -80.0, 135.0, 80.0; 1: 180.0, -180.0, 180.0, 180.0 222- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: +): max gap 4.19e-12; angles (0°, 60°, 140°, 260°) at t = 0.25: 45.0, -16.4, 45.0, 16.4; 0.5: 90.0, -38.3, 90.0, 38.3; 0.75: 135.0, -80.0, 135.0, 80.0; 1: 180.0, -180.0, 180.0, 180.0
223- closed form tan(ρ₁/2) = k·tan(ρ₂/2), k = cos((α+β)/2) / cos((α−β)/2) = 0.3473 for α = 60°, β = 80°
224- solved curves sampled at N + 1 points and interpolated, max gap on a sheet of side 2: N = 16: linear 1.0e-2, cubic 1.07e-3; N = 32: linear 2.49e-3, cubic 1.22e-4; N = 64: linear 6.27e-4, cubic 1.49e-5; N = 128: linear 1.57e-4, cubic 1.83e-6; N = 256: linear 3.92e-5, cubic 2.25e-7
196 225
197## Case 4 — inside reverse fold, 4×2 sheet folded on its spine y = 1 226## Case 4 — inside reverse fold, 4×2 sheet folded on its spine y = 1
198- start gap 0. Body spine and tip spine start at 180, reverse creases A (upper layer) and B (lower layer) at 0. Angles below are measured from the geometry and unwrapped, so a value past ±180 means a face went through its neighbour at the hinge. 227- start gap 0. Body spine and tip spine start at 180, reverse creases A (upper layer) and B (lower layer) at 0. Angles below are measured from the geometry and unwrapped, so a value past ±180 means a face went through its neighbour at the hinge.
docs/superpowers/plans/2026-10-19-fold.md +163 −29
@@ -4,7 +4,7 @@
4 4
5**Goal:** An iOS app that folds traditional origami models under your finger and generates their Yoshizawa–Randlett diagrams from the same data, so the diagram and the model cannot disagree. 5**Goal:** An iOS app that folds traditional origami models under your finger and generates their Yoshizawa–Randlett diagrams from the same data, so the diagram and the model cannot disagree.
6 6
7**Architecture:** A model is one FOLD file whose `file_frames` are its steps, sharing one topology: frame 0 is the sheet already subdivided by every crease the sequence will use. Each frame carries an authored `krz:step` naming its kind, technique, instruction, axes, moving sets and viewpoint. Intermediate geometry is rigid rotation of the moving facets on one parameter the finger drives; how coupled multi-axis steps move is decided by measurement in Task 0 before anything encodes it. Draw order is hybrid — the depth buffer between clusters of near-coplanar overlapping faces, the active `faceOrders` within each. The frames are produced by a macOS fold-script compiler that ships with the repo but not in the app. 7**Architecture:** A model is one FOLD file whose `file_frames` are its steps, sharing one topology: frame 0 is the sheet already subdivided by every crease the sequence will use. Each frame carries an authored `krz:step` naming its kind, technique, instruction, axes, moving sets and viewpoint. Intermediate geometry is rigid rotation of the moving facets on one parameter the finger drives: a step's axes form a tree, each with its own window on that parameter and, where faces form loops, an angle curve `foldc` solves (decision 0001). Reverse folds, sinks and inversions have no rigid path and are flagged non-rigid, moving by the model Task 0b chooses. Draw order is hybrid — the depth buffer between clusters of near-coplanar overlapping faces, the active `faceOrders` within each. The frames are produced by a macOS fold-script compiler that ships with the repo but not in the app.
8 8
9**Tech Stack:** Swift 6, iOS 26, SwiftUI, Metal, `simd`, Swift Testing, XcodeGen. No third-party runtime dependencies in the app. 9**Tech Stack:** Swift 6, iOS 26, SwiftUI, Metal, `simd`, Swift Testing, XcodeGen. No third-party runtime dependencies in the app.
10 10
@@ -26,7 +26,8 @@
26- **One topology across every frame.** Enforced by the decoder and the validator. 26- **One topology across every frame.** Enforced by the decoder and the validator.
27- **Steps are authored, never derived from a frame diff.** That includes `instruction`, which is the accessibility label. 27- **Steps are authored, never derived from a frame diff.** That includes `instruction`, which is the accessibility label.
28- **`turnOver` and `rotate` change the coordinates.** Frame n is frame n − 1 rotated about its bounding-box centre; the camera does not move. 28- **`turnOver` and `rotate` change the coordinates.** Frame n is frame n − 1 rotated about its bounding-box centre; the camera does not move.
29- Paper is rigid flat facets hinged at straight creases. No bending, stiffness, self-collision response or crumpling. 29- Paper is rigid flat facets hinged at straight creases, except during a step flagged `nonRigid`. No stiffness, self-collision response or crumpling.
30- **Interpolation (decision 0001, option A).** A step's axes form a tree: an axis may name a parent axis whose motion carries it. Each axis has a window on *t* (default 0…1) and either a linear angle or a solved curve of 257 samples, rebuilt by cubic Hermite interpolation. Steps whose technique has no rigid path — inside and outside reverse folds, sinks, inversions — carry `nonRigid: true`; the isometry gate does not apply to them and Task 0b's strain bound does.
30- Layer order is authored, never computed. Corrections to the compiler's guess live in the fold script. 31- Layer order is authored, never computed. Corrections to the compiler's guess live in the fold script.
31- v1 ships **four** traditional models: the cup, the crane, the sampan and the box (the masu). Every `file_author` is exactly `"Traditional"`, enforced by the validator. 32- v1 ships **four** traditional models: the cup, the crane, the sampan and the box (the masu). Every `file_author` is exactly `"Traditional"`, enforced by the validator.
32- Every shipped model is produced by `foldc` from a committed crease pattern and fold script, and recompiling them reproduces the shipped file (structurally, coordinates within 1e-12). Hand-edited `.fold` files are not shipped. 33- Every shipped model is produced by `foldc` from a committed crease pattern and fold script, and recompiling them reproduces the shipped file (structurally, coordinates within 1e-12). Hand-edited `.fold` files are not shipped.
@@ -38,7 +39,7 @@
38 39
39## Review Focus 40## Review Focus
40 41
411. **A step with several simultaneous axes.** A petal fold and a reverse fold move several facet sets about several creases at once on one shared parameter, and their faces form closed loops around interior vertices. The interpolation model for these is measured in Task 0 and implemented in Task 4; the axis records are read in Task 3. 421. **A step with several simultaneous axes.** A petal fold moves several facet sets about several creases at once on one shared parameter; where faces form closed loops around interior vertices the angles are coupled nonlinearly, and some axes are carried by others. Decision 0001 settled the model; the axis tree, windows and curves are read in Task 3, applied in Task 4 and solved in Task 7. Steps with no rigid path are Task 0b's.
422. **Two facets that are both moving.** The end frame's ordering does not order two simultaneously moving sets against each other during the motion. Such a step must carry `krz:faceOrders_midFold` or be rejected. Test in Task 2. Task 0 also reports whether this rule has a consumer the clusters do not already cover. 432. **Two facets that are both moving.** The end frame's ordering does not order two simultaneously moving sets against each other during the motion. Such a step must carry `krz:faceOrders_midFold` or be rejected. Test in Task 2. Task 0 also reports whether this rule has a consumer the clusters do not already cover.
433. **Coplanar stacked facets, and orbiting underneath.** The depth buffer cannot order coplanar or nearly coplanar facets, and `faceOrders`'s `s` sign reverses when the view crosses `g`'s plane. Stacked facets must not z-fight at any orbit angle or at the start and end of a fold, and the stack must not invert when you orbit under it. Test in Tasks 5 and 10. 443. **Coplanar stacked facets, and orbiting underneath.** The depth buffer cannot order coplanar or nearly coplanar facets, and `faceOrders`'s `s` sign reverses when the view crosses `g`'s plane. Stacked facets must not z-fight at any orbit angle or at the start and end of a fold, and the stack must not invert when you orbit under it. Test in Tasks 5 and 10.
444. **A degenerate drag direction.** When the moving facet's centroid travels nearly along the view direction the drag projection approaches zero and the fold becomes uncontrollable. Test in Task 12. 454. **A degenerate drag direction.** When the moving facet's centroid travels nearly along the view direction the drag projection approaches zero and the fold becomes uncontrollable. Test in Task 12.
@@ -58,6 +59,7 @@ Every fixture except where noted has `file_author: "Traditional"`, an `instructi
58| `mountain.fold` | as `half.fold` | 1: mountain fold f1 behind f0 about e6, 0 → −180 | 59| `mountain.fold` | as `half.fold` | 1: mountain fold f1 behind f0 about e6, 0 → −180 |
59| `letter.fold` | 3×3; v0 (0,0), v1 (1,0), v2 (2,0), v3 (3,0), v4 (3,3), v5 (2,3), v6 (1,3), v7 (0,3); e0–e7 the boundary, e8 = v1–v6 (x = 1, valley), e9 = v2–v5 (x = 2, mountain); f0 = [v0,v1,v6,v7], f1 = [v1,v2,v5,v6], f2 = [v2,v3,v4,v5] | 1: one step, two axes: f0 valley folds in front of f1, f2 mountain folds behind it. The sets overlap in projection on opposite sides of f1, so frame 1 carries `krz:faceOrders_midFold` | 60| `letter.fold` | 3×3; v0 (0,0), v1 (1,0), v2 (2,0), v3 (3,0), v4 (3,3), v5 (2,3), v6 (1,3), v7 (0,3); e0–e7 the boundary, e8 = v1–v6 (x = 1, valley), e9 = v2–v5 (x = 2, mountain); f0 = [v0,v1,v6,v7], f1 = [v1,v2,v5,v6], f2 = [v2,v3,v4,v5] | 1: one step, two axes: f0 valley folds in front of f1, f2 mountain folds behind it. The sets overlap in projection on opposite sides of f1, so frame 1 carries `krz:faceOrders_midFold` |
60| `letter-sequential.fold` | as `letter.fold`, both creases valley | 1: f0 over f1. 2: f2 over both, `repeatOf: 1` | 61| `letter-sequential.fold` | as `letter.fold`, both creases valley | 1: f0 over f1. 2: f2 over both, `repeatOf: 1` |
62| `letter-staggered.fold` | as `letter.fold`, both creases valley | 1: one step, two axes: f0 over f1 on window 0…0.5, then f2 over both on 0.5…1. The sets overlap in projection, so frame 1 carries `krz:faceOrders_midFold`, equal to its `faceOrders`. Frame 1 is `letter-sequential.fold`'s frame 2 |
61| `quarters.fold` | 2×2; v0 (0,0), v1 (1,0), v2 (2,0), v3 (2,1), v4 (2,2), v5 (1,2), v6 (0,2), v7 (0,1), v8 (1,1); e0–e7 the boundary, e8 = v1–v8, e9 = v8–v5 (x = 1), e10 = v7–v8, e11 = v8–v3 (y = 1); f0 = [v0,v1,v8,v7], f1 = [v1,v2,v3,v8], f2 = [v8,v3,v4,v5], f3 = [v7,v8,v5,v6] | 1: `foldAndUnfold` on e8, moving f1 and f2, peak 180; frame 1 carries `krz:faceOrders_midFold` with the order at the peak (f1 on f0, f2 on f3). 2: valley fold the top half (f2, f3) down about e10. 3: valley fold the right half of both layers (f1, f2) over about e8 — e8 and e9 are now coincident; e9 is on the flipped layer and ends at −180, `M` | 63| `quarters.fold` | 2×2; v0 (0,0), v1 (1,0), v2 (2,0), v3 (2,1), v4 (2,2), v5 (1,2), v6 (0,2), v7 (0,1), v8 (1,1); e0–e7 the boundary, e8 = v1–v8, e9 = v8–v5 (x = 1), e10 = v7–v8, e11 = v8–v3 (y = 1); f0 = [v0,v1,v8,v7], f1 = [v1,v2,v3,v8], f2 = [v8,v3,v4,v5], f3 = [v7,v8,v5,v6] | 1: `foldAndUnfold` on e8, moving f1 and f2, peak 180; frame 1 carries `krz:faceOrders_midFold` with the order at the peak (f1 on f0, f2 on f3). 2: valley fold the top half (f2, f3) down about e10. 3: valley fold the right half of both layers (f1, f2) over about e8 — e8 and e9 are now coincident; e9 is on the flipped layer and ends at −180, `M` |
62| `occlusion.fold` | 4×4; v0 (0,0), v1 (2,0), v2 (2.5,0), v3 (4,0), v4 (4,4), v5 (2.5,4), v6 (0,4), v7 (0,2); e0–e7 the boundary, e8 = v7–v1 (diagonal), e9 = v2–v5; f0 = [v0,v1,v7], f1 = [v1,v2,v5,v6,v7], f2 = [v2,v3,v4,v5] | 1: valley fold the corner f0 up about e8 (v0 lands on (2,2)). 2: valley fold the strip f2 over about e9 (it lands on x ∈ [1, 2.5], covering part of f0). 3: `turnOver`, vertical, so that step 3's diagram draws frame 2 | 64| `occlusion.fold` | 4×4; v0 (0,0), v1 (2,0), v2 (2.5,0), v3 (4,0), v4 (4,4), v5 (2.5,4), v6 (0,4), v7 (0,2); e0–e7 the boundary, e8 = v7–v1 (diagonal), e9 = v2–v5; f0 = [v0,v1,v7], f1 = [v1,v2,v5,v6,v7], f2 = [v2,v3,v4,v5] | 1: valley fold the corner f0 up about e8 (v0 lands on (2,2)). 2: valley fold the strip f2 over about e9 (it lands on x ∈ [1, 2.5], covering part of f0). 3: `turnOver`, vertical, so that step 3's diagram draws frame 2 |
63 65
@@ -98,6 +100,7 @@ Done once, before Task 0.
98 | Batch | Tasks | Branch | 100 | Batch | Tasks | Branch |
99 |---|---|---| 101 |---|---|---|
100 | A | 0 — interpolation spike | `spike-interpolation` | 102 | A | 0 — interpolation spike | `spike-interpolation` |
103 | A2 | 0b — non-rigid steps, petal fold, sampan, masu | `spike-non-rigid` |
101 | B | 1–3 — decoding, validator, steps | `format-and-steps` | 104 | B | 1–3 — decoding, validator, steps | `format-and-steps` |
102 | C | 4–6 — interpolation, layer order, interpenetration | `folding-engine` | 105 | C | 4–6 — interpolation, layer order, interpenetration | `folding-engine` |
103 | D | 7–8 — `foldc`, `foldlint`, the cup | `compiler-and-cup` | 106 | D | 7–8 — `foldc`, `foldlint`, the cup | `compiler-and-cup` |
@@ -105,7 +108,7 @@ Done once, before Task 0.
105 | F | 11–14 — the app | `app` | 108 | F | 11–14 — the app | `app` |
106 | G | 15 — crane, sampan, box | `models` | 109 | G | 15 — crane, sampan, box | `models` |
107 110
108 Batch A merges alone, since Task 0 can stop the plan. Each batch commits task by task on its branch, ends with `gitbay mr create --source <branch> --target main`, merges when `swift test --package-path Packages/FoldKit` (and, from batch F, the `xcodebuild` test) is green, and the branch is then deleted locally and remotely. Commit messages end with `Ref #N` for the batch's issue; the batch's last commit uses `Closes #N`. 111 Batches A and A2 merge alone, since Tasks 0 and 0b can stop the plan. Each batch commits task by task on its branch, ends with `gitbay mr create --source <branch> --target main`, merges when `swift test --package-path Packages/FoldKit` (and, from batch F, the `xcodebuild` test) is green, and the branch is then deleted locally and remotely. Commit messages end with `Ref #N` for the batch's issue; the batch's last commit uses `Closes #N`.
1094. If `xcrun metal --version` fails, run `xcodebuild -downloadComponent MetalToolchain`. SwiftPM invokes `metal` for the `.metal` file in Task 10; on 2026-10-19 this machine had no Metal toolchain. 1124. If `xcrun metal --version` fails, run `xcodebuild -downloadComponent MetalToolchain`. SwiftPM invokes `metal` for the `.metal` file in Task 10; on 2026-10-19 this machine had no Metal toolchain.
110 113
111--- 114---
@@ -150,18 +153,69 @@ Done once, before Task 0.
150 153
151This is a measurement, not TDD. 154This is a measurement, not TDD.
152 155
153- [ ] **Step 1: Build the spike package and the five cases** 156- [x] **Step 1: Build the spike package and the five cases**
154- [ ] **Step 2: Implement M1 and M2, and M3 and M4 as far as case 4 needs them** 157- [x] **Step 2: Implement M1 and M2, and M3 and M4 as far as case 4 needs them**
155- [ ] **Step 3: Run and record** 158- [x] **Step 3: Run and record**
156 159
157Run: `swift run --package-path spikes/interpolation` 160Run: `swift run --package-path spikes/interpolation`
158 161
162- [x] **Step 4: Write the decision record and apply the exit criteria**
163- [x] **Step 5: Commit**
164
165```bash
166git add spikes docs
167git commit -m "Interpolation model spike and decision record"
168```
169
170---
171
172### Task 0b: Non-rigid steps and the remaining coupled steps
173
174**Files:**
175- Modify: `spikes/interpolation` — cases 6–9
176- Create: `docs/decisions/0002-non-rigid-steps.md`
177- Modify at the end: the design doc's *Interpolation* section, this plan's Tasks 1, 3, 4, 7, 8 and 15, and `CLAUDE.md`
178
179**Why.** Decision 0001 found no rigid motion that makes an inside reverse fold with the flap closed, and chose option A: such steps are flagged `nonRigid` and move by a designed non-rigid motion held to a stated strain bound. This task chooses that motion and the bound, and measures the coupled steps 0001 left open. Task 1 encodes the result, so it comes first.
180
181**Cases**, continuing 0001's numbering:
182
1836. **Reverse fold with bending**, on case 4's flap. Candidates:
184 - **virtual creases** — extra edges in the flap's layers near the vertex (a fan from it), never drawn, flat in every frame and free to fold during the step. If some number of them gives a rigid path that keeps the flap mostly closed, the step is rigid on a finer mesh: zero gap, and the bend shows as their largest angle. They are subdivision edges in the format, which already allows them.
185 - **pose interpolation** — per-face transforms through solved intermediate poses (the flap opened to φ, the tip swung through), interpolated between them; strain is the gap.
186
187 Measure for each: the largest gap, the largest opening of the flap, the largest virtual-crease angle, and collisions, across φ and the number of virtual creases. 0001 measured naive schedules at 0.24–1.6 of the flap's height; the question is how far a designed motion gets below that.
1887. **Petal fold, verified.** A bird-base crease pattern with its mountain–valley assignment from a citable source — Lang, *Origami Design Secrets*, or the base folded in Oriedita and exported — recorded with its source. Check it is flat-foldable at every vertex (Kawasaki, and Maekawa against the assignment). Then measure the petal fold as 0001's case 5 did, and check that the inner layers' corners stay down.
1898. **Sampan, turning inside out.** The crease pattern of the sequence Task 15 will author, with its source. Does any rigid path exist? Rigid (M2), or flagged.
1909. **Masu, raising the walls.** The traditional masu's crease pattern, walls ending at 90°. Does M2 find a rigid path? Rigid, or flagged.
191
192**Exit criteria:**
193
194- `docs/decisions/0002-non-rigid-steps.md` holds: the non-rigid model and the data it adds to `krz:step`; the strain metric and the bound the app promises; and, for every v1 step that is not a single independent fold, whether it is rigid (M2) or flagged, with the case that stands in for it.
195- In the same merge request, apply the result:
196 - the design doc's *Interpolation* section;
197 - Task 1 (the non-rigid step's data) and Task 3;
198 - Task 4 (the non-rigid path and its tests);
199 - Task 7 (how `foldc` produces a non-rigid step);
200 - Task 8 (the bound's test for flagged steps);
201 - Task 15 (which steps are flagged);
202 - `CLAUDE.md`.
203- If a v1 step is neither rigid nor within a bound worth promising: **stop**. The author decides, as after Task 0.
204
205This is a measurement, not TDD.
206
207- [ ] **Step 1: Find the bird base and the sampan's crease patterns, and record their sources**
208- [ ] **Step 2: Add cases 6–9 to the spike**
209- [ ] **Step 3: Run and record**
210
211Run: `swift run -c release --package-path spikes/interpolation`
212
159- [ ] **Step 4: Write the decision record and apply the exit criteria** 213- [ ] **Step 4: Write the decision record and apply the exit criteria**
160- [ ] **Step 5: Commit** 214- [ ] **Step 5: Commit**
161 215
162```bash 216```bash
163git add spikes docs 217git add spikes docs
164git commit -m "Interpolation model spike and decision record" 218git commit -m "Non-rigid steps: model, bound and the remaining coupled steps"
165``` 219```
166 220
167--- 221---
@@ -185,9 +239,9 @@ git commit -m "Interpolation model spike and decision record"
185 - `enum StepKind: String, Codable, Sendable { case fold, foldAndUnfold, turnOver, rotate }` 239 - `enum StepKind: String, Codable, Sendable { case fold, foldAndUnfold, turnOver, rotate }`
186 - `enum StepTechnique: String, Codable, Sendable { case plain, insideReverse, outsideReverse, squash, petal, sink }` 240 - `enum StepTechnique: String, Codable, Sendable { case plain, insideReverse, outsideReverse, squash, petal, sink }`
187 - `enum TurnOverAxis: String, Codable, Sendable { case vertical, horizontal }` 241 - `enum TurnOverAxis: String, Codable, Sendable { case vertical, horizontal }`
188 - `struct AxisRecord: Codable, Equatable, Sendable { let edge: Int; let movingFaces: [Int]; let startAngle: Double; let endAngle: Double; let peakAngle: Double? }` 242 - `struct AxisRecord: Codable, Equatable, Sendable { let edge: Int; let movingFaces: [Int]; let startAngle: Double; let endAngle: Double; let peakAngle: Double?; let parent: Int?; let window: [Double]?; let angles: [Double]? }` — `parent` is the index, in the same step's `axes`, of the axis whose motion carries this one; `window` is `[t0, t1]`, default `[0, 1]`; `angles` is a solved curve, the fold angle at 257 evenly spaced points of the window, absent for a linear axis
189 - `struct Viewpoint: Codable, Equatable, Sendable { let eye: SIMD3<Double>; let up: SIMD3<Double> }` — `eye` is the unit direction toward the viewer 243 - `struct Viewpoint: Codable, Equatable, Sendable { let eye: SIMD3<Double>; let up: SIMD3<Double> }` — `eye` is the unit direction toward the viewer
190 - `struct StepRecord: Codable, Equatable, Sendable { let kind: StepKind; let technique: StepTechnique; let instruction: String?; let axes: [AxisRecord]; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let viewpoint: Viewpoint }` 244 - `struct StepRecord: Codable, Equatable, Sendable { let kind: StepKind; let technique: StepTechnique; let instruction: String?; let axes: [AxisRecord]; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let nonRigid: Bool; let viewpoint: Viewpoint }` — `nonRigid` decodes to `false` when absent; Task 0b adds the data a non-rigid step carries
191 - `struct FoldFrame: Codable, Sendable { var verticesCoords: [SIMD3<Double>]; var edgesAssignment: [EdgeAssignment]; var edgesFoldAngle: [Double]; var faceOrders: [[Int]]; var faceOrdersMidFold: [[Int]]?; var step: StepRecord? }` 245 - `struct FoldFrame: Codable, Sendable { var verticesCoords: [SIMD3<Double>]; var edgesAssignment: [EdgeAssignment]; var edgesFoldAngle: [Double]; var faceOrders: [[Int]]; var faceOrdersMidFold: [[Int]]?; var step: StepRecord? }`
192 - `struct FoldFile: Codable, Sendable { var fileSpec: Double; var fileCreator: String?; var fileTitle: String?; var fileAuthor: String?; var fileClasses: [String]; var edgesVertices: [[Int]]; var facesVertices: [[Int]]; var edgesFirstCreasedAtStep: [Int?]; var frames: [FoldFrame] }` — `frames[0]` is the key frame, `frames[n]` is frame n 246 - `struct FoldFile: Codable, Sendable { var fileSpec: Double; var fileCreator: String?; var fileTitle: String?; var fileAuthor: String?; var fileClasses: [String]; var edgesVertices: [[Int]]; var facesVertices: [[Int]]; var edgesFirstCreasedAtStep: [Int?]; var frames: [FoldFrame] }` — `frames[0]` is the key frame, `frames[n]` is frame n
193 - `var (FoldFile).stepCount: Int { get }` — `frames.count − 1` 247 - `var (FoldFile).stepCount: Int { get }` — `frames.count − 1`
@@ -245,6 +299,21 @@ Package manifest: swift-tools-version 6.2, platforms `.iOS(.v26)`, `.macOS(.v26)
245 #expect(step?.viewpoint == Viewpoint(eye: SIMD3(0, 0, 1), up: SIMD3(0, 1, 0))) 299 #expect(step?.viewpoint == Viewpoint(eye: SIMD3(0, 0, 1), up: SIMD3(0, 1, 0)))
246} 300}
247 301
302@Test func decodesAnAxisTreeWithWindowsAndACurve() throws {
303 let json = #"{"edge": 3, "movingFaces": [2], "startAngle": 0, "endAngle": 180, "parent": 0,"# +
304 #" "window": [0.25, 1], "angles": [0, 90, 180]}"#
305 let axis = try JSONDecoder().decode(AxisRecord.self, from: Data(json.utf8))
306 #expect(axis.parent == 0)
307 #expect(axis.window == [0.25, 1])
308 #expect(axis.angles == [0, 90, 180])
309}
310
311@Test func windowsDecodeOnAStaggeredStep() throws {
312 let step = try FoldFile(contentsOf: fixture("letter-staggered.fold")).frames[1].step
313 #expect(step?.axes.map(\.window) == [[0, 0.5], [0.5, 1]])
314 #expect(step?.nonRigid == false)
315}
316
248@Test func decodesFirstCreasedAtStepWithNullForBoundaries() throws { 317@Test func decodesFirstCreasedAtStepWithNullForBoundaries() throws {
249 let f = try FoldFile(contentsOf: fixture("half.fold")) 318 let f = try FoldFile(contentsOf: fixture("half.fold"))
250 #expect(f.edgesFirstCreasedAtStep == [nil, nil, nil, nil, nil, nil, 1]) 319 #expect(f.edgesFirstCreasedAtStep == [nil, nil, nil, nil, nil, nil, 1])
@@ -324,7 +393,7 @@ The interpenetration checker (Task 6) finds faces that collide in motion. It can
324 393
325```swift 394```swift
326@Test(arguments: ["square.fold", "half.fold", "mountain.fold", "letter.fold", "letter-sequential.fold", 395@Test(arguments: ["square.fold", "half.fold", "mountain.fold", "letter.fold", "letter-sequential.fold",
327 "quarters.fold", "occlusion.fold"]) 396 "letter-staggered.fold", "quarters.fold", "occlusion.fold"])
328func acceptsAValidModel(_ name: String) throws { 397func acceptsAValidModel(_ name: String) throws {
329 #expect(validate(try FoldFile(contentsOf: fixture(name))).isEmpty) 398 #expect(validate(try FoldFile(contentsOf: fixture(name))).isEmpty)
330} 399}
@@ -446,21 +515,26 @@ git commit -m "FOLD validator: topology, angles, isometry, cycles and mid-fold o
446**Files:** 515**Files:**
447- Create: `Packages/FoldKit/Sources/Folding/FoldStep.swift` 516- Create: `Packages/FoldKit/Sources/Folding/FoldStep.swift`
448- Create: `Packages/FoldKit/Sources/Folding/StepReader.swift` 517- Create: `Packages/FoldKit/Sources/Folding/StepReader.swift`
518- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/DegreeFourVertex.swift`
449- Test: `Packages/FoldKit/Tests/FoldingTests/StepReadingTests.swift` 519- Test: `Packages/FoldKit/Tests/FoldingTests/StepReadingTests.swift`
450 520
451**Interfaces:** 521**Interfaces:**
452- Consumes: Task 1 types. 522- Consumes: Task 1 types.
453- Produces: 523- Produces:
454 - `struct FoldAxis: Equatable, Sendable { let edge: Int; let origin: SIMD3<Double>; let direction: SIMD3<Double>; let movingFaces: Set<Int>; let startAngle: Double; let endAngle: Double; let peakAngle: Double? }` 524 - `struct FoldAxis: Equatable, Sendable { let edge: Int; let origin: SIMD3<Double>; let direction: SIMD3<Double>; let movingFaces: Set<Int>; let startAngle: Double; let endAngle: Double; let peakAngle: Double?; let parent: Int?; let window: ClosedRange<Double>; let curve: [Double]? }`
455 - `func (FoldAxis).angle(at t: Double, kind: StepKind) -> Double` 525 - `func (FoldAxis).angle(at t: Double, kind: StepKind) -> Double`
456 - `struct FoldStep: Equatable, Sendable { let index: Int; let kind: StepKind; let technique: StepTechnique; let instruction: String; let axes: [FoldAxis]; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let viewpoint: Viewpoint }` 526 - `struct FoldStep: Equatable, Sendable { let index: Int; let kind: StepKind; let technique: StepTechnique; let instruction: String; let axes: [FoldAxis]; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let nonRigid: Bool; let viewpoint: Viewpoint }` — `axes` is ordered so every parent comes before its children
457 - `var (FoldStep).movingFaceUnion: Set<Int> { get }` 527 - `var (FoldStep).movingFaceUnion: Set<Int> { get }`
458 - `func readSteps(_ file: FoldFile) throws -> [FoldStep]` — `result[k].index == k + 1` 528 - `func readSteps(_ file: FoldFile) throws -> [FoldStep]` — `result[k].index == k + 1`
459 - `enum StepError: Error, Equatable, Sendable { case axisNotAnEdge(step: Int, edge: Int); case axisNotOnMovingSetBoundary(step: Int, edge: Int); case movingFacesOutOfRange(step: Int); case overlappingMovingSetsWithinAStep(step: Int); case rotateWithoutDegrees(step: Int); case turnOverWithoutAxis(step: Int); case foldAndUnfoldWithoutPeak(step: Int); case missingInstruction(step: Int) }` 529 - `enum StepError: Error, Equatable, Sendable { case axisNotAnEdge(step: Int, edge: Int); case axisNotOnMovingSetBoundary(step: Int, edge: Int); case movingFacesOutOfRange(step: Int); case overlappingMovingSetsWithinAStep(step: Int); case rotateWithoutDegrees(step: Int); case turnOverWithoutAxis(step: Int); case foldAndUnfoldWithoutPeak(step: Int); case missingInstruction(step: Int); case axisParentCycle(step: Int); case axisWindowOutOfRange(step: Int); case curveTooShort(step: Int) }`
460 530
461`readSteps` **reads** the authored `krz:step`; it does not infer axes or moving sets from a frame diff. Deriving a multi-axis decomposition has genuine ambiguities — which side moved, whether a reorientation is a fold, how to partition simultaneous axes — and the author already knows the answer. This task and Task 4 own Review Focus item 1, in the form Task 0 settles. 531`readSteps` **reads** the authored `krz:step`; it does not infer axes or moving sets from a frame diff. Deriving a multi-axis decomposition has genuine ambiguities — which side moved, whether a reorientation is a fold, how to partition simultaneous axes — and the author already knows the answer. This task and Task 4 own Review Focus item 1, in the form Task 0 settles.
462 532
463`FoldAxis.origin` and `direction` come from the axis edge's endpoints in frame `index − 1`. The direction is the way the moving face adjacent to the edge traverses it in `faces_vertices` order, and the origin is the vertex that traversal starts from, so that a positive rotation about it (right-hand rule) turns the moving face toward its normal — a valley — and the rotation for any step is `angle(t) − startAngle` with FOLD's own sign. `angle(at:)` is `startAngle + t·(endAngle − startAngle)` for `fold`, and `startAngle + (peakAngle − startAngle)·(1 − |2t − 1|)` for `foldAndUnfold`. 533`FoldAxis.origin` and `direction` come from the axis edge's endpoints in frame `index − 1`. The direction is the way the moving face adjacent to the edge traverses it in `faces_vertices` order, and the origin is the vertex that traversal starts from, so that a positive rotation about it (right-hand rule) turns the moving face toward its normal — a valley — and the rotation for any step is `angle(t) − startAngle` with FOLD's own sign. `angle(at:)` first maps `t` onto the axis's window, `u = clamp((t − t0) / (t1 − t0), 0, 1)`, so an axis waits before its window and holds after it. Then it is `startAngle + u·(endAngle − startAngle)` for `fold`, `startAngle + (peakAngle − startAngle)·(1 − |2u − 1|)` for `foldAndUnfold`, or, when the axis has a curve, the curve at `u` by cubic Hermite interpolation with central-difference tangents (one-sided at the ends). Decision 0001 measured that 257 samples rebuilt this way keep a coupled vertex's tear under 1e-6.
534
535For an axis with a parent, `origin` and `direction` are still in frame `index − 1`'s coordinates: Task 4 applies the axis's own rotation first and its ancestors' after, so the parent's motion carries it.
536
537`degreeFourVertex()` builds decision 0001's case 3 in code, since its curves cannot be typed: a 2×2 sheet with creases from the centre at 0°, 60°, 140° and 260° (sectors 60°, 80°, 120°, 100°), and one `fold` step from flat to flat-folded. The face between the 140° and 260° creases holds still. Its axes are the 140° crease, linear 0 → 180; the 260° crease, a curve; and the 0° crease, carried by the 260° axis, linear 0 → 180. The 60° crease is off the tree. The curve is the closed form for a flat-foldable degree-4 vertex, `ρ = 2·atan(k·tan(90°·u))` with `k = cos 70° / cos 10°`, sampled at 257 points; the 60° crease follows as `−ρ`. Frame 1 is the flat-folded sheet. `degreeFourExactAngle(_:at:)` evaluates the closed form directly.
464 538
465- [ ] **Step 1: Write the failing tests** 539- [ ] **Step 1: Write the failing tests**
466 540
@@ -519,6 +593,20 @@ func movingFaceSetsWithinOneStepAreDisjoint(_ name: String) throws {
519 #expect(try readSteps(f)[0].instruction == f.frames[1].step?.instruction) 593 #expect(try readSteps(f)[0].instruction == f.frames[1].step?.instruction)
520} 594}
521 595
596@Test func aWindowedAxisWaitsAndThenHolds() throws {
597 let s = try readSteps(FoldFile(contentsOf: fixture("letter-staggered.fold")))[0]
598 #expect(s.axes[0].angle(at: 0.25, kind: s.kind) == 90)
599 #expect(s.axes[1].angle(at: 0.25, kind: s.kind) == 0)
600 #expect(s.axes[0].angle(at: 0.75, kind: s.kind) == 180)
601 #expect(s.axes[1].angle(at: 0.75, kind: s.kind) == 90)
602}
603
604@Test func aCurveIsInterpolatedBetweenItsSamples() throws {
605 let axis = try readSteps(degreeFourVertex()).first!.axes.first { $0.curve != nil }!
606 let t = 0.5 + 0.5 / 256 // halfway between two samples
607 #expect(abs(axis.angle(at: t, kind: .fold) - degreeFourExactAngle(axis.edge, at: t)) < 1e-6)
608}
609
522@Test func rotateWithoutDegreesThrows() { 610@Test func rotateWithoutDegreesThrows() {
523 #expect(throws: StepError.rotateWithoutDegrees(step: 3)) { 611 #expect(throws: StepError.rotateWithoutDegrees(step: 3)) {
524 try readSteps(FoldFile(contentsOf: fixture("rotate-no-degrees.fold"))) 612 try readSteps(FoldFile(contentsOf: fixture("rotate-no-degrees.fold")))
@@ -559,7 +647,7 @@ git commit -m "Read authored fold steps, including multi-axis and reorientation
559- Create: `Packages/FoldKit/Sources/Folding/FoldInterpolator.swift` 647- Create: `Packages/FoldKit/Sources/Folding/FoldInterpolator.swift`
560- Test: `Packages/FoldKit/Tests/FoldingTests/InterpolationTests.swift` 648- Test: `Packages/FoldKit/Tests/FoldingTests/InterpolationTests.swift`
561 649
562**Interfaces** (as of before Task 0; Task 0 amends them for coupled steps): 650**Interfaces** (decision 0001; Task 0b adds the path for `nonRigid` steps):
563- Consumes: Task 1 and Task 3 types. 651- Consumes: Task 1 and Task 3 types.
564- Produces: 652- Produces:
565 - `struct FoldInterpolator: Sendable { init(file: FoldFile, step: FoldStep) }` — interpolates from frame `step.index − 1` to frame `step.index` 653 - `struct FoldInterpolator: Sendable { init(file: FoldFile, step: FoldStep) }` — interpolates from frame `step.index − 1` to frame `step.index`
@@ -571,7 +659,7 @@ There is no separate orientation output: a `turnOver` or `rotate` step's end fra
571 659
572```swift 660```swift
573let modelFixtures = ["half.fold", "mountain.fold", "letter.fold", "letter-sequential.fold", 661let modelFixtures = ["half.fold", "mountain.fold", "letter.fold", "letter-sequential.fold",
574 "quarters.fold", "occlusion.fold"] 662 "letter-staggered.fold", "quarters.fold", "occlusion.fold"]
575 663
576@Test func tZeroReproducesTheStartFrame() throws { 664@Test func tZeroReproducesTheStartFrame() throws {
577 let (file, i) = try interpolator("half.fold", step: 1) 665 let (file, i) = try interpolator("half.fold", step: 1)
@@ -629,6 +717,31 @@ func everyEdgeLengthIsPreservedThroughoutEveryStep(_ name: String) throws {
629 .allSatisfy { simd_distance($0, $1) < 1e-9 }) 717 .allSatisfy { simd_distance($0, $1) < 1e-9 })
630} 718}
631 719
720@Test func aCoupledVertexStaysWholeThroughout() throws {
721 // decision 0001, case 3: curves from the closed form, sampled at 257 points
722 let file = degreeFourVertex()
723 let i = FoldInterpolator(file: file, step: try readSteps(file)[0])
724 for n in 0...1024 {
725 #expect(maxEdgeLengthDrift(i.positions(at: Double(n) / 1024), file) < 1e-6)
726 }
727 #expect(zip(i.positions(at: 1), file.frames[1].verticesCoords)
728 .allSatisfy { simd_distance($0, $1) < 1e-9 })
729}
730
731@Test func theSameVertexWithLinearAnglesTears() throws {
732 // the control: drop the curve and the paper does not hold together
733 let file = degreeFourVertex(linear: true)
734 let i = FoldInterpolator(file: file, step: try readSteps(file)[0])
735 #expect(maxEdgeLengthDrift(i.positions(at: 0.5), file) > 0.1)
736}
737
738@Test func aStaggeredAxisMovesOnlyInItsWindow() throws {
739 let (file, i) = try interpolator("letter-staggered.fold", step: 1)
740 let start = file.frames[0].verticesCoords
741 #expect(simd_distance(i.positions(at: 0.25)[3], start[3]) < 1e-12) // right flap waits
742 #expect(simd_distance(i.positions(at: 0.5)[0], SIMD3(2, 0, 0)) < 1e-9) // left flap down
743}
744
632@Test func turnOverRotatesTheModelRigidly() throws { 745@Test func turnOverRotatesTheModelRigidly() throws {
633 let (_, i) = try interpolator("half.fold", step: 2) 746 let (_, i) = try interpolator("half.fold", step: 2)
634 #expect(pairwiseDistancesAgree(i.positions(at: 0.5), i.positions(at: 0))) 747 #expect(pairwiseDistancesAgree(i.positions(at: 0.5), i.positions(at: 0)))
@@ -652,7 +765,7 @@ Expected: FAIL.
652 765
653- [ ] **Step 3: Implement `positions(at:)`** 766- [ ] **Step 3: Implement `positions(at:)`**
654 767
655For each axis, rotate its moving faces' vertices about the line through `origin` along `direction` by `angle(t) − startAngle`, converted to radians, with `simd_quatd(angle:axis:)` about the origin-shifted axis. A vertex in no moving set is unchanged. Reorientation steps rotate every vertex as described above. 768Each axis's own transform is the rotation about the line through `origin` along `direction` by `angle(t) − startAngle`, converted to radians, built with `simd_quatd(angle:axis:)` about the origin-shifted axis. A moving face's transform is its axis's own transform followed by its parent's full transform, and so on up the tree, so a carried axis moves with its parent. A vertex in no moving set is unchanged. A vertex shared by faces of different sets takes its position from the first face in `faces_vertices` order that contains it. `foldc`'s curves keep the copies within the isometry tolerance, and the catalogue test (Task 8) checks this. Reorientation steps rotate every vertex as described above. `degreeFourVertex(linear:)` gains a `linear` flag that replaces the curves with straight lines, for the control test.
656 769
657- [ ] **Step 4: Run tests to verify they pass** 770- [ ] **Step 4: Run tests to verify they pass**
658 771
@@ -663,7 +776,7 @@ Expected: PASS.
663 776
664```bash 777```bash
665git add Packages/FoldKit 778git add Packages/FoldKit
666git commit -m "Rigid interpolation, including reorientation steps" 779git commit -m "Rigid interpolation on an axis tree with windows and solved curves"
667``` 780```
668 781
669--- 782---
@@ -834,6 +947,12 @@ git commit -m "Near-coplanar clustering and view-relative layer order"
834 #expect(!interpenetrations(i, faces: file.facesVertices, samples: 64).isEmpty) 947 #expect(!interpenetrations(i, faces: file.facesVertices, samples: 64).isEmpty)
835} 948}
836 949
950@Test func staggeredFlapsDoNotCollide() throws {
951 // the same two flaps on separate windows of t
952 let (file, i) = try interpolator("letter-staggered.fold", step: 1)
953 #expect(interpenetrations(i, faces: file.facesVertices, samples: 64).isEmpty)
954}
955
837@Test func aFaceSwingingThroughAFaceItSharesAVertexWithIsDetected() throws { 956@Test func aFaceSwingingThroughAFaceItSharesAVertexWithIsDetected() throws {
838 // built in code: fixed triangle (0,0,0), (1,1.2,0.4), (-1,1.2,0.4); moving triangle 957 // built in code: fixed triangle (0,0,0), (1,1.2,0.4), (-1,1.2,0.4); moving triangle
839 // (0,0,0), (0,2,0), (-1,1,0) hinged on its edge along the y-axis, folding toward +z 958 // (0,0,0), (0,2,0), (-1,1,0) hinged on its edge along the y-axis, folding toward +z
@@ -890,9 +1009,10 @@ git commit -m "Facet interpenetration checker"
890- Create: `Packages/FoldKit/Sources/FoldCompiler/FoldScript.swift` 1009- Create: `Packages/FoldKit/Sources/FoldCompiler/FoldScript.swift`
891- Create: `Packages/FoldKit/Sources/FoldCompiler/FrameCompiler.swift` 1010- Create: `Packages/FoldKit/Sources/FoldCompiler/FrameCompiler.swift`
892- Create: `Packages/FoldKit/Sources/FoldCompiler/LayerOrderGuess.swift` 1011- Create: `Packages/FoldKit/Sources/FoldCompiler/LayerOrderGuess.swift`
893- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{half,mountain,letter,letter-sequential,quarters,occlusion}-cp.fold` — each model fixture's sheet and creases as an editor would export them: no frames, every crease carrying its **final** `M`/`V` assignment from the fixture's last frame (`F` for a crease that ends flat). `compile` resets frame 0 to `F` and 0 1012- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{half,mountain,letter,letter-sequential,letter-staggered,quarters,occlusion}-cp.fold` — each model fixture's sheet and creases as an editor would export them: no frames, every crease carrying its **final** `M`/`V` assignment from the fixture's last frame (`F` for a crease that ends flat). `compile` resets frame 0 to `F` and 0
894- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{half,mountain,letter,letter-sequential,quarters,occlusion}.foldscript` 1013- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{half,mountain,letter,letter-sequential,letter-staggered,quarters,occlusion}.foldscript`
895- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{unresolved-crease,angle-out-of-range}.foldscript` 1014- Create: `Packages/FoldKit/Sources/FoldKitTestSupport/Fixtures/{unresolved-crease,angle-out-of-range}.foldscript`
1015- Modify: `Packages/FoldKit/Sources/FoldKitTestSupport/DegreeFourVertex.swift` — `degreeFourPattern()` and `degreeFourScript()`, the same vertex as a crease pattern and a one-step script driven by the 140° crease
896- Test: `Packages/FoldKit/Tests/FoldCompilerTests/CompilerTests.swift` 1016- Test: `Packages/FoldKit/Tests/FoldCompilerTests/CompilerTests.swift`
897 1017
898**Interfaces:** 1018**Interfaces:**
@@ -900,7 +1020,7 @@ git commit -m "Facet interpenetration checker"
900- Produces: 1020- Produces:
901 - `struct FoldScript: Codable, Sendable { let creasePattern: String; let title: String; let steps: [ScriptStep] }` — `creasePattern` is relative to the script 1021 - `struct FoldScript: Codable, Sendable { let creasePattern: String; let title: String; let steps: [ScriptStep] }` — `creasePattern` is relative to the script
902 - `init (FoldScript).init(contentsOf url: URL) throws` 1022 - `init (FoldScript).init(contentsOf url: URL) throws`
903 - `struct ScriptStep: Codable, Sendable { let kind: StepKind; let technique: StepTechnique?; let instruction: String; let creases: [CreaseRef]; let movingSide: [SIMD2<Double>]; let angles: [Double]?; let peakAngles: [Double]?; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let viewpoint: Viewpoint?; let faceOrders: [OrderOverride]?; let faceOrdersMidFold: [OrderOverride]? }` 1023 - `struct ScriptStep: Codable, Sendable { let kind: StepKind; let technique: StepTechnique?; let instruction: String; let creases: [CreaseRef]; let movingSide: [SIMD2<Double>]; let angles: [Double]?; let peakAngles: [Double]?; let rotateDegrees: Double?; let turnOverAxis: TurnOverAxis?; let repeatOf: Int?; let viewpoint: Viewpoint?; let faceOrders: [OrderOverride]?; let faceOrdersMidFold: [OrderOverride]?; let driver: CreaseRef?; let windows: [[Double]]? }` — `windows` pairs with `creases`
904 - `enum CreaseRef: Codable, Sendable { case betweenVertices(SIMD2<Double>, SIMD2<Double>); case edgeIndex(Int) }` 1024 - `enum CreaseRef: Codable, Sendable { case betweenVertices(SIMD2<Double>, SIMD2<Double>); case edgeIndex(Int) }`
905 - `struct OrderOverride: Codable, Sendable { let above: SIMD2<Double>; let below: SIMD2<Double> }` — points in crease-pattern coordinates naming two faces, "above" as seen from the step's viewpoint 1025 - `struct OrderOverride: Codable, Sendable { let above: SIMD2<Double>; let below: SIMD2<Double> }` — points in crease-pattern coordinates naming two faces, "above" as seen from the step's viewpoint
906 - `func compile(_ script: FoldScript, pattern: FoldFile) throws -> FoldFile` 1026 - `func compile(_ script: FoldScript, pattern: FoldFile) throws -> FoldFile`
@@ -911,7 +1031,9 @@ git commit -m "Facet interpenetration checker"
911 1031
912**This task is the reason the project is buildable.** No existing FOLD tool authors a multi-frame sequence with folded coordinates, per-frame layer order and per-step moving sets; hand-writing them is hundreds of exact numbers per frame. `foldc` takes a crease pattern exported from an existing editor plus a short script that names each step's creases (by the points they run between), which side moves (by a point inside it), and the step kind, and **computes** every frame by applying the rotations in order. It guesses `faceOrders`, applies the script's overrides, and runs the Task 2 validator and the Task 6 checker after each step. 1032**This task is the reason the project is buildable.** No existing FOLD tool authors a multi-frame sequence with folded coordinates, per-frame layer order and per-step moving sets; hand-writing them is hundreds of exact numbers per frame. `foldc` takes a crease pattern exported from an existing editor plus a short script that names each step's creases (by the points they run between), which side moves (by a point inside it), and the step kind, and **computes** every frame by applying the rotations in order. It guesses `faceOrders`, applies the script's overrides, and runs the Task 2 validator and the Task 6 checker after each step.
913 1033
914Defaults: `angles` are each crease's end fold angle, ±180 by the pattern's assignment; `viewpoint` is the previous step's, or `[0, 0, 1]` / `[0, 1, 0]` for step 1; `technique` is `plain`. 1034Defaults: `angles` are each crease's end fold angle, ±180 by the pattern's assignment; `viewpoint` is the previous step's, or `[0, 0, 1]` / `[0, 1, 0]` for step 1; `technique` is `plain`; `driver` is the first crease; `windows` are all `[0, 1]`.
1035
1036**Coupled steps (decision 0001).** The step's creases cut the sheet into regions, each connected across edges this step does not fold. The fixed region is the one no `movingSide` point lies in. A spanning tree of regions, grown from the fixed region across the step's creases, gives each moving region its axis and each axis its parent. A step crease left off that tree closes a loop. If there is none, every axis is linear on its window. If there are some, `foldc` holds the driver linear on its window and solves the other tree axes as the spike does: damped Gauss–Newton on the gap between vertex copies, continued along *t*. It writes each solved axis's curve at 257 points. Each curve is then checked at four times that density, and its samples are doubled until the gap stays under 1e-6 × the sheet's size. A loop that does not close (the solver's gap stays above that) fails the step: the step has no rigid motion and needs `nonRigid` (Task 0b).
915 1037
916Layer-order corrections are `faceOrders` overrides **in the script**. The generated file is never edited; Task 8 checks that recompiling reproduces it. 1038Layer-order corrections are `faceOrders` overrides **in the script**. The generated file is never edited; Task 8 checks that recompiling reproduces it.
917 1039
@@ -920,7 +1042,7 @@ macOS only. Never linked into the app.
920- [ ] **Step 1: Write the failing tests** 1042- [ ] **Step 1: Write the failing tests**
921 1043
922```swift 1044```swift
923@Test(arguments: ["half", "mountain", "letter", "letter-sequential", "quarters", "occlusion"]) 1045@Test(arguments: ["half", "mountain", "letter", "letter-sequential", "letter-staggered", "quarters", "occlusion"])
924func compilingASyntheticScriptReproducesItsHandWrittenFixture(_ name: String) throws { 1046func compilingASyntheticScriptReproducesItsHandWrittenFixture(_ name: String) throws {
925 let out = try compile(FoldScript(contentsOf: fixture("\(name).foldscript")), 1047 let out = try compile(FoldScript(contentsOf: fixture("\(name).foldscript")),
926 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold"))) 1048 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold")))
@@ -960,6 +1082,17 @@ func compilingASyntheticScriptReproducesItsHandWrittenFixture(_ name: String) th
960 #expect(throws: Never.self) { try LayerOrder(faceOrders: swapped, normals: faceNormals(frame, file)) } 1082 #expect(throws: Never.self) { try LayerOrder(faceOrders: swapped, normals: faceNormals(frame, file)) }
961} 1083}
962 1084
1085@Test func aCoupledStepIsSolvedIntoCurves() throws {
1086 // decision 0001's case 3 as a script: the 140° crease drives, the 260° crease
1087 // gets a curve, the 0° crease rides on it, the 60° crease closes the loop
1088 let out = try compile(degreeFourScript(), pattern: degreeFourPattern())
1089 let axes = try #require(out.frames[1].step?.axes)
1090 #expect(axes.filter { $0.angles != nil }.count == 1)
1091 #expect(axes.contains { $0.parent != nil })
1092 let curved = axes.first { $0.angles != nil }!
1093 #expect(abs(curved.angles![128] - degreeFourExactAngle(curved.edge, at: 0.5)) < 1e-6)
1094}
1095
963@Test func anUnresolvedCreaseNamesItsStep() { 1096@Test func anUnresolvedCreaseNamesItsStep() {
964 #expect(throws: CompileError.unresolvedCrease(step: 2)) { 1097 #expect(throws: CompileError.unresolvedCrease(step: 2)) {
965 try compile(FoldScript(contentsOf: fixture("unresolved-crease.foldscript")), 1098 try compile(FoldScript(contentsOf: fixture("unresolved-crease.foldscript")),
@@ -1039,11 +1172,12 @@ Its crease pattern and `.foldscript` are committed next to the generated `.fold`
1039} 1172}
1040 1173
1041@Test func noShippedModelStretchesAtAnyStep() throws { 1174@Test func noShippedModelStretchesAtAnyStep() throws {
1175 // flagged non-rigid steps are held to Task 0b's bound instead
1042 for file in try ModelLibrary.all() { 1176 for file in try ModelLibrary.all() {
1043 for step in try readSteps(file) { 1177 for step in try readSteps(file) where !step.nonRigid {
1044 let i = FoldInterpolator(file: file, step: step) 1178 let i = FoldInterpolator(file: file, step: step)
1045 for t in stride(from: 0.0, through: 1.0, by: 1.0 / 64) { 1179 for t in stride(from: 0.0, through: 1.0, by: 1.0 / 256) {
1046 #expect(maxEdgeLengthDrift(i.positions(at: t), file) < 1e-9, 1180 #expect(maxEdgeLengthDrift(i.positions(at: t), file) < 1e-6,
1047 "\(file.fileTitle ?? "?") step \(step.index) t \(t)") 1181 "\(file.fileTitle ?? "?") step \(step.index) t \(t)")
1048 } 1182 }
1049 } 1183 }
@@ -1215,7 +1349,7 @@ Reference, per the spec: Randlett's conventions in *The Art of Origami* (1961) a
1215} 1349}
1216 1350
1217@Test func everyStepMatchesItsGoldenImage() throws { 1351@Test func everyStepMatchesItsGoldenImage() throws {
1218 for name in ["half", "mountain", "letter", "letter-sequential", "quarters", "occlusion"] { 1352 for name in ["half", "mountain", "letter", "letter-sequential", "letter-staggered", "quarters", "occlusion"] {
1219 let file = try FoldFile(contentsOf: fixture("\(name).fold")) 1353 let file = try FoldFile(contentsOf: fixture("\(name).fold"))
1220 for step in try readSteps(file) { 1354 for step in try readSteps(file) {
1221 try expectSnapshot(render(buildDiagram(file: file, step: step)), named: "\(name)-\(step.index)") 1355 try expectSnapshot(render(buildDiagram(file: file, step: step)), named: "\(name)-\(step.index)")
@@ -1758,7 +1892,7 @@ Expected: FAIL — only the cup is in the catalogue.
1758 1892
1759- [ ] **Step 3: Author the three models** 1893- [ ] **Step 3: Author the three models**
1760 1894
1761Box and sampan first, then the crane. Neither is shallow: the masu's wall-raising and the sampan's final turn inside out are coupled 3D steps, and both use whatever Task 0 decided for coupled steps. Run `foldc`, then `foldlint`, correcting guessed orderings with script overrides where the interpenetration checker or the validator's layer-order rules object. Check each in the app before committing: the checks prove no facet passes through another and no ordering is impossible, but only your eye tells you the fold reads correctly. 1895Box and sampan first, then the crane. Neither is shallow: the masu's wall-raising and the sampan's final turn inside out are coupled 3D steps, classified by Task 0b as rigid or flagged. The crane's inside reverse folds (neck, tail, head) are flagged `nonRigid` and use Task 0b's model; its petal folds use whatever 0b found. Run `foldc`, then `foldlint`, correcting guessed orderings with script overrides where the interpenetration checker or the validator's layer-order rules object. Check each in the app before committing: the checks prove no facet passes through another and no ordering is impossible, but only your eye tells you the fold reads correctly.
1762 1896
1763- [ ] **Step 4: Run tests to verify they pass** 1897- [ ] **Step 4: Run tests to verify they pass**
1764 1898
docs/superpowers/specs/2026-10-19-fold-design.md +51 −31
@@ -39,8 +39,10 @@ angle, at your pace, stopping where you stop.
39 39
40## Non-goals 40## Non-goals
41 41
42- Paper simulation. No bending, no stiffness, no self-collision response, 42- Paper simulation. No stiffness, no self-collision response, no
43 no crumpling. Paper is rigid flat facets hinged at creases. 43 crumpling. Paper is rigid flat facets hinged at creases, except during a
44 step flagged `nonRigid` (see *Interpolation*), whose bending is designed,
45 not simulated.
44- Deriving layer order from geometry. Layer order is authored and checked, 46- Deriving layer order from geometry. Layer order is authored and checked,
45 never computed. Computing it in general is a hard problem and getting it 47 never computed. Computing it in general is a hard problem and getting it
46 wrong looks worse than any amount of authoring effort. 48 wrong looks worse than any amount of authoring effort.
@@ -217,15 +219,22 @@ Each frame's `krz:step` carries it explicitly:
217 | "squash" | "petal" | "sink", 219 | "squash" | "petal" | "sink",
218 "instruction": "Valley fold the right corner to the left edge.", 220 "instruction": "Valley fold the right corner to the left edge.",
219 "axes": [ { "edge": 17, "movingFaces": [3, 4, 5], 221 "axes": [ { "edge": 17, "movingFaces": [3, 4, 5],
220 "startAngle": 0, "endAngle": 180, "peakAngle": null } ], 222 "startAngle": 0, "endAngle": 180, "peakAngle": null,
223 "parent": null, "window": [0, 1], "angles": null } ],
221 "rotateDegrees": 90, 224 "rotateDegrees": 90,
222 "turnOverAxis": "vertical" | "horizontal", 225 "turnOverAxis": "vertical" | "horizontal",
223 "repeatOf": 4, 226 "repeatOf": 4,
227 "nonRigid": false,
224 "viewpoint": { "eye": [0, 0, 1], "up": [0, 1, 0] } } 228 "viewpoint": { "eye": [0, 0, 1], "up": [0, 1, 0] } }
225``` 229```
226 230
227- `axes`: the angles are the axis edge's `edges_foldAngle` at the start, 231- `axes`: the angles are the axis edge's `edges_foldAngle` at the start,
228 at the end, and — for `foldAndUnfold` only — at the turning point. 232 at the end, and — for `foldAndUnfold` only — at the turning point.
233 `parent` is the index of the axis whose motion carries this one,
234 `window` its span of *t*, and `angles` a solved curve (see
235 *Interpolation*); `foldc` writes all three.
236- `nonRigid`: the step has no rigid motion and moves by the non-rigid model
237 (see *Interpolation*). Reverse folds, sinks and inversions.
229- `technique`: drives the notation and the instruction's wording; geometry 238- `technique`: drives the notation and the instruction's wording; geometry
230 ignores it. `plain` for anything that is not a named technique. 239 ignores it. `plain` for anything that is not a named technique.
231- `instruction`: the step in words, written by the author in the fold 240- `instruction`: the step in words, written by the author in the fold
@@ -243,8 +252,8 @@ Each frame's `krz:step` carries it explicitly:
243 252
244All of a step's axes share one parameter, so a petal fold or a reverse fold 253All of a step's axes share one parameter, so a petal fold or a reverse fold
245is one step with several axes and several moving sets, driven together. 254is one step with several axes and several moving sets, driven together.
246The traditional models need this. How those axes move together is the 255The traditional models need this. How those axes move together is set out
247subject of Task 0; see *Interpolation*. 256in *Interpolation*.
248 257
249### Step kinds 258### Step kinds
250 259
@@ -272,12 +281,11 @@ save file size and cost correctness.
272 281
273### Interpolation 282### Interpolation
274 283
275This section is the model Task 0 tests, and Task 0 rewrites it with the 284Decided by measurement: `docs/decisions/0001-interpolation-model.md`.
276result. Until then it is provisional; nothing that encodes it is built
277before Task 0 finishes.
278 285
279Between frame n − 1 and frame n, each of step n's axes rotates its moving 286Between frame n − 1 and frame n, step n's axes form a tree. Each axis
280faces rigidly about its crease line, on one shared parameter *t* in 0...1: 287rotates its moving faces rigidly about its crease line, on one shared
288parameter *t* in 0...1, and carries its children with it:
281 289
282- The crease line is the axis edge's endpoints in frame n − 1. 290- The crease line is the axis edge's endpoints in frame n − 1.
283- The axis is directed the way the moving face adjacent to the edge 291- The axis is directed the way the moving face adjacent to the edge
@@ -285,24 +293,33 @@ faces rigidly about its crease line, on one shared parameter *t* in 0...1:
285 direction (right-hand rule) turns the moving face toward the side its 293 direction (right-hand rule) turns the moving face toward the side its
286 normal points to, which is a valley — so the rotation is 294 normal points to, which is a valley — so the rotation is
287 `angle(t) − startAngle`, with the sign FOLD already gives fold angles. 295 `angle(t) − startAngle`, with the sign FOLD already gives fold angles.
288- `angle(t)` is `startAngle + t·(endAngle − startAngle)` for `fold`, and 296- A face's transform is its axis's rotation followed by the parent axis's
289 `startAngle + (peakAngle − startAngle)·(1 − |2t − 1|)` for 297 transform, up the tree.
290 `foldAndUnfold`, which reaches its peak at *t* = 0.5. 298- Each axis runs on its **window** `[t0, t1]` of *t*, waiting before it and
299 holding after it. Two flaps of equal reach folding toward each other on
300 one window collide at 120°. On separate windows they do not, and
301 `foldc`'s scripts stagger them.
302- `angle` is linear on the window for `fold`, and a tent through
303 `peakAngle` for `foldAndUnfold`, unless the axis has a **curve**.
304- Where the step's faces form loops around interior vertices, the angles
305 are coupled nonlinearly — at a flat-foldable degree-4 vertex with
306 consecutive sectors α, β, tan(ρ₁/2) = k·tan(ρ₂/2), k = cos((α+β)/2) /
307 cos((α−β)/2). Linear angles tear such a vertex by more than half the
308 sheet partway through. `foldc` holds one driving crease linear and solves
309 the rest so every loop closes. It writes each solved angle as a curve of
310 257 samples; cubic Hermite interpolation between them keeps the tear
311 under 1e-6.
291- `turnOver` and `rotate` rotate every vertex about the start frame's 312- `turnOver` and `rotate` rotate every vertex about the start frame's
292 bounding-box centre by *t* times the step's angle. 313 bounding-box centre by *t* times the step's angle.
293 314
294This is exact when the moving sets are disjoint, share no vertex except on 315**Non-rigid steps.** An inside reverse fold has no rigid motion with the flap
295their own axes, and no axis is carried by another set's motion — the letter 316closed. The only rigid path unfolds the flap flat and refolds it, which on
296fold, and most single valley and mountain folds. It is **not** exact for 317the crane would undo earlier steps on screen. Reverse folds, sinks and
297squash, petal and reverse folds, nor the masu's wall-raising step. There the 318inversions are therefore flagged `nonRigid`. They move by a designed
298faces form closed loops around interior vertices, the fold angles at a 319non-rigid motion, chosen by Task 0b, and are held to a strain bound that
299vertex are coupled nonlinearly (at a flat-foldable degree-4 vertex, 3200b sets instead of the isometry gate. The interpenetration check still
300tan(ρ₁/2) = k·tan(ρ₂/2)), and some axes are carried by other moving faces. 321applies to them. Task 0b also settles the petal fold, the sampan's
301Linear, independent rotation of each set tears the paper at the shared 322inversion and the masu's wall-raising.
302vertices partway through the fold even though both end frames are exact.
303For an inside reverse fold there is a further question of whether any rigid
304motion exists that keeps the rest of the flap still. Task 0 measures this
305on synthetic cases before any type commits to an answer.
306 323
307### Layer ordering during a fold 324### Layer ordering during a fold
308 325
@@ -574,11 +591,14 @@ The headline bars get mechanical checks rather than judgement:
5741. **Name.** "Fold" is not going to be available. The repo and bundle ID 5911. **Name.** "Fold" is not going to be available. The repo and bundle ID
575 use `fold` / `sh.krz.fold` as working names. 592 use `fold` / `sh.krz.fold` as working names.
5762. **Authoring tooling, and how many models.** Settled: build the 5932. **Authoring tooling, and how many models.** Settled: build the
577 compiler, cup first, four models for v1. The plan is 16 tasks: the 594 compiler, cup first, four models for v1. The plan is 17 tasks: two
578 interpolation spike (Task 0), the engine, the compiler, the app and the 595 interpolation spikes (Tasks 0 and 0b), the engine, the compiler, the app and the
579 cup, then the crane, sampan and box as one gated authoring task. 596 cup, then the crane, sampan and box as one gated authoring task.
5803. **The interpolation model for coupled steps.** Task 0 measures the 5973. **The interpolation model for coupled steps.** Settled (decision 0001,
581 candidates and recommends one. If no rigid model covers a v1 step, the 598 option A): an axis tree with windows and solved curves for rigid steps,
582 choice between splitting the step, dropping it and relaxing the 599 flagged non-rigid steps for reverse folds, sinks and inversions. The
583 isometry rule for it is the author's. 600 non-rigid model and its strain bound are Task 0b's.
5844. **Which boat.** Settled: the sampan (see *Rights*). 6014. **Which boat.** Settled: the sampan (see *Rights*).
6025. **The overlapping-moving-sets rule.** Decision 0001 found no case it
603 covers that staggered windows and the near-coplanar clusters do not.
604 Removing it is open.
spikes/interpolation/Sources/Spike/main.swift +40
@@ -63,6 +63,46 @@ if only == nil || only == "degree4" {
63 let at = { (t: Double) in [0, 1, 2, 3].map { fmt(m2.angle(e[$0], at: t)) }.joined(separator: ", ") } 63 let at = { (t: Double) in [0, 1, 2, 3].map { fmt(m2.angle(e[$0], at: t)) }.joined(separator: ", ") }
64 line("- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: \(s0 > 0 ? "+" : "−")): max gap \(sci(m2.maxGap)); angles (0°, 60°, 140°, 260°) at t = 0.25: \(at(0.25)); 0.5: \(at(0.5)); 0.75: \(at(0.75)); 1: \(at(1))") 64 line("- M2, 140° crease driven 0 → 180, 0° and 260° creases solved, 60° crease measured (seed for 0°: \(s0 > 0 ? "+" : "−")): max gap \(sci(m2.maxGap)); angles (0°, 60°, 140°, 260°) at t = 0.25: \(at(0.25)); 0.5: \(at(0.5)); 0.75: \(at(0.75)); 1: \(at(1))")
65 } 65 }
66 // The closed form for a flat-foldable degree-4 vertex with consecutive sectors α, β.
67 let k4 = cos((60.0 + 80) / 2 * .pi / 180) / cos((60.0 - 80) / 2 * .pi / 180)
68 line("- closed form tan(ρ₁/2) = k·tan(ρ₂/2), k = cos((α+β)/2) / cos((α−β)/2) = \(fmt(k4, 4)) for α = 60°, β = 80°")
69 // How densely must foldc sample a solved curve? Sample the solved angles at
70 // N + 1 points, rebuild them by linear or cubic interpolation, and measure the tear.
71 let reference = continuation(k, start: lin([0, 0, 0, 0])(0), drivers: [e[2]: { 180 * $0 }], free: [e[0], e[3]],
72 seed: [e[0]: 180, e[3]: 180], steps: 1024, collisions: false)
73 func sampled(_ n: Int) -> [[Double]] {
74 (0...n).map { i in [e[0], e[3]].map { reference.angle($0, at: Double(i) / Double(n)) } }
75 }
76 func cubic(_ ys: [Double], _ t: Double) -> Double {
77 let n = ys.count - 1
78 let x = t * Double(n)
79 let i = min(Int(x), n - 1), u = x - Double(i)
80 let m = { (j: Int) -> Double in
81 j == 0 ? ys[1] - ys[0] : j == n ? ys[n] - ys[n - 1] : (ys[j + 1] - ys[j - 1]) / 2
82 }
83 let (p0, p1, m0, m1) = (ys[i], ys[i + 1], m(i), m(i + 1))
84 let u2 = u * u, u3 = u2 * u
85 return (2 * u3 - 3 * u2 + 1) * p0 + (u3 - 2 * u2 + u) * m0 + (-2 * u3 + 3 * u2) * p1 + (u3 - u2) * m1
86 }
87 var rows: [String] = []
88 for n in [16, 32, 64, 128, 256] {
89 let samples = sampled(n)
90 func angles(_ interpolate: @escaping ([Double], Double) -> Double) -> (Double) -> [Double] {
91 { t in
92 var a = lin([0, 0, 0, 0])(0)
93 a[e[2]] = 180 * t
94 for (j, edge) in [e[0], e[3]].enumerated() { a[edge] = interpolate(samples.map { $0[j] }, t) }
95 return a
96 }
97 }
98 let linear = prescribed(k, steps: 2048, collisions: false, angles { ys, t in
99 let x = t * Double(ys.count - 1), i = min(Int(x), ys.count - 2), u = x - Double(i)
100 return ys[i] + u * (ys[i + 1] - ys[i])
101 })
102 let smooth = prescribed(k, steps: 2048, collisions: false, angles(cubic))
103 rows.append("N = \(n): linear \(sci(linear.maxGap)), cubic \(sci(smooth.maxGap))")
104 }
105 line("- solved curves sampled at N + 1 points and interpolated, max gap on a sheet of side 2: " + rows.joined(separator: "; "))
66 line("") 106 line("")
67} 107}
68 108