Commit a23f485bbc
Verified · cmc
Layout: unified · split
Packages/FoldKit/Sources/FoldFormat/FoldValidator.swift +6 −3
| @@ -182,13 +182,16 @@ private func nonConvexFaces(_ file: FoldFile) -> [FoldDefect] { | ||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /// A non-boundary edge without `edges_krz:firstCreasedAtStep` is a defect unless it is a |
| 185 | /// subdivision edge: `F` and flat in every frame. | |
| 185 | /// subdivision edge: `F` and flat in every frame, and never the axis of a step. | |
| 186 | 186 | private func missingFirstCreasedAtStep(_ file: FoldFile) -> [FoldDefect] { |
| 187 | file.edgesVertices.indices.compactMap { e in | |
| 187 | let axisEdges = Set(file.frames.compactMap(\.step).flatMap { step in | |
| 188 | (step.axes + (step.pop?.openAxes ?? []) + (step.pop?.closeAxes ?? [])).map(\.edge) | |
| 189 | }) | |
| 190 | return file.edgesVertices.indices.compactMap { e in | |
| 188 | 191 | let assignment = file.frames[0].edgesAssignment |
| 189 | 192 | guard e < assignment.count, assignment[e] != .boundary else { return nil } |
| 190 | 193 | if e < file.edgesFirstCreasedAtStep.count, file.edgesFirstCreasedAtStep[e] != nil { return nil } |
| 191 | let subdivision = file.frames.allSatisfy { frame in | |
| 194 | let subdivision = !axisEdges.contains(e) && file.frames.allSatisfy { frame in | |
| 192 | 195 | e < frame.edgesAssignment.count && e < frame.edgesFoldAngle.count |
| 193 | 196 | && frame.edgesAssignment[e] == .flat && frame.edgesFoldAngle[e] == 0 |
| 194 | 197 | } |
Packages/FoldKit/Tests/FoldFormatTests/ValidatorTests.swift +9
| @@ -96,3 +96,12 @@ func acceptsAValidModel(_ name: String) throws { | ||
| 96 | 96 | #expect(validate(try FoldFile(contentsOf: fixture("bad-index.fold"))) |
| 97 | 97 | == [.vertexIndexOutOfRange(edge: 0)]) |
| 98 | 98 | } |
| 99 | ||
| 100 | @Test func rejectsAFoldAndUnfoldCreaseWithoutFirstCreasedAtStep() throws { | |
| 101 | // without step 3, x = 1 is only folded and unfolded in step 1, so e8 is F and flat throughout | |
| 102 | var file = try FoldFile(contentsOf: fixture("quarters.fold")) | |
| 103 | file.frames.removeLast() | |
| 104 | file.edgesFirstCreasedAtStep[8] = nil | |
| 105 | file.edgesFirstCreasedAtStep[9] = nil | |
| 106 | #expect(validate(file).contains(.missingFirstCreasedAtStep(edge: 8))) | |
| 107 | } | |