@ahrowe/ui 0.41.2 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/cjs-types/common/floorPlan/floorPlan.graph.d.ts +10 -3
  2. package/dist/cjs-types/common/floorPlan/floorPlan.plan.d.ts +5 -0
  3. package/dist/cjs-types/common/floorPlan/floorPlan.rooms.d.ts +6 -2
  4. package/dist/cjs-types/common/floorPlan/floorPlan.snap.d.ts +1 -3
  5. package/dist/cjs-types/common/floorPlan/index.d.ts +1 -3
  6. package/dist/cjs-types/common/planCanvas/planCanvas.types.d.ts +1 -1
  7. package/dist/cjs-types/common/roomDrawer/roomDrawer.types.d.ts +29 -8
  8. package/dist/cjs-types/common/roomViewer/roomViewer.types.d.ts +4 -2
  9. package/dist/esm/common/floorPlan/floorPlan.faces.mjs +1 -1
  10. package/dist/esm/common/floorPlan/floorPlan.faces.mjs.map +1 -1
  11. package/dist/esm/common/floorPlan/floorPlan.geometry.mjs +1 -1
  12. package/dist/esm/common/floorPlan/floorPlan.geometry.mjs.map +1 -1
  13. package/dist/esm/common/floorPlan/floorPlan.graph.mjs +1 -1
  14. package/dist/esm/common/floorPlan/floorPlan.graph.mjs.map +1 -1
  15. package/dist/esm/common/floorPlan/floorPlan.hit.mjs +1 -1
  16. package/dist/esm/common/floorPlan/floorPlan.hit.mjs.map +1 -1
  17. package/dist/esm/common/floorPlan/floorPlan.json.mjs +1 -1
  18. package/dist/esm/common/floorPlan/floorPlan.json.mjs.map +1 -1
  19. package/dist/esm/common/floorPlan/floorPlan.mesh.mjs +1 -1
  20. package/dist/esm/common/floorPlan/floorPlan.mesh.mjs.map +1 -1
  21. package/dist/esm/common/floorPlan/floorPlan.path.mjs +1 -1
  22. package/dist/esm/common/floorPlan/floorPlan.path.mjs.map +1 -1
  23. package/dist/esm/common/floorPlan/floorPlan.plan.mjs +1 -1
  24. package/dist/esm/common/floorPlan/floorPlan.plan.mjs.map +1 -1
  25. package/dist/esm/common/floorPlan/floorPlan.rooms.mjs +1 -1
  26. package/dist/esm/common/floorPlan/floorPlan.rooms.mjs.map +1 -1
  27. package/dist/esm/common/floorPlan/floorPlan.snap.mjs +1 -1
  28. package/dist/esm/common/floorPlan/floorPlan.snap.mjs.map +1 -1
  29. package/dist/esm/common/floorPlan/floorPlan.triangulate.mjs +1 -1
  30. package/dist/esm/common/floorPlan/floorPlan.triangulate.mjs.map +1 -1
  31. package/dist/esm/common/floorPlan/floorPlan.types.mjs +1 -1
  32. package/dist/esm/common/floorPlan/floorPlan.types.mjs.map +1 -1
  33. package/dist/esm/common/planCanvas/planCanvas.mjs +1 -1
  34. package/dist/esm/common/planCanvas/planCanvas.mjs.map +1 -1
  35. package/dist/esm/common/roomDrawer/roomDrawer.mjs +1 -1
  36. package/dist/esm/common/roomDrawer/roomDrawer.mjs.map +1 -1
  37. package/dist/esm/common/roomViewer/roomViewer.mjs +1 -1
  38. package/dist/esm/common/roomViewer/roomViewer.mjs.map +1 -1
  39. package/dist/esm/floor-plan.mjs +1 -0
  40. package/dist/esm/index.mjs +1 -1
  41. package/dist/floor-plan.cjs +1 -0
  42. package/dist/floorPlan-DLe5XAx6.cjs +2 -0
  43. package/dist/floorPlan-DLe5XAx6.cjs.map +1 -0
  44. package/dist/index.cjs +3 -3
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/types/common/floorPlan/floorPlan.graph.d.ts +10 -3
  47. package/dist/types/common/floorPlan/floorPlan.plan.d.ts +5 -0
  48. package/dist/types/common/floorPlan/floorPlan.rooms.d.ts +6 -2
  49. package/dist/types/common/floorPlan/floorPlan.snap.d.ts +1 -3
  50. package/dist/types/common/floorPlan/index.d.ts +1 -3
  51. package/dist/types/common/planCanvas/planCanvas.types.d.ts +1 -1
  52. package/dist/types/common/roomDrawer/roomDrawer.types.d.ts +29 -8
  53. package/dist/types/common/roomViewer/roomViewer.types.d.ts +4 -2
  54. package/docs/CLAUDE.md +3 -1
  55. package/docs/FloorPlan.md +18 -14
  56. package/docs/RoomDrawer.md +42 -13
  57. package/docs/RoomViewer.md +1 -14
  58. package/package.json +18 -1
  59. package/dist/cjs-types/common/floorPlan/legacySvg.d.ts +0 -27
  60. package/dist/esm/common/floorPlan/legacySvg.mjs +0 -2
  61. package/dist/esm/common/floorPlan/legacySvg.mjs.map +0 -1
  62. package/dist/types/common/floorPlan/legacySvg.d.ts +0 -27
@@ -5,6 +5,13 @@ import { PlanEdit, PlanFloor, PlanIssue, PlanNode, PlanOpening, PlanPoint, PlanW
5
5
  * reproducible.
6
6
  */
7
7
  export declare function newId(prefix: string): string;
8
+ /**
9
+ * The first of `nameFor(start)`, `nameFor(start + 1)`, … that `used` does not hold.
10
+ *
11
+ * Bounded because `nameFor` is the caller's: one that ignores its number would never reach a
12
+ * free name. An injective one always finds one within `used.size + 1` tries.
13
+ */
14
+ export declare function freshName(nameFor: (n: number) => string, start: number, used: ReadonlySet<string>): string;
8
15
  /** Test-only: makes generated ids reproducible within a single test. */
9
16
  export declare function __resetIdSeq(): void;
10
17
  declare function wallLength(floor: PlanFloor, wall: PlanWall): number;
@@ -157,9 +164,9 @@ export declare function transformPlan(floor: PlanFloor, dx: number, dy: number):
157
164
  /**
158
165
  * Multiplies every coordinate and dimension by `factor`.
159
166
  *
160
- * The one place a scale factor belongs: converting a unitless legacy plan into the
161
- * module's millimetre invariant, once, at the import boundary. The caller picks the
162
- * factor, because nothing in the old data says what it should be.
167
+ * The one place a scale factor belongs: converting geometry drawn in another unit into
168
+ * the module's millimetre invariant, once, where it enters. The caller picks the factor,
169
+ * because nothing in the data says what it should be.
163
170
  */
164
171
  export declare function scalePlan(floor: PlanFloor, factor: number): PlanFloor;
165
172
  export declare function addOpening(floor: PlanFloor, opening: Omit<PlanOpening, 'id'>): PlanEdit<{
@@ -34,6 +34,11 @@ export declare function floorIndex(plan: FloorPlan, floorId: string): number;
34
34
  export declare function floorBelow(plan: FloorPlan, floorId: string): PlanFloor | null;
35
35
  export interface AddFloorOptions {
36
36
  label?: string;
37
+ /**
38
+ * Names the floor when `label` is not given. `n` is the floor count plus one, moved past
39
+ * any number whose name is taken. Default `` (n) => `Floor ${n}` ``.
40
+ */
41
+ nameFor?: (n: number) => string;
37
42
  /** Millimetres. Defaults to the storey height of the floor it is added above. */
38
43
  height?: number;
39
44
  /** Where to put it. Defaults to directly above `aboveFloorId`, else on top. */
@@ -22,8 +22,12 @@ export declare function derivePlan(floor: PlanFloor): PlanDerivation;
22
22
  /** Test-only: makes the room sequence counter reproducible. */
23
23
  export declare function __resetRoomSeq(): void;
24
24
  export interface CommitDerivationOptions {
25
- /** Names new rooms. Receives the 1-based index among rooms created in this call. */
26
- nameFor?: (index: number, face: DerivedRoom) => string;
25
+ /**
26
+ * Names a new room. `n` is the floor's room count plus one, moved past any number whose
27
+ * name is taken, so `` (n) => `Raum ${n}` `` numbers rooms the way the default does.
28
+ * Default `` (n) => `Room ${n}` ``.
29
+ */
30
+ nameFor?: (n: number, face: DerivedRoom) => string;
27
31
  }
28
32
  /**
29
33
  * Mints a `PlanRoom` for every face that matched nothing.
@@ -35,7 +35,7 @@ export interface SnapOptions {
35
35
  export declare const DEFAULT_SNAP_OPTIONS: SnapOptions;
36
36
  export interface SnapContext {
37
37
  floor: PlanFloor;
38
- /** World units per screen pixel at the current zoom. See `screenScale`. */
38
+ /** World units per screen pixel at the current zoom: `1 / view.zoom`. */
39
39
  pxToWorld: number;
40
40
  /** The anchored point. Required for angle lock; also enables the length readout. */
41
41
  origin?: PlanPoint;
@@ -70,8 +70,6 @@ export interface SnapResult {
70
70
  */
71
71
  angleRelativeTo?: 'world' | 'reference';
72
72
  }
73
- /** World units per screen pixel, from the element's current transform. */
74
- export declare function screenScale(svg: SVGSVGElement): number;
75
73
  /**
76
74
  * Client (screen) coordinates to world coordinates. Pure conversion, no snapping.
77
75
  *
@@ -18,7 +18,7 @@ export { HIT_PX, HIT_PX_COARSE, hitTest, selectionsEqual, worldTolerances } from
18
18
  export type { HitTestOptions, HitTolerances } from './floorPlan.hit.js';
19
19
  export { DEFAULT_WALL_ATTRS, addOpening, addRect, addWall, cleanupPlan, detachWall, dissolveNode, mergeNodes, moveNode, removeOpening, removeWall, scalePlan, splitWall, transformPlan, updateOpening, validatePlan, wallLength, weldShortWalls, } from './floorPlan.graph.js';
20
20
  export type { DetachWallResult, DissolveNodeOptions, ResolveNodeResult, SplitWallResult, WallAttrs, } from './floorPlan.graph.js';
21
- export { DEFAULT_SNAP_OPTIONS, SnapKind, clientToWorld, resolveSnap, screenScale } from './floorPlan.snap.js';
21
+ export { DEFAULT_SNAP_OPTIONS, SnapKind, clientToWorld, resolveSnap } from './floorPlan.snap.js';
22
22
  export type { SnapContext, SnapGuide, SnapOptions, SnapResult } from './floorPlan.snap.js';
23
23
  export { buildWallPaths, openingGeometry, wallCentrelineSpans } from './floorPlan.path.js';
24
24
  export type { BuildWallPathsOptions, WallCapLine, WallCapReason, WallPathGroup, WallPathResult, } from './floorPlan.path.js';
@@ -26,5 +26,3 @@ export { PLAN_FORMAT_VERSION, planFromJson, planToJson } from './floorPlan.json.
26
26
  export type { PlanParseResult } from './floorPlan.json.js';
27
27
  export { buildPlanMesh } from './floorPlan.mesh.js';
28
28
  export type { BuildPlanMeshOptions, PlanMesh, PlanMeshGroup, PlanMeshPart } from './floorPlan.mesh.js';
29
- export { planFromLegacySvg } from './legacySvg.js';
30
- export type { LegacyImportOptions } from './legacySvg.js';
@@ -33,7 +33,7 @@ export interface PlanCanvasProps {
33
33
  area: number;
34
34
  faceId: string;
35
35
  }) => ReactNode;
36
- /** Accessible name for a room. */
36
+ /** Accessible name for an interactive room. RoomViewer supplies the default, from its labels. */
37
37
  getRoomLabel?: (room: PlanRoom | null, context: {
38
38
  area: number;
39
39
  }) => string;
@@ -27,7 +27,10 @@ export interface RoomDrawerChangeMeta {
27
27
  /** Ids of whatever the change touched, for syncing an external selection. */
28
28
  targetIds: string[];
29
29
  }
30
- /** Every string the drawer's own chrome renders, for localisation. */
30
+ /**
31
+ * Every string the drawer produces of its own, for localisation: its chrome, and the names it
32
+ * gives the rooms and floors it creates, which are stored in the plan.
33
+ */
31
34
  export interface RoomDrawerLabels {
32
35
  /** The toolbar, read out by screen readers. */
33
36
  tools?: string;
@@ -54,12 +57,21 @@ export interface RoomDrawerLabels {
54
57
  floorHeight?: string;
55
58
  moveFloorUp?: string;
56
59
  moveFloorDown?: string;
60
+ /** Name of a new room. `n` counts the floor's rooms, skipping names already taken. */
61
+ newRoomName?: (n: number) => string;
62
+ /** Name of a floor added with the `+` button. `n` counts the floors, skipping names already taken. */
63
+ newFloorName?: (n: number) => string;
64
+ /** Name of a copied floor, from the name of the floor it copies. */
65
+ copiedFloorName?: (name: string) => string;
66
+ /** Name of the one floor an empty plan starts with, uncontrolled or after `clear()`. */
67
+ initialFloorName?: string;
57
68
  /** The inspector's noun for a floor, shown when nothing is selected. */
58
69
  selectedFloor?: string;
59
70
  /** Shown in the hint line when an opened file could not be read at all. */
60
71
  importFailed?: string;
61
72
  snap?: string;
62
- angleLock?: string;
73
+ /** The angle lock toggle, given `constrainAngle`. */
74
+ angleLock?: (angle: number) => string;
63
75
  grid?: string;
64
76
  zoomIn?: string;
65
77
  zoomOut?: string;
@@ -69,22 +81,27 @@ export interface RoomDrawerLabels {
69
81
  thickness?: string;
70
82
  width?: string;
71
83
  sill?: string;
72
- head?: string;
73
84
  deleteSelection?: string;
74
- /** Shown when several things are selected. `{count}` is replaced with the number. */
75
- selectedCount?: string;
85
+ /** What the inspector calls several things selected at once. */
86
+ selectedCount?: (count: number) => string;
76
87
  /** What the inspector calls the current selection. */
77
- selectedNothing?: string;
78
88
  selectedRoom?: string;
79
89
  selectedWall?: string;
80
90
  selectedCorner?: string;
81
- /** Overrides the opening's own kind, which is used by default. */
82
- selectedOpening?: string;
91
+ selectedDoor?: string;
92
+ selectedWindow?: string;
93
+ selectedArchway?: string;
94
+ selectedGap?: string;
95
+ /** Hint for the select tool with `multiSelect` on. */
83
96
  hintSelect?: string;
97
+ /** Hint for the select tool with `multiSelect` off. */
98
+ hintSelectSingle?: string;
84
99
  hintWall?: string;
85
100
  hintRect?: string;
86
101
  hintMeasure?: string;
87
102
  hintOpening?: string;
103
+ /** A drawing angle measured from the previous wall, given the formatted angle. */
104
+ relativeAngle?: (angle: string) => string;
88
105
  }
89
106
  /** Every icon in the chrome is overridable. */
90
107
  export interface RoomDrawerIcons {
@@ -259,6 +276,10 @@ export interface RoomDrawerProps extends Omit<HtmlProps<HTMLDivElement>, 'onChan
259
276
  showMeasurements?: boolean;
260
277
  formatLength?: (lengthMm: number) => string;
261
278
  formatArea?: (areaMm2: number) => string;
279
+ /** A drawing angle, in degrees from -180 to 180. */
280
+ formatAngle?: (degrees: number) => string;
281
+ /** The zoom readout. `zoom` is screen pixels per millimetre, so `1` reads as 100%. */
282
+ formatZoom?: (zoom: number) => string;
262
283
  showToolbar?: boolean;
263
284
  showInspector?: boolean;
264
285
  showHint?: boolean;
@@ -10,8 +10,10 @@ export interface RoomViewerLabels {
10
10
  zoomOut?: string;
11
11
  fit?: string;
12
12
  empty?: string;
13
- /** Announced when a room is selected. `{name}` and `{area}` are replaced. */
14
- selectedRoom?: string;
13
+ /** Stands in for the name of a room that has none. */
14
+ unnamedRoom?: string;
15
+ /** Announced when a room is selected, given its name and its formatted area. */
16
+ selectedRoom?: (name: string, area: string) => string;
15
17
  /** Announced when the selection is cleared. */
16
18
  noRoomSelected?: string;
17
19
  }
@@ -1,2 +1,2 @@
1
- "use client";import{dist as e,perimeter as t,pointInRing as n,representativePoint as r,signedArea as i}from"./floorPlan.geometry.mjs";function a(t){return Object.values(t.walls).filter(n=>{if(n.a===n.b)return!1;let r=t.nodes[n.a],i=t.nodes[n.b];return!r||!i?!1:e(r,i)>=10})}function o(e){let t=a(e),n=Array(t.length*2);for(let e=0;e<t.length;e++){let r=t[e];n[2*e]={wallId:r.id,from:r.a,to:r.b},n[2*e+1]={wallId:r.id,from:r.b,to:r.a}}let r=t=>e.nodes[t],i=new Map;for(let e=0;e<n.length;e++){let t=i.get(n[e].from);t?t.push(e):i.set(n[e].from,[e])}let o=e=>{let t=r(n[e].from),i=r(n[e].to);return Math.atan2(i.y-t.y,i.x-t.x)};for(let e of i.values())e.sort((e,t)=>{let r=o(e),i=o(t);if(r!==i)return r-i;let a=n[e].wallId,s=n[t].wallId;return a===s?e-t:a<s?-1:1});let s=new Int32Array(n.length);for(let e of i.values())for(let t=0;t<e.length;t++)s[e[t]]=t;return{darts:n,outgoing:i,ringIndex:s,nodeOf:r}}function s(e,t){let n=e.outgoing.get(e.darts[t].to);return!n||n.length===0?t^1:n[(e.ringIndex[t^1]-1+n.length)%n.length]}function c(e){let t=new Uint8Array(e.darts.length),n=[];for(let r=0;r<e.darts.length;r++){if(t[r])continue;let i=[],a=r,o=0;do if(t[a]=1,i.push(a),a=s(e,a),++o>e.darts.length+1)break;while(a!==r&&!t[a]);n.push(i)}return n}function l(e){let t=new Map,n=e=>{let n=e;for(;t.get(n)!==n;)n=t.get(n)??n;let r=e;for(;t.get(r)!==n;){let e=t.get(r)??n;t.set(r,n),r=e}return n};for(let n of e.outgoing.keys())t.set(n,n);for(let r=0;r<e.darts.length;r+=2){let i=n(e.darts[r].from),a=n(e.darts[r].to);i!==a&&t.set(i,a)}let r=new Map;for(let t of e.outgoing.keys())r.set(t,n(t));return r}function u(e,t){return t.map(t=>{let n=e.nodeOf(e.darts[t].from);return{x:n.x,y:n.y}})}function d(e,t){let n=``;for(let r of t){let t=`${e.darts[r].wallId}>${e.darts[r].from}`;(n===``||t<n)&&(n=t)}return`f:${n}`}function f(e){let a=o(e);if(a.darts.length===0)return[];let s=l(a),f=c(a),p=[],m=new Map;for(let e of f){let n=u(a,e),r=i(n),o=s.get(a.darts[e[0]].from)??``;r>100?p.push({face:{id:d(a,e),outer:n,holes:[],area:r,perimeter:t(n),wallIds:e.map(e=>a.darts[e].wallId),nodeIds:e.map(e=>a.darts[e].from)},component:o,outerArea:r}):r<-100&&m.set(o,n)}for(let[e,t]of m){let a=Math.abs(i(t));if(a<=100)continue;let o=r(t),s=null;for(let t of p)t.component!==e&&(t.outerArea<=a||n(o,t.face.outer)&&(!s||t.outerArea<s.outerArea)&&(s=t));s&&s.face.holes.push(t)}for(let e of p){let t=e.outerArea;for(let n of e.face.holes)t-=Math.abs(i(n));e.face.area=t}return p.map(e=>e.face)}function p(e){let t=new Map;for(let n of a(e))t.set(n.a,(t.get(n.a)??0)+1),t.set(n.b,(t.get(n.b)??0)+1);return t}export{f as deriveFaces,p as nodeDegrees};
1
+ import{dist as e,perimeter as t,pointInRing as n,representativePoint as r,signedArea as i}from"./floorPlan.geometry.mjs";function a(t){return Object.values(t.walls).filter(n=>{if(n.a===n.b)return!1;let r=t.nodes[n.a],i=t.nodes[n.b];return!r||!i?!1:e(r,i)>=10})}function o(e){let t=a(e),n=Array(t.length*2);for(let e=0;e<t.length;e++){let r=t[e];n[2*e]={wallId:r.id,from:r.a,to:r.b},n[2*e+1]={wallId:r.id,from:r.b,to:r.a}}let r=t=>e.nodes[t],i=new Map;for(let e=0;e<n.length;e++){let t=i.get(n[e].from);t?t.push(e):i.set(n[e].from,[e])}let o=e=>{let t=r(n[e].from),i=r(n[e].to);return Math.atan2(i.y-t.y,i.x-t.x)};for(let e of i.values())e.sort((e,t)=>{let r=o(e),i=o(t);if(r!==i)return r-i;let a=n[e].wallId,s=n[t].wallId;return a===s?e-t:a<s?-1:1});let s=new Int32Array(n.length);for(let e of i.values())for(let t=0;t<e.length;t++)s[e[t]]=t;return{darts:n,outgoing:i,ringIndex:s,nodeOf:r}}function s(e,t){let n=e.outgoing.get(e.darts[t].to);return!n||n.length===0?t^1:n[(e.ringIndex[t^1]-1+n.length)%n.length]}function c(e){let t=new Uint8Array(e.darts.length),n=[];for(let r=0;r<e.darts.length;r++){if(t[r])continue;let i=[],a=r,o=0;do if(t[a]=1,i.push(a),a=s(e,a),++o>e.darts.length+1)break;while(a!==r&&!t[a]);n.push(i)}return n}function l(e){let t=new Map,n=e=>{let n=e;for(;t.get(n)!==n;)n=t.get(n)??n;let r=e;for(;t.get(r)!==n;){let e=t.get(r)??n;t.set(r,n),r=e}return n};for(let n of e.outgoing.keys())t.set(n,n);for(let r=0;r<e.darts.length;r+=2){let i=n(e.darts[r].from),a=n(e.darts[r].to);i!==a&&t.set(i,a)}let r=new Map;for(let t of e.outgoing.keys())r.set(t,n(t));return r}function u(e,t){return t.map(t=>{let n=e.nodeOf(e.darts[t].from);return{x:n.x,y:n.y}})}function d(e,t){let n=``;for(let r of t){let t=`${e.darts[r].wallId}>${e.darts[r].from}`;(n===``||t<n)&&(n=t)}return`f:${n}`}function f(e){let a=o(e);if(a.darts.length===0)return[];let s=l(a),f=c(a),p=[],m=new Map;for(let e of f){let n=u(a,e),r=i(n),o=s.get(a.darts[e[0]].from)??``;r>100?p.push({face:{id:d(a,e),outer:n,holes:[],area:r,perimeter:t(n),wallIds:e.map(e=>a.darts[e].wallId),nodeIds:e.map(e=>a.darts[e].from)},component:o,outerArea:r}):r<-100&&m.set(o,n)}for(let[e,t]of m){let a=Math.abs(i(t));if(a<=100)continue;let o=r(t),s=null;for(let t of p)t.component!==e&&(t.outerArea<=a||n(o,t.face.outer)&&(!s||t.outerArea<s.outerArea)&&(s=t));s&&s.face.holes.push(t)}for(let e of p){let t=e.outerArea;for(let n of e.face.holes)t-=Math.abs(i(n));e.face.area=t}return p.map(e=>e.face)}function p(e){let t=new Map;for(let n of a(e))t.set(n.a,(t.get(n.a)??0)+1),t.set(n.b,(t.get(n.b)??0)+1);return t}export{f as deriveFaces,p as nodeDegrees};
2
2
  //# sourceMappingURL=floorPlan.faces.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"floorPlan.faces.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.faces.ts"],"sourcesContent":["/**\n * Planar face extraction: turns the wall graph into the enclosed rooms it forms.\n *\n * Each wall becomes two darts (directed half-edges), wall `i` owning darts `2i` and\n * `2i + 1`, so `twin(d) === d ^ 1` with no lookup. The darts leaving each node are\n * sorted by angle, and the face walk is:\n *\n * next(d) = the cyclic PREDECESSOR of twin(d) in the sorted ring at head(d)\n *\n * Because the shoelace sum runs on the same raw coordinates as the angular sort, the\n * rule needs no orientation convention: bounded faces come out with POSITIVE signed\n * area and each connected component's outer boundary comes out negative, whichever way\n * you read the y axis.\n *\n * A dangling wall (one endpoint of degree 1) is handled by the rule itself: a\n * one-element ring's cyclic predecessor is itself, so the walk goes out along the spur\n * and straight back. Both of its darts land in the same cycle, no extra face appears,\n * and the face gains a zero-width slit that contributes nothing to area, fill or\n * point-in-polygon.\n */\n\nimport {\n EPS_AREA,\n MIN_WALL_LENGTH,\n areaCentroid,\n dist,\n perimeter as ringPerimeter,\n pointInRing,\n representativePoint,\n signedArea,\n} from './floorPlan.geometry';\nimport type { PlanFace, PlanFloor, PlanNode, PlanPoint, PlanWall } from './floorPlan.types';\n\ninterface Dart {\n wallId: string;\n from: string;\n to: string;\n}\n\ninterface DartGraph {\n darts: Dart[];\n /** Node id to its outgoing dart indices, sorted by angle ascending. */\n outgoing: Map<string, number[]>;\n /** Dart index to its position within its own outgoing ring. */\n ringIndex: Int32Array;\n nodeOf: (id: string) => PlanNode;\n}\n\n/** Walls that are safe to traverse: real nodes at both ends, and long enough to have an angle. */\nfunction usableWalls(floor: PlanFloor): PlanWall[] {\n return Object.values(floor.walls).filter((w) => {\n if (w.a === w.b) return false;\n const a = floor.nodes[w.a];\n const b = floor.nodes[w.b];\n if (!a || !b) return false;\n return dist(a, b) >= MIN_WALL_LENGTH;\n });\n}\n\nfunction buildDartGraph(floor: PlanFloor): DartGraph {\n const walls = usableWalls(floor);\n const darts: Dart[] = new Array(walls.length * 2);\n\n for (let i = 0; i < walls.length; i++) {\n const w = walls[i];\n darts[2 * i] = { wallId: w.id, from: w.a, to: w.b };\n darts[2 * i + 1] = { wallId: w.id, from: w.b, to: w.a };\n }\n\n const nodeOf = (id: string): PlanNode => floor.nodes[id];\n\n const outgoing = new Map<string, number[]>();\n for (let d = 0; d < darts.length; d++) {\n const list = outgoing.get(darts[d].from);\n if (list) list.push(d);\n else outgoing.set(darts[d].from, [d]);\n }\n\n const angleOf = (d: number): number => {\n const from = nodeOf(darts[d].from);\n const to = nodeOf(darts[d].to);\n return Math.atan2(to.y - from.y, to.x - from.x);\n };\n\n for (const ring of outgoing.values()) {\n ring.sort((x, y) => {\n const ax = angleOf(x);\n const ay = angleOf(y);\n if (ax !== ay) return ax - ay;\n // Deterministic tie-break. A genuine tie means two walls leave this node in the\n // same direction, which validatePlan reports as OverlappingWalls: the sort stays\n // stable so the walk cannot hang, but the resulting face is still wrong.\n const wx = darts[x].wallId;\n const wy = darts[y].wallId;\n if (wx !== wy) return wx < wy ? -1 : 1;\n return x - y;\n });\n }\n\n const ringIndex = new Int32Array(darts.length);\n for (const ring of outgoing.values()) {\n for (let i = 0; i < ring.length; i++) ringIndex[ring[i]] = i;\n }\n\n return { darts, outgoing, ringIndex, nodeOf };\n}\n\nfunction nextDart(g: DartGraph, d: number): number {\n const ring = g.outgoing.get(g.darts[d].to);\n /* c8 ignore next -- head() always has the twin in its ring by construction */\n if (!ring || ring.length === 0) return d ^ 1;\n const i = g.ringIndex[d ^ 1];\n return ring[(i - 1 + ring.length) % ring.length];\n}\n\n/** Every dart belongs to exactly one cycle. */\nfunction walkCycles(g: DartGraph): number[][] {\n const visited = new Uint8Array(g.darts.length);\n const cycles: number[][] = [];\n\n for (let d0 = 0; d0 < g.darts.length; d0++) {\n if (visited[d0]) continue;\n const cycle: number[] = [];\n let d = d0;\n let guard = 0;\n do {\n visited[d] = 1;\n cycle.push(d);\n d = nextDart(g, d);\n // Only reachable if the dart permutation is corrupt (duplicate walls producing\n // an exact angular tie). Bail rather than spin.\n if (++guard > g.darts.length + 1) break;\n } while (d !== d0 && !visited[d]);\n cycles.push(cycle);\n }\n\n return cycles;\n}\n\n/** Union-find over node ids, joined by each wall. */\nfunction connectedComponents(g: DartGraph): Map<string, string> {\n const parent = new Map<string, string>();\n const find = (x: string): string => {\n let root = x;\n while (parent.get(root) !== root) root = parent.get(root) ?? root;\n let cur = x;\n while (parent.get(cur) !== root) {\n const nxt = parent.get(cur) ?? root;\n parent.set(cur, root);\n cur = nxt;\n }\n return root;\n };\n\n for (const nodeId of g.outgoing.keys()) parent.set(nodeId, nodeId);\n for (let d = 0; d < g.darts.length; d += 2) {\n const ra = find(g.darts[d].from);\n const rb = find(g.darts[d].to);\n if (ra !== rb) parent.set(ra, rb);\n }\n\n const out = new Map<string, string>();\n for (const nodeId of g.outgoing.keys()) out.set(nodeId, find(nodeId));\n return out;\n}\n\nfunction cycleRing(g: DartGraph, cycle: number[]): PlanPoint[] {\n return cycle.map((d) => {\n const n = g.nodeOf(g.darts[d].from);\n return { x: n.x, y: n.y };\n });\n}\n\n/**\n * A face id derived from the boundary itself, so it stays stable across derives for as\n * long as the geometry is unchanged.\n */\nfunction faceId(g: DartGraph, cycle: number[]): string {\n let best = '';\n for (const d of cycle) {\n const key = `${g.darts[d].wallId}>${g.darts[d].from}`;\n if (best === '' || key < best) best = key;\n }\n return `f:${best}`;\n}\n\n/**\n * Extracts every enclosed face from the wall graph, with nested components attached as\n * holes.\n *\n * Returned faces are positively wound (visually clockwise in SVG space) and their\n * `area` already has holes subtracted.\n */\nexport function deriveFaces(floor: PlanFloor): PlanFace[] {\n const g = buildDartGraph(floor);\n if (g.darts.length === 0) return [];\n\n const componentOf = connectedComponents(g);\n const cycles = walkCycles(g);\n\n interface Candidate {\n face: PlanFace;\n component: string;\n outerArea: number;\n }\n\n const candidates: Candidate[] = [];\n /** One outer (negatively wound) cycle per connected component. */\n const outerRings = new Map<string, PlanPoint[]>();\n\n for (const cycle of cycles) {\n const ring = cycleRing(g, cycle);\n const area = signedArea(ring);\n const component = componentOf.get(g.darts[cycle[0]].from) ?? '';\n\n if (area > EPS_AREA) {\n candidates.push({\n face: {\n id: faceId(g, cycle),\n outer: ring,\n holes: [],\n area,\n perimeter: ringPerimeter(ring),\n wallIds: cycle.map((d) => g.darts[d].wallId),\n nodeIds: cycle.map((d) => g.darts[d].from),\n },\n component,\n outerArea: area,\n });\n } else if (area < -EPS_AREA) {\n // This component's outer boundary. Kept at its negative winding, which is what\n // `PlanFace.holes` promises: opposite to the parent's positively wound `outer`.\n outerRings.set(component, ring);\n }\n // |area| <= EPS_AREA encloses nothing: a tree component or an isolated stub.\n }\n\n // Attach each component's outer boundary as a hole in the smallest face from a\n // different component that encloses it. Smallest-containing-area is what makes\n // arbitrary nesting depth work: with A > B > C, C's ring goes to B, never to A.\n for (const [component, ring] of outerRings) {\n const ringArea = Math.abs(signedArea(ring));\n if (ringArea <= EPS_AREA) continue;\n // An interior probe rather than a vertex, so two components that happen to touch\n // do not produce an on-boundary coin flip.\n const probe = representativePoint(ring);\n let parent: Candidate | null = null;\n for (const cand of candidates) {\n if (cand.component === component) continue;\n // The probe test alone is not sufficient: with one component nested inside\n // another, the OUTER component's probe also falls inside the inner component's\n // face, which would attach the big room as a hole of the small one. A face can\n // only enclose a ring smaller than itself.\n if (cand.outerArea <= ringArea) continue;\n if (!pointInRing(probe, cand.face.outer)) continue;\n if (!parent || cand.outerArea < parent.outerArea) parent = cand;\n }\n // No parent simply means this is a top-level component.\n if (parent) parent.face.holes.push(ring);\n }\n\n for (const cand of candidates) {\n let area = cand.outerArea;\n for (const hole of cand.face.holes) area -= Math.abs(signedArea(hole));\n cand.face.area = area;\n }\n\n return candidates.map((c) => c.face);\n}\n\n/**\n * Euler's formula per connected component: `V - E + F === 2C`, counting every cycle as\n * a face, including each component's own outer boundary.\n *\n * Note it is `2C`, not the `1 + C` of a single connected embedding. The dart walk\n * cannot bridge between disconnected components, so the region between two of them is\n * produced once per component rather than once in total.\n *\n * Exported for tests and dev assertions: it is the cheapest whole-graph check that the\n * dart permutation is intact.\n */\nexport function eulerCheck(floor: PlanFloor): {\n v: number;\n e: number;\n f: number;\n c: number;\n holds: boolean;\n} {\n const g = buildDartGraph(floor);\n const componentOf = connectedComponents(g);\n const v = g.outgoing.size;\n const e = g.darts.length / 2;\n const f = walkCycles(g).length;\n const c = new Set(componentOf.values()).size;\n return { v, e, f, c, holds: v - e + f === 2 * c };\n}\n\n/** Test/diagnostic helper: how many cycles each dart appears in. Must be all 1s. */\nexport function dartCycleCounts(floor: PlanFloor): number[] {\n const g = buildDartGraph(floor);\n const counts = new Array<number>(g.darts.length).fill(0);\n for (const cycle of walkCycles(g)) for (const d of cycle) counts[d] += 1;\n return counts;\n}\n\n/** Degree of each node, by id. Used by wall-path chaining and by validation. */\nexport function nodeDegrees(floor: PlanFloor): Map<string, number> {\n const degrees = new Map<string, number>();\n for (const w of usableWalls(floor)) {\n degrees.set(w.a, (degrees.get(w.a) ?? 0) + 1);\n degrees.set(w.b, (degrees.get(w.b) ?? 0) + 1);\n }\n return degrees;\n}\n\nexport { areaCentroid };\n"],"mappings":"sIAiDA,SAAS,EAAY,EAA8B,CACjD,OAAO,OAAO,OAAO,EAAM,KAAK,CAAC,CAAC,OAAQ,GAAM,CAC9C,GAAI,EAAE,IAAM,EAAE,EAAG,MAAO,GACxB,IAAM,EAAI,EAAM,MAAM,EAAE,GAClB,EAAI,EAAM,MAAM,EAAE,GAExB,MADI,CAAC,GAAK,CAAC,EAAU,GACd,EAAK,EAAG,CAAC,GAAA,EAClB,CAAC,CACH,CAEA,SAAS,EAAe,EAA6B,CACnD,IAAM,EAAQ,EAAY,CAAK,EACzB,EAAoB,MAAM,EAAM,OAAS,CAAC,EAEhD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAI,EAAM,GAChB,EAAM,EAAI,GAAK,CAAE,OAAQ,EAAE,GAAI,KAAM,EAAE,EAAG,GAAI,EAAE,CAAE,EAClD,EAAM,EAAI,EAAI,GAAK,CAAE,OAAQ,EAAE,GAAI,KAAM,EAAE,EAAG,GAAI,EAAE,CAAE,CACxD,CAEA,IAAM,EAAU,GAAyB,EAAM,MAAM,GAE/C,EAAW,IAAI,IACrB,IAAK,I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AO,aAAW,EAAS,IAGzD,GAAQ,EAAO,KAAK,MAAM,KAAK,CAAI,CACzC,CAEA,IAAK,IAAM,KAAQ,EAAY,CAC7B,IAAI,EAAO,EAAK,UAChB,IAAK,IAAM,KAAQ,EAAK,KAAK,MAAO,GAAQ,KAAK,IAAI,EAAW,CAAI,CAAC,EACrE,EAAK,KAAK,KAAO,CACnB,CAEA,OAAO,EAAW,IAAK,GAAM,EAAE,IAAI,CACrC,CAsCA,SAAgB,EAAY,EAAuC,CACjE,IAAM,EAAU,IAAI,IACpB,IAAK,IAAM,KAAK,EAAY,CAAK,EAC/B,EAAQ,IAAI,EAAE,GAAI,EAAQ,IAAI,EAAE,CAAC,GAAK,GAAK,CAAC,EAC5C,EAAQ,IAAI,EAAE,GAAI,EAAQ,IAAI,EAAE,CAAC,GAAK,GAAK,CAAC,EAE9C,OAAO,CACT"}
1
+ {"version":3,"file":"floorPlan.faces.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.faces.ts"],"sourcesContent":["/**\n * Planar face extraction: turns the wall graph into the enclosed rooms it forms.\n *\n * Each wall becomes two darts (directed half-edges), wall `i` owning darts `2i` and\n * `2i + 1`, so `twin(d) === d ^ 1` with no lookup. The darts leaving each node are\n * sorted by angle, and the face walk is:\n *\n * next(d) = the cyclic PREDECESSOR of twin(d) in the sorted ring at head(d)\n *\n * Because the shoelace sum runs on the same raw coordinates as the angular sort, the\n * rule needs no orientation convention: bounded faces come out with POSITIVE signed\n * area and each connected component's outer boundary comes out negative, whichever way\n * you read the y axis.\n *\n * A dangling wall (one endpoint of degree 1) is handled by the rule itself: a\n * one-element ring's cyclic predecessor is itself, so the walk goes out along the spur\n * and straight back. Both of its darts land in the same cycle, no extra face appears,\n * and the face gains a zero-width slit that contributes nothing to area, fill or\n * point-in-polygon.\n */\n\nimport {\n EPS_AREA,\n MIN_WALL_LENGTH,\n areaCentroid,\n dist,\n perimeter as ringPerimeter,\n pointInRing,\n representativePoint,\n signedArea,\n} from './floorPlan.geometry';\nimport type { PlanFace, PlanFloor, PlanNode, PlanPoint, PlanWall } from './floorPlan.types';\n\ninterface Dart {\n wallId: string;\n from: string;\n to: string;\n}\n\ninterface DartGraph {\n darts: Dart[];\n /** Node id to its outgoing dart indices, sorted by angle ascending. */\n outgoing: Map<string, number[]>;\n /** Dart index to its position within its own outgoing ring. */\n ringIndex: Int32Array;\n nodeOf: (id: string) => PlanNode;\n}\n\n/** Walls that are safe to traverse: real nodes at both ends, and long enough to have an angle. */\nfunction usableWalls(floor: PlanFloor): PlanWall[] {\n return Object.values(floor.walls).filter((w) => {\n if (w.a === w.b) return false;\n const a = floor.nodes[w.a];\n const b = floor.nodes[w.b];\n if (!a || !b) return false;\n return dist(a, b) >= MIN_WALL_LENGTH;\n });\n}\n\nfunction buildDartGraph(floor: PlanFloor): DartGraph {\n const walls = usableWalls(floor);\n const darts: Dart[] = new Array(walls.length * 2);\n\n for (let i = 0; i < walls.length; i++) {\n const w = walls[i];\n darts[2 * i] = { wallId: w.id, from: w.a, to: w.b };\n darts[2 * i + 1] = { wallId: w.id, from: w.b, to: w.a };\n }\n\n const nodeOf = (id: string): PlanNode => floor.nodes[id];\n\n const outgoing = new Map<string, number[]>();\n for (let d = 0; d < darts.length; d++) {\n const list = outgoing.get(darts[d].from);\n if (list) list.push(d);\n else outgoing.set(darts[d].from, [d]);\n }\n\n const angleOf = (d: number): number => {\n const from = nodeOf(darts[d].from);\n const to = nodeOf(darts[d].to);\n return Math.atan2(to.y - from.y, to.x - from.x);\n };\n\n for (const ring of outgoing.values()) {\n ring.sort((x, y) => {\n const ax = angleOf(x);\n const ay = angleOf(y);\n if (ax !== ay) return ax - ay;\n // Deterministic tie-break. A genuine tie means two walls leave this node in the\n // same direction, which validatePlan reports as OverlappingWalls: the sort stays\n // stable so the walk cannot hang, but the resulting face is still wrong.\n const wx = darts[x].wallId;\n const wy = darts[y].wallId;\n if (wx !== wy) return wx < wy ? -1 : 1;\n return x - y;\n });\n }\n\n const ringIndex = new Int32Array(darts.length);\n for (const ring of outgoing.values()) {\n for (let i = 0; i < ring.length; i++) ringIndex[ring[i]] = i;\n }\n\n return { darts, outgoing, ringIndex, nodeOf };\n}\n\nfunction nextDart(g: DartGraph, d: number): number {\n const ring = g.outgoing.get(g.darts[d].to);\n /* c8 ignore next -- head() always has the twin in its ring by construction */\n if (!ring || ring.length === 0) return d ^ 1;\n const i = g.ringIndex[d ^ 1];\n return ring[(i - 1 + ring.length) % ring.length];\n}\n\n/** Every dart belongs to exactly one cycle. */\nfunction walkCycles(g: DartGraph): number[][] {\n const visited = new Uint8Array(g.darts.length);\n const cycles: number[][] = [];\n\n for (let d0 = 0; d0 < g.darts.length; d0++) {\n if (visited[d0]) continue;\n const cycle: number[] = [];\n let d = d0;\n let guard = 0;\n do {\n visited[d] = 1;\n cycle.push(d);\n d = nextDart(g, d);\n // Only reachable if the dart permutation is corrupt (duplicate walls producing\n // an exact angular tie). Bail rather than spin.\n if (++guard > g.darts.length + 1) break;\n } while (d !== d0 && !visited[d]);\n cycles.push(cycle);\n }\n\n return cycles;\n}\n\n/** Union-find over node ids, joined by each wall. */\nfunction connectedComponents(g: DartGraph): Map<string, string> {\n const parent = new Map<string, string>();\n const find = (x: string): string => {\n let root = x;\n while (parent.get(root) !== root) root = parent.get(root) ?? root;\n let cur = x;\n while (parent.get(cur) !== root) {\n const nxt = parent.get(cur) ?? root;\n parent.set(cur, root);\n cur = nxt;\n }\n return root;\n };\n\n for (const nodeId of g.outgoing.keys()) parent.set(nodeId, nodeId);\n for (let d = 0; d < g.darts.length; d += 2) {\n const ra = find(g.darts[d].from);\n const rb = find(g.darts[d].to);\n if (ra !== rb) parent.set(ra, rb);\n }\n\n const out = new Map<string, string>();\n for (const nodeId of g.outgoing.keys()) out.set(nodeId, find(nodeId));\n return out;\n}\n\nfunction cycleRing(g: DartGraph, cycle: number[]): PlanPoint[] {\n return cycle.map((d) => {\n const n = g.nodeOf(g.darts[d].from);\n return { x: n.x, y: n.y };\n });\n}\n\n/**\n * A face id derived from the boundary itself, so it stays stable across derives for as\n * long as the geometry is unchanged.\n */\nfunction faceId(g: DartGraph, cycle: number[]): string {\n let best = '';\n for (const d of cycle) {\n const key = `${g.darts[d].wallId}>${g.darts[d].from}`;\n if (best === '' || key < best) best = key;\n }\n return `f:${best}`;\n}\n\n/**\n * Extracts every enclosed face from the wall graph, with nested components attached as\n * holes.\n *\n * Returned faces are positively wound (visually clockwise in SVG space) and their\n * `area` already has holes subtracted.\n */\nexport function deriveFaces(floor: PlanFloor): PlanFace[] {\n const g = buildDartGraph(floor);\n if (g.darts.length === 0) return [];\n\n const componentOf = connectedComponents(g);\n const cycles = walkCycles(g);\n\n interface Candidate {\n face: PlanFace;\n component: string;\n outerArea: number;\n }\n\n const candidates: Candidate[] = [];\n /** One outer (negatively wound) cycle per connected component. */\n const outerRings = new Map<string, PlanPoint[]>();\n\n for (const cycle of cycles) {\n const ring = cycleRing(g, cycle);\n const area = signedArea(ring);\n const component = componentOf.get(g.darts[cycle[0]].from) ?? '';\n\n if (area > EPS_AREA) {\n candidates.push({\n face: {\n id: faceId(g, cycle),\n outer: ring,\n holes: [],\n area,\n perimeter: ringPerimeter(ring),\n wallIds: cycle.map((d) => g.darts[d].wallId),\n nodeIds: cycle.map((d) => g.darts[d].from),\n },\n component,\n outerArea: area,\n });\n } else if (area < -EPS_AREA) {\n // This component's outer boundary. Kept at its negative winding, which is what\n // `PlanFace.holes` promises: opposite to the parent's positively wound `outer`.\n outerRings.set(component, ring);\n }\n // |area| <= EPS_AREA encloses nothing: a tree component or an isolated stub.\n }\n\n // Attach each component's outer boundary as a hole in the smallest face from a\n // different component that encloses it. Smallest-containing-area is what makes\n // arbitrary nesting depth work: with A > B > C, C's ring goes to B, never to A.\n for (const [component, ring] of outerRings) {\n const ringArea = Math.abs(signedArea(ring));\n if (ringArea <= EPS_AREA) continue;\n // An interior probe rather than a vertex, so two components that happen to touch\n // do not produce an on-boundary coin flip.\n const probe = representativePoint(ring);\n let parent: Candidate | null = null;\n for (const cand of candidates) {\n if (cand.component === component) continue;\n // The probe test alone is not sufficient: with one component nested inside\n // another, the OUTER component's probe also falls inside the inner component's\n // face, which would attach the big room as a hole of the small one. A face can\n // only enclose a ring smaller than itself.\n if (cand.outerArea <= ringArea) continue;\n if (!pointInRing(probe, cand.face.outer)) continue;\n if (!parent || cand.outerArea < parent.outerArea) parent = cand;\n }\n // No parent simply means this is a top-level component.\n if (parent) parent.face.holes.push(ring);\n }\n\n for (const cand of candidates) {\n let area = cand.outerArea;\n for (const hole of cand.face.holes) area -= Math.abs(signedArea(hole));\n cand.face.area = area;\n }\n\n return candidates.map((c) => c.face);\n}\n\n/**\n * Euler's formula per connected component: `V - E + F === 2C`, counting every cycle as\n * a face, including each component's own outer boundary.\n *\n * Note it is `2C`, not the `1 + C` of a single connected embedding. The dart walk\n * cannot bridge between disconnected components, so the region between two of them is\n * produced once per component rather than once in total.\n *\n * Exported for tests and dev assertions: it is the cheapest whole-graph check that the\n * dart permutation is intact.\n */\nexport function eulerCheck(floor: PlanFloor): {\n v: number;\n e: number;\n f: number;\n c: number;\n holds: boolean;\n} {\n const g = buildDartGraph(floor);\n const componentOf = connectedComponents(g);\n const v = g.outgoing.size;\n const e = g.darts.length / 2;\n const f = walkCycles(g).length;\n const c = new Set(componentOf.values()).size;\n return { v, e, f, c, holds: v - e + f === 2 * c };\n}\n\n/** Test/diagnostic helper: how many cycles each dart appears in. Must be all 1s. */\nexport function dartCycleCounts(floor: PlanFloor): number[] {\n const g = buildDartGraph(floor);\n const counts = new Array<number>(g.darts.length).fill(0);\n for (const cycle of walkCycles(g)) for (const d of cycle) counts[d] += 1;\n return counts;\n}\n\n/** Degree of each node, by id. Used by wall-path chaining and by validation. */\nexport function nodeDegrees(floor: PlanFloor): Map<string, number> {\n const degrees = new Map<string, number>();\n for (const w of usableWalls(floor)) {\n degrees.set(w.a, (degrees.get(w.a) ?? 0) + 1);\n degrees.set(w.b, (degrees.get(w.b) ?? 0) + 1);\n }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IAAI,EAAE,CAAC,GAAK,GAAK,CAAC,EAE9C,OAAO,CACT"}
@@ -1,2 +1,2 @@
1
- "use client";var e=10,t=1e-4,n=100;function r(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function i(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function a(e,t,n){let i=n.x-t.x,a=n.y-t.y,o=i*i+a*a;if(o===0)return{dist:r(e,t),t:0,point:{x:t.x,y:t.y}};let s=((e.x-t.x)*i+(e.y-t.y)*a)/o,c=s<0?0:s>1?1:s,l={x:t.x+c*i,y:t.y+c*a};return{dist:r(e,l),t:c,point:l}}function o(e,t,n){return a(e,t,n).point}function s(e,t,n,a,o=1){let s=r(e,t),c=r(n,a);if(s<1e-9||c<1e-9)return{kind:`none`};let l=t.x-e.x,u=t.y-e.y,d=a.x-n.x,f=a.y-n.y,p=l*f-u*d,m=Math.abs(i(e,t,n))/s,h=Math.abs(i(e,t,a))/s;if(Math.abs(p)<1e-12||m<o&&h<o){if(m>=o||h>=o)return{kind:`none`};let t=l*l+u*u,r=((n.x-e.x)*l+(n.y-e.y)*u)/t,i=((a.x-e.x)*l+(a.y-e.y)*u)/t,c=Math.min(r,i),d=Math.max(r,i),f=o/s;return d<f||c>1-f||Math.min(d,1)-Math.max(c,0)<f?{kind:`collinearDisjoint`}:{kind:`collinearOverlap`}}let g=((n.x-e.x)*f-(n.y-e.y)*d)/p,_=((n.x-e.x)*u-(n.y-e.y)*l)/p,v=o/s,y=o/c;if(g<-v||g>1+v||_<-y||_>1+y)return{kind:`none`};let b={x:e.x+g*l,y:e.y+g*u},x=g<=v||g>=1-v,S=_<=y||_>=1-y;return x||S?{kind:`touch`,t:g,s:_,point:b}:{kind:`proper`,t:g,s:_,point:b}}function c(e){let t=e.length;if(t<3)return 0;let n=0;for(let r=0,i=t-1;r<t;i=r++)n+=e[i].x*e[r].y-e[r].x*e[i].y;return n/2}function l(e){let t=e.length;if(t<2)return 0;let n=0;for(let i=0,a=t-1;i<t;a=i++)n+=r(e[a],e[i]);return n}function u(e){let t=e.length;if(t===0)return{x:0,y:0};if(t<3)return{x:e.reduce((e,t)=>e+t.x,0)/t,y:e.reduce((e,t)=>e+t.y,0)/t};let n=0,r=0,i=0;for(let a=0,o=t-1;a<t;o=a++){let t=e[o].x*e[a].y-e[a].x*e[o].y;n+=t,r+=(e[o].x+e[a].x)*t,i+=(e[o].y+e[a].y)*t}return Math.abs(n)<1e-9?{x:e.reduce((e,t)=>e+t.x,0)/t,y:e.reduce((e,t)=>e+t.y,0)/t}:{x:r/(3*n),y:i/(3*n)}}function d(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r].x,o=t[r].y,s=t[i].x,c=t[i].y;o>e.y!=c>e.y&&e.x<(s-a)*(e.y-o)/(c-o)+a&&(n=!n)}return n}function f(e,t,n=[]){if(!d(e,t))return!1;for(let t of n)if(d(e,t))return!1;return!0}function p(e,t=[]){if(e.length===0)return{x:0,y:0};let n=u(e);if(f(n,e,t))return n;let r=1/0,i=-1/0;for(let t of e)t.y<r&&(r=t.y),t.y>i&&(i=t.y);if(!Number.isFinite(r)||i-r<1e-9)return n;let a=[e,...t],o=null;for(let e=1;e<=7;e++){let t=r+(i-r)*e/8,n=[];for(let e of a)for(let r=0,i=e.length-1;r<e.length;i=r++){let a=e[i],o=e[r];a.y>t!=o.y>t&&n.push(a.x+(t-a.y)*(o.x-a.x)/(o.y-a.y))}n.sort((e,t)=>e-t);for(let e=0;e+1<n.length;e+=2){let r=n[e+1]-n[e];r>2&&(!o||r>o.width)&&(o={point:{x:(n[e]+n[e+1])/2,y:t},width:r})}}return o?o.point:n}function m(e){let t=e.slice(),n=!0;for(;n&&t.length>3;){n=!1;let e=[],i=t.length;for(let a=0;a<i;a++){let o=t[(a-1+i)%i],s=t[(a+1)%i];if(r(o,s)<1){n=!0;continue}e.push(t[a])}n&&(t=e.filter((t,n)=>r(t,e[(n+1)%e.length])>=1))}return t}function h(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)a.x<t&&(t=a.x),a.y<n&&(n=a.y),a.x>r&&(r=a.x),a.y>i&&(i=a.y);return{minX:t,minY:n,maxX:r,maxY:i}}export{t as EPS_ANGLE,n as MIN_OPENING_WIDTH,e as MIN_WALL_LENGTH,u as areaCentroid,h as boundsOf,i as cross,r as dist,l as perimeter,d as pointInRing,f as pointInRings,a as pointToSegment,o as projectOnSegment,p as representativePoint,s as segmentIntersection,c as signedArea,m as stripSpurs};
1
+ var e=10,t=1e-4,n=100;function r(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function i(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function a(e,t,n){let i=n.x-t.x,a=n.y-t.y,o=i*i+a*a;if(o===0)return{dist:r(e,t),t:0,point:{x:t.x,y:t.y}};let s=((e.x-t.x)*i+(e.y-t.y)*a)/o,c=s<0?0:s>1?1:s,l={x:t.x+c*i,y:t.y+c*a};return{dist:r(e,l),t:c,point:l}}function o(e,t,n){return a(e,t,n).point}function s(e,t,n,a,o=1){let s=r(e,t),c=r(n,a);if(s<1e-9||c<1e-9)return{kind:`none`};let l=t.x-e.x,u=t.y-e.y,d=a.x-n.x,f=a.y-n.y,p=l*f-u*d,m=Math.abs(i(e,t,n))/s,h=Math.abs(i(e,t,a))/s;if(Math.abs(p)<1e-12||m<o&&h<o){if(m>=o||h>=o)return{kind:`none`};let t=l*l+u*u,r=((n.x-e.x)*l+(n.y-e.y)*u)/t,i=((a.x-e.x)*l+(a.y-e.y)*u)/t,c=Math.min(r,i),d=Math.max(r,i),f=o/s;return d<f||c>1-f||Math.min(d,1)-Math.max(c,0)<f?{kind:`collinearDisjoint`}:{kind:`collinearOverlap`}}let g=((n.x-e.x)*f-(n.y-e.y)*d)/p,_=((n.x-e.x)*u-(n.y-e.y)*l)/p,v=o/s,y=o/c;if(g<-v||g>1+v||_<-y||_>1+y)return{kind:`none`};let b={x:e.x+g*l,y:e.y+g*u},x=g<=v||g>=1-v,S=_<=y||_>=1-y;return x||S?{kind:`touch`,t:g,s:_,point:b}:{kind:`proper`,t:g,s:_,point:b}}function c(e){let t=e.length;if(t<3)return 0;let n=0;for(let r=0,i=t-1;r<t;i=r++)n+=e[i].x*e[r].y-e[r].x*e[i].y;return n/2}function l(e){let t=e.length;if(t<2)return 0;let n=0;for(let i=0,a=t-1;i<t;a=i++)n+=r(e[a],e[i]);return n}function u(e){let t=e.length;if(t===0)return{x:0,y:0};if(t<3)return{x:e.reduce((e,t)=>e+t.x,0)/t,y:e.reduce((e,t)=>e+t.y,0)/t};let n=0,r=0,i=0;for(let a=0,o=t-1;a<t;o=a++){let t=e[o].x*e[a].y-e[a].x*e[o].y;n+=t,r+=(e[o].x+e[a].x)*t,i+=(e[o].y+e[a].y)*t}return Math.abs(n)<1e-9?{x:e.reduce((e,t)=>e+t.x,0)/t,y:e.reduce((e,t)=>e+t.y,0)/t}:{x:r/(3*n),y:i/(3*n)}}function d(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r].x,o=t[r].y,s=t[i].x,c=t[i].y;o>e.y!=c>e.y&&e.x<(s-a)*(e.y-o)/(c-o)+a&&(n=!n)}return n}function f(e,t,n=[]){if(!d(e,t))return!1;for(let t of n)if(d(e,t))return!1;return!0}function p(e,t=[]){if(e.length===0)return{x:0,y:0};let n=u(e);if(f(n,e,t))return n;let r=1/0,i=-1/0;for(let t of e)t.y<r&&(r=t.y),t.y>i&&(i=t.y);if(!Number.isFinite(r)||i-r<1e-9)return n;let a=[e,...t],o=null;for(let e=1;e<=7;e++){let t=r+(i-r)*e/8,n=[];for(let e of a)for(let r=0,i=e.length-1;r<e.length;i=r++){let a=e[i],o=e[r];a.y>t!=o.y>t&&n.push(a.x+(t-a.y)*(o.x-a.x)/(o.y-a.y))}n.sort((e,t)=>e-t);for(let e=0;e+1<n.length;e+=2){let r=n[e+1]-n[e];r>2&&(!o||r>o.width)&&(o={point:{x:(n[e]+n[e+1])/2,y:t},width:r})}}return o?o.point:n}function m(e){let t=e.slice(),n=!0;for(;n&&t.length>3;){n=!1;let e=[],i=t.length;for(let a=0;a<i;a++){let o=t[(a-1+i)%i],s=t[(a+1)%i];if(r(o,s)<1){n=!0;continue}e.push(t[a])}n&&(t=e.filter((t,n)=>r(t,e[(n+1)%e.length])>=1))}return t}function h(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)a.x<t&&(t=a.x),a.y<n&&(n=a.y),a.x>r&&(r=a.x),a.y>i&&(i=a.y);return{minX:t,minY:n,maxX:r,maxY:i}}export{t as EPS_ANGLE,n as MIN_OPENING_WIDTH,e as MIN_WALL_LENGTH,u as areaCentroid,h as boundsOf,i as cross,r as dist,l as perimeter,d as pointInRing,f as pointInRings,a as pointToSegment,o as projectOnSegment,p as representativePoint,s as segmentIntersection,c as signedArea,m as stripSpurs};
2
2
  //# sourceMappingURL=floorPlan.geometry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"floorPlan.geometry.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.geometry.ts"],"sourcesContent":["/**\n * Pure vector and polygon primitives. Nothing here knows about the plan model.\n *\n * All lengths are millimetres (see floorPlan.types.ts).\n */\n\nimport type { PlanPoint } from './floorPlan.types';\n\n// ─── Model-integrity epsilons ──────────────────────────────────────────────────\n// These are FIXED millimetre values describing when the model itself is degenerate.\n// They are a separate family from the user-intent tolerances in floorPlan.snap.ts,\n// which are screen pixels converted through the current zoom. Conflating the two\n// gives you either a model that accumulates 0.2mm walls, or snapping that stops\n// working when zoomed in.\n\n/** Shortest wall the graph will accept. Keeps zero-length walls out entirely. */\nexport const MIN_WALL_LENGTH = 10;\n/** Two points closer than this are the same point. */\nexport const EPS_COINCIDENT = 1;\n/** A ring with |area| below this encloses nothing (0.0001 m²). */\nexport const EPS_AREA = 100;\n/** Angular tolerance for \"these two walls are collinear\", in radians. */\nexport const EPS_ANGLE = 1e-4;\n/** Narrowest scanline span that counts as room interior rather than a slit. */\nexport const EPS_SPAN = 2;\n/** Narrowest opening worth keeping when a wall shortens under it. */\nexport const MIN_OPENING_WIDTH = 100;\n\n// ─── Vectors ───────────────────────────────────────────────────────────────────\n\nexport function dist(a: PlanPoint, b: PlanPoint): number {\n return Math.hypot(a.x - b.x, a.y - b.y);\n}\n\nexport function distSq(a: PlanPoint, b: PlanPoint): number {\n const dx = a.x - b.x;\n const dy = a.y - b.y;\n return dx * dx + dy * dy;\n}\n\n/** Cross product of ab and ac. Positive when c is clockwise of b in SVG's y-down space. */\nexport function cross(a: PlanPoint, b: PlanPoint, c: PlanPoint): number {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nexport function lerp(a: PlanPoint, b: PlanPoint, t: number): PlanPoint {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\n\n/** Unit vector from a to b, or null when they are coincident. */\nexport function direction(a: PlanPoint, b: PlanPoint): PlanPoint | null {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const len = Math.hypot(dx, dy);\n if (len < 1e-9) return null;\n return { x: dx / len, y: dy / len };\n}\n\n/** Left-hand normal of the direction from a to b, or null when coincident. */\nexport function normal(a: PlanPoint, b: PlanPoint): PlanPoint | null {\n const d = direction(a, b);\n return d ? { x: -d.y, y: d.x } : null;\n}\n\n// ─── Point / segment ───────────────────────────────────────────────────────────\n\n/**\n * Distance from p to segment ab, plus the clamped parameter t of the closest point.\n * `t` is clamped to [0, 1], so the closest point is always on the segment.\n */\nexport function pointToSegment(\n p: PlanPoint,\n a: PlanPoint,\n b: PlanPoint,\n): { dist: number; t: number; point: PlanPoint } {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const len2 = dx * dx + dy * dy;\n if (len2 === 0) return { dist: dist(p, a), t: 0, point: { x: a.x, y: a.y } };\n const raw = ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2;\n const t = raw < 0 ? 0 : raw > 1 ? 1 : raw;\n const point = { x: a.x + t * dx, y: a.y + t * dy };\n return { dist: dist(p, point), t, point };\n}\n\n/**\n * Exact projection of p onto segment ab, clamped to the segment.\n *\n * Used after a fuzzy hit tolerance has decided that p belongs to this segment: intent\n * is allowed to be approximate, the stored model never is.\n */\nexport function projectOnSegment(p: PlanPoint, a: PlanPoint, b: PlanPoint): PlanPoint {\n return pointToSegment(p, a, b).point;\n}\n\nexport type SegmentIntersectionKind =\n /** The segments cross strictly inside both. */\n | 'proper'\n /** They are parallel and do not touch. */\n | 'none'\n /** They lie on the same line and overlap over a non-zero length. */\n | 'collinearOverlap'\n /** They lie on the same line but do not overlap. */\n | 'collinearDisjoint'\n /** An endpoint of one lies on the other, or they share an endpoint. */\n | 'touch';\n\nexport interface SegmentIntersection {\n kind: SegmentIntersectionKind;\n /** Parameter along ab, for 'proper' and 'touch'. */\n t?: number;\n /** Parameter along cd, for 'proper' and 'touch'. */\n s?: number;\n point?: PlanPoint;\n}\n\n/**\n * Classifies how segments ab and cd meet.\n *\n * `eps` is a millimetre distance tolerance, not a parameter tolerance, so the result\n * does not change with segment length.\n */\nexport function segmentIntersection(\n a: PlanPoint,\n b: PlanPoint,\n c: PlanPoint,\n d: PlanPoint,\n eps = EPS_COINCIDENT,\n): SegmentIntersection {\n const abLen = dist(a, b);\n const cdLen = dist(c, d);\n if (abLen < 1e-9 || cdLen < 1e-9) return { kind: 'none' };\n\n const rx = b.x - a.x;\n const ry = b.y - a.y;\n const sx = d.x - c.x;\n const sy = d.y - c.y;\n const denom = rx * sy - ry * sx;\n\n // Perpendicular distance of c and d from line ab, used to tell parallel from collinear.\n const distC = Math.abs(cross(a, b, c)) / abLen;\n const distD = Math.abs(cross(a, b, d)) / abLen;\n\n if (Math.abs(denom) < 1e-12 || (distC < eps && distD < eps)) {\n if (distC >= eps || distD >= eps) return { kind: 'none' };\n // Collinear: compare parameters along ab.\n const len2 = rx * rx + ry * ry;\n const tc = ((c.x - a.x) * rx + (c.y - a.y) * ry) / len2;\n const td = ((d.x - a.x) * rx + (d.y - a.y) * ry) / len2;\n const lo = Math.min(tc, td);\n const hi = Math.max(tc, td);\n const epsT = eps / abLen;\n if (hi < epsT || lo > 1 - epsT) return { kind: 'collinearDisjoint' };\n if (Math.min(hi, 1) - Math.max(lo, 0) < epsT) return { kind: 'collinearDisjoint' };\n return { kind: 'collinearOverlap' };\n }\n\n const t = ((c.x - a.x) * sy - (c.y - a.y) * sx) / denom;\n const s = ((c.x - a.x) * ry - (c.y - a.y) * rx) / denom;\n const epsT = eps / abLen;\n const epsS = eps / cdLen;\n\n if (t < -epsT || t > 1 + epsT || s < -epsS || s > 1 + epsS) return { kind: 'none' };\n\n const point = { x: a.x + t * rx, y: a.y + t * ry };\n const atAbEnd = t <= epsT || t >= 1 - epsT;\n const atCdEnd = s <= epsS || s >= 1 - epsS;\n if (atAbEnd || atCdEnd) return { kind: 'touch', t, s, point };\n return { kind: 'proper', t, s, point };\n}\n\n// ─── Rings ─────────────────────────────────────────────────────────────────────\n\n/**\n * Shoelace area of a closed ring (first vertex not repeated).\n *\n * Positive means visually clockwise in SVG's y-down space. See `PlanFace.outer`.\n */\nexport function signedArea(ring: readonly PlanPoint[]): number {\n const n = ring.length;\n if (n < 3) return 0;\n let sum = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n sum += ring[j].x * ring[i].y - ring[i].x * ring[j].y;\n }\n return sum / 2;\n}\n\nexport function perimeter(ring: readonly PlanPoint[]): number {\n const n = ring.length;\n if (n < 2) return 0;\n let sum = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) sum += dist(ring[j], ring[i]);\n return sum;\n}\n\n/**\n * Area-weighted centroid of a ring.\n *\n * Deliberately not the vertex mean: a dangling wall adds an out-and-back vertex pair\n * that skews the mean but contributes nothing to the area moment. Falls back to the\n * vertex mean only for a degenerate (zero-area) ring.\n */\nexport function areaCentroid(ring: readonly PlanPoint[]): PlanPoint {\n const n = ring.length;\n if (n === 0) return { x: 0, y: 0 };\n if (n < 3) {\n return {\n x: ring.reduce((s, p) => s + p.x, 0) / n,\n y: ring.reduce((s, p) => s + p.y, 0) / n,\n };\n }\n let a = 0;\n let cx = 0;\n let cy = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n const f = ring[j].x * ring[i].y - ring[i].x * ring[j].y;\n a += f;\n cx += (ring[j].x + ring[i].x) * f;\n cy += (ring[j].y + ring[i].y) * f;\n }\n if (Math.abs(a) < 1e-9) {\n return {\n x: ring.reduce((s, p) => s + p.x, 0) / n,\n y: ring.reduce((s, p) => s + p.y, 0) / n,\n };\n }\n return { x: cx / (3 * a), y: cy / (3 * a) };\n}\n\n/** Ray-casting point-in-ring test. Points exactly on an edge are unspecified. */\nexport function pointInRing(p: PlanPoint, ring: readonly PlanPoint[]): boolean {\n let inside = false;\n for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {\n const xi = ring[i].x;\n const yi = ring[i].y;\n const xj = ring[j].x;\n const yj = ring[j].y;\n if (yi > p.y !== yj > p.y && p.x < ((xj - xi) * (p.y - yi)) / (yj - yi) + xi) {\n inside = !inside;\n }\n }\n return inside;\n}\n\n/** Inside `outer` and outside every hole. */\nexport function pointInRings(\n p: PlanPoint,\n outer: readonly PlanPoint[],\n holes: readonly (readonly PlanPoint[])[] = [],\n): boolean {\n if (!pointInRing(p, outer)) return false;\n for (const hole of holes) if (pointInRing(p, hole)) return false;\n return true;\n}\n\n/**\n * A point guaranteed to lie strictly inside the ring set, placed somewhere visually\n * central where possible.\n *\n * The area centroid is preferred, but it is not guaranteed to be inside a concave\n * polygon (an L-shaped room's centroid can land in the notch), so a scanline fallback\n * picks the widest interior span across several horizontal lines. The EPS_SPAN test on\n * that span is what stops an anchor landing inside the zero-width slit that a dangling\n * wall leaves in a face.\n */\nexport function representativePoint(\n outer: readonly PlanPoint[],\n holes: readonly (readonly PlanPoint[])[] = [],\n): PlanPoint {\n if (outer.length === 0) return { x: 0, y: 0 };\n\n const centre = areaCentroid(outer);\n if (pointInRings(centre, outer, holes)) return centre;\n\n let ymin = Infinity;\n let ymax = -Infinity;\n for (const p of outer) {\n if (p.y < ymin) ymin = p.y;\n if (p.y > ymax) ymax = p.y;\n }\n if (!Number.isFinite(ymin) || ymax - ymin < 1e-9) return centre;\n\n const rings: readonly (readonly PlanPoint[])[] = [outer, ...holes];\n let best: { point: PlanPoint; width: number } | null = null;\n\n const SAMPLES = 7;\n for (let k = 1; k <= SAMPLES; k++) {\n const y = ymin + ((ymax - ymin) * k) / (SAMPLES + 1);\n const xs: number[] = [];\n // One crossing list across ALL rings, so even-odd pairing yields interior spans\n // directly. Running the scanline per ring would not compose with holes.\n for (const ring of rings) {\n for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {\n const p = ring[j];\n const q = ring[i];\n if (p.y > y !== q.y > y) {\n xs.push(p.x + ((y - p.y) * (q.x - p.x)) / (q.y - p.y));\n }\n }\n }\n xs.sort((m, n) => m - n);\n for (let i = 0; i + 1 < xs.length; i += 2) {\n const width = xs[i + 1] - xs[i];\n if (width > EPS_SPAN && (!best || width > best.width)) {\n best = { point: { x: (xs[i] + xs[i + 1]) / 2, y }, width };\n }\n }\n }\n\n return best ? best.point : centre;\n}\n\n/**\n * Removes out-and-back spurs (`... P, Q, P ...`) from a ring, repeatedly until none\n * remain.\n *\n * A face containing a dangling wall is a valid fill but is not a simple polygon, which\n * breaks polygon offsetting and makes some triangulators emit zero-area triangles. Run\n * this before triangulating a floor slab; keep the raw ring for the 2D fill, where the\n * slit is harmless and `wallIds` alignment matters.\n */\nexport function stripSpurs(ring: readonly PlanPoint[]): PlanPoint[] {\n let out = ring.slice();\n let changed = true;\n while (changed && out.length > 3) {\n changed = false;\n const next: PlanPoint[] = [];\n const n = out.length;\n for (let i = 0; i < n; i++) {\n const prev = out[(i - 1 + n) % n];\n const nextPt = out[(i + 1) % n];\n // The middle of an out-and-back is the vertex whose neighbours coincide.\n if (dist(prev, nextPt) < EPS_COINCIDENT) {\n changed = true;\n continue;\n }\n next.push(out[i]);\n }\n if (changed) {\n // Drop the now-duplicated turning point left behind by each removed spur tip.\n out = next.filter((p, i) => dist(p, next[(i + 1) % next.length]) >= EPS_COINCIDENT);\n }\n }\n return out;\n}\n\nexport function rectToPoints(x: number, y: number, w: number, h: number): PlanPoint[] {\n return [\n { x, y },\n { x: x + w, y },\n { x: x + w, y: y + h },\n { x, y: y + h },\n ];\n}\n\nexport function boundsOf(points: readonly PlanPoint[]): {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n} | null {\n if (points.length === 0) return null;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const p of points) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n return { minX, minY, maxX, maxY };\n}\n"],"mappings":"aAgBA,IAAa,EAAkB,GAMlB,EAAY,KAIZ,EAAoB,IAIjC,SAAgB,EAAK,EAAc,EAAsB,CACvD,OAAO,KAAK,MAAM,EAAE,EAAI,EAAE,EAAG,EAAE,EAAI,EAAE,CAAC,CACxC,CASA,SAAgB,EAAM,EAAc,EAAc,EAAsB,CACtE,OAAQ,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,EAC5D,CA2BA,SAAgB,EACd,EACA,EACA,EAC+C,CAC/C,IAAM,EAAK,EAAE,EAAI,EAAE,EACb,EAAK,EAAE,EAAI,EAAE,EACb,EAAO,EAAK,EAAK,EAAK,EAC5B,GAAI,IAAS,EAAG,MAAO,CAAE,KAAM,EAAK,EAAG,CAAC,EAAG,EAAG,EAAG,MAAO,CAAE,EAAG,EAAE,EAAG,EAAG,EAAE,CAAE,CAAE,EAC3E,IAAM,IAAQ,EAAE,EAAI,EAAE,GAAK,GAAM,EAAE,EAAI,EAAE,GAAK,GAAM,EAC9C,EAAI,EAAM,EAAI,EAAI,E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M,EAAG,GAAE,EAAG,OAAM,EAE7D,CACF,CAEA,OAAO,EAAO,EAAK,MAAQ,CAC7B,CAWA,SAAgB,EAAW,EAAyC,CAClE,IAAI,EAAM,EAAK,MAAM,EACjB,EAAU,GACd,KAAO,GAAW,EAAI,OAAS,GAAG,CAChC,EAAU,GACV,IAAM,EAAoB,CAAC,EACrB,EAAI,EAAI,OACd,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CAC1B,IAAM,EAAO,GAAK,EAAI,EAAI,GAAK,GACzB,EAAS,GAAK,EAAI,GAAK,GAE7B,GAAI,EAAK,EAAM,CAAM,EAAA,EAAoB,CACvC,EAAU,GACV,QACF,CACA,EAAK,KAAK,EAAI,EAAE,CAClB,CACI,IAEF,EAAM,EAAK,QAAQ,EAAG,IAAM,EAAK,EAAG,GAAM,EAAI,GAAK,EAAK,OAAO,GAAA,CAAmB,EAEtF,CACA,OAAO,CACT,CAWA,SAAgB,EAAS,EAKhB,CACP,GAAI,EAAO,SAAW,EAAG,OAAO,KAChC,IAAI,EAAO,IACP,EAAO,IACP,EAAO,KACP,EAAO,KACX,IAAK,IAAM,KAAK,EACV,EAAE,EAAI,IAAM,EAAO,EAAE,GACrB,EAAE,EAAI,IAAM,EAAO,EAAE,GACrB,EAAE,EAAI,IAAM,EAAO,EAAE,GACrB,EAAE,EAAI,IAAM,EAAO,EAAE,GAE3B,MAAO,CAAE,OAAM,OAAM,OAAM,MAAK,CAClC"}
1
+ {"version":3,"file":"floorPlan.geometry.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.geometry.ts"],"sourcesContent":["/**\n * Pure vector and polygon primitives. Nothing here knows about the plan model.\n *\n * All lengths are millimetres (see floorPlan.types.ts).\n */\n\nimport type { PlanPoint } from './floorPlan.types';\n\n// ─── Model-integrity epsilons ──────────────────────────────────────────────────\n// These are FIXED millimetre values describing when the model itself is degenerate.\n// They are a separate family from the user-intent tolerances in floorPlan.snap.ts,\n// which are screen pixels converted through the current zoom. Conflating the two\n// gives you either a model that accumulates 0.2mm walls, or snapping that stops\n// working when zoomed in.\n\n/** Shortest wall the graph will accept. Keeps zero-length walls out entirely. */\nexport const MIN_WALL_LENGTH = 10;\n/** Two points closer than this are the same point. */\nexport const EPS_COINCIDENT = 1;\n/** A ring with |area| below this encloses nothing (0.0001 m²). */\nexport const EPS_AREA = 100;\n/** Angular tolerance for \"these two walls are collinear\", in radians. */\nexport const EPS_ANGLE = 1e-4;\n/** Narrowest scanline span that counts as room interior rather than a slit. */\nexport const EPS_SPAN = 2;\n/** Narrowest opening worth keeping when a wall shortens under it. */\nexport const MIN_OPENING_WIDTH = 100;\n\n// ─── Vectors ───────────────────────────────────────────────────────────────────\n\nexport function dist(a: PlanPoint, b: PlanPoint): number {\n return Math.hypot(a.x - b.x, a.y - b.y);\n}\n\nexport function distSq(a: PlanPoint, b: PlanPoint): number {\n const dx = a.x - b.x;\n const dy = a.y - b.y;\n return dx * dx + dy * dy;\n}\n\n/** Cross product of ab and ac. Positive when c is clockwise of b in SVG's y-down space. */\nexport function cross(a: PlanPoint, b: PlanPoint, c: PlanPoint): number {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nexport function lerp(a: PlanPoint, b: PlanPoint, t: number): PlanPoint {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\n\n/** Unit vector from a to b, or null when they are coincident. */\nexport function direction(a: PlanPoint, b: PlanPoint): PlanPoint | null {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const len = Math.hypot(dx, dy);\n if (len < 1e-9) return null;\n return { x: dx / len, y: dy / len };\n}\n\n/** Left-hand normal of the direction from a to b, or null when coincident. */\nexport function normal(a: PlanPoint, b: PlanPoint): PlanPoint | null {\n const d = direction(a, b);\n return d ? { x: -d.y, y: d.x } : null;\n}\n\n// ─── Point / segment ───────────────────────────────────────────────────────────\n\n/**\n * Distance from p to segment ab, plus the clamped parameter t of the closest point.\n * `t` is clamped to [0, 1], so the closest point is always on the segment.\n */\nexport function pointToSegment(\n p: PlanPoint,\n a: PlanPoint,\n b: PlanPoint,\n): { dist: number; t: number; point: PlanPoint } {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const len2 = dx * dx + dy * dy;\n if (len2 === 0) return { dist: dist(p, a), t: 0, point: { x: a.x, y: a.y } };\n const raw = ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2;\n const t = raw < 0 ? 0 : raw > 1 ? 1 : raw;\n const point = { x: a.x + t * dx, y: a.y + t * dy };\n return { dist: dist(p, point), t, point };\n}\n\n/**\n * Exact projection of p onto segment ab, clamped to the segment.\n *\n * Used after a fuzzy hit tolerance has decided that p belongs to this segment: intent\n * is allowed to be approximate, the stored model never is.\n */\nexport function projectOnSegment(p: PlanPoint, a: PlanPoint, b: PlanPoint): PlanPoint {\n return pointToSegment(p, a, b).point;\n}\n\nexport type SegmentIntersectionKind =\n /** The segments cross strictly inside both. */\n | 'proper'\n /** They are parallel and do not touch. */\n | 'none'\n /** They lie on the same line and overlap over a non-zero length. */\n | 'collinearOverlap'\n /** They lie on the same line but do not overlap. */\n | 'collinearDisjoint'\n /** An endpoint of one lies on the other, or they share an endpoint. */\n | 'touch';\n\nexport interface SegmentIntersection {\n kind: SegmentIntersectionKind;\n /** Parameter along ab, for 'proper' and 'touch'. */\n t?: number;\n /** Parameter along cd, for 'proper' and 'touch'. */\n s?: number;\n point?: PlanPoint;\n}\n\n/**\n * Classifies how segments ab and cd meet.\n *\n * `eps` is a millimetre distance tolerance, not a parameter tolerance, so the result\n * does not change with segment length.\n */\nexport function segmentIntersection(\n a: PlanPoint,\n b: PlanPoint,\n c: PlanPoint,\n d: PlanPoint,\n eps = EPS_COINCIDENT,\n): SegmentIntersection {\n const abLen = dist(a, b);\n const cdLen = dist(c, d);\n if (abLen < 1e-9 || cdLen < 1e-9) return { kind: 'none' };\n\n const rx = b.x - a.x;\n const ry = b.y - a.y;\n const sx = d.x - c.x;\n const sy = d.y - c.y;\n const denom = rx * sy - ry * sx;\n\n // Perpendicular distance of c and d from line ab, used to tell parallel from collinear.\n const distC = Math.abs(cross(a, b, c)) / abLen;\n const distD = Math.abs(cross(a, b, d)) / abLen;\n\n if (Math.abs(denom) < 1e-12 || (distC < eps && distD < eps)) {\n if (distC >= eps || distD >= eps) return { kind: 'none' };\n // Collinear: compare parameters along ab.\n const len2 = rx * rx + ry * ry;\n const tc = ((c.x - a.x) * rx + (c.y - a.y) * ry) / len2;\n const td = ((d.x - a.x) * rx + (d.y - a.y) * ry) / len2;\n const lo = Math.min(tc, td);\n const hi = Math.max(tc, td);\n const epsT = eps / abLen;\n if (hi < epsT || lo > 1 - epsT) return { kind: 'collinearDisjoint' };\n if (Math.min(hi, 1) - Math.max(lo, 0) < epsT) return { kind: 'collinearDisjoint' };\n return { kind: 'collinearOverlap' };\n }\n\n const t = ((c.x - a.x) * sy - (c.y - a.y) * sx) / denom;\n const s = ((c.x - a.x) * ry - (c.y - a.y) * rx) / denom;\n const epsT = eps / abLen;\n const epsS = eps / cdLen;\n\n if (t < -epsT || t > 1 + epsT || s < -epsS || s > 1 + epsS) return { kind: 'none' };\n\n const point = { x: a.x + t * rx, y: a.y + t * ry };\n const atAbEnd = t <= epsT || t >= 1 - epsT;\n const atCdEnd = s <= epsS || s >= 1 - epsS;\n if (atAbEnd || atCdEnd) return { kind: 'touch', t, s, point };\n return { kind: 'proper', t, s, point };\n}\n\n// ─── Rings ─────────────────────────────────────────────────────────────────────\n\n/**\n * Shoelace area of a closed ring (first vertex not repeated).\n *\n * Positive means visually clockwise in SVG's y-down space. See `PlanFace.outer`.\n */\nexport function signedArea(ring: readonly PlanPoint[]): number {\n const n = ring.length;\n if (n < 3) return 0;\n let sum = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n sum += ring[j].x * ring[i].y - ring[i].x * ring[j].y;\n }\n return sum / 2;\n}\n\nexport function perimeter(ring: readonly PlanPoint[]): number {\n const n = ring.length;\n if (n < 2) return 0;\n let sum = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) sum += dist(ring[j], ring[i]);\n return sum;\n}\n\n/**\n * Area-weighted centroid of a ring.\n *\n * Deliberately not the vertex mean: a dangling wall adds an out-and-back vertex pair\n * that skews the mean but contributes nothing to the area moment. Falls back to the\n * vertex mean only for a degenerate (zero-area) ring.\n */\nexport function areaCentroid(ring: readonly PlanPoint[]): PlanPoint {\n const n = ring.length;\n if (n === 0) return { x: 0, y: 0 };\n if (n < 3) {\n return {\n x: ring.reduce((s, p) => s + p.x, 0) / n,\n y: ring.reduce((s, p) => s + p.y, 0) / n,\n };\n }\n let a = 0;\n let cx = 0;\n let cy = 0;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n const f = ring[j].x * ring[i].y - ring[i].x * ring[j].y;\n a += f;\n cx += (ring[j].x + ring[i].x) * f;\n cy += (ring[j].y + ring[i].y) * f;\n }\n if (Math.abs(a) < 1e-9) {\n return {\n x: ring.reduce((s, p) => s + p.x, 0) / n,\n y: ring.reduce((s, p) => s + p.y, 0) / n,\n };\n }\n return { x: cx / (3 * a), y: cy / (3 * a) };\n}\n\n/** Ray-casting point-in-ring test. Points exactly on an edge are unspecified. */\nexport function pointInRing(p: PlanPoint, ring: readonly PlanPoint[]): boolean {\n let inside = false;\n for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {\n const xi = ring[i].x;\n const yi = ring[i].y;\n const xj = ring[j].x;\n const yj = ring[j].y;\n if (yi > p.y !== yj > p.y && p.x < ((xj - xi) * (p.y - yi)) / (yj - yi) + xi) {\n inside = !inside;\n }\n }\n return inside;\n}\n\n/** Inside `outer` and outside every hole. */\nexport function pointInRings(\n p: PlanPoint,\n outer: readonly PlanPoint[],\n holes: readonly (readonly PlanPoint[])[] = [],\n): boolean {\n if (!pointInRing(p, outer)) return false;\n for (const hole of holes) if (pointInRing(p, hole)) return false;\n return true;\n}\n\n/**\n * A point guaranteed to lie strictly inside the ring set, placed somewhere visually\n * central where possible.\n *\n * The area centroid is preferred, but it is not guaranteed to be inside a concave\n * polygon (an L-shaped room's centroid can land in the notch), so a scanline fallback\n * picks the widest interior span across several horizontal lines. The EPS_SPAN test on\n * that span is what stops an anchor landing inside the zero-width slit that a dangling\n * wall leaves in a face.\n */\nexport function representativePoint(\n outer: readonly PlanPoint[],\n holes: readonly (readonly PlanPoint[])[] = [],\n): PlanPoint {\n if (outer.length === 0) return { x: 0, y: 0 };\n\n const centre = areaCentroid(outer);\n if (pointInRings(centre, outer, holes)) return centre;\n\n let ymin = Infinity;\n let ymax = -Infinity;\n for (const p of outer) {\n if (p.y < ymin) ymin = p.y;\n if (p.y > ymax) ymax = p.y;\n }\n if (!Number.isFinite(ymin) || ymax - ymin < 1e-9) return centre;\n\n const rings: readonly (readonly PlanPoint[])[] = [outer, ...holes];\n let best: { point: PlanPoint; width: number } | null = null;\n\n const SAMPLES = 7;\n for (let k = 1; k <= SAMPLES; k++) {\n const y = ymin + ((ymax - ymin) * k) / (SAMPLES + 1);\n const xs: number[] = [];\n // One crossing list across ALL rings, so even-odd pairing yields interior spans\n // directly. Running the scanline per ring would not compose with holes.\n for (const ring of rings) {\n for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {\n const p = ring[j];\n const q = ring[i];\n if (p.y > y !== q.y > y) {\n xs.push(p.x + ((y - p.y) * (q.x - p.x)) / (q.y - p.y));\n }\n }\n }\n xs.sort((m, n) => m - n);\n for (let i = 0; i + 1 < xs.length; i += 2) {\n const width = xs[i + 1] - xs[i];\n if (width > EPS_SPAN && (!best || width > best.width)) {\n best = { point: { x: (xs[i] + xs[i + 1]) / 2, y }, width };\n }\n }\n }\n\n return best ? best.point : centre;\n}\n\n/**\n * Removes out-and-back spurs (`... P, Q, P ...`) from a ring, repeatedly until none\n * remain.\n *\n * A face containing a dangling wall is a valid fill but is not a simple polygon, which\n * breaks polygon offsetting and makes some triangulators emit zero-area triangles. Run\n * this before triangulating a floor slab; keep the raw ring for the 2D fill, where the\n * slit is harmless and `wallIds` alignment matters.\n */\nexport function stripSpurs(ring: readonly PlanPoint[]): PlanPoint[] {\n let out = ring.slice();\n let changed = true;\n while (changed && out.length > 3) {\n changed = false;\n const next: PlanPoint[] = [];\n const n = out.length;\n for (let i = 0; i < n; i++) {\n const prev = out[(i - 1 + n) % n];\n const nextPt = out[(i + 1) % n];\n // The middle of an out-and-back is the vertex whose neighbours coincide.\n if (dist(prev, nextPt) < EPS_COINCIDENT) {\n changed = true;\n continue;\n }\n next.push(out[i]);\n }\n if (changed) {\n // Drop the now-duplicated turning point left behind by each removed spur tip.\n out = next.filter((p, i) => dist(p, next[(i + 1) % next.length]) >= EPS_COINCIDENT);\n }\n }\n return out;\n}\n\nexport function rectToPoints(x: number, y: number, w: number, h: number): PlanPoint[] {\n return [\n { x, y },\n { x: x + w, y },\n { x: x + w, y: y + h },\n { x, y: y + h },\n ];\n}\n\nexport function boundsOf(points: readonly PlanPoint[]): {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n} | null {\n if (points.length === 0) return null;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const p of points) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n return { minX, minY, maxX, maxY };\n}\n"],"mappings":"AAgBA,IAAa,EAAkB,GAMlB,EAAY,KAIZ,EAAoB,IAIjC,SAAgB,EAAK,EAAc,EAAsB,CACvD,OAAO,KAAK,MAAM,EAAE,EAAI,EAAE,EAAG,EAAE,EAAI,EAAE,CAAC,CACxC,CASA,SAAgB,EAAM,EAAc,EAAc,EAAsB,CACtE,OAAQ,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,IAAM,EAAE,EAAI,EAAE,EAC5D,CA2BA,SAAgB,EACd,EACA,EACA,EAC+C,CAC/C,IAAM,EAAK,EAAE,EAAI,EAAE,EACb,EAAK,EAAE,EAAI,EAAE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}from"./floorPlan.types.mjs";import{cross as n,dist as r,pointToSegment as i,projectOnSegment as a,segmentIntersection as o}from"./floorPlan.geometry.mjs";var s=0;function c(e){return s+=1,`${e}_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10)}${s.toString(36)}`}function l(e){return{...e,nodes:{...e.nodes},walls:{...e.walls},openings:{...e.openings},rooms:{...e.rooms}}}function u(e,t,n={}){return{kind:e,message:t,...n}}function d(e,t){let n=e.nodes[t.a],i=e.nodes[t.b];return!n||!i?0:r(n,i)}function f(e,t){return Object.values(e.walls).filter(e=>e.a===t||e.b===t)}function p(e,t,n){for(let r of Object.values(e.walls))if(r.a===t&&r.b===n||r.a===n&&r.b===t)return r;return null}var m=250;function h(e,t){return`${Math.round(e/m)}|${Math.round(t/m)}`}function g(e){let t=new Map;for(let n of Object.values(e.nodes)){let e=h(n.x,n.y),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function _(e,t,n){let i=g(e),a=Math.round(t.x/m),o=Math.round(t.y/m),s=null,c=n,l=Math.max(1,Math.ceil(n/m));for(let e=-l;e<=l;e++)for(let n=-l;n<=l;n++)for(let l of i.get(`${a+e}|${o+n}`)??[]){let e=r(t,l);e<=c&&(s=l,c=e)}return s}function v(e,t,n,r){let a=null;for(let o of Object.values(e.walls)){if(r?.has(o.id))continue;let s=e.nodes[o.a],c=e.nodes[o.b];if(!s||!c)continue;let l=i(t,s,c);l.dist<=n&&(!a||l.dist<a.dist)&&(a={wall:o,t:l.t,point:l.point,dist:l.dist})}return a}function y(t,n,i){let o=t.walls[n];if(!o)return{floor:t,result:{nodeId:``,wallIds:null,droppedOpeningIds:[]},issues:[]};let s=t.nodes[o.a],d=t.nodes[o.b];if(!s||!d)return{floor:t,result:{nodeId:``,wallIds:null,droppedOpeningIds:[]},issues:[]};let f=r(s,d),p=typeof i==`number`?{x:s.x+(d.x-s.x)*i,y:s.y+(d.y-s.y)*i}:i,m=a(p,s,d),h=r(s,m);if(h<10)return{floor:t,result:{nodeId:o.a,wallIds:null,droppedOpeningIds:[]},issues:[]};if(f-h<10)return{floor:t,result:{nodeId:o.b,wallIds:null,droppedOpeningIds:[]},issues:[]};let g=l(t),_=c(`n`);g.nodes[_]={id:_,x:m.x,y:m.y};let v=c(`w`),y=c(`w`),b={thickness:o.thickness,type:o.type,height:o.height,baseHeight:o.baseHeight};g.walls[v]={...b,id:v,a:o.a,b:_},g.walls[y]={...b,id:y,a:_,b:o.b},delete g.walls[n];let x=[],S=[];for(let r of Object.values(t.openings)){if(r.wallId!==n)continue;let t=r.offset<=h,i=t?v:y,a=t?h:f-h,o=t?r.offset:r.offset-h,s=Math.min(r.width,a-2,o*2,(a-o)*2);if(s<100){delete g.openings[r.id],x.push(r.id),S.push(u(e.OpeningDropped,`An opening was removed: the wall it sat on became too short for it.`,{openingIds:[r.id],wallIds:[n]}));continue}g.openings[r.id]={...r,wallId:i,offset:o,width:s}}return{floor:g,result:{nodeId:_,wallIds:[v,y],droppedOpeningIds:x},issues:S}}function b(e,t,n){let r=_(e,t,n);if(r)return{floor:e,result:{nodeId:r.id,createdNode:!1,splitWallId:null},issues:[]};let i=v(e,t,n);if(i){let t=y(e,i.wall.id,i.point);if(t.result.nodeId)return{floor:t.floor,result:{nodeId:t.result.nodeId,createdNode:t.result.wallIds!==null,splitWallId:t.result.wallIds?i.wall.id:null},issues:t.issues}}let a=l(e),o=c(`n`);return a.nodes[o]={id:o,x:t.x,y:t.y},{floor:a,result:{nodeId:o,createdNode:!0,splitWallId:null},issues:[]}}var x={thickness:200,type:t.Interior};function S(t,n,a,s=x,l=1){let d=[];if(r(n,a)<10)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:d};let f=b(t,n,l),m=f.floor;d.push(...f.issues);let h=b(m,a,l);m=h.floor,d.push(...h.issues);let g=f.result.nodeId,_=h.result.nodeId;if(g===_)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:d};let v=m.nodes[g],S=m.nodes[_],C=r(v,S);if(C<10)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:d};let w=[{t:0,nodeId:g},{t:1,nodeId:_}],T=new Map,E=[],D=e=>i(e,v,S).t;for(let e of Object.values(m.walls)){let t=m.nodes[e.a],n=m.nodes[e.b];if(!t||!n)continue;let r=o(v,S,t,n,l);if(r.kind===`collinearOverlap`){let e=D(t),r=D(n);E.push([Math.min(e,r),Math.max(e,r)]);for(let[i,a]of[[t,e],[n,r]])a*C>10&&(1-a)*C>10&&w.push({t:a,nodeId:i.id});continue}if(r.kind===`proper`&&r.t!==void 0&&r.s!==void 0){let t=T.get(e.id);t?t.push(r.s):T.set(e.id,[r.s]),w.push({t:r.t,nodeId:null,pending:{wallId:e.id,s:r.s}});continue}if(r.kind===`touch`&&r.t!==void 0&&r.s!==void 0){let e=r.s<=.5?t:n,a=D(e);i(e,v,S).dist<=l&&a*C>10&&(1-a)*C>10&&w.push({t:a,nodeId:e.id})}}for(let e of Object.values(m.nodes)){if(e.id===g||e.id===_)continue;let t=i(e,v,S);t.dist>l||t.t*C<=10||(1-t.t)*C<=10||w.push({t:t.t,nodeId:e.id})}for(let[e,n]of T){let r=[...n].sort((e,t)=>t-e),i=e,a=new Set(r);for(let n of r){let r=m.walls[i];if(!r)break;let o=m.nodes[r.a],s=m.nodes[r.b];if(!o||!s)break;let c=t.walls[e],l=m.nodes[c?.a??r.a]??o,u=m.nodes[c?.b??r.b]??s,f={x:l.x+(u.x-l.x)*n,y:l.y+(u.y-l.y)*n},p=y(m,i,f);m=p.floor,d.push(...p.issues),a.delete(n);for(let t of w)t.pending&&t.pending.wallId===e&&t.pending.s===n&&(t.nodeId=p.result.nodeId,t.pending=void 0);if(p.result.wallIds){let[e,t]=p.result.wallIds,r=Math.max(...a,-1);i=r>=0&&r>n?t:e}}}let O=w.filter(e=>!!e.nodeId);O.sort((e,t)=>e.t-t.t);let k=[];for(let e of O){let t=k[k.length-1];if(!t){k.push(e);continue}if(t.nodeId!==e.nodeId){if((e.t-t.t)*C<10){e.t>=1-1e-9&&(k[k.length-1]=e);continue}k.push(e)}}let A=[];for(let e=0;e+1<k.length;e++){let t=k[e],n=k[e+1],i=(t.t+n.t)/2;if(E.some(([e,t])=>i>e+1e-9&&i<t-1e-9)||p(m,t.nodeId,n.nodeId))continue;let a=m.nodes[t.nodeId],o=m.nodes[n.nodeId];if(!a||!o||r(a,o)<10)continue;let l=c(`w`);m={...m,walls:{...m.walls,[l]:{...s,id:l,a:t.nodeId,b:n.nodeId}}},A.push(l)}return A.length===0&&E.length>0&&d.push(u(e.DuplicateWall,`A wall already covers that span, so nothing was added.`)),{floor:m,result:{wallIds:A,nodeIds:k.map(e=>e.nodeId)},issues:d}}function C(e,t,n,r=x,i=1){let a=Math.min(t.x,n.x),o=Math.max(t.x,n.x),s=Math.min(t.y,n.y),c=Math.max(t.y,n.y);if(o-a<10||c-s<10)return{floor:e,result:{wallIds:[]},issues:[]};let l=[{x:a,y:s},{x:o,y:s},{x:o,y:c},{x:a,y:c}],u=e,d=[],f=[];for(let e=0;e<4;e++){let t=S(u,l[e],l[(e+1)%4],r,i);u=t.floor,d.push(...t.result.wallIds),f.push(...t.issues)}return{floor:u,result:{wallIds:d},issues:f}}function w(t,n,r){if(n===r||!t.nodes[n]||!t.nodes[r])return{floor:t,result:{removedWallIds:[]},issues:[]};let i=l(t),a=[],o=[];for(let e of Object.values(i.walls))e.a===r&&(i.walls[e.id]={...i.walls[e.id],a:n}),e.b===r&&(i.walls[e.id]={...i.walls[e.id],b:n});for(let e of Object.values(i.walls))if(e.a===e.b){delete i.walls[e.id],a.push(e.id);for(let t of Object.values(i.openings))t.wallId===e.id&&delete i.openings[t.id]}let s=new Map;for(let t of Object.values(i.walls)){let n=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,r=s.get(n);if(!r){s.set(n,t);continue}let c=t.thickness>=r.thickness?t:r,l=c===t?r:t;for(let e of Object.values(i.openings))e.wallId===l.id&&(i.openings[e.id]={...e,wallId:c.id});delete i.walls[l.id],a.push(l.id),s.set(n,c),o.push(u(e.DuplicateWall,`Two walls became the same wall and were merged.`,{wallIds:[c.id,l.id]}))}return delete i.nodes[r],{floor:i,result:{removedWallIds:a},issues:o}}function T(t,i,a={}){let{force:o=!1}=a,s=t.nodes[i];if(!s)return{floor:t,result:null,issues:[]};let p=f(t,i);if(p.length!==2)return{floor:t,result:null,issues:[]};let[m,h]=p,g=m.thickness===h.thickness&&m.type===h.type&&m.height===h.height&&m.baseHeight===h.baseHeight;if(!g&&!o)return{floor:t,result:null,issues:[]};let _=m.a===i?m.b:m.a,v=h.a===i?h.b:h.a;if(_===v)return{floor:t,result:null,issues:[]};let y=t.nodes[_],b=t.nodes[v];if(!y||!b)return{floor:t,result:null,issues:[]};let x=r(y,b);if(x<10||!o&&Math.abs(n(y,b,s))/x>Math.max(1,x*1e-4))return{floor:t,result:null,issues:[]};let S=!g&&m.thickness<h.thickness?h:m,C=l(t),w=c(`w`);C.walls[w]={id:w,a:_,b:v,thickness:S.thickness,type:S.type,height:S.height,baseHeight:S.baseHeight};let T=r(y,s),E=r(s,b),D=T+E>0?x/(T+E):1,O=[];for(let n of Object.values(t.openings)){if(n.wallId!==m.id&&n.wallId!==h.id)continue;let r=n.wallId===m.id,a=r?m:h,o=a.a===i,s=d(t,a),c=o?n.offset:s-n.offset,l=(r?T-c:T+c)*D,f=Math.min(n.width*D,x-2);if(f<100){O.push(u(e.OpeningDropped,`An opening was removed: the wall it sat on became too short for it.`,{openingIds:[n.id],wallIds:[a.id]})),delete C.openings[n.id];continue}C.openings[n.id]={...n,wallId:w,width:f,offset:Math.min(Math.max(l,f/2),x-f/2)}}return delete C.walls[m.id],delete C.walls[h.id],delete C.nodes[i],{floor:C,result:{wallId:w},issues:O}}function E(e,t,n){let r=e.walls[t];if(!r||r.a===r.b||Math.hypot(n.x,n.y)<10)return{floor:e,result:null,issues:[]};let i=[r.a,r.b],a=[r.a,r.b],o=[null,null],s=[],c=[],u=e;i.forEach((i,s)=>{let c=e.nodes[i];if(!c)return;let d={x:c.x+n.x,y:c.y+n.y},p=f(e,i).filter(e=>e.id!==t);if(p.length===0){let e=l(u);e.nodes[i]={...e.nodes[i],x:d.x,y:d.y},u=e;return}let m=b(u,d,1);u=m.floor,a[s]=m.result.nodeId,o[s]=p.length===1?p[0]:r});let d=l(u);d.walls[t]={...d.walls[t],a:a[0],b:a[1]},u=d,i.forEach((e,t)=>{let n=o[t],r=u.nodes[e],i=u.nodes[a[t]];if(!n||!r||!i)return;let l=S(u,r,i,{thickness:n.thickness,type:n.type,height:n.height,baseHeight:n.baseHeight});u=l.floor,s.push(...l.result.wallIds),c.push(...l.issues)});let p=[];return i.forEach((e,t)=>{if(a[t]===e)return;let n=T(u,e);n.result&&(u=n.floor,p.push(e),c.push(...n.issues))}),{floor:u,result:{nodeIds:a,connectorIds:s,dissolvedNodeIds:p},issues:c}}function D(e,t=10){let n=e,i=[],a=[];for(let o=Object.keys(e.walls).length;o>0;o--){let e=Object.values(n.walls).find(e=>{if(e.a===e.b)return!1;let i=n.nodes[e.a],a=n.nodes[e.b];return i&&a&&r(i,a)<t});if(!e)break;let o=f(n,e.b).length>f(n,e.a).length?e.b:e.a,s=w(n,o,o===e.a?e.b:e.a);if(s.floor===n)break;n=s.floor,i.push(e.id),a.push(...s.issues)}return{floor:n,result:{weldedWallIds:i},issues:a}}function O(e,t,n={}){let{pruneOrphanNodes:r=!0,dissolveCollinear:i=!0}=n,a=e.walls[t];if(!a)return{floor:e,result:{removedNodeIds:[],dissolvedWallIds:[]},issues:[]};let o=l(e);delete o.walls[t];for(let e of Object.values(o.openings))e.wallId===t&&delete o.openings[e.id];let s=[],c=[],u=[];for(let e of[a.a,a.b]){let t=f(o,e).length;if(t===0&&r)delete o.nodes[e],s.push(e);else if(t===2&&i){let t=T(o,e);t.result&&(o=t.floor,c.push(t.result.wallId),s.push(e),u.push(...t.issues))}}return{floor:o,result:{removedNodeIds:s,dissolvedWallIds:c},issues:u}}function k(e,t,n){let r=e.nodes[t];if(!r)return{floor:e,result:void 0,issues:[]};let i=l(e);return i.nodes[t]={...r,x:n.x,y:n.y},{floor:i,result:void 0,issues:[]}}function A(e,t,n){let r=l(e);for(let i of Object.values(e.nodes))r.nodes[i.id]={...i,x:i.x+t,y:i.y+n};for(let i of Object.values(e.rooms))r.rooms[i.id]={...i,anchor:{x:i.anchor.x+t,y:i.anchor.y+n}};return r}function j(e,t){let n=l(e);for(let r of Object.values(e.nodes))n.nodes[r.id]={...r,x:r.x*t,y:r.y*t};for(let r of Object.values(e.walls))n.walls[r.id]={...r,thickness:r.thickness*t,height:r.height===void 0?void 0:r.height*t,baseHeight:r.baseHeight===void 0?void 0:r.baseHeight*t};for(let r of Object.values(e.openings))n.openings[r.id]={...r,offset:r.offset*t,width:r.width*t,sill:r.sill*t,head:r.head*t};for(let r of Object.values(e.rooms))n.rooms[r.id]={...r,anchor:{x:r.anchor.x*t,y:r.anchor.y*t},area:r.area*t*t};return n}function M(t,n){let r=t.walls[n.wallId];if(!r)return{floor:t,result:{openingId:null},issues:[]};let i=d(t,r),a=Math.min(n.width,i-2);if(a<100)return{floor:t,result:{openingId:null},issues:[u(e.OpeningDropped,`That wall is too short for an opening.`,{wallIds:[r.id]})]};let o=Math.min(Math.max(n.offset,a/2),i-a/2),s=l(t),f=c(`o`);return s.openings[f]={...n,id:f,offset:o,width:a},{floor:s,result:{openingId:f},issues:[]}}function N(e,t,n){let r=e.openings[t];if(!r)return{floor:e,result:void 0,issues:[]};let i=e.walls[r.wallId];if(!i)return{floor:e,result:void 0,issues:[]};let a=d(e,i),o={...r,...n},s=Math.min(Math.max(o.width,100),Math.max(a-2,100)),c=Math.min(Math.max(o.offset,s/2),Math.max(a-s/2,s/2)),u=l(e);return u.openings[t]={...o,width:s,offset:c},{floor:u,result:void 0,issues:[]}}function P(e,t){if(!e.openings[t])return{floor:e,result:void 0,issues:[]};let n=l(e);return delete n.openings[t],{floor:n,result:void 0,issues:[]}}function F(t){let n=[],a=Object.values(t.walls);for(let i of a){let a=t.nodes[i.a],o=t.nodes[i.b];if(i.a===i.b){n.push(u(e.SelfLoopWall,`A wall starts and ends at the same node.`,{wallIds:[i.id]}));continue}if(!a||!o){n.push(u(e.ZeroLengthWall,`A wall references a missing node.`,{wallIds:[i.id]}));continue}r(a,o)<10&&n.push(u(e.ZeroLengthWall,`A wall is shorter than the minimum length.`,{wallIds:[i.id]}))}let s=new Map;for(let t of a){let r=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,i=s.get(r);i?n.push(u(e.DuplicateWall,`Two walls connect the same pair of nodes.`,{wallIds:[i,t.id]})):s.set(r,t.id)}let c=Object.values(t.nodes);for(let t=0;t<c.length;t++)for(let i=t+1;i<c.length;i++)r(c[t],c[i])<1&&n.push(u(e.CoincidentNodes,`Two nodes occupy the same position.`,{nodeIds:[c[t].id,c[i].id]}));for(let r=0;r<a.length;r++)for(let i=r+1;i<a.length;i++){let s=a[r],c=a[i],l=t.nodes[s.a],d=t.nodes[s.b],f=t.nodes[c.a],p=t.nodes[c.b];if(!l||!d||!f||!p)continue;let m=o(l,d,f,p);m.kind===`proper`?n.push(u(e.UnsplitCrossing,`Two walls cross with no node at the intersection.`,{wallIds:[s.id,c.id]})):m.kind===`collinearOverlap`&&n.push(u(e.OverlappingWalls,`Two walls overlap along the same line.`,{wallIds:[s.id,c.id]}))}for(let r of a){let a=t.nodes[r.a],o=t.nodes[r.b];if(a&&o)for(let t of c){if(t.id===r.a||t.id===r.b)continue;let s=i(t,a,o);s.dist<1&&s.t>0&&s.t<1&&n.push(u(e.UnsplitNodeOnWall,`A node sits on a wall that was never split there.`,{wallIds:[r.id],nodeIds:[t.id]}))}}for(let r of Object.values(t.openings))t.walls[r.wallId]||n.push(u(e.DanglingOpening,`An opening references a wall that no longer exists.`,{openingIds:[r.id]}));let l=new Set;for(let e of a)l.add(e.a),l.add(e.b);for(let t of c)l.has(t.id)||n.push(u(e.OrphanNode,`A node has no walls.`,{nodeIds:[t.id]}));return n}function I(t){let n=[],i=D(t),a=l(i.floor);for(let t of i.result.weldedWallIds)n.push(u(e.ZeroLengthWall,`Welded the two ends of a wall with no length.`,{wallIds:[t]}));for(let t of Object.values(a.walls)){let i=a.nodes[t.a],o=a.nodes[t.b];(t.a===t.b||!i||!o||r(i,o)<10)&&(delete a.walls[t.id],n.push(u(e.ZeroLengthWall,`Removed a degenerate wall.`,{wallIds:[t.id]})))}let o=new Map;for(let t of Object.values(a.walls)){let r=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,i=o.get(r);if(!i){o.set(r,t);continue}let s=t.thickness>=i.thickness?t:i,c=s===t?i:t;for(let e of Object.values(a.openings))e.wallId===c.id&&(a.openings[e.id]={...e,wallId:s.id});delete a.walls[c.id],o.set(r,s),n.push(u(e.DuplicateWall,`Removed a duplicate wall.`,{wallIds:[c.id]}))}for(let t of Object.values(a.openings))a.walls[t.wallId]||(delete a.openings[t.id],n.push(u(e.DanglingOpening,`Removed an opening with no wall.`,{openingIds:[t.id]})));let s=new Set;for(let e of Object.values(a.walls))s.add(e.a),s.add(e.b);for(let t of Object.values(a.nodes))s.has(t.id)||(delete a.nodes[t.id],n.push(u(e.OrphanNode,`Removed a node with no walls.`,{nodeIds:[t.id]})));return{floor:a,result:n,issues:n}}export{x as DEFAULT_WALL_ATTRS,M as addOpening,C as addRect,S as addWall,I as cleanupPlan,E as detachWall,T as dissolveNode,_ as findNodeNear,p as findWallBetween,v as findWallNear,w as mergeNodes,k as moveNode,c as newId,P as removeOpening,O as removeWall,b as resolveNodeAt,j as scalePlan,y as splitWall,A as transformPlan,N as updateOpening,F as validatePlan,d as wallLength,f as wallsAtNode,D as weldShortWalls};
1
+ import{PlanIssueKind as e,WallType as t}from"./floorPlan.types.mjs";import{cross as n,dist as r,pointToSegment as i,projectOnSegment as a,segmentIntersection as o}from"./floorPlan.geometry.mjs";var s=0;function c(e){return s+=1,`${e}_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID().slice(0,8):Math.random().toString(36).slice(2,10)}${s.toString(36)}`}function l(e,t,n){let r=e(t);for(let i=t+1;n.has(r)&&i<=t+n.size;i++)r=e(i);return r}function u(e){return{...e,nodes:{...e.nodes},walls:{...e.walls},openings:{...e.openings},rooms:{...e.rooms}}}function d(e,t,n={}){return{kind:e,message:t,...n}}function f(e,t){let n=e.nodes[t.a],i=e.nodes[t.b];return!n||!i?0:r(n,i)}function p(e,t){return Object.values(e.walls).filter(e=>e.a===t||e.b===t)}function m(e,t,n){for(let r of Object.values(e.walls))if(r.a===t&&r.b===n||r.a===n&&r.b===t)return r;return null}var h=250;function g(e,t){return`${Math.round(e/h)}|${Math.round(t/h)}`}function _(e){let t=new Map;for(let n of Object.values(e.nodes)){let e=g(n.x,n.y),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function v(e,t,n){let i=_(e),a=Math.round(t.x/h),o=Math.round(t.y/h),s=null,c=n,l=Math.max(1,Math.ceil(n/h));for(let e=-l;e<=l;e++)for(let n=-l;n<=l;n++)for(let l of i.get(`${a+e}|${o+n}`)??[]){let e=r(t,l);e<=c&&(s=l,c=e)}return s}function y(e,t,n,r){let a=null;for(let o of Object.values(e.walls)){if(r?.has(o.id))continue;let s=e.nodes[o.a],c=e.nodes[o.b];if(!s||!c)continue;let l=i(t,s,c);l.dist<=n&&(!a||l.dist<a.dist)&&(a={wall:o,t:l.t,point:l.point,dist:l.dist})}return a}function b(t,n,i){let o=t.walls[n];if(!o)return{floor:t,result:{nodeId:``,wallIds:null,droppedOpeningIds:[]},issues:[]};let s=t.nodes[o.a],l=t.nodes[o.b];if(!s||!l)return{floor:t,result:{nodeId:``,wallIds:null,droppedOpeningIds:[]},issues:[]};let f=r(s,l),p=typeof i==`number`?{x:s.x+(l.x-s.x)*i,y:s.y+(l.y-s.y)*i}:i,m=a(p,s,l),h=r(s,m);if(h<10)return{floor:t,result:{nodeId:o.a,wallIds:null,droppedOpeningIds:[]},issues:[]};if(f-h<10)return{floor:t,result:{nodeId:o.b,wallIds:null,droppedOpeningIds:[]},issues:[]};let g=u(t),_=c(`n`);g.nodes[_]={id:_,x:m.x,y:m.y};let v=c(`w`),y=c(`w`),b={thickness:o.thickness,type:o.type,height:o.height,baseHeight:o.baseHeight};g.walls[v]={...b,id:v,a:o.a,b:_},g.walls[y]={...b,id:y,a:_,b:o.b},delete g.walls[n];let x=[],S=[];for(let r of Object.values(t.openings)){if(r.wallId!==n)continue;let t=r.offset<=h,i=t?v:y,a=t?h:f-h,o=t?r.offset:r.offset-h,s=Math.min(r.width,a-2,o*2,(a-o)*2);if(s<100){delete g.openings[r.id],x.push(r.id),S.push(d(e.OpeningDropped,`An opening was removed: the wall it sat on became too short for it.`,{openingIds:[r.id],wallIds:[n]}));continue}g.openings[r.id]={...r,wallId:i,offset:o,width:s}}return{floor:g,result:{nodeId:_,wallIds:[v,y],droppedOpeningIds:x},issues:S}}function x(e,t,n){let r=v(e,t,n);if(r)return{floor:e,result:{nodeId:r.id,createdNode:!1,splitWallId:null},issues:[]};let i=y(e,t,n);if(i){let t=b(e,i.wall.id,i.point);if(t.result.nodeId)return{floor:t.floor,result:{nodeId:t.result.nodeId,createdNode:t.result.wallIds!==null,splitWallId:t.result.wallIds?i.wall.id:null},issues:t.issues}}let a=u(e),o=c(`n`);return a.nodes[o]={id:o,x:t.x,y:t.y},{floor:a,result:{nodeId:o,createdNode:!0,splitWallId:null},issues:[]}}var S={thickness:200,type:t.Interior};function C(t,n,a,s=S,l=1){let u=[];if(r(n,a)<10)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:u};let f=x(t,n,l),p=f.floor;u.push(...f.issues);let h=x(p,a,l);p=h.floor,u.push(...h.issues);let g=f.result.nodeId,_=h.result.nodeId;if(g===_)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:u};let v=p.nodes[g],y=p.nodes[_],C=r(v,y);if(C<10)return{floor:t,result:{wallIds:[],nodeIds:[]},issues:u};let w=[{t:0,nodeId:g},{t:1,nodeId:_}],T=new Map,E=[],D=e=>i(e,v,y).t;for(let e of Object.values(p.walls)){let t=p.nodes[e.a],n=p.nodes[e.b];if(!t||!n)continue;let r=o(v,y,t,n,l);if(r.kind===`collinearOverlap`){let e=D(t),r=D(n);E.push([Math.min(e,r),Math.max(e,r)]);for(let[i,a]of[[t,e],[n,r]])a*C>10&&(1-a)*C>10&&w.push({t:a,nodeId:i.id});continue}if(r.kind===`proper`&&r.t!==void 0&&r.s!==void 0){let t=T.get(e.id);t?t.push(r.s):T.set(e.id,[r.s]),w.push({t:r.t,nodeId:null,pending:{wallId:e.id,s:r.s}});continue}if(r.kind===`touch`&&r.t!==void 0&&r.s!==void 0){let e=r.s<=.5?t:n,a=D(e);i(e,v,y).dist<=l&&a*C>10&&(1-a)*C>10&&w.push({t:a,nodeId:e.id})}}for(let e of Object.values(p.nodes)){if(e.id===g||e.id===_)continue;let t=i(e,v,y);t.dist>l||t.t*C<=10||(1-t.t)*C<=10||w.push({t:t.t,nodeId:e.id})}for(let[e,n]of T){let r=[...n].sort((e,t)=>t-e),i=e,a=new Set(r);for(let n of r){let r=p.walls[i];if(!r)break;let o=p.nodes[r.a],s=p.nodes[r.b];if(!o||!s)break;let c=t.walls[e],l=p.nodes[c?.a??r.a]??o,d=p.nodes[c?.b??r.b]??s,f={x:l.x+(d.x-l.x)*n,y:l.y+(d.y-l.y)*n},m=b(p,i,f);p=m.floor,u.push(...m.issues),a.delete(n);for(let t of w)t.pending&&t.pending.wallId===e&&t.pending.s===n&&(t.nodeId=m.result.nodeId,t.pending=void 0);if(m.result.wallIds){let[e,t]=m.result.wallIds,r=Math.max(...a,-1);i=r>=0&&r>n?t:e}}}let O=w.filter(e=>!!e.nodeId);O.sort((e,t)=>e.t-t.t);let k=[];for(let e of O){let t=k[k.length-1];if(!t){k.push(e);continue}if(t.nodeId!==e.nodeId){if((e.t-t.t)*C<10){e.t>=1-1e-9&&(k[k.length-1]=e);continue}k.push(e)}}let A=[];for(let e=0;e+1<k.length;e++){let t=k[e],n=k[e+1],i=(t.t+n.t)/2;if(E.some(([e,t])=>i>e+1e-9&&i<t-1e-9)||m(p,t.nodeId,n.nodeId))continue;let a=p.nodes[t.nodeId],o=p.nodes[n.nodeId];if(!a||!o||r(a,o)<10)continue;let l=c(`w`);p={...p,walls:{...p.walls,[l]:{...s,id:l,a:t.nodeId,b:n.nodeId}}},A.push(l)}return A.length===0&&E.length>0&&u.push(d(e.DuplicateWall,`A wall already covers that span, so nothing was added.`)),{floor:p,result:{wallIds:A,nodeIds:k.map(e=>e.nodeId)},issues:u}}function w(e,t,n,r=S,i=1){let a=Math.min(t.x,n.x),o=Math.max(t.x,n.x),s=Math.min(t.y,n.y),c=Math.max(t.y,n.y);if(o-a<10||c-s<10)return{floor:e,result:{wallIds:[]},issues:[]};let l=[{x:a,y:s},{x:o,y:s},{x:o,y:c},{x:a,y:c}],u=e,d=[],f=[];for(let e=0;e<4;e++){let t=C(u,l[e],l[(e+1)%4],r,i);u=t.floor,d.push(...t.result.wallIds),f.push(...t.issues)}return{floor:u,result:{wallIds:d},issues:f}}function T(t,n,r){if(n===r||!t.nodes[n]||!t.nodes[r])return{floor:t,result:{removedWallIds:[]},issues:[]};let i=u(t),a=[],o=[];for(let e of Object.values(i.walls))e.a===r&&(i.walls[e.id]={...i.walls[e.id],a:n}),e.b===r&&(i.walls[e.id]={...i.walls[e.id],b:n});for(let e of Object.values(i.walls))if(e.a===e.b){delete i.walls[e.id],a.push(e.id);for(let t of Object.values(i.openings))t.wallId===e.id&&delete i.openings[t.id]}let s=new Map;for(let t of Object.values(i.walls)){let n=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,r=s.get(n);if(!r){s.set(n,t);continue}let c=t.thickness>=r.thickness?t:r,l=c===t?r:t;for(let e of Object.values(i.openings))e.wallId===l.id&&(i.openings[e.id]={...e,wallId:c.id});delete i.walls[l.id],a.push(l.id),s.set(n,c),o.push(d(e.DuplicateWall,`Two walls became the same wall and were merged.`,{wallIds:[c.id,l.id]}))}return delete i.nodes[r],{floor:i,result:{removedWallIds:a},issues:o}}function E(t,i,a={}){let{force:o=!1}=a,s=t.nodes[i];if(!s)return{floor:t,result:null,issues:[]};let l=p(t,i);if(l.length!==2)return{floor:t,result:null,issues:[]};let[m,h]=l,g=m.thickness===h.thickness&&m.type===h.type&&m.height===h.height&&m.baseHeight===h.baseHeight;if(!g&&!o)return{floor:t,result:null,issues:[]};let _=m.a===i?m.b:m.a,v=h.a===i?h.b:h.a;if(_===v)return{floor:t,result:null,issues:[]};let y=t.nodes[_],b=t.nodes[v];if(!y||!b)return{floor:t,result:null,issues:[]};let x=r(y,b);if(x<10||!o&&Math.abs(n(y,b,s))/x>Math.max(1,x*1e-4))return{floor:t,result:null,issues:[]};let S=!g&&m.thickness<h.thickness?h:m,C=u(t),w=c(`w`);C.walls[w]={id:w,a:_,b:v,thickness:S.thickness,type:S.type,height:S.height,baseHeight:S.baseHeight};let T=r(y,s),E=r(s,b),D=T+E>0?x/(T+E):1,O=[];for(let n of Object.values(t.openings)){if(n.wallId!==m.id&&n.wallId!==h.id)continue;let r=n.wallId===m.id,a=r?m:h,o=a.a===i,s=f(t,a),c=o?n.offset:s-n.offset,l=(r?T-c:T+c)*D,u=Math.min(n.width*D,x-2);if(u<100){O.push(d(e.OpeningDropped,`An opening was removed: the wall it sat on became too short for it.`,{openingIds:[n.id],wallIds:[a.id]})),delete C.openings[n.id];continue}C.openings[n.id]={...n,wallId:w,width:u,offset:Math.min(Math.max(l,u/2),x-u/2)}}return delete C.walls[m.id],delete C.walls[h.id],delete C.nodes[i],{floor:C,result:{wallId:w},issues:O}}function D(e,t,n){let r=e.walls[t];if(!r||r.a===r.b||Math.hypot(n.x,n.y)<10)return{floor:e,result:null,issues:[]};let i=[r.a,r.b],a=[r.a,r.b],o=[null,null],s=[],c=[],l=e;i.forEach((i,s)=>{let c=e.nodes[i];if(!c)return;let d={x:c.x+n.x,y:c.y+n.y},f=p(e,i).filter(e=>e.id!==t);if(f.length===0){let e=u(l);e.nodes[i]={...e.nodes[i],x:d.x,y:d.y},l=e;return}let m=x(l,d,1);l=m.floor,a[s]=m.result.nodeId,o[s]=f.length===1?f[0]:r});let d=u(l);d.walls[t]={...d.walls[t],a:a[0],b:a[1]},l=d,i.forEach((e,t)=>{let n=o[t],r=l.nodes[e],i=l.nodes[a[t]];if(!n||!r||!i)return;let u=C(l,r,i,{thickness:n.thickness,type:n.type,height:n.height,baseHeight:n.baseHeight});l=u.floor,s.push(...u.result.wallIds),c.push(...u.issues)});let f=[];return i.forEach((e,t)=>{if(a[t]===e)return;let n=E(l,e);n.result&&(l=n.floor,f.push(e),c.push(...n.issues))}),{floor:l,result:{nodeIds:a,connectorIds:s,dissolvedNodeIds:f},issues:c}}function O(e,t=10){let n=e,i=[],a=[];for(let o=Object.keys(e.walls).length;o>0;o--){let e=Object.values(n.walls).find(e=>{if(e.a===e.b)return!1;let i=n.nodes[e.a],a=n.nodes[e.b];return i&&a&&r(i,a)<t});if(!e)break;let o=p(n,e.b).length>p(n,e.a).length?e.b:e.a,s=T(n,o,o===e.a?e.b:e.a);if(s.floor===n)break;n=s.floor,i.push(e.id),a.push(...s.issues)}return{floor:n,result:{weldedWallIds:i},issues:a}}function k(e,t,n={}){let{pruneOrphanNodes:r=!0,dissolveCollinear:i=!0}=n,a=e.walls[t];if(!a)return{floor:e,result:{removedNodeIds:[],dissolvedWallIds:[]},issues:[]};let o=u(e);delete o.walls[t];for(let e of Object.values(o.openings))e.wallId===t&&delete o.openings[e.id];let s=[],c=[],l=[];for(let e of[a.a,a.b]){let t=p(o,e).length;if(t===0&&r)delete o.nodes[e],s.push(e);else if(t===2&&i){let t=E(o,e);t.result&&(o=t.floor,c.push(t.result.wallId),s.push(e),l.push(...t.issues))}}return{floor:o,result:{removedNodeIds:s,dissolvedWallIds:c},issues:l}}function A(e,t,n){let r=e.nodes[t];if(!r)return{floor:e,result:void 0,issues:[]};let i=u(e);return i.nodes[t]={...r,x:n.x,y:n.y},{floor:i,result:void 0,issues:[]}}function j(e,t,n){let r=u(e);for(let i of Object.values(e.nodes))r.nodes[i.id]={...i,x:i.x+t,y:i.y+n};for(let i of Object.values(e.rooms))r.rooms[i.id]={...i,anchor:{x:i.anchor.x+t,y:i.anchor.y+n}};return r}function M(e,t){let n=u(e);for(let r of Object.values(e.nodes))n.nodes[r.id]={...r,x:r.x*t,y:r.y*t};for(let r of Object.values(e.walls))n.walls[r.id]={...r,thickness:r.thickness*t,height:r.height===void 0?void 0:r.height*t,baseHeight:r.baseHeight===void 0?void 0:r.baseHeight*t};for(let r of Object.values(e.openings))n.openings[r.id]={...r,offset:r.offset*t,width:r.width*t,sill:r.sill*t,head:r.head*t};for(let r of Object.values(e.rooms))n.rooms[r.id]={...r,anchor:{x:r.anchor.x*t,y:r.anchor.y*t},area:r.area*t*t};return n}function N(t,n){let r=t.walls[n.wallId];if(!r)return{floor:t,result:{openingId:null},issues:[]};let i=f(t,r),a=Math.min(n.width,i-2);if(a<100)return{floor:t,result:{openingId:null},issues:[d(e.OpeningDropped,`That wall is too short for an opening.`,{wallIds:[r.id]})]};let o=Math.min(Math.max(n.offset,a/2),i-a/2),s=u(t),l=c(`o`);return s.openings[l]={...n,id:l,offset:o,width:a},{floor:s,result:{openingId:l},issues:[]}}function P(e,t,n){let r=e.openings[t];if(!r)return{floor:e,result:void 0,issues:[]};let i=e.walls[r.wallId];if(!i)return{floor:e,result:void 0,issues:[]};let a=f(e,i),o={...r,...n},s=Math.min(Math.max(o.width,100),Math.max(a-2,100)),c=Math.min(Math.max(o.offset,s/2),Math.max(a-s/2,s/2)),l=u(e);return l.openings[t]={...o,width:s,offset:c},{floor:l,result:void 0,issues:[]}}function F(e,t){if(!e.openings[t])return{floor:e,result:void 0,issues:[]};let n=u(e);return delete n.openings[t],{floor:n,result:void 0,issues:[]}}function I(t){let n=[],a=Object.values(t.walls);for(let i of a){let a=t.nodes[i.a],o=t.nodes[i.b];if(i.a===i.b){n.push(d(e.SelfLoopWall,`A wall starts and ends at the same node.`,{wallIds:[i.id]}));continue}if(!a||!o){n.push(d(e.ZeroLengthWall,`A wall references a missing node.`,{wallIds:[i.id]}));continue}r(a,o)<10&&n.push(d(e.ZeroLengthWall,`A wall is shorter than the minimum length.`,{wallIds:[i.id]}))}let s=new Map;for(let t of a){let r=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,i=s.get(r);i?n.push(d(e.DuplicateWall,`Two walls connect the same pair of nodes.`,{wallIds:[i,t.id]})):s.set(r,t.id)}let c=Object.values(t.nodes);for(let t=0;t<c.length;t++)for(let i=t+1;i<c.length;i++)r(c[t],c[i])<1&&n.push(d(e.CoincidentNodes,`Two nodes occupy the same position.`,{nodeIds:[c[t].id,c[i].id]}));for(let r=0;r<a.length;r++)for(let i=r+1;i<a.length;i++){let s=a[r],c=a[i],l=t.nodes[s.a],u=t.nodes[s.b],f=t.nodes[c.a],p=t.nodes[c.b];if(!l||!u||!f||!p)continue;let m=o(l,u,f,p);m.kind===`proper`?n.push(d(e.UnsplitCrossing,`Two walls cross with no node at the intersection.`,{wallIds:[s.id,c.id]})):m.kind===`collinearOverlap`&&n.push(d(e.OverlappingWalls,`Two walls overlap along the same line.`,{wallIds:[s.id,c.id]}))}for(let r of a){let a=t.nodes[r.a],o=t.nodes[r.b];if(a&&o)for(let t of c){if(t.id===r.a||t.id===r.b)continue;let s=i(t,a,o);s.dist<1&&s.t>0&&s.t<1&&n.push(d(e.UnsplitNodeOnWall,`A node sits on a wall that was never split there.`,{wallIds:[r.id],nodeIds:[t.id]}))}}for(let r of Object.values(t.openings))t.walls[r.wallId]||n.push(d(e.DanglingOpening,`An opening references a wall that no longer exists.`,{openingIds:[r.id]}));let l=new Set;for(let e of a)l.add(e.a),l.add(e.b);for(let t of c)l.has(t.id)||n.push(d(e.OrphanNode,`A node has no walls.`,{nodeIds:[t.id]}));return n}function L(t){let n=[],i=O(t),a=u(i.floor);for(let t of i.result.weldedWallIds)n.push(d(e.ZeroLengthWall,`Welded the two ends of a wall with no length.`,{wallIds:[t]}));for(let t of Object.values(a.walls)){let i=a.nodes[t.a],o=a.nodes[t.b];(t.a===t.b||!i||!o||r(i,o)<10)&&(delete a.walls[t.id],n.push(d(e.ZeroLengthWall,`Removed a degenerate wall.`,{wallIds:[t.id]})))}let o=new Map;for(let t of Object.values(a.walls)){let r=t.a<t.b?`${t.a}|${t.b}`:`${t.b}|${t.a}`,i=o.get(r);if(!i){o.set(r,t);continue}let s=t.thickness>=i.thickness?t:i,c=s===t?i:t;for(let e of Object.values(a.openings))e.wallId===c.id&&(a.openings[e.id]={...e,wallId:s.id});delete a.walls[c.id],o.set(r,s),n.push(d(e.DuplicateWall,`Removed a duplicate wall.`,{wallIds:[c.id]}))}for(let t of Object.values(a.openings))a.walls[t.wallId]||(delete a.openings[t.id],n.push(d(e.DanglingOpening,`Removed an opening with no wall.`,{openingIds:[t.id]})));let s=new Set;for(let e of Object.values(a.walls))s.add(e.a),s.add(e.b);for(let t of Object.values(a.nodes))s.has(t.id)||(delete a.nodes[t.id],n.push(d(e.OrphanNode,`Removed a node with no walls.`,{nodeIds:[t.id]})));return{floor:a,result:n,issues:n}}export{S as DEFAULT_WALL_ATTRS,N as addOpening,w as addRect,C as addWall,L as cleanupPlan,D as detachWall,E as dissolveNode,v as findNodeNear,m as findWallBetween,y as findWallNear,l as freshName,T as mergeNodes,A as moveNode,c as newId,F as removeOpening,k as removeWall,x as resolveNodeAt,M as scalePlan,b as splitWall,j as transformPlan,P as updateOpening,I as validatePlan,f as wallLength,p as wallsAtNode,O as weldShortWalls};
2
2
  //# sourceMappingURL=floorPlan.graph.mjs.map