Commit db09babfe7

db09babfe76cac61a0c2a73c4c84aa7946269679

parent: b56cd8779b

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-23 02:31 UTC

Review fixes: docs for the fallback, band and mesh; mesh test over the shipped models

Ref #7

Layout: unified · split

Packages/FoldKit/Sources/FoldCompiler/FrameCompiler.swift −1
@@ -776,7 +776,6 @@ private func symmetricEigen(_ matrix: [[Double]]) -> (values: [Double], vectors:
776776 return ((0..<n).map { a[$0][$0] }, (0..<n).map { i in (0..<n).map { v[$0][i] } })
777777}
778778
779
780779/// Gaussian elimination with partial pivoting; nil when `a` is singular.
781780private func solveLinear(_ a: [[Double]], _ b: [Double]) -> [Double]? {
782781 var m = a, x = b
Packages/FoldKit/Sources/Folding/FoldInterpolator.swift +8 −2
@@ -171,7 +171,12 @@ public struct FoldInterpolator: Sendable {
171171/// toward the layer across the spine. The tip is `tip`; its spine is the edges of `spine` with both
172172/// faces in it. A tip face's partner is the face across the spine from the faces it joins without
173173/// crossing the spine. A triangle at distance d from the spine's line in `start` (frame n − 1),
174/// its centroid's, has weight d / b, b being the largest such distance of a tip triangle.
174/// its centroid's, has weight d / b, b being the largest such distance of a tip triangle; one
175/// with weight 1 or more is not blended.
176///
177/// Limitations: each tip layer takes one partner face, the first met across the spine, so a
178/// layer facing several faces across it blends toward only one of them; and the spine's line is
179/// the first tip-spine edge's, so a tip spine that is not straight is measured from that edge.
175180private func band(mesh: RenderMesh, file: FoldFile, tip: Set<Int>, spine: [Int],
176181 start: [SIMD3<Double>]) -> [Bending.Blend] {
177182 let edgeFaces = edgesFaces(file)
@@ -217,7 +222,8 @@ private func band(mesh: RenderMesh, file: FoldFile, tip: Set<Int>, spine: [Int],
217222
218223/// Decision 0003's ruling R78: the tip's mesh vertices on its spine's line in `start` (frame
219224/// n − 1), grouped where they coincide in `start` and in every pose of `poses`, so that the
220/// halves' coincident fold edges on that line move together during the pop.
225/// halves' coincident fold edges on that line move together during the pop. As for the band, the
226/// line is the first tip-spine edge's.
221227private func spineTies(mesh: RenderMesh, file: FoldFile, tip: Set<Int>, spine: [Int], start: [SIMD3<Double>],
222228 poses: [[SIMD3<Double>]]) -> [[Int]] {
223229 let edgeFaces = edgesFaces(file)
Packages/FoldKit/Sources/Folding/FoldParameterMapping.swift +4 −1
@@ -38,7 +38,10 @@ public struct FoldParameterMapping: Sendable {
3838 private static let samples = 129
3939 private static let minimumLength = 8.0
4040 /// Points dragged down for the whole step where a segment's path is under `minimumLength`: 160,
41 /// or half the view's height when that is less, so a fallback stretch ends inside the view.
41 /// or half the view's height when that is less. A stretch that starts in the upper half of the
42 /// view then ends inside it; one that starts lower can run past its bottom edge, as the crane's
43 /// head pop does on iPhone (it starts at y ≈ 316 of 362 points). Its direction stays down
44 /// pending a check on a device (ruling R84).
4245 private let fallbackThrow: Double
4346 /// How much further, in points, another axis's centroid must travel to replace the previous
4447 /// segment's axis.
Packages/FoldKit/Sources/Folding/LayerOrder.swift +5 −3
@@ -202,9 +202,9 @@ public func stackDepth(positions: [SIMD3<Double>], faces: [[Int]]) -> Int {
202202
203203// MARK: - Helpers
204204
205/// The connected components of `linked` over `0..<count`, each in index order, ordered by their
206/// smallest member.
207/// The faces of each near-coplanar cluster, in index order, as `LayerOrder.clusters` links them.
205/// The faces of each near-coplanar cluster, in index order, ordered by their smallest face, as
206/// `LayerOrder.clusters` links them: normals within 2° of one line, each face's vertices within
207/// sin 2° × the positions' bounding-box diagonal of the other's plane, and interiors overlapping.
208208func clusterMembers(positions: [SIMD3<Double>], faces: [[Int]]) -> [[Int]] {
209209 let normals = faceNormals(positions: positions, faces: faces)
210210 let diagonal = boundingBoxDiagonal(positions)
@@ -226,6 +226,8 @@ func clusterMembers(positions: [SIMD3<Double>], faces: [[Int]]) -> [[Int]] {
226226 return components(faces.count, linked: linked)
227227}
228228
229/// The connected components of `linked` over `0..<count`, each in index order, ordered by their
230/// smallest member.
229231private func components(_ count: Int, linked: (Int, Int) -> Bool) -> [[Int]] {
230232 var component = Array<Int?>(repeating: nil, count: count)
231233 var result: [[Int]] = []
Packages/FoldKit/Sources/Folding/RenderMesh.swift +1
@@ -7,6 +7,7 @@ import simd
77/// is triangulated on those points by ear clipping, point insertion and Lawson flips, so it is
88/// Delaunay within the face. Faces sharing a side share its points, so the mesh is one connected
99/// sheet. The FOLD topology is unchanged; a non-rigid step bends this mesh, not the FOLD faces.
10/// The construction assumes convex faces, which the validator enforces.
1011public struct RenderMesh: Sendable {
1112 /// Frame 0 positions in its plane.
1213 public let vertices: [SIMD2<Double>]
Packages/FoldKit/Tests/FoldingTests/RenderMeshTests.swift +8 −3
@@ -89,10 +89,15 @@ private func meshTestFiles() throws -> [FoldFile] {
8989 offGrid()]
9090}
9191
92/// The shipped models' crease patterns, whose faces are their frame 0's.
93private func shippedPatterns() throws -> [FoldFile] {
94 try ["cup", "box", "sampan", "crane"].map { try FoldFile(contentsOf: pattern($0)) }
95}
96
9297@Test func noMeshEdgeIsMuchShorterThanTheSpacing() throws {
93 // decision 0003: 0.15 of the spacing, except where a crease is shorter or creases meet sharply,
94 // which none of these sheets has
95 for file in try meshTestFiles() {
98 // decision 0003: 0.15 of the spacing, except where a crease is shorter or creases meet sharply;
99 // none of these sheets needs the exception, the shipped models' included
100 for file in try meshTestFiles() + shippedPatterns() {
96101 let spacing = RenderMesh.spacing(for: file)
97102 let mesh = RenderMesh(file: file, spacing: spacing)
98103 let shortest = edges(mesh).map { simd_distance(mesh.vertices[$0.x], mesh.vertices[$0.y]) }.min()!
docs/decisions/0003-bending-openings.md +8 −7
@@ -97,8 +97,7 @@ The fixture is not a clean comparison. Its pop strain depends on the mesh, rangi
9797each other, at about 9%. The grid's 7.46% is partly an artifact of its edges running
9898only in three directions.
9999
100**Recommendation: the Delaunay construction.** Keep the bound on edge strain and report
101principal strain alongside it.
100**Recommendation: the Delaunay construction.** Keep the bound on edge strain.
102101
103102## 2. Crane: neck, tail and head
104103
@@ -324,8 +323,7 @@ them.
324323 is a rigid M2 motion, like any coupled step.
3253243. **Pop: banded slerp** (§2), at a default opening of 20° from flat. Plain slerp also
326325 passes the crane at 20° (8.74%, 9.01%), with little margin.
3274. **Bound: 10% edge strain on the Delaunay mesh, unchanged.** Principal strain is
328 reported beside it.
3264. **Bound: 10% edge strain on the Delaunay mesh, unchanged.**
3293275. **Sampan: not solved by bending.** The options are under *Decisions for the author*.
330328
331329## Cost
@@ -365,11 +363,14 @@ them.
365363 - With `openOn`, the open axes are the tree that the loop solver closes, driven by
366364 `openOn` from its angle to ±α; the close is the same in reverse after the pop.
367365 - Mesh interpenetration is checked in all three phases.
368- **`Bending`**: per-triangle turn targets. A tip triangle at distance d from the tip's
369 spine (in frame n − 1) has width b, the tip's width there. Its target is
366- **`Bending`**: per-triangle turn targets. A tip triangle lies at distance d from the
367 tip's spine (in frame n − 1); b is one width for the whole tip, the largest such d of a
368 tip triangle, as the spike computed it. A triangle with d / b < 1 has target
370369 slerp(mid, own, w), where:
371370 - mid = slerp(own, other, ½);
372 - w = min(1, d / b) + (1 − min(1, d / b))·(1 − 4s(1 − s)).
371 - w = d / b + (1 − d / b)·(1 − 4s(1 − s)).
372
373 Triangles with d / b ≥ 1 are not blended and keep their own turn.
373374- **Crane pattern:** bend lines on the spine's line through the front wing's centre and
374375 the layer under it, added with the neck and tail creases.
375376- **Tests** (Task 15):