import type { Segment, Alignment, Mat3 } from '../types'; import { parseGcode } from '../gcode/parser'; import { projectSegments } from '../geometry/transform'; export interface AppState { segments: Segment[]; alignment: Alignment; homography: Mat3 | null; loadGcode(text: string): string[]; setHomography(H: Mat3 | null): void; projected(): Segment[]; } export function createState(): AppState { const state: AppState = { segments: [], alignment: { tx: 0, ty: 0, rot: 0 }, homography: null, loadGcode(text: string): string[] { const { segments, warnings } = parseGcode(text); state.segments = segments; return warnings; }, setHomography(H: Mat3 | null): void { state.homography = H; }, projected(): Segment[] { if (!state.homography) return []; return projectSegments(state.segments, state.alignment, state.homography); }, }; return state; }