Packages/FoldKit/Tests/FoldingTests/LayerMotionTests.swift

main
fold/Packages/FoldKit/Tests/FoldingTests/LayerMotionTests.swift history · blame · raw

47 lines · 2370 bytes

4 symbols in this file
 1import Testing
 2import FoldFormat
 3import Folding
 4import FoldKitTestSupport
 5
 6@Test func aFlapArrivingFromTheSideOppositeItsOrderIsFlagged() throws {
 7    // frame 2 puts f2 between f0 and f1; f2 folds over the top, so it arrives from above f0
 8    var file = try FoldFile(contentsOf: fixture("letter-sequential.fold"))
 9    file.frames[2].faceOrders = [[0, 1, 1], [0, 2, -1], [1, 2, 1]]
10    // x = 1 is f2's edge, not its interior, so the taco rules do not catch it
11    #expect(validate(file).isEmpty)
12    #expect(layerMotionDefects(file) == [.movesThroughStillFace(step: 2, moving: 2, still: 0)])
13}
14
15@Test func oneStepIsCheckedOnTheFramesUpToIt() throws {
16    var file = try FoldFile(contentsOf: fixture("letter-sequential.fold"))
17    file.frames[2].faceOrders = [[0, 1, 1], [0, 2, -1], [1, 2, 1]]
18    var head = file
19    head.frames.removeLast()
20    #expect(layerMotionDefects(step: 1, in: head).isEmpty)
21    #expect(layerMotionDefects(step: 2, in: file) == [.movesThroughStillFace(step: 2, moving: 2, still: 0)])
22}
23
24@Test func aFlapDepartingTowardALayerAboveItIsFlagged() throws {
25    // step 3 unfolds f0 from under f2, which covers f0's hinge at x = 1
26    var file = try FoldFile(contentsOf: fixture("letter-sequential.fold"))
27    var points = file.frames[2].verticesCoords
28    points[0] = SIMD3(0, 0, 0)
29    points[7] = SIMD3(0, 3, 0)
30    var assignment = file.frames[2].edgesAssignment
31    assignment[8] = .flat
32    var angles = file.frames[2].edgesFoldAngle
33    angles[8] = 0
34    let step = StepRecord(kind: .fold, instruction: "Unfold the left third.",
35                          axes: [AxisRecord(edge: 8, movingFaces: [0], startAngle: 180, endAngle: 0)],
36                          viewpoint: Viewpoint(eye: SIMD3(0, 0, 1), up: SIMD3(0, 1, 0)))
37    file.frames.append(FoldFrame(verticesCoords: points, edgesAssignment: assignment, edgesFoldAngle: angles,
38                                 faceOrders: [[1, 2, 1]], step: step))
39    #expect(validate(file).isEmpty)
40    #expect(layerMotionDefects(file) == [.movesThroughStillFace(step: 3, moving: 0, still: 2)])
41}
42
43@Test(arguments: ["square", "half", "mountain", "letter", "letter-sequential", "letter-staggered", "quarters",
44                  "occlusion"])
45func noSyntheticModelMovesThroughAStillFace(_ name: String) throws {
46    #expect(layerMotionDefects(try FoldFile(contentsOf: fixture("\(name).fold"))).isEmpty)
47}