import Testing import FoldFormat import Folding import FoldKitTestSupport @Test func aFlapArrivingFromTheSideOppositeItsOrderIsFlagged() throws { // frame 2 puts f2 between f0 and f1; f2 folds over the top, so it arrives from above f0 var file = try FoldFile(contentsOf: fixture("letter-sequential.fold")) file.frames[2].faceOrders = [[0, 1, 1], [0, 2, -1], [1, 2, 1]] // x = 1 is f2's edge, not its interior, so the taco rules do not catch it #expect(validate(file).isEmpty) #expect(layerMotionDefects(file) == [.movesThroughStillFace(step: 2, moving: 2, still: 0)]) } @Test func oneStepIsCheckedOnTheFramesUpToIt() throws { var file = try FoldFile(contentsOf: fixture("letter-sequential.fold")) file.frames[2].faceOrders = [[0, 1, 1], [0, 2, -1], [1, 2, 1]] var head = file head.frames.removeLast() #expect(layerMotionDefects(step: 1, in: head).isEmpty) #expect(layerMotionDefects(step: 2, in: file) == [.movesThroughStillFace(step: 2, moving: 2, still: 0)]) } @Test func aFlapDepartingTowardALayerAboveItIsFlagged() throws { // step 3 unfolds f0 from under f2, which covers f0's hinge at x = 1 var file = try FoldFile(contentsOf: fixture("letter-sequential.fold")) var points = file.frames[2].verticesCoords points[0] = SIMD3(0, 0, 0) points[7] = SIMD3(0, 3, 0) var assignment = file.frames[2].edgesAssignment assignment[8] = .flat var angles = file.frames[2].edgesFoldAngle angles[8] = 0 let step = StepRecord(kind: .fold, instruction: "Unfold the left third.", axes: [AxisRecord(edge: 8, movingFaces: [0], startAngle: 180, endAngle: 0)], viewpoint: Viewpoint(eye: SIMD3(0, 0, 1), up: SIMD3(0, 1, 0))) file.frames.append(FoldFrame(verticesCoords: points, edgesAssignment: assignment, edgesFoldAngle: angles, faceOrders: [[1, 2, 1]], step: step)) #expect(validate(file).isEmpty) #expect(layerMotionDefects(file) == [.movesThroughStillFace(step: 3, moving: 0, still: 2)]) } @Test(arguments: ["square", "half", "mountain", "letter", "letter-sequential", "letter-staggered", "quarters", "occlusion"]) func noSyntheticModelMovesThroughAStillFace(_ name: String) throws { #expect(layerMotionDefects(try FoldFile(contentsOf: fixture("\(name).fold"))).isEmpty) }