Fix atomic model-v8 draft writes

Issue: #314
User-Visible: yes
This commit is contained in:
Matysh
2026-08-26 09:13:50 +03:00
parent 5da7812099
commit 2347e8df88
16 changed files with 657 additions and 198 deletions
+26 -1
View File
@@ -10,7 +10,7 @@
import {
canonicalizeConfigGeometryInPlace, LATTICE_NOISE_STEPS,
} from './coordinate-canonicalization';
import { roomPoly } from './logic';
import { roomPoly, samePoint } from './logic';
import { sanitizeOpenSpans } from './open-spans';
import { GRID_STEP_N } from './space-geometry';
import {
@@ -79,6 +79,31 @@ const canonicalSpan = (a: number[], b: number[]): [Point, Point] => (
);
const lengthOf = (a: number[], b: number[]): number => Math.hypot(b[0] - a[0], b[1] - a[1]);
/**
* Remove zero-length adjacent draft edges without moving identity to a
* neighbouring carrier. The caller owns whole-record validation; this pure
* write-boundary helper owns the index relationship between points and
* segments (#314).
*/
export const sanitizeRoomDraftPath = (draft: any): {
points: number[][];
segments: Array<{ id?: string; cm: number; [key: string]: any }>;
} => {
const points: number[][] = [[Number(draft.points[0][0]), Number(draft.points[0][1])]];
const segments: Array<{ id?: string; cm: number; [key: string]: any }> = [];
for (let index = 1; index < draft.points.length; index++) {
const next = [Number(draft.points[index][0]), Number(draft.points[index][1])];
if (samePoint(points[points.length - 1], next)) continue;
points.push(next);
const source = draft.segments?.[index - 1];
segments.push({
...(source && typeof source === 'object' ? source : {}),
cm: Math.max(1, Math.min(100, Number(source?.cm) || 15)),
});
}
return { points, segments };
};
/** Unique authored/derived contour coordinates that are materially off-grid. */
export const wallModelOffGridValueCount = (
space: any, additionalPoints: readonly (readonly number[])[] = [],