GCodeOverlay/src/app/state.ts

34 lines
909 B
TypeScript
Raw Normal View History

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