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 {
331 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold"))) 331 pattern: FoldFile(contentsOf: fixture("\(name)-cp.fold")))
332} 332}
333 333
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
334/// Whether two files have the same metadata, topology, assignments, layer orders and steps, with 340/// Whether two files have the same metadata, topology, assignments, layer orders and steps, with
335/// coordinates, angles and pop phases within `tolerance`. Face orders compare as sets; 341/// coordinates, angles and pop phases within `tolerance`. Face orders compare as sets;
336/// `file_creator` is ignored. 342/// `file_creator` is ignored.
Packages/FoldKit/Tests/FoldingTests/FoldParameterTests.swift +35 −9
@@ -41,9 +41,7 @@ import Testing
41 41
42@Test func aNonRigidStepIsDraggedPhaseByPhase() throws { 42@Test func aNonRigidStepIsDraggedPhaseByPhase() throws {
43 // following the path's own samples in order reaches t = 1 without ever going back 43 // 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], 44 let m = try reverseMapping(openAngle: 30)
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))
47 var t = 0.0 45 var t = 0.0
48 for p in m.path.dropFirst() { 46 for p in m.path.dropFirst() {
49 let next = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t) 47 let next = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t)
@@ -127,9 +125,15 @@ import Testing
127 #expect(abs(back - 0.6) < 0.01) 125 #expect(abs(back - 0.6) < 0.01)
128} 126}
129 127
130/// The mapping for the reverse fixture's non-rigid step, seen from above. 128/// The reverse fixture opened to `openAngle` from flat.
131private func reverseMapping() throws -> FoldParameterMapping { 129private func reverseFixture(openAngle: Double) throws -> FoldFile {
132 let file = try compiled("reverse") 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)
133 return FoldParameterMapping(file: file, step: try readSteps(file)[1], 137 return FoldParameterMapping(file: file, step: try readSteps(file)[1],
134 camera: Camera(eye: SIMD3(2, 1, 8), target: SIMD3(2, 1, 0), up: SIMD3(0, 1, 0), fieldOfView: .pi / 4), 138 camera: Camera(eye: SIMD3(2, 1, 8), target: SIMD3(2, 1, 0), up: SIMD3(0, 1, 0), fieldOfView: .pi / 4),
135 viewportSize: SIMD2(800, 600)) 139 viewportSize: SIMD2(800, 600))
@@ -137,7 +141,7 @@ private func reverseMapping() throws -> FoldParameterMapping {
137 141
138@Test func aNonRigidStepCanBeDraggedBackThroughItsPhases() throws { 142@Test func aNonRigidStepCanBeDraggedBackThroughItsPhases() throws {
139 // the pop's path starts back along the open's, so dragging back passes that turnaround too 143 // 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)
141 var t = 0.0 145 var t = 0.0
142 for p in m.path.dropFirst() { t = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t) } 146 for p in m.path.dropFirst() { t = m.parameter(grabbedAt: m.path[0], translation: p - m.path[0], current: t) }
143 #expect(t == 1) 147 #expect(t == 1)
@@ -177,8 +181,8 @@ private func reverseMapping() throws -> FoldParameterMapping {
177@Test func aDragOnARetracedStretchStaysInItsPhase() throws { 181@Test func aDragOnARetracedStretchStaysInItsPhase() throws {
178 // the pop's samples 44...54 lie within half a point of the open's path; a finger there stays 182 // the pop's samples 44...54 lie within half a point of the open's path; a finger there stays
179 // in the phase the drag is in until it reaches the turnaround 183 // in the phase the drag is in until it reaches the turnaround
180 let m = try reverseMapping() 184 let m = try reverseMapping(openAngle: 30)
181 let phases = try readSteps(compiled("reverse"))[1].pop!.phases 185 let phases = try readSteps(reverseFixture(openAngle: 30))[1].pop!.phases
182 var opening = m.position(at: 0) 186 var opening = m.position(at: 0)
183 for k in 1...36 { opening = m.position(grabbedAt: m.path[0], translation: m.path[k] - m.path[0], current: opening) } 187 for k in 1...36 { opening = m.position(grabbedAt: m.path[0], translation: m.path[k] - m.path[0], current: opening) }
184 var popping = opening 188 var popping = opening
@@ -190,3 +194,25 @@ private func reverseMapping() throws -> FoldParameterMapping {
190 #expect(m.position(grabbedAt: m.path[0], translation: p, current: popping).t > phases.lowerBound, "sample \(k)") 194 #expect(m.position(grabbedAt: m.path[0], translation: p, current: popping).t > phases.lowerBound, "sample \(k)")
191 } 195 }
192} 196}
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}