GCodeOverlay/src/app/state.ts
2026-06-11 09:23:42 +02:00

33 lines
909 B
TypeScript

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