Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | /** * Pure description generator for the construction log. * * Maps PostCompletionActions and given ConstructionElements to display entries * with postulate/proposition citations and entity-marked descriptions. */ import type { PostCompletionAction } from '../engine/replayConstruction' import type { ConstructionState, ConstructionElement, CompassPhase, StraightedgePhase, ExtendPhase, MacroPhase, } from '../types' import { getPoint } from '../engine/constructionState' export interface LedgerEntryDescriptor { /** Citation label: "Post.1", "Post.3", "I.1", or null */ citation: string | null /** Description with entity markers: "Join {pt:A} to {pt:B}" */ markedDescription: string } /** Resolve a point ID to its label, falling back to stripping the pt- prefix. */ function label(state: ConstructionState, id: string): string { return getPoint(state, id)?.label ?? id.replace(/^pt-/, '') } /** Generate a ledger entry descriptor for a post-completion action. */ export function describeAction( action: PostCompletionAction, state: ConstructionState ): LedgerEntryDescriptor { switch (action.type) { case 'segment': { const from = label(state, action.fromId) const to = label(state, action.toId) return { citation: 'Post.1', markedDescription: `Join {pt:${from}} to {pt:${to}}`, } } case 'extend': { const base = label(state, action.baseId) const through = label(state, action.throughId) const pt = label(state, action.pointId) return { citation: 'Post.2', markedDescription: `Produce {seg:${base}${through}} beyond {pt:${through}} to {pt:${pt}}`, } } case 'circle': { const center = label(state, action.centerId) const radius = label(state, action.radiusPointId) return { citation: 'Post.3', markedDescription: `Describe circle with center {pt:${center}} through {pt:${radius}}`, } } case 'intersection': { // Find the point that was created — it's the last point whose origin is 'intersection' // We can't easily know the exact point from the action alone, so we look for the // most recent intersection point in state const allPts = state.elements.filter( (e): e is Extract<typeof e, { kind: 'point' }> => e.kind === 'point' && e.origin === 'intersection' ) const pt = allPts[allPts.length - 1] const ptLabel = pt?.label ?? '?' return { citation: null, markedDescription: `Mark intersection point {pt:${ptLabel}}`, } } case 'macro': { // Resolve input points to labels const inputLabels = action.inputPointIds.map((id) => `{pt:${label(state, id)}}`) return { citation: `I.${action.propId}`, markedDescription: `Apply {prop:${action.propId}} to ${inputLabels.join(', ')}`, } } case 'free-point': { return { citation: null, markedDescription: `Place point {pt:${action.label}}`, } } } } export interface ToolPhaseSnapshot { compass: CompassPhase straightedge: StraightedgePhase extend: ExtendPhase macro: MacroPhase /** Currently snapped point ID (from cursor hover during straightedge drag) */ snappedPointId: string | null } /** * Derive a preview ledger entry from the current tool phase state. * Returns null when all tools are idle (nothing to preview). */ export function describeToolPhase( phases: ToolPhaseSnapshot, state: ConstructionState ): LedgerEntryDescriptor | null { // Extend takes priority over straightedge (it's a sub-mode) if (phases.extend.tag === 'extending') { const base = label(state, phases.extend.baseId) const through = label(state, phases.extend.throughId) return { citation: 'Post.2', markedDescription: `Produce {seg:${base}${through}} beyond {pt:${through}} …`, } } if (phases.straightedge.tag === 'from-set') { const from = label(state, phases.straightedge.fromId) if (phases.snappedPointId && phases.snappedPointId !== phases.straightedge.fromId) { const to = label(state, phases.snappedPointId) return { citation: 'Post.1', markedDescription: `Join {pt:${from}} to {pt:${to}}`, } } return { citation: 'Post.1', markedDescription: `Join {pt:${from}} to …`, } } if (phases.compass.tag !== 'idle') { const center = label(state, phases.compass.centerId) if (phases.compass.tag === 'center-set') { return { citation: 'Post.3', markedDescription: `Circle with center {pt:${center}} …`, } } // radius-set or sweeping — both carry radiusPointId const radius = label(state, phases.compass.radiusPointId) return { citation: 'Post.3', markedDescription: `Describe circle with center {pt:${center}} through {pt:${radius}}`, } } if (phases.macro.tag === 'selecting') { const { propId, inputs, selectedPointIds } = phases.macro const selected = selectedPointIds.map((id) => `{pt:${label(state, id)}}`) const remaining = inputs.length - selectedPointIds.length const suffix = remaining > 0 ? ', …' : '' return { citation: `I.${propId}`, markedDescription: `Apply {prop:${propId}} to ${selected.join(', ')}${suffix}`, } } return null } /** Generate a ledger entry descriptor for a given (initial) element. */ export function describeGivenElement(el: ConstructionElement): LedgerEntryDescriptor { switch (el.kind) { case 'point': return { citation: 'Given', markedDescription: `Given: point {pt:${el.label}}`, } case 'segment': return { citation: 'Given', markedDescription: `Given: segment {seg:${el.fromId.replace(/^pt-/, '')}${el.toId.replace(/^pt-/, '')}}`, } case 'circle': return { citation: 'Given', markedDescription: `Given: circle with center ${el.centerId.replace(/^pt-/, '')} through ${el.radiusPointId.replace(/^pt-/, '')}`, } } } |