Commit aed8aad97f

aed8aad97f8b9ff46e99b49c48eae775f8ffb0ab

parent: d22ef01e39

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 18:37 UTC

Name the fold-and-unfold end angle in the travel range; check the sampan's rims stand above its floor

Ref #7

Layout: unified · split

Packages/FoldKit/Sources/FoldCompiler/FrameCompiler.swift +9 −7
@@ -501,18 +501,20 @@ func axesOnCycles(_ step: FoldStep, loops: [Int], _ file: FoldFile) -> Set<Int>
501501 }
502502}
503503
504/// Checks every axis's angle stays within ±180°, and a linear axis's between its start angle and
505/// its end angle, or its peak angle for a fold-and-unfold, to within 1e-6°, at four times the
506/// curve sample density over its window. A solved curve may turn back within ±180°. A non-rigid
507/// step is checked on its pop's open and close axes, which are what move it.
504/// Checks every axis's angle stays within ±180°, and a linear axis's within the range of its start,
505/// end and, for a fold-and-unfold, peak angles, to within 1e-6°, at four times the curve sample
506/// density over its window. A fold-and-unfold's end angle equals its start angle, so its range runs
507/// from the start to the peak. A solved curve may turn back within ±180°. A non-rigid step is
508/// checked on its pop's open and close axes, which are what move it.
508509func checkTravel(_ n: Int, _ step: FoldStep) throws {
509510 let moving = step.pop.map { ($0.openAxes + $0.closeAxes, StepKind.fold) } ?? (step.axes, step.kind)
510511 let intervals = 4 * (curveSamples - 1)
511512 for axis in moving.0 {
512 let far = moving.1 == .foldAndUnfold ? axis.peakAngle ?? axis.endAngle : axis.endAngle
513 let scripted = [axis.startAngle, axis.endAngle]
514 + (moving.1 == .foldAndUnfold ? [axis.peakAngle ?? axis.endAngle] : [])
513515 let linear = axis.curve == nil
514 let low = (linear ? max(min(axis.startAngle, far), -180) : -180) - angleSnapTolerance
515 let high = (linear ? min(max(axis.startAngle, far), 180) : 180) + angleSnapTolerance
516 let low = (linear ? max(scripted.min()!, -180) : -180) - angleSnapTolerance
517 let high = (linear ? min(scripted.max()!, 180) : 180) + angleSnapTolerance
516518 let w = axis.window
517519 for k in 0...intervals {
518520 let angle = axis.angle(at: w.lowerBound + Double(k) / Double(intervals) * (w.upperBound - w.lowerBound),
Packages/FoldKit/Tests/ModelsTests/CatalogueTests.swift +13 −5
@@ -142,12 +142,20 @@ private func sessionCamera(_ file: FoldFile, _ step: FoldStep, aspect: Double) -
142142}
143143
144144@Test func theSampanTurnsInsideOutRigidlyAndEndsWithItsSidesUp() throws {
145 // decision 0002: the inside-out step closes, so it is rigid; the boat is not flat at the end
145 // decision 0002: the inside-out step closes, so it is rigid; at the end the floor's corners
146 // (½, 1½), (3½, 1½), (3½, 2½), (½, 2½) lie level and the sides' top corners (1, 1), (3, 1),
147 // (3, 3), (1, 3) stand at least 0.4 above them
146148 let sampan = try ModelLibrary.model(named: "sampan")
147 let steps = try readSteps(sampan)
148 #expect(steps.allSatisfy { !$0.nonRigid })
149 let heights = sampan.frames[sampan.stepCount].verticesCoords.map(\.z)
150 #expect(heights.max()! - heights.min()! > 0.4)
149 #expect(try readSteps(sampan).allSatisfy { !$0.nonRigid })
150 let flat = sampan.frames[0].verticesCoords, last = sampan.frames[sampan.stepCount].verticesCoords
151 func height(_ x: Double, _ y: Double) throws -> Double {
152 try #require(flat.indices.first { abs(flat[$0].x - x) < 1e-9 && abs(flat[$0].y - y) < 1e-9 }.map { last[$0].z })
153 }
154 let floor = try [(0.5, 1.5), (3.5, 1.5), (3.5, 2.5), (0.5, 2.5)].map { try height($0.0, $0.1) }
155 #expect(floor.max()! - floor.min()! < 1e-9)
156 for (x, y) in [(1.0, 1.0), (3.0, 1.0), (3.0, 3.0), (1.0, 3.0)] {
157 #expect(try height(x, y) - floor[0] > 0.4, "rim corner (\(x), \(y))")
158 }
151159}
152160
153161@Test func theCupContainsATurnOverStep() throws {