Commit a23f485bbc

a23f485bbc691dc4e152264345a974ac525cda10

parent: 9bbedb1fd5

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-19 21:22 UTC

Validator: a fold-and-unfold crease is not a subdivision edge

Ref #2

Layout: unified · split

Packages/FoldKit/Sources/FoldFormat/FoldValidator.swift +6 −3
@@ -182,13 +182,16 @@ private func nonConvexFaces(_ file: FoldFile) -> [FoldDefect] {
182182}
183183
184184/// 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.
186186private 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
188191 let assignment = file.frames[0].edgesAssignment
189192 guard e < assignment.count, assignment[e] != .boundary else { return nil }
190193 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
192195 e < frame.edgesAssignment.count && e < frame.edgesFoldAngle.count
193196 && frame.edgesAssignment[e] == .flat && frame.edgesFoldAngle[e] == 0
194197 }
Packages/FoldKit/Tests/FoldFormatTests/ValidatorTests.swift +9
@@ -96,3 +96,12 @@ func acceptsAValidModel(_ name: String) throws {
9696 #expect(validate(try FoldFile(contentsOf: fixture("bad-index.fold")))
9797 == [.vertexIndexOutOfRange(edge: 0)])
9898}
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}