public enum StepKind: String, Codable, Sendable { case fold, foldAndUnfold, turnOver, rotate } public enum StepTechnique: String, Codable, Sendable { case plain, insideReverse, outsideReverse, squash, petal, sink } public enum TurnOverAxis: String, Codable, Sendable { case vertical, horizontal } /// One crease of a step. `parent` is the index, in the same step's `axes`, of the axis whose /// motion carries this one; `window` is `[t0, t1]`, `[0, 1]` when absent; `angles` is a solved /// curve, the fold angle at 257 evenly spaced points of the window, absent for a linear axis. public struct AxisRecord: Codable, Equatable, Sendable { public let edge: Int public let movingFaces: [Int] public let startAngle: Double public let endAngle: Double public let peakAngle: Double? public let parent: Int? public let window: [Double]? public let angles: [Double]? public init(edge: Int, movingFaces: [Int], startAngle: Double, endAngle: Double, peakAngle: Double? = nil, parent: Int? = nil, window: [Double]? = nil, angles: [Double]? = nil) { self.edge = edge self.movingFaces = movingFaces self.startAngle = startAngle self.endAngle = endAngle self.peakAngle = peakAngle self.parent = parent self.window = window self.angles = angles } } /// `eye` is the unit direction from the model toward the viewer; `up` is screen-up. public struct Viewpoint: Codable, Equatable, Sendable { public let eye: SIMD3 public let up: SIMD3 public init(eye: SIMD3, up: SIMD3) { self.eye = eye self.up = up } } /// The open, pop and close of a non-rigid step: `openAxes` open the flap on `[0, phases[0]]`, the /// first turning the opening crease to `openAngle` (the `spine`, or for a nested opening an /// earlier fold's spine), every vertex reaches `popped` by `phases[1]`, and `closeAxes`, relative /// to `popped`, close the flap on `[phases[1], 1]`. `spine` lists the kept edges of the spine's /// line and, for a nested opening, of the opening crease's line: the edges the open and close turn /// and return, which the pop does not crease. public struct PopRecord: Codable, Equatable, Sendable { public let spine: [Int] public let openAngle: Double public let phases: [Double] public let openAxes: [AxisRecord] public let popped: [SIMD3] public let closeAxes: [AxisRecord] public init(spine: [Int], openAngle: Double, phases: [Double], openAxes: [AxisRecord], popped: [SIMD3], closeAxes: [AxisRecord]) { self.spine = spine self.openAngle = openAngle self.phases = phases self.openAxes = openAxes self.popped = popped self.closeAxes = closeAxes } } /// `krz:step`: the authored step that produced a frame. A non-rigid step's `axes` still list its /// creases with their start and end angles; its motion is `pop`. public struct StepRecord: Codable, Equatable, Sendable { public let kind: StepKind public let technique: StepTechnique public let instruction: String? public let axes: [AxisRecord] public let rotateDegrees: Double? public let turnOverAxis: TurnOverAxis? public let repeatOf: Int? public let nonRigid: Bool public let pop: PopRecord? public let viewpoint: Viewpoint public init(kind: StepKind, technique: StepTechnique = .plain, instruction: String?, axes: [AxisRecord], rotateDegrees: Double? = nil, turnOverAxis: TurnOverAxis? = nil, repeatOf: Int? = nil, nonRigid: Bool = false, pop: PopRecord? = nil, viewpoint: Viewpoint) { self.kind = kind self.technique = technique self.instruction = instruction self.axes = axes self.rotateDegrees = rotateDegrees self.turnOverAxis = turnOverAxis self.repeatOf = repeatOf self.nonRigid = nonRigid self.pop = pop self.viewpoint = viewpoint } public init(from decoder: any Decoder) throws { let c = try decoder.container(keyedBy: CodingKeys.self) kind = try c.decode(StepKind.self, forKey: .kind) technique = try c.decodeIfPresent(StepTechnique.self, forKey: .technique) ?? .plain instruction = try c.decodeIfPresent(String.self, forKey: .instruction) axes = try c.decode([AxisRecord].self, forKey: .axes) rotateDegrees = try c.decodeIfPresent(Double.self, forKey: .rotateDegrees) turnOverAxis = try c.decodeIfPresent(TurnOverAxis.self, forKey: .turnOverAxis) repeatOf = try c.decodeIfPresent(Int.self, forKey: .repeatOf) nonRigid = try c.decodeIfPresent(Bool.self, forKey: .nonRigid) ?? false pop = try c.decodeIfPresent(PopRecord.self, forKey: .pop) viewpoint = try c.decode(Viewpoint.self, forKey: .viewpoint) } }