Commit ef476d07c5

ef476d07c504258ab91f8d6b95ebd8061440d489

parent: 7f5a2ded37

Verified · cmc

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

Give the unfold arrow only to an axis moving toward flat

Ref #7

Layout: unified · split

Packages/FoldKit/Sources/Notation/DiagramBuilder.swift +2 −2
@@ -69,7 +69,7 @@ private let arcBulge = 0.3
69/// not drawn. An edge the step creases (its two faces move differently) is dashed for a valley as 69/// not drawn. An edge the step creases (its two faces move differently) is dashed for a valley as
70/// seen and dash-dot for a mountain, whatever its assignment, unless it is folded in the drawn 70/// seen and dash-dot for a mountain, whatever its assignment, unless it is folded in the drawn
71/// frame; `B` edges and folded creases are solid; earlier creases flat again are light. An axis 71/// frame; `B` edges and folded creases are solid; earlier creases flat again are light. An axis
72/// folded in the drawn frame gets the unfold arrow. Each edge is clipped by `visibleSegments`, and 72/// that moves toward flat gets the unfold arrow. Each edge is clipped by `visibleSegments`, and
73/// a piece coincident with one already drawn is drawn once, step creases before solid before light. 73/// a piece coincident with one already drawn is drawn once, step creases before solid before light.
74/// 74///
75/// - Precondition: `validate(file)` is empty. 75/// - Precondition: `validate(file)` is empty.
@@ -201,7 +201,7 @@ private func arrows(_ file: FoldFile, _ step: FoldStep, valley: [Bool], project:
201 let over = apex(from, to) 201 let over = apex(from, to)
202 if step.kind == .foldAndUnfold { 202 if step.kind == .foldAndUnfold {
203 arrows.append(.foldAndUnfold(from: from, over: over, to: to, mountain: !valley[i])) 203 arrows.append(.foldAndUnfold(from: from, over: over, to: to, mountain: !valley[i]))
204 } else if abs(axis.startAngle) > 1e-9 { 204 } else if abs(axis.endAngle) < abs(axis.startAngle) - 1e-9 {
205 arrows.append(.unfold(from: from, over: over, to: to)) 205 arrows.append(.unfold(from: from, over: over, to: to))
206 } else if valley[i] { 206 } else if valley[i] {
207 arrows.append(.valleyFold(from: from, over: over, to: to)) 207 arrows.append(.valleyFold(from: from, over: over, to: to))
Packages/FoldKit/Tests/NotationTests/DiagramTests.swift +17
@@ -118,6 +118,23 @@ private func halfWithWallRaised() throws -> (FoldFrame, FoldFile) {
118 #expect(d.arrows.allSatisfy { if case .unfold = $0 { true } else { false } }) 118 #expect(d.arrows.allSatisfy { if case .unfold = $0 { true } else { false } })
119} 119}
120 120
121@Test func anAxisAlreadyFoldedThatFoldsFurtherGetsAFoldArrowNotAnUnfoldArrow() throws {
122 // half.fold with f1 already stood up at 90° about e6, then folded on to 180: e6 stays the
123 // existing line, and the arrow is the valley fold as seen from the oblique eye
124 var (frame, file) = try halfWithWallRaised()
125 frame.edgesFoldAngle[6] = 90
126 file.frames[0] = frame
127 let flat = try readStep(1, in: FoldFile(contentsOf: fixture("half.fold"))).axes[0]
128 let axis = FoldAxis(edge: flat.edge, origin: flat.origin, direction: flat.direction,
129 movingFaces: flat.movingFaces, startAngle: 90, endAngle: 180)
130 let step = FoldStep(index: 1, kind: .fold, instruction: "Fold the wall down.", axes: [axis],
131 viewpoint: Viewpoint(eye: SIMD3(-1, 0, 1), up: SIMD3(0, 1, 0)))
132 let d = buildDiagram(file: file, step: step)
133 #expect(d.edges.filter { $0.edge == 6 }.allSatisfy { $0.style == .solid })
134 #expect(d.arrows.count == 1)
135 #expect(d.arrows.allSatisfy { if case .valleyFold = $0 { true } else { false } })
136}
137
121@Test func anUnfoldArrowHasAHollowHead() { 138@Test func anUnfoldArrowHasAHollowHead() {
122 let square = [SIMD2<Double>(0, 0), SIMD2(1, 0), SIMD2(1, 1), SIMD2(0, 1)] 139 let square = [SIMD2<Double>(0, 0), SIMD2(1, 0), SIMD2(1, 1), SIMD2(0, 1)]
123 let edges = square.indices.map { DiagramEdge(edge: $0, from: square[$0], to: square[($0 + 1) % 4], style: .solid) } 140 let edges = square.indices.map { DiagramEdge(edge: $0, from: square[$0], to: square[($0 + 1) % 4], style: .solid) }
Packages/FoldKit/Tests/NotationTests/Snapshots/NOTATION.md +5 −3
@@ -25,9 +25,11 @@ points.
25Valley and mountain are as seen from the step's viewpoint, not FOLD's assignment. 25Valley and mountain are as seen from the step's viewpoint, not FOLD's assignment.
26 26
27A crease the step moves that is already folded in the frame drawn is the existing line, solid 27A crease the step moves that is already folded in the frame drawn is the existing line, solid
28where visible, never dashed or dash-dot: the reader is holding that fold. An axis folded in the 28where visible, never dashed or dash-dot: the reader is holding that fold. An axis that moves
29frame drawn, such as box step 7's corners, gets the unfold arrow instead of a valley or mountain 29toward flat (its end angle is smaller in size than its start angle), such as box step 7's corners,
30arrow. 30gets the unfold arrow instead of a valley or mountain arrow. An axis already folded that folds
31further, such as the wall creases of box steps 9 and 11, keeps its valley or mountain arrow as
32seen.
31 33
32Arrow geometry: a fold arrow runs from the area-weighted centroid of the axis's moving set before 34Arrow geometry: a fold arrow runs from the area-weighted centroid of the axis's moving set before
33the step to the same point after it (at the peak for a fold and unfold), its apex 0.3 of the chord 35the step to the same point after it (at the peak for a fold and unfold), its apex 0.3 of the chord