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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | /** * renderFrame — Pure function that draws one complete frame of the Euclid canvas. * * Extracted from the RAF render loop in EuclidCanvas.tsx. * Handles pre-render computation (hidden IDs, candidate filter, correction rotation) * and dispatches all render subsystem calls. */ import type { RAFContext } from '../engine/rafContext' import type { CompassPhase, StraightedgePhase, ExtendPhase } from '../types' import { resolveSelector } from '../engine/selectors' import { getHiddenElementIds } from '../engine/macroExecution' import { getAllPoints } from '../engine/constructionState' import { RECIPE_REGISTRY } from '../engine/recipe/definitions/registry' import { rotatePoint } from '../engine/viewportMath' import { BYRNE_CYCLE } from '../types' import { renderConstruction, renderDragInvitation, BG_COLOR } from './renderConstruction' import { renderToolOverlay } from './renderToolOverlay' import { renderTutorialHint } from './renderTutorialHint' import { renderEqualityMarks } from './renderEqualityMarks' import { renderGhostGeometry } from './renderGhostGeometry' import { renderProductionSegments } from './renderProductionSegments' import { renderAngleArcs } from './renderAngleArcs' import { renderSuperpositionFlash } from './renderSuperpositionFlash' import { renderSuperpositionInteraction } from './renderSuperpositionInteraction' import { renderCitationFlashes } from './renderCitationFlash' import { renderMacroPreview } from './renderMacroPreview' import { renderChatHighlight } from './renderChatHighlight' import { renderInfluenceHighlight, renderMotionTrail, renderBreakFreeFlash, renderConstraintField, renderConstraintFieldFlow, updateInfluenceTarget, } from './renderInfluenceHighlight' export function renderFrame( ctx: RAFContext, drawCtx: CanvasRenderingContext2D, cssWidth: number, cssHeight: number ): void { const prop = ctx.propositionRef.current // ── Derive candidate filter from current step's expected intersection ── const curStep = ctx.currentStepRef.current const curExpected = curStep < ctx.stepsRef.current.length ? ctx.stepsRef.current[curStep].expected : null let candFilter: { ofA: string; ofB: string; beyondId?: string } | null = null if (curExpected?.type === 'intersection' && curExpected.ofA != null && curExpected.ofB != null) { const resolvedA = resolveSelector(curExpected.ofA, ctx.constructionRef.current) const resolvedB = resolveSelector(curExpected.ofB, ctx.constructionRef.current) if (resolvedA && resolvedB) { candFilter = { ofA: resolvedA, ofB: resolvedB, beyondId: curExpected.beyondId } } } const complete = ctx.playgroundModeRef.current || curStep >= ctx.stepsRef.current.length // ── Compute hidden elements during macro animation ── const hiddenIds = getHiddenElementIds(ctx.macroAnimationRef.current) // Also hide macro output elements while the ceremony is playing const ceremonyHidden = ctx.macroRevealRef.current?.hiddenElementIds if (ceremonyHidden) { for (const id of ceremonyHidden) hiddenIds.add(id) } // ── Handle straightedge drawing animation ── const drawAnim = ctx.straightedgeDrawAnimRef.current if (drawAnim) { const elapsed = performance.now() - drawAnim.startTime if (elapsed >= drawAnim.duration) { ctx.straightedgeDrawAnimRef.current = null } else { hiddenIds.add(drawAnim.segmentId) ctx.needsDrawRef.current = true } } // ── Compute drawState (possibly with correction rotation) ── let drawState = ctx.constructionRef.current if (ctx.correctionRef.current?.active) { const correction = ctx.correctionRef.current const t = Math.min(1, (performance.now() - correction.startTime) / correction.duration) const ease = t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2 const angle = correction.fromAngle + (correction.toAngle - correction.fromAngle) * ease const state = ctx.constructionRef.current const updatedElements = state.elements.map((el) => { if (el.kind === 'point') { const rotated = rotatePoint({ x: el.x, y: el.y }, correction.center, angle) return { ...el, x: rotated.x, y: rotated.y } } return el }) drawState = { ...state, elements: updatedElements } ctx.needsDrawRef.current = true } // ── 0. Background fill + constraint response field ── // Painted before the geometry so the construction lines, points, and // labels sit on top of them. We do the bg fill here (instead of letting // renderConstruction handle it) and pass 'preserve' below, so the conic // gradient survives into the geometry pass instead of being overwritten. drawCtx.fillStyle = BG_COLOR drawCtx.fillRect(0, 0, cssWidth, cssHeight) renderConstraintField( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, ctx.influenceHighlightStateRef.current, ctx.pointerWorldRef.current ) renderConstraintFieldFlow( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, ctx.influenceHighlightStateRef.current, ctx.pointerWorldRef.current ) // ── 1. Main construction geometry ── renderConstruction( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, ctx.compassPhaseRef.current as CompassPhase, ctx.straightedgePhaseRef.current as StraightedgePhase, ctx.pointerWorldRef.current, ctx.snappedPointIdRef.current, ctx.candidatesRef.current, drawState.nextColorIndex, candFilter, complete, complete ? ctx.effectiveResultSegmentsRef.current : undefined, hiddenIds.size > 0 ? hiddenIds : undefined, 'preserve', // transparentBg — bg + field already painted above complete ? ctx.playgroundModeRef.current ? getAllPoints(drawState).map((pt) => pt.id) : RECIPE_REGISTRY[prop.id] ? getAllPoints(drawState).map((pt) => pt.id) : prop.draggablePointIds : undefined, complete ? ctx.postCompletionActionsRef.current : undefined ) // Keep redrawing while ripple rings are visible if ( complete && (ctx.playgroundModeRef.current ? getAllPoints(drawState).length > 0 : RECIPE_REGISTRY[prop.id] ? getAllPoints(drawState).length > 0 : prop.draggablePointIds?.length) ) { ctx.needsDrawRef.current = true } // ── 2. Post.2 production segments (extensions to intersection points) ── renderProductionSegments( drawCtx, drawState, ctx.stepsRef.current, ctx.currentStepRef.current, ctx.viewportRef.current, cssWidth, cssHeight ) // ── 3. Ghost geometry (dependency scaffolding from macros) ── if (ctx.ghostLayersRef.current.length > 0) { const cer = ctx.macroRevealRef.current let ceremonyRevealCounts: Map<string, number> | null = null if (cer) { ceremonyRevealCounts = new Map<string, number>() for (const [key, groupCount] of cer.preRevealedLayers) { ceremonyRevealCounts.set(key, groupCount) } for (let i = 0; i < cer.revealed; i++) { const entry = cer.sequence[i] ceremonyRevealCounts.set(entry.layerKey, entry.groupIndex) } } const ghostAnimating = renderGhostGeometry( drawCtx, ctx.ghostLayersRef.current, ctx.viewportRef.current, cssWidth, cssHeight, ctx.hoveredMacroStepRef.current, ctx.ghostOpacitiesRef.current, ceremonyRevealCounts, cer?.elementAnims ?? null, cer ? performance.now() : undefined ) if (ghostAnimating || ctx.hoveredMacroStepRef.current !== null) { ctx.needsDrawRef.current = true } } // ── 4. Macro preview (unbound markers + live ghost geometry) ── if (ctx.macroPhaseRef.current.tag === 'selecting') { const previewAnimating = renderMacroPreview( drawCtx, ctx.macroPhaseRef.current, ctx.constructionRef.current, ctx.viewportRef.current, cssWidth, cssHeight, ctx.pointerWorldRef.current, ctx.snappedPointIdRef.current ) if (previewAnimating) ctx.needsDrawRef.current = true } // ── 5. Equality tick marks on segments with proven equalities ── if (ctx.factStoreRef.current.facts.length > 0) { renderEqualityMarks( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, ctx.factStoreRef.current, hiddenIds.size > 0 ? hiddenIds : undefined, complete ? ctx.effectiveResultSegmentsRef.current : undefined ) } // ── 6. Angle arcs (static from proposition + dynamic from fact store) ── if (prop.givenAngles || ctx.factStoreRef.current.angleFacts.length > 0) { renderAngleArcs( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, prop.givenAngles, prop.equalAngles, ctx.factStoreRef.current ) } // ── 6½. Superposition interaction (interactive drag/flip/snap) ── if (ctx.superpositionPhaseRef.current.tag !== 'idle') { if ( renderSuperpositionInteraction( drawCtx, ctx.superpositionPhaseRef.current, drawState, ctx.viewportRef.current, cssWidth, cssHeight, performance.now() ) ) { ctx.needsDrawRef.current = true } } // ── 7. Superposition flash animation (C.N.4) ── if (ctx.superpositionFlashRef.current) { const stillAnimating = renderSuperpositionFlash( drawCtx, ctx.superpositionFlashRef.current, drawState, ctx.viewportRef.current, cssWidth, cssHeight, performance.now() ) if (stillAnimating) { ctx.needsDrawRef.current = true } else { ctx.superpositionFlashRef.current = null } } // ── 8. Citation flashes (Post.1/2/3) ── if (ctx.citationFlashesRef.current.length > 0) { ctx.citationFlashesRef.current = renderCitationFlashes( drawCtx, ctx.citationFlashesRef.current, ctx.viewportRef.current, cssWidth, cssHeight, performance.now() ) if (ctx.citationFlashesRef.current.length > 0) { ctx.needsDrawRef.current = true } } // ── 9. Drag invitation text post-completion ── if (complete && ctx.completionTimeRef.current > 0 && prop.draggablePointIds) { const stillShowing = renderDragInvitation( drawCtx, cssWidth, cssHeight, ctx.completionTimeRef.current ) if (stillShowing) { ctx.needsDrawRef.current = true } } // ── 10. Chat entity highlight (golden glow on hovered geometric refs) ── if (ctx.chatHighlightRef.current) { renderChatHighlight( drawCtx, drawState, ctx.chatHighlightRef.current, ctx.viewportRef.current, cssWidth, cssHeight ) ctx.needsDrawRef.current = true } // ── 11. Voice highlight (golden glow from voice tool calls) ── if (ctx.euclidVoiceHighlightRef.current) { renderChatHighlight( drawCtx, drawState, ctx.euclidVoiceHighlightRef.current, ctx.viewportRef.current, cssWidth, cssHeight ) ctx.needsDrawRef.current = true } // ── 11½. Influence highlight (hover over derived → pulsing ring on given) ── { const hlState = ctx.influenceHighlightStateRef.current const now = performance.now() / 1000 updateInfluenceTarget( hlState, ctx.hoveredDerivedPointIdRef.current, ctx.influentialGivenPointIdRef.current, now * 1000 ) const influenceAnimating = renderInfluenceHighlight( drawCtx, drawState, ctx.viewportRef.current, cssWidth, cssHeight, hlState, now, ctx.pointerWorldRef.current ) if (influenceAnimating) { ctx.needsDrawRef.current = true } } // ── 11¾. Motion trail (fading afterimage on given point during constrained drag) ── if (ctx.motionTrailStateRef.current.count >= 2) { const trailAnimating = renderMotionTrail(drawCtx, ctx.motionTrailStateRef.current) if (trailAnimating) { ctx.needsDrawRef.current = true } } // ── 11⅞. Break-free flash (constraint snap animation) ── if (ctx.breakFreeFlashRef.current) { const stillAnimating = renderBreakFreeFlash( drawCtx, ctx.breakFreeFlashRef.current, performance.now() ) if (stillAnimating) { ctx.needsDrawRef.current = true } else { ctx.breakFreeFlashRef.current = null } } // ── 12. Tool overlay (geometric previews + physical tool body) ── const nextColor = BYRNE_CYCLE[ctx.constructionRef.current.nextColorIndex % BYRNE_CYCLE.length] renderToolOverlay( drawCtx, ctx.activeToolRef.current, ctx.compassPhaseRef.current as CompassPhase, ctx.straightedgePhaseRef.current as StraightedgePhase, ctx.pointerWorldRef.current, ctx.constructionRef.current, ctx.viewportRef.current, cssWidth, cssHeight, nextColor, complete, ctx.straightedgeDrawAnimRef.current, ctx.extendPhaseRef.current as ExtendPhase, ctx.extendPreviewRef.current ) // ── 13. Tutorial hint on top ── renderTutorialHint( drawCtx, ctx.currentHintRef.current, ctx.constructionRef.current, ctx.viewportRef.current, cssWidth, cssHeight, ctx.candidatesRef.current, performance.now() / 1000 ) } |