Commit aa644a399c

aa644a399cb2bb710c95fa54a293fb9ee0e54ef8

parent: 058a42d32c

Verified · cmc

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

Drag tests: keep the retraced-stretch cases at 30°, add the 20° pop's turnarounds

Ref #7

Layout: unified · split

Packages/FoldKit/Sources/FoldKitTestSupport/Helpers.swift +6
@@ -331,6 +331,12 @@ public func compiled(_ name: String) throws -> FoldFile {
331331 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold")))
332332}
333333
334/// `compiled(name)` with step `step`'s `openAngle` set to `degrees`. Steps count from 1.
335public func compiled(_ name: String, openAngle degrees: Double, step: Int) throws -> FoldFile {
336 try compile(FoldScript(contentsOf: fixture("\(name).foldscript")).withOpenAngle(degrees, step: step),
337 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold")))
338}
339
334340/// Whether two files have the same metadata, topology, assignments, layer orders and steps, with
335341/// coordinates, angles and pop phases within `tolerance`. Face orders compare as sets;
336342/// `file_creator` is ignored.
Packages/FoldKit/Tests/FoldingTests/FoldParameterTests.swift +35 −9
@@ -41,9 +41,7 @@ import Testing
4141
4242@Test func aNonRigidStepIsDraggedPhaseByPhase() throws {
4343 // following the path's own samples in order reaches t = 1 without ever going back
44 let m = try FoldParameterMapping(file: compiled("reverse"), step: readSteps(compiled("reverse"))[1],
45 camera: Camera(eye: SIMD3(2, 1, 8), target: SIMD3(2, 1, 0), up: SIMD3(0, 1, 0), fieldOfView: .pi / 4),
46 viewportSize: SIMD2(800, 600))
44 let m = try reverseMapping(openAngle: 30)
4745 var t = 0.0
4846 for p in m.path.dropFirst() {
4947 let next = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t)
@@ -127,9 +125,15 @@ import Testing
127125 #expect(abs(back - 0.6) < 0.01)
128126}
129127
130/// The mapping for the reverse fixture's non-rigid step, seen from above.
131private func reverseMapping() throws -> FoldParameterMapping {
132 let file = try compiled("reverse")
128/// The reverse fixture opened to `openAngle` from flat.
129private func reverseFixture(openAngle: Double) throws -> FoldFile {
130 try compiled("reverse", openAngle: openAngle, step: 2)
131}
132
133/// The mapping for the reverse fixture's non-rigid step, seen from above. Opened to 30° from flat
134/// the pop moves the tip far enough to be followed, and its path starts back along the open's.
135private func reverseMapping(openAngle: Double) throws -> FoldParameterMapping {
136 let file = try reverseFixture(openAngle: openAngle)
133137 return FoldParameterMapping(file: file, step: try readSteps(file)[1],
134138 camera: Camera(eye: SIMD3(2, 1, 8), target: SIMD3(2, 1, 0), up: SIMD3(0, 1, 0), fieldOfView: .pi / 4),
135139 viewportSize: SIMD2(800, 600))
@@ -137,7 +141,7 @@ private func reverseMapping() throws -> FoldParameterMapping {
137141
138142@Test func aNonRigidStepCanBeDraggedBackThroughItsPhases() throws {
139143 // the pop's path starts back along the open's, so dragging back passes that turnaround too
140 let m = try reverseMapping()
144 let m = try reverseMapping(openAngle: 30)
141145 var t = 0.0
142146 for p in m.path.dropFirst() { t = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t) }
143147 #expect(t == 1)
@@ -177,8 +181,8 @@ private func reverseMapping() throws -> FoldParameterMapping {
177181@Test func aDragOnARetracedStretchStaysInItsPhase() throws {
178182 // the pop's samples 44...54 lie within half a point of the open's path; a finger there stays
179183 // in the phase the drag is in until it reaches the turnaround
180 let m = try reverseMapping()
181 let phases = try readSteps(compiled("reverse"))[1].pop!.phases
184 let m = try reverseMapping(openAngle: 30)
185 let phases = try readSteps(reverseFixture(openAngle: 30))[1].pop!.phases
182186 var opening = m.position(at: 0)
183187 for k in 1...36 { opening = m.position(grabbedAt: m.path[0], translation: m.path[k] - m.path[0], current: opening) }
184188 var popping = opening
@@ -190,3 +194,25 @@ private func reverseMapping() throws -> FoldParameterMapping {
190194 #expect(m.position(grabbedAt: m.path[0], translation: p, current: popping).t > phases.lowerBound, "sample \(k)")
191195 }
192196}
197
198@Test func aPopTooSmallToFollowIsDraggedThroughItsTurnarounds() throws {
199 // at the default 20° from flat the pop moves the tip too little to follow, so its path is the
200 // straight line down, retracing the open's seen from above; a finger following the path
201 // passes through each turnaround, where the drag changes phase, forward and back
202 let m = try reverseMapping(openAngle: 20)
203 let phases = try readSteps(reverseFixture(openAngle: 20))[1].pop!.phases
204 let ts = ((1...128).map { Double($0) / 128 } + [phases.lowerBound, phases.upperBound]).sorted()
205 var position = m.position(at: 0)
206 for t in ts {
207 let next = m.position(grabbedAt: m.path[0], translation: m.point(at: t) - m.path[0], current: position)
208 #expect(next.t >= position.t - 1e-9)
209 position = next
210 }
211 #expect(position.t == 1)
212 for t in ts.reversed().dropFirst() + [0] {
213 let next = m.position(grabbedAt: m.path[0], translation: m.point(at: t) - m.path[0], current: position)
214 #expect(next.t <= position.t + 1e-9)
215 position = next
216 }
217 #expect(position.t < 0.01)
218}