Commit 72fe3dbb26

72fe3dbb26dd22ed6893168ddcce913856721f71

parent: 8099ab2642

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 18:57 UTC

Draw an unfold on the existing lines with the unfold arrow

Ref #7

Layout: unified · split

Packages/FoldKit/Sources/Notation/DiagramBuilder.swift +8 −3
@@ -21,6 +21,8 @@ public enum DiagramArrow: Equatable, Sendable {
2121 case valleyFold(from: SIMD2<Double>, over: SIMD2<Double>, to: SIMD2<Double>)
2222 case mountainFold(from: SIMD2<Double>, over: SIMD2<Double>, to: SIMD2<Double>)
2323 case foldAndUnfold(from: SIMD2<Double>, over: SIMD2<Double>, to: SIMD2<Double>, mountain: Bool)
24 /// A crease folded before the step opened out again.
25 case unfold(from: SIMD2<Double>, over: SIMD2<Double>, to: SIMD2<Double>)
2426 /// The technique's symbol at the midpoint of the step's first crease, pointing toward where
2527 /// that axis's moving set ends.
2628 case technique(StepTechnique, at: SIMD2<Double>, toward: SIMD2<Double>)
@@ -65,8 +67,9 @@ private let arcBulge = 0.3
6567///
6668/// Edges whose `edges_krz:firstCreasedAtStep` is later than the step, and subdivision edges, are
6769/// not drawn. An edge the step creases (its two faces move differently) is dashed for a valley as
68/// seen and dash-dot for a mountain, whatever its assignment; other `B` edges and folded creases
69/// are solid; earlier creases flat again are light. Each edge is clipped by `visibleSegments`, and
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
72/// folded in the drawn frame gets the unfold arrow. Each edge is clipped by `visibleSegments`, and
7073/// a piece coincident with one already drawn is drawn once, step creases before solid before light.
7174///
7275/// - Precondition: `validate(file)` is empty.
@@ -94,7 +97,7 @@ public func buildDiagram(file: FoldFile, step: FoldStep) -> Diagram {
9497 candidates.append((e, .solid, 1))
9598 } else if created == nil {
9699 continue
97 } else if let axis = creasing[e] {
100 } else if let axis = creasing[e], abs(frame.edgesFoldAngle[e]) <= 1e-9 {
98101 candidates.append((e, valley[axis] ? .dashed : .dashDot, 0))
99102 } else if abs(frame.edgesFoldAngle[e]) > 1e-9 {
100103 candidates.append((e, .solid, 1))
@@ -198,6 +201,8 @@ private func arrows(_ file: FoldFile, _ step: FoldStep, valley: [Bool], project:
198201 let over = apex(from, to)
199202 if step.kind == .foldAndUnfold {
200203 arrows.append(.foldAndUnfold(from: from, over: over, to: to, mountain: !valley[i]))
204 } else if abs(axis.startAngle) > 1e-9 {
205 arrows.append(.unfold(from: from, over: over, to: to))
201206 } else if valley[i] {
202207 arrows.append(.valleyFold(from: from, over: over, to: to))
203208 } else {
Packages/FoldKit/Sources/Notation/DiagramDrawing.swift +5 −1
@@ -22,7 +22,8 @@ public func drawDiagram(_ diagram: Diagram, style: DiagramStyle, in context: CGC
2222 var points = diagram.edges.flatMap { [$0.from, $0.to] }
2323 for arrow in diagram.arrows {
2424 switch arrow {
25 case let .valleyFold(from, over, to), let .mountainFold(from, over, to), let .foldAndUnfold(from, over, to, _):
25 case let .valleyFold(from, over, to), let .mountainFold(from, over, to), let .foldAndUnfold(from, over, to, _),
26 let .unfold(from, over, to):
2627 points += [from, over, to]
2728 case let .technique(_, at, toward):
2829 points += [at, toward]
@@ -90,6 +91,9 @@ public func drawDiagram(_ diagram: Diagram, style: DiagramStyle, in context: CGC
9091 drawTurnOver(context, style, centre: symbolCentre, vertical: axis == .vertical)
9192 case let .rotate(degrees):
9293 drawRotate(context, style, centre: symbolCentre, degrees: degrees)
94 case let .unfold(from, over, to):
95 drawFoldArrow(context, style, pixel(from), pixel(over), pixel(to), head: .hollowFull, returnHead: false,
96 tick: repeated)
9397 case .repeatMark:
9498 break
9599 }
Packages/FoldKit/Tests/NotationTests/DiagramTests.swift +23
@@ -106,6 +106,29 @@ private func halfWithWallRaised() throws -> (FoldFrame, FoldFile) {
106106 .contains { if case .foldAndUnfold = $0 { true } else { false } })
107107}
108108
109@Test func anUnfoldIsDrawnOnTheExistingLinesWithTheUnfoldArrow() throws {
110 // box step 7 unfolds the top and bottom corners, folded at 180 in frame 6: their creases are
111 // drawn as they stand, not as new folds, and each axis gets the unfold arrow
112 let box = try ModelLibrary.model(named: "box")
113 let d = buildDiagram(file: box, step: try readStep(7, in: box))
114 #expect(!d.edges.contains { $0.style == .dashed || $0.style == .dashDot })
115 #expect(d.edges.filter { [25, 77].contains($0.edge) }.allSatisfy { $0.style == .solid })
116 #expect(Set(d.edges.map(\.edge)).isSuperset(of: [25, 77]))
117 #expect(d.arrows.count == 2)
118 #expect(d.arrows.allSatisfy { if case .unfold = $0 { true } else { false } })
119}
120
121@Test func anUnfoldArrowHasAHollowHead() {
122 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) }
124 let (from, over, to) = (SIMD2<Double>(0.2, 0.5), SIMD2<Double>(0.5, 0.8), SIMD2<Double>(0.8, 0.5))
125 let valley = inkedPixels(render(Diagram(edges: edges, arrows: [.valleyFold(from: from, over: over, to: to)])))
126 let unfold = inkedPixels(render(Diagram(edges: edges, arrows: [.unfold(from: from, over: over, to: to)])))
127 let bare = inkedPixels(render(Diagram(edges: edges, arrows: [])))
128 #expect(unfold > bare)
129 #expect(unfold < valley)
130}
131
109132@Test func turnOverStepCarriesTheTurnOverSymbol() throws {
110133 #expect(try diagram("half.fold", step: 2).arrows.contains(.turnOver(.vertical)))
111134}
Packages/FoldKit/Tests/NotationTests/Snapshots/NOTATION.md +6
@@ -15,6 +15,7 @@ points.
1515| Valley-fold arrow | curved arrow, filled full head | OrigamiUSA (filled head) |
1616| Mountain-fold arrow | curved arrow, hollow half head, barb on the outside of the arc | Randlett and OrigamiUSA agree |
1717| Fold and unfold | curved arrow, fold head at the destination, hollow full head at the start pointing back | OrigamiUSA (double-headed form; the zig-zag form is not used) |
18| Unfold | curved arrow, hollow full head at the destination, no head at the start | Randlett and OrigamiUSA agree (the unfold arrow) |
1819| Inside and outside reverse fold, sink, squash | hollow push arrow with a notched tail, tip on the crease | OrigamiUSA (push) |
1920| Petal fold | valley-fold arrow lifting the flap | OrigamiUSA |
2021| Turn over | loop-the-loop arrow: left to right for a vertical axis, bottom to top for a horizontal one | Randlett and OrigamiUSA agree |
@@ -23,6 +24,11 @@ points.
2324
2425Valley and mountain are as seen from the step's viewpoint, not FOLD's assignment.
2526
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
29frame drawn, such as box step 7's corners, gets the unfold arrow instead of a valley or mountain
30arrow.
31
2632Arrow geometry: a fold arrow runs from the area-weighted centroid of the axis's moving set before
2733the step to the same point after it (at the peak for a fold and unfold), its apex 0.3 of the chord
2834from the chord's midpoint, toward screen-up or, for a vertical chord, screen-right. Arrows of a
Packages/FoldKit/Tests/NotationTests/Snapshots/box-11.png

Binary file not shown.

Packages/FoldKit/Tests/NotationTests/Snapshots/box-7.png

Binary file not shown.

Packages/FoldKit/Tests/NotationTests/Snapshots/box-9.png

Binary file not shown.