@mark1russell7/room-view 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -229,6 +229,30 @@ The model does not stop on a record with faults. It does not make the solids tha
229
229
 
230
230
  The model has a range of lengths. A size of 0.001 mm or less is 0 for the checks. A length above 1 000 km (`LARGEST_LENGTH`) is a fault, and the model does not make a part with such a length. Thus each number of the model is finite.
231
231
 
232
+ ## Anchors and layers
233
+
234
+ An add-on puts the records of one topic on the core, for example the outlets of an electrical add-on. The core names no topic.
235
+
236
+ - `Scene.layers` keeps the records of each add-on, by the name of the format of its layer, for example `electrical/1`. The core does not read a layer.
237
+ - An anchor is a place for a record: on a face of a wall, on the floor, on the ceiling or on a placed object.
238
+ - `sceneSpace` gives the space of a scene. Its function `frame` gives the point of an anchor and the direction out of its surface, in meters.
239
+ - `checkAnchor` gives the faults of an anchor. An error tells that the anchor has no position. A warning tells a fault that the model can show.
240
+
241
+ An add-on is an `AddOn` value: the name of the format of its layer, and the functions `parse`, `anchors`, `withAnchors` and `check`. `checkLayers` examines the layers of a scene with a list of add-ons:
242
+
243
+ ```ts
244
+ import { checkLayers } from "@mark1russell7/room-view";
245
+
246
+ const findings = checkLayers(scene, addOns);
247
+ ```
248
+
249
+ - Each layer gets the faults of its form, of each anchor and of the meaning of its records.
250
+ - A layer of no add-on of the list gets a warning, and the scene keeps the layer.
251
+ - The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.
252
+ - The add-ons do not know each other. Two add-ons can put records on one object.
253
+
254
+ `ANCHOR_CODES` and `LAYER_CODES` have the codes of the core. The design of the add-ons is in `docs/ADD-ONS.md` of the repository.
255
+
232
256
  ## The loads of the circuits
233
257
 
234
258
  `circuitStates` gives the load of each circuit against its limit, with a level: `ok`, `near`, `over` or `unknown`. The loads are input data of the scene. This package does not calculate the power of a computer.
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as metersPer, S as lengthsInRange, _ as WallFace, a as Opening, b as LENGTH_UNITS, c as PlacedObject, d as Room, f as SCENE_SCHEMA, g as Wall, h as WALL_SIDES, i as OPENING_KINDS, l as PlanPoint, m as WALL_FACES, n as CircuitLoad, o as OpeningKind, p as Scene, r as Floor, s as Outlet, t as Circuit, u as ROOM_SCHEMA, v as WallSide, w as unitsPer, x as LengthUnit, y as LARGEST_LENGTH } from "./room-BUlXejkm.js";
2
- import { A as solidVolume, B as wallTransform, C as SolidShape, D as roomSolids, E as objectTransforms, F as wallFootprints, I as WallFrame, L as wallFrames, M as JoinOptions, N as MITER_LIMIT, O as sceneSolids, P as WallFootprint, R as wallHasOutline, S as SolidOptions, T as boundsOfSolids, _ as PlacedBox, a as LoadLevel, b as Solid, c as SHAPE_OUTLINES, d as levelShape, f as outletLevels, g as OUTLET_PLATE, h as GLASS_THICKNESS, i as LevelShape, j as JOIN_TOLERANCE, k as solidCorners, l as ShapeOutline, m as FLOOR_DEPTH, n as LEVEL_SHAPES, o as LoadOptions, p as shapeRing, r as LOAD_LEVELS, s as NEAR_LIMIT, t as CircuitState, u as circuitStates, v as Prism, w as TO_Y_UP, x as SolidKind, y as SOLID_KINDS, z as wallPoint } from "./loads-H-VFEx6b.js";
3
- import { A as SurveyTurn, C as SurveyCheckResult, D as SurveyOutlet, E as SurveyOptions, M as expandSurvey, O as SurveyResult, S as SurveyCheck, T as SurveyObject, _ as expandLevel, a as ConnectionFault, b as SURVEY_SCHEMA, c as Level, d as LevelOptions, f as LevelResult, g as RoomPlace, h as ROOM_PLACES, i as ConnectionEnd, j as convertSurvey, k as SurveySide, l as LevelConnection, m as LevelRoomResult, n as CONNECTION_TURN_LIMIT, o as ConnectionUse, p as LevelRoom, r as CONNECTION_USES, s as LEVEL_SCHEMA, t as CONNECTION_FAULTS, u as LevelConnectionResult, v as CLOSURE_LIMIT, w as SurveyClosure, x as Survey, y as SQUARE_TURNS } from "./level-84nrw7oL.js";
4
- import { Ring } from "@mark1russell7/layout-contract";
1
+ import { C as lengthsInRange, S as LengthUnit, T as unitsPer, _ as WallFace, a as Opening, b as LARGEST_LENGTH, c as PlacedObject, d as Room, f as SCENE_SCHEMA, g as Wall, h as WALL_SIDES, i as OPENING_KINDS, l as PlanPoint, m as WALL_FACES, n as CircuitLoad, o as OpeningKind, p as Scene, r as Floor, s as Outlet, t as Circuit, u as ROOM_SCHEMA, v as WallSide, w as metersPer, x as LENGTH_UNITS, y as isLayerName } from "./room-x9FxGjGi.js";
2
+ import { A as solidVolume, B as wallTransform, C as SolidShape, D as roomSolids, E as objectTransforms, F as wallFootprints, I as WallFrame, L as wallFrames, M as JoinOptions, N as MITER_LIMIT, O as sceneSolids, P as WallFootprint, R as wallHasOutline, S as SolidOptions, T as boundsOfSolids, _ as PlacedBox, a as LoadLevel, b as Solid, c as SHAPE_OUTLINES, d as levelShape, f as outletLevels, g as OUTLET_PLATE, h as GLASS_THICKNESS, i as LevelShape, j as JOIN_TOLERANCE, k as solidCorners, l as ShapeOutline, m as FLOOR_DEPTH, n as LEVEL_SHAPES, o as LoadOptions, p as shapeRing, r as LOAD_LEVELS, s as NEAR_LIMIT, t as CircuitState, u as circuitStates, v as Prism, w as TO_Y_UP, x as SolidKind, y as SOLID_KINDS, z as wallPoint } from "./loads-spBbQkb0.js";
3
+ import { A as SurveyTurn, C as SurveyCheckResult, D as SurveyOutlet, E as SurveyOptions, M as expandSurvey, O as SurveyResult, S as SurveyCheck, T as SurveyObject, _ as expandLevel, a as ConnectionFault, b as SURVEY_SCHEMA, c as Level, d as LevelOptions, f as LevelResult, g as RoomPlace, h as ROOM_PLACES, i as ConnectionEnd, j as convertSurvey, k as SurveySide, l as LevelConnection, m as LevelRoomResult, n as CONNECTION_TURN_LIMIT, o as ConnectionUse, p as LevelRoom, r as CONNECTION_USES, s as LEVEL_SCHEMA, t as CONNECTION_FAULTS, u as LevelConnectionResult, v as CLOSURE_LIMIT, w as SurveyClosure, x as Survey, y as SQUARE_TURNS } from "./level-Cgja5fXb.js";
4
+ import { Point3, Ring, Transform3 } from "@mark1russell7/layout-contract";
5
5
  /** The outline of one solid in the plan of a room: the solid as a camera above the room sees it. */
6
6
  export interface PlanShape {
7
7
  /** The `id` of the solid. */
@@ -35,6 +35,76 @@ export interface PlanOptions extends SolidOptions {
35
35
  * Thus a drawing in this sequence shows the room as a camera above it sees the room.
36
36
  */
37
37
  export declare function planShapes(scene: Scene, options?: PlanOptions): readonly PlanShape[];
38
+ /** These are the surfaces that an anchor can be on. */
39
+ export declare const ANCHOR_SURFACES: readonly ["wall", "floor", "ceiling", "object"];
40
+ /** A surface of an anchor. */
41
+ export type AnchorSurface = (typeof ANCHOR_SURFACES)[number];
42
+ /** An anchor on a face of a wall. The lengths are in the unit of the room. */
43
+ export interface WallAnchor {
44
+ readonly on: "wall";
45
+ /** The `id` of the wall. */
46
+ readonly wall: string;
47
+ readonly face: WallFace;
48
+ /** The distance along the line of the wall, from `from` to the anchor. */
49
+ readonly offset: number;
50
+ /** The height of the anchor above the floor. */
51
+ readonly height: number;
52
+ }
53
+ /** An anchor on the floor, at a point of the plan. */
54
+ export interface FloorAnchor {
55
+ readonly on: "floor";
56
+ readonly at: PlanPoint;
57
+ /** The `id` of the floor that has the point. Without it, the point is on any floor of the room. */
58
+ readonly floor?: string | undefined;
59
+ }
60
+ /** An anchor on the ceiling, above a point of the plan. The ceiling is at the height of the room. */
61
+ export interface CeilingAnchor {
62
+ readonly on: "ceiling";
63
+ readonly at: PlanPoint;
64
+ /** The `id` of the floor below the point. Without it, the point is above any floor of the room. */
65
+ readonly floor?: string | undefined;
66
+ }
67
+ /**
68
+ * An anchor on a placed object. The point and the direction are in the frame of the object, before its turn.
69
+ * The origin of that frame is the center of the bottom of the object.
70
+ */
71
+ export interface ObjectAnchor {
72
+ readonly on: "object";
73
+ /** The `id` of the placed object. */
74
+ readonly object: string;
75
+ /** The point in the frame of the object. The default is the center of its top. */
76
+ readonly at?: readonly [number, number, number] | undefined;
77
+ /** The direction out of the surface, in the frame of the object. The default is up: `[0, 0, 1]`. */
78
+ readonly out?: readonly [number, number, number] | undefined;
79
+ }
80
+ /** An anchor: a place in the space of the core, for a record of an add-on. */
81
+ export type Anchor = WallAnchor | FloorAnchor | CeilingAnchor | ObjectAnchor;
82
+ /** The position of an anchor in the room, in meters. */
83
+ export interface AnchorFrame {
84
+ /** The point of the anchor. */
85
+ readonly at: Point3;
86
+ /** The unit vector out of the surface, into the space of the room. */
87
+ readonly out: Point3;
88
+ }
89
+ /**
90
+ * The space of a scene, for the add-ons. It reads each wall, object and anchor of the scene.
91
+ * Make it once with `sceneSpace`, and give it to each add-on.
92
+ */
93
+ export interface SceneSpace {
94
+ readonly scene: Scene;
95
+ /** The length of the unit of the room, in meters. */
96
+ readonly scale: number;
97
+ /** This function gives the frame of a wall in meters, or `undefined` when the room does not have the wall. */
98
+ readonly wall: (id: string) => WallFrame | undefined;
99
+ /** This function gives a placed object of the scene, or `undefined` when the scene does not have it. */
100
+ readonly object: (id: string) => PlacedObject | undefined;
101
+ /** This function gives the transform of a placed object in meters, or `undefined` when the object has no place. */
102
+ readonly transform: (id: string) => Transform3 | undefined;
103
+ /** This function gives the position of an anchor, or `undefined` when the anchor has no position. `checkAnchor` tells the reason. */
104
+ readonly frame: (anchor: Anchor) => AnchorFrame | undefined;
105
+ }
106
+ /** This function gives the space of a scene. The transforms of the objects are calculated one time, at the first use. */
107
+ export declare function sceneSpace(scene: Scene): SceneSpace;
38
108
  /** These are the levels of a finding. An error is a fault that the model cannot show. A warning is a fault that the model can show. */
39
109
  export declare const FINDING_LEVELS: readonly ["error", "warning"];
40
110
  /** A level of a finding. */
@@ -43,6 +113,16 @@ export type FindingLevel = (typeof FINDING_LEVELS)[number];
43
113
  export declare const RECORD_KINDS: readonly ["room", "wall", "opening", "floor", "outlet", "circuit", "object", "load"];
44
114
  /** A kind of record. */
45
115
  export type RecordKind = (typeof RECORD_KINDS)[number];
116
+ /**
117
+ * This function gives the name of a record: its kind, a colon and its `id`, for example `object:desk`.
118
+ * The kind of a record of a layer is the name of the layer, for example `electrical/1`. A finding, a mark and the selection use this name.
119
+ */
120
+ export declare function recordName(kind: string, id: string): string;
121
+ /** This function gives the kind and the `id` of a record name, or `undefined` for a text with no kind. A kind has no colon, so the first colon ends it. */
122
+ export declare function parseRecordName(name: string): {
123
+ readonly kind: string;
124
+ readonly id: string;
125
+ } | undefined;
46
126
  /** These are the codes of the findings. */
47
127
  export declare const FINDING_CODES: readonly ["number-not-finite", "number-too-large", "id-duplicate", "size-not-positive", "wall-length", "wall-short", "wall-overlap", "opening-wall", "opening-range", "opening-height", "opening-overlap", "outlet-wall", "outlet-circuit", "outlet-range", "outlet-in-opening", "floor-ring", "circuit-limit", "object-parent", "object-cycle", "object-outlet", "object-outside", "object-overlap", "object-in-wall", "load-circuit", "load-watts"];
48
128
  /** A code of a finding. */
@@ -79,5 +159,89 @@ export declare function checkRoom(room: Room, options?: CheckOptions): readonly
79
159
  * A scene with no finding of the level `error` gives a full model.
80
160
  */
81
161
  export declare function checkScene(scene: Scene, options?: CheckOptions): readonly Finding[];
82
- export { CLOSURE_LIMIT, CONNECTION_FAULTS, CONNECTION_TURN_LIMIT, CONNECTION_USES, Circuit, CircuitLoad, CircuitState, ConnectionEnd, ConnectionFault, ConnectionUse, FLOOR_DEPTH, Floor, GLASS_THICKNESS, JOIN_TOLERANCE, JoinOptions, LARGEST_LENGTH, LENGTH_UNITS, LEVEL_SCHEMA, LEVEL_SHAPES, LOAD_LEVELS, LengthUnit, Level, LevelConnection, LevelConnectionResult, LevelOptions, LevelResult, LevelRoom, LevelRoomResult, LevelShape, LoadLevel, LoadOptions, MITER_LIMIT, NEAR_LIMIT, OPENING_KINDS, OUTLET_PLATE, Opening, OpeningKind, Outlet, PlacedBox, PlacedObject, PlanPoint, Prism, ROOM_PLACES, ROOM_SCHEMA, Room, RoomPlace, SCENE_SCHEMA, SHAPE_OUTLINES, SOLID_KINDS, SQUARE_TURNS, SURVEY_SCHEMA, Scene, ShapeOutline, Solid, SolidKind, SolidOptions, SolidShape, Survey, SurveyCheck, SurveyCheckResult, SurveyClosure, SurveyObject, SurveyOptions, SurveyOutlet, SurveyResult, SurveySide, SurveyTurn, TO_Y_UP, WALL_FACES, WALL_SIDES, Wall, WallFace, WallFootprint, WallFrame, WallSide, boundsOfSolids, circuitStates, convertSurvey, expandLevel, expandSurvey, lengthsInRange, levelShape, metersPer, objectTransforms, outletLevels, roomSolids, sceneSolids, shapeRing, solidCorners, solidVolume, unitsPer, wallFootprints, wallFrames, wallHasOutline, wallPoint, wallTransform };
162
+ /** These are the codes of the faults of an anchor. */
163
+ export declare const ANCHOR_CODES: readonly ["anchor-not-finite", "anchor-wall", "anchor-object", "anchor-floor", "anchor-range", "anchor-direction", "anchor-in-opening", "anchor-outside"];
164
+ /** A code of a fault of an anchor. */
165
+ export type AnchorCode = (typeof ANCHOR_CODES)[number];
166
+ /** A fault of an anchor. `checkLayers` gives it the layer and the key of the anchor. */
167
+ export interface AnchorFault {
168
+ readonly level: FindingLevel;
169
+ readonly code: AnchorCode;
170
+ /** The fault in plain words, with the values. */
171
+ readonly message: string;
172
+ /** The `id` of the second record of the fault: the opening that the anchor is in. A different fault has none. */
173
+ readonly other?: string | undefined;
174
+ }
175
+ /**
176
+ * This function gives the faults of an anchor in the space of a scene. `name` starts each message.
177
+ * An error tells that the anchor has no position. A warning tells a fault that the model can show.
178
+ */
179
+ export declare function checkAnchor(anchor: Anchor, space: SceneSpace, name?: string): readonly AnchorFault[];
180
+ /** The result of the read of a layer: the layer, or the faults of its form. */
181
+ export type LayerParse<Layer> = {
182
+ readonly ok: true;
183
+ readonly layer: Layer;
184
+ } | {
185
+ readonly ok: false;
186
+ readonly errors: readonly string[];
187
+ };
188
+ /** A fault that an add-on finds in its layer. */
189
+ export interface AddOnFault {
190
+ readonly level: FindingLevel;
191
+ /** The code of the fault. The add-on gives its own codes. */
192
+ readonly code: string;
193
+ /** The `id` of the record with the fault. For the layer, it is empty. */
194
+ readonly at: string;
195
+ /** The fault in plain words, with the values. */
196
+ readonly message: string;
197
+ /** The `id` of the second record of the fault. A fault of one record has none. */
198
+ readonly other?: string | undefined;
199
+ }
200
+ /**
201
+ * An add-on: one topic on the core, for example electrical, plumbing or light.
202
+ * A host gives a list of add-ons to `checkLayers`. The core knows only this type.
203
+ */
204
+ export interface AddOn<Layer> {
205
+ /** The name of the format of the layer, for example `electrical/1`. It is the key of the layer in `Scene.layers`. */
206
+ readonly schema: string;
207
+ /** This function reads the JSON of a layer. */
208
+ parse(value: unknown): LayerParse<Layer>;
209
+ /**
210
+ * This function gives the anchors of the records of a layer, by a key.
211
+ * The key is the `id` of a record, or the `id` and a position for a record with many anchors.
212
+ */
213
+ anchors(layer: Layer): ReadonlyMap<string, Anchor>;
214
+ /** This function gives the layer with new anchors, by the keys of `anchors`. The core uses it when it moves the records of a room. */
215
+ withAnchors(layer: Layer, anchors: ReadonlyMap<string, Anchor>): Layer;
216
+ /** This function gives the faults of the meaning of a layer. The core examines the anchors, so this function does not. */
217
+ check(layer: Layer, space: SceneSpace): readonly AddOnFault[];
218
+ }
219
+ /** These are the codes of the faults of a layer that the core finds. */
220
+ export declare const LAYER_CODES: readonly ["layer-name", "layer-unknown", "layer-form"];
221
+ /** A finding of a layer: a fault of its form, of an anchor or of the meaning of its records. */
222
+ export interface LayerFinding {
223
+ readonly level: FindingLevel;
224
+ /** A code of `LAYER_CODES` or `ANCHOR_CODES`, or a code of the add-on. */
225
+ readonly code: string;
226
+ /** The key of the layer in `Scene.layers`. */
227
+ readonly layer: string;
228
+ /** The key of the anchor, or the `id` of the record with the fault. For the layer, it is empty. */
229
+ readonly at: string;
230
+ /** The fault in plain words, with the values. */
231
+ readonly message: string;
232
+ /** The `id` of the second record of the fault. A fault of one record has none. */
233
+ readonly other?: string | undefined;
234
+ }
235
+ /** This function reads the layer of an add-on in a scene. It gives `undefined` when the scene has no layer of the add-on. */
236
+ export declare function readLayer<Layer>(scene: Scene, addOn: AddOn<Layer>): LayerParse<Layer> | undefined;
237
+ /**
238
+ * This function gives the findings of the layers of a scene, with a list of add-ons.
239
+ * Each layer gets the faults of its form, of each anchor and of the meaning of its records. A layer of no add-on of the list gets a warning.
240
+ * The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.
241
+ *
242
+ * The name of the record of a finding is `recordName(finding.layer, finding.at)`, so a finding selects its mark.
243
+ * `checkScene` examines the core, and this function examines the layers.
244
+ */
245
+ export declare function checkLayers(scene: Scene, addOns: readonly AddOn<unknown>[]): readonly LayerFinding[];
246
+ export { CLOSURE_LIMIT, CONNECTION_FAULTS, CONNECTION_TURN_LIMIT, CONNECTION_USES, Circuit, CircuitLoad, CircuitState, ConnectionEnd, ConnectionFault, ConnectionUse, FLOOR_DEPTH, Floor, GLASS_THICKNESS, JOIN_TOLERANCE, JoinOptions, LARGEST_LENGTH, LENGTH_UNITS, LEVEL_SCHEMA, LEVEL_SHAPES, LOAD_LEVELS, LengthUnit, Level, LevelConnection, LevelConnectionResult, LevelOptions, LevelResult, LevelRoom, LevelRoomResult, LevelShape, LoadLevel, LoadOptions, MITER_LIMIT, NEAR_LIMIT, OPENING_KINDS, OUTLET_PLATE, Opening, OpeningKind, Outlet, PlacedBox, PlacedObject, PlanPoint, Prism, ROOM_PLACES, ROOM_SCHEMA, Room, RoomPlace, SCENE_SCHEMA, SHAPE_OUTLINES, SOLID_KINDS, SQUARE_TURNS, SURVEY_SCHEMA, Scene, ShapeOutline, Solid, SolidKind, SolidOptions, SolidShape, Survey, SurveyCheck, SurveyCheckResult, SurveyClosure, SurveyObject, SurveyOptions, SurveyOutlet, SurveyResult, SurveySide, SurveyTurn, TO_Y_UP, WALL_FACES, WALL_SIDES, Wall, WallFace, WallFootprint, WallFrame, WallSide, boundsOfSolids, circuitStates, convertSurvey, expandLevel, expandSurvey, isLayerName, lengthsInRange, levelShape, metersPer, objectTransforms, outletLevels, roomSolids, sceneSolids, shapeRing, solidCorners, solidVolume, unitsPer, wallFootprints, wallFrames, wallHasOutline, wallPoint, wallTransform };
83
247
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plan.ts","../src/check.ts"],"mappings":";;;;;iBAKiB;;WAEN;WACA,MAAM;;WAEN;;WAEA,MAAM;;WAEN;;WAEA;;;;;;wBAOK,UAAU,OAAO,QAAQ;;iBAgBxB,oBAAoB;;;;;WAK1B;;;;;;;wBAQK,WAAW,OAAO,OAAO,UAAS,uBAA4B;;qBC5CjE;;YAGD,uBAAuB;;qBAGtB;;YAYD,qBAAqB;;qBAGpB;;YAuDD,sBAAsB;;iBAGjB;WACN,OAAO;WACP,MAAM;;WAEN,QAAQ;;WAER;;WAEA;;;;;WAKA;;;iBAIM;;WAEN,QAAQ;;;;;;;wBA2CH,UAAU,MAAM,MAAM,UAAS,wBAA6B;;;;;wBAsK5D,WAAW,OAAO,OAAO,UAAS,wBAA6B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plan.ts","../src/anchors.ts","../src/check.ts","../src/layers.ts"],"mappings":";;;;;iBAKiB;;WAEN;WACA,MAAM;;WAEN;;WAEA,MAAM;;WAEN;;WAEA;;;;;;wBAOK,UAAU,OAAO,QAAQ;;iBAgBxB,oBAAoB;;;;;WAK1B;;;;;;;wBAQK,WAAW,OAAO,OAAO,UAAS,uBAA4B;;qBC1CjE;;YAGD,wBAAwB;;iBAGnB;WACN;;WAEA;WACA,MAAM;;WAEN;;WAEA;;;iBAIM;WACN;WACA,IAAI;;WAEJ;;;iBAIM;WACN;WACA,IAAI;;WAEJ;;;;;;iBAOM;WACN;;WAEA;;WAEA;;WAEA;;;YAIC,SAAS,aAAa,cAAc,gBAAgB;;iBAG/C;;WAEN,IAAI;;WAEJ,KAAK;;;;;;iBAOC;WACN,OAAO;;WAEP;;WAEA,OAAO,eAAe;;WAEtB,SAAS,eAAe;;WAExB,YAAY,eAAe;;WAE3B,QAAQ,QAAQ,WAAW;;;wBAYtB,WAAW,OAAO,QAAQ;;qBCtF7B;;YAGD,uBAAuB;;qBAGtB;;YAYD,qBAAqB;;;;;wBAMjB,WAAW,cAAc;;wBAKzB,gBAAgB;WAA0B;WAAuB;;;qBAMpE;;YAuDD,sBAAsB;;iBAGjB;WACN,OAAO;WACP,MAAM;;WAEN,QAAQ;;WAER;;WAEA;;;;;WAKA;;;iBAIM;;WAEN,QAAQ;;;;;;;wBA2CH,UAAU,MAAM,MAAM,UAAS,wBAA6B;;;;;wBAsK5D,WAAW,OAAO,OAAO,UAAS,wBAA6B;;qBAkFlE;;YAYD,qBAAqB;;iBAGhB;WACN,OAAO;WACP,MAAM;;WAEN;;WAEA;;;;;;wBAOK,YAAY,QAAQ,QAAQ,OAAO,YAAY,yBAAuC;;YC/a1F,WAAW;WAAoB;WAAmB,OAAO;;WAAqB;WAAoB;;;iBAG7F;WACN,OAAO;;WAEP;;WAEA;;WAEA;;WAEA;;;;;;iBAOM,MAAM;;WAEZ;;EAET,MAAM,iBAAiB,WAAW;;;;;EAKlC,QAAQ,OAAO,QAAQ,oBAAoB;;EAE3C,YAAY,OAAO,OAAO,SAAS,oBAAoB,UAAU;;EAEjE,MAAM,OAAO,OAAO,OAAO,sBAAsB;;;qBAItC;;iBAGI;WACN,OAAO;;WAEP;;WAEA;;WAEA;;WAEA;;WAEA;;;wBAgBK,UAAU,OAAO,OAAO,OAAO,OAAO,MAAM,SAAS,WAAW;;;;;;;;;wBAahE,YAAY,OAAO,OAAO,iBAAiB,4BAA4B"}
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as unitsPer, i as metersPer, n as LENGTH_UNITS, r as lengthsInRange, t as LARGEST_LENGTH } from "./units-BZmvVyu4.js";
2
- import { a as ROOM_PLACES, c as SQUARE_TURNS, d as expandSurvey, f as OPENING_KINDS, g as WALL_SIDES, h as WALL_FACES, i as LEVEL_SCHEMA, l as SURVEY_SCHEMA, m as SCENE_SCHEMA, n as CONNECTION_TURN_LIMIT, o as expandLevel, p as ROOM_SCHEMA, r as CONNECTION_USES, s as CLOSURE_LIMIT, t as CONNECTION_FAULTS, u as convertSurvey } from "./level-xTO7P1Fn.js";
2
+ import { _ as isLayerName, a as ROOM_PLACES, c as SQUARE_TURNS, d as expandSurvey, f as OPENING_KINDS, g as WALL_SIDES, h as WALL_FACES, i as LEVEL_SCHEMA, l as SURVEY_SCHEMA, m as SCENE_SCHEMA, n as CONNECTION_TURN_LIMIT, o as expandLevel, p as ROOM_SCHEMA, r as CONNECTION_USES, s as CLOSURE_LIMIT, t as CONNECTION_FAULTS, u as convertSurvey } from "./level-Cu8vgrwN.js";
3
3
  import { C as wallFrames, E as wallTransform, S as wallFootprints, T as wallPoint, _ as sceneSolids, a as circuitStates, b as JOIN_TOLERANCE, c as shapeRing, d as OUTLET_PLATE, f as SOLID_KINDS, g as roomSolids, h as objectTransforms, i as SHAPE_OUTLINES, l as FLOOR_DEPTH, m as boundsOfSolids, n as LOAD_LEVELS, o as levelShape, p as TO_Y_UP, r as NEAR_LIMIT, s as outletLevels, t as LEVEL_SHAPES, u as GLASS_THICKNESS, v as solidCorners, w as wallHasOutline, x as MITER_LIMIT, y as solidVolume } from "./loads-Br73kIsQ.js";
4
- import { convexOverlap, pointInRing, regionArea, transformPoint3 } from "@mark1russell7/layout-contract";
4
+ import { convexOverlap, length3, pointInRing, regionArea, rotatePoint3, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
5
5
  // src/plan.ts
6
6
  /**
7
7
  * This function gives the outline of a solid in the plan.
@@ -81,6 +81,21 @@ const RECORD_KINDS = [
81
81
  "object",
82
82
  "load"
83
83
  ];
84
+ /**
85
+ * This function gives the name of a record: its kind, a colon and its `id`, for example `object:desk`.
86
+ * The kind of a record of a layer is the name of the layer, for example `electrical/1`. A finding, a mark and the selection use this name.
87
+ */
88
+ function recordName(kind, id) {
89
+ return `${kind}:${id}`;
90
+ }
91
+ /** This function gives the kind and the `id` of a record name, or `undefined` for a text with no kind. A kind has no colon, so the first colon ends it. */
92
+ function parseRecordName(name) {
93
+ const colon = name.indexOf(":");
94
+ return colon < 1 ? void 0 : {
95
+ kind: name.slice(0, colon),
96
+ id: name.slice(colon + 1)
97
+ };
98
+ }
84
99
  /** These are the codes of the findings. */
85
100
  const FINDING_CODES = [
86
101
  "number-not-finite",
@@ -386,6 +401,278 @@ function checkScene(scene, options = {}) {
386
401
  }
387
402
  return findings;
388
403
  }
389
- export { CLOSURE_LIMIT, CONNECTION_FAULTS, CONNECTION_TURN_LIMIT, CONNECTION_USES, FINDING_CODES, FINDING_LEVELS, FLOOR_DEPTH, GLASS_THICKNESS, JOIN_TOLERANCE, LARGEST_LENGTH, LENGTH_UNITS, LEVEL_SCHEMA, LEVEL_SHAPES, LOAD_LEVELS, MITER_LIMIT, NEAR_LIMIT, OPENING_KINDS, OUTLET_PLATE, RECORD_KINDS, ROOM_PLACES, ROOM_SCHEMA, SCENE_SCHEMA, SHAPE_OUTLINES, SOLID_KINDS, SQUARE_TURNS, SURVEY_SCHEMA, TO_Y_UP, WALL_FACES, WALL_SIDES, boundsOfSolids, checkRoom, checkScene, circuitStates, convertSurvey, expandLevel, expandSurvey, lengthsInRange, levelShape, metersPer, objectTransforms, outletLevels, planShape, planShapes, roomSolids, sceneSolids, shapeRing, solidCorners, solidVolume, unitsPer, wallFootprints, wallFrames, wallHasOutline, wallPoint, wallTransform };
404
+ /** These are the codes of the faults of an anchor. */
405
+ const ANCHOR_CODES = [
406
+ "anchor-not-finite",
407
+ "anchor-wall",
408
+ "anchor-object",
409
+ "anchor-floor",
410
+ "anchor-range",
411
+ "anchor-direction",
412
+ "anchor-in-opening",
413
+ "anchor-outside"
414
+ ];
415
+ /**
416
+ * This function gives the faults of an anchor in the space of a scene. `name` starts each message.
417
+ * An error tells that the anchor has no position. A warning tells a fault that the model can show.
418
+ */
419
+ function checkAnchor(anchor, space, name = "The anchor") {
420
+ const error = (code, message) => [{
421
+ level: "error",
422
+ code,
423
+ message: `${name} ${message}`
424
+ }];
425
+ const { scene, scale } = space;
426
+ if (holdsBadNumber(anchor)) return error("anchor-not-finite", "has a number that is not finite.");
427
+ if (anchor.on === "wall") {
428
+ const wall = space.wall(anchor.wall);
429
+ if (wall === void 0) return error("anchor-wall", `is on the wall "${anchor.wall}", which the room does not have.`);
430
+ const along = anchor.offset * scale;
431
+ const height = anchor.height * scale;
432
+ if (!(along >= 0 && along <= wall.length + SMALL && height >= 0 && height <= wall.height + SMALL)) return error("anchor-range", `is at ${show(anchor.offset)} along the wall "${anchor.wall}" and at the height ${show(anchor.height)}. The wall has the length ${show(wall.length / scale)} and the height ${show(wall.height / scale)}.`);
433
+ const hole = (scene.room.openings ?? []).find((opening) => {
434
+ const sill = (opening.sill ?? 0) * scale;
435
+ return opening.wall === anchor.wall && along > opening.offset * scale && along < (opening.offset + opening.width) * scale && height > sill && height < sill + opening.height * scale;
436
+ });
437
+ return hole === void 0 ? [] : [{
438
+ level: "warning",
439
+ code: "anchor-in-opening",
440
+ message: `${name} is in the opening "${hole.id}" of the wall "${anchor.wall}".`,
441
+ other: hole.id
442
+ }];
443
+ }
444
+ if (anchor.on === "object") {
445
+ const object = space.object(anchor.object);
446
+ if (object === void 0) return error("anchor-object", `is on the object "${anchor.object}", which the scene does not have.`);
447
+ if (space.transform(anchor.object) === void 0) return error("anchor-object", `is on the object "${anchor.object}", which has no place in the room.`);
448
+ const small = SMALL / scale;
449
+ if (anchor.at !== void 0) {
450
+ const [x, y, z] = anchor.at;
451
+ const [width, depth, height] = object.size;
452
+ if (!(Math.abs(x) <= width / 2 + small && Math.abs(y) <= depth / 2 + small && z >= -small && z <= height + small)) return error("anchor-range", `is at (${anchor.at.map(show).join(", ")}) in the frame of the object "${anchor.object}". The object has the size ${object.size.map(show).join(" by ")}.`);
453
+ }
454
+ if (anchor.out !== void 0) {
455
+ const [x, y, z] = anchor.out;
456
+ if (!(length3({
457
+ x,
458
+ y,
459
+ z
460
+ }) > 0)) return error("anchor-direction", "has a direction with the length 0. A direction must have a length above 0.");
461
+ }
462
+ return [];
463
+ }
464
+ const [x, y] = anchor.at;
465
+ if (!lengthsInRange(x * scale, y * scale)) return error("anchor-range", "is at a point above 1 000 km, the largest length of the model.");
466
+ const word = anchor.on === "floor" ? "on" : "above";
467
+ const floors = scene.room.floors ?? [];
468
+ if (anchor.floor !== void 0) {
469
+ const floor = floors.find((item) => item.id === anchor.floor);
470
+ if (floor === void 0) return error("anchor-floor", `is ${word} the floor "${anchor.floor}", which the room does not have.`);
471
+ return pointInRing(x, y, floor.ring) ? [] : [{
472
+ level: "warning",
473
+ code: "anchor-outside",
474
+ message: `${name} is not ${word} the floor "${anchor.floor}".`
475
+ }];
476
+ }
477
+ if (floors.length === 0 || floors.some((floor) => pointInRing(x, y, floor.ring))) return [];
478
+ return [{
479
+ level: "warning",
480
+ code: "anchor-outside",
481
+ message: `${name} is not ${word} a floor of the room.`
482
+ }];
483
+ }
484
+ // src/anchors.ts
485
+ /** These are the surfaces that an anchor can be on. */
486
+ const ANCHOR_SURFACES = [
487
+ "wall",
488
+ "floor",
489
+ "ceiling",
490
+ "object"
491
+ ];
492
+ const UP = {
493
+ x: 0,
494
+ y: 0,
495
+ z: 1
496
+ };
497
+ const DOWN = {
498
+ x: 0,
499
+ y: 0,
500
+ z: -1
501
+ };
502
+ /** This function tells if each value of a point is a length in the range of the model. */
503
+ function inRange(point) {
504
+ return Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z) && lengthsInRange(point.x, point.y, point.z);
505
+ }
506
+ /** This function gives the space of a scene. The transforms of the objects are calculated one time, at the first use. */
507
+ function sceneSpace(scene) {
508
+ const scale = metersPer(scene.room.unit);
509
+ const walls = new Map(wallFrames(scene.room).map((frame) => [frame.id, frame]));
510
+ const objects = new Map((scene.objects ?? []).map((object) => [object.id, object]));
511
+ let transforms;
512
+ const transform = (id) => {
513
+ transforms ??= objectTransforms(scene);
514
+ return transforms.get(id);
515
+ };
516
+ const frame = (anchor) => {
517
+ let found;
518
+ if (anchor.on === "wall") {
519
+ const wall = walls.get(anchor.wall);
520
+ if (wall === void 0) return void 0;
521
+ const point = wallPoint(wall, anchor.offset * scale, anchor.face === "left" ? wall.leftOffset : wall.rightOffset);
522
+ const sign = anchor.face === "left" ? 1 : -1;
523
+ found = {
524
+ at: {
525
+ x: point.x,
526
+ y: point.y,
527
+ z: anchor.height * scale
528
+ },
529
+ out: {
530
+ x: wall.left.x * sign,
531
+ y: wall.left.y * sign,
532
+ z: 0
533
+ }
534
+ };
535
+ } else if (anchor.on === "floor") found = {
536
+ at: {
537
+ x: anchor.at[0] * scale,
538
+ y: anchor.at[1] * scale,
539
+ z: 0
540
+ },
541
+ out: UP
542
+ };
543
+ else if (anchor.on === "ceiling") found = {
544
+ at: {
545
+ x: anchor.at[0] * scale,
546
+ y: anchor.at[1] * scale,
547
+ z: scene.room.height * scale
548
+ },
549
+ out: DOWN
550
+ };
551
+ else {
552
+ const object = objects.get(anchor.object);
553
+ const place = transform(anchor.object);
554
+ if (object === void 0 || place === void 0) return void 0;
555
+ const [x, y, z] = anchor.at ?? [
556
+ 0,
557
+ 0,
558
+ object.size[2]
559
+ ];
560
+ const [ox, oy, oz] = anchor.out ?? [
561
+ 0,
562
+ 0,
563
+ 1
564
+ ];
565
+ const out = {
566
+ x: ox,
567
+ y: oy,
568
+ z: oz
569
+ };
570
+ const size = length3(out);
571
+ if (!(size > 0) || !Number.isFinite(size)) return void 0;
572
+ found = {
573
+ at: transformPoint3(place, {
574
+ x: x * scale,
575
+ y: y * scale,
576
+ z: z * scale
577
+ }),
578
+ out: rotatePoint3(place.rotation, scalePoint3(out, 1 / size))
579
+ };
580
+ }
581
+ return inRange(found.at) && inRange(found.out) ? found : void 0;
582
+ };
583
+ return {
584
+ scene,
585
+ scale,
586
+ wall: (id) => walls.get(id),
587
+ object: (id) => objects.get(id),
588
+ transform,
589
+ frame
590
+ };
591
+ }
592
+ // src/layers.ts
593
+ /** These are the codes of the faults of a layer that the core finds. */
594
+ const LAYER_CODES = [
595
+ "layer-name",
596
+ "layer-unknown",
597
+ "layer-form"
598
+ ];
599
+ /** This function compares two texts by their code points, so the order does not change with the language of a computer. */
600
+ function compareText(a, b) {
601
+ return a < b ? -1 : a > b ? 1 : 0;
602
+ }
603
+ /** This function gives the add-on of each schema name. The first add-on of a name is used. */
604
+ function addOnsByName(addOns) {
605
+ const byName = /* @__PURE__ */ new Map();
606
+ for (const addOn of addOns) if (!byName.has(addOn.schema)) byName.set(addOn.schema, addOn);
607
+ return byName;
608
+ }
609
+ /** This function reads the layer of an add-on in a scene. It gives `undefined` when the scene has no layer of the add-on. */
610
+ function readLayer(scene, addOn) {
611
+ const layers = scene.layers ?? {};
612
+ return Object.hasOwn(layers, addOn.schema) ? addOn.parse(layers[addOn.schema]) : void 0;
613
+ }
614
+ /**
615
+ * This function gives the findings of the layers of a scene, with a list of add-ons.
616
+ * Each layer gets the faults of its form, of each anchor and of the meaning of its records. A layer of no add-on of the list gets a warning.
617
+ * The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.
618
+ *
619
+ * The name of the record of a finding is `recordName(finding.layer, finding.at)`, so a finding selects its mark.
620
+ * `checkScene` examines the core, and this function examines the layers.
621
+ */
622
+ function checkLayers(scene, addOns) {
623
+ const byName = addOnsByName(addOns);
624
+ const layers = scene.layers ?? {};
625
+ const findings = [];
626
+ let space;
627
+ for (const name of Object.keys(layers).sort(compareText)) {
628
+ if (!isLayerName(name)) {
629
+ findings.push({
630
+ level: "error",
631
+ code: "layer-name",
632
+ layer: name,
633
+ at: "",
634
+ message: `The layer "${name}" has a name that is not a word, a slash and a version, for example "electrical/1".`
635
+ });
636
+ continue;
637
+ }
638
+ const addOn = byName.get(name);
639
+ if (addOn === void 0) {
640
+ findings.push({
641
+ level: "warning",
642
+ code: "layer-unknown",
643
+ layer: name,
644
+ at: "",
645
+ message: `The scene has the layer "${name}", and no add-on of the check reads it. The scene keeps the layer.`
646
+ });
647
+ continue;
648
+ }
649
+ const read = addOn.parse(layers[name]);
650
+ if (!read.ok) {
651
+ for (const message of read.errors) findings.push({
652
+ level: "error",
653
+ code: "layer-form",
654
+ layer: name,
655
+ at: "",
656
+ message
657
+ });
658
+ continue;
659
+ }
660
+ space ??= sceneSpace(scene);
661
+ const own = [];
662
+ for (const [key, anchor] of addOn.anchors(read.layer)) for (const fault of checkAnchor(anchor, space, `The anchor "${key}" of the layer "${name}"`)) own.push({
663
+ ...fault,
664
+ layer: name,
665
+ at: key
666
+ });
667
+ for (const fault of addOn.check(read.layer, space)) own.push({
668
+ ...fault,
669
+ layer: name
670
+ });
671
+ own.sort((a, b) => compareText(a.at, b.at));
672
+ findings.push(...own);
673
+ }
674
+ return findings;
675
+ }
676
+ export { ANCHOR_CODES, ANCHOR_SURFACES, CLOSURE_LIMIT, CONNECTION_FAULTS, CONNECTION_TURN_LIMIT, CONNECTION_USES, FINDING_CODES, FINDING_LEVELS, FLOOR_DEPTH, GLASS_THICKNESS, JOIN_TOLERANCE, LARGEST_LENGTH, LAYER_CODES, LENGTH_UNITS, LEVEL_SCHEMA, LEVEL_SHAPES, LOAD_LEVELS, MITER_LIMIT, NEAR_LIMIT, OPENING_KINDS, OUTLET_PLATE, RECORD_KINDS, ROOM_PLACES, ROOM_SCHEMA, SCENE_SCHEMA, SHAPE_OUTLINES, SOLID_KINDS, SQUARE_TURNS, SURVEY_SCHEMA, TO_Y_UP, WALL_FACES, WALL_SIDES, boundsOfSolids, checkAnchor, checkLayers, checkRoom, checkScene, circuitStates, convertSurvey, expandLevel, expandSurvey, isLayerName, lengthsInRange, levelShape, metersPer, objectTransforms, outletLevels, parseRecordName, planShape, planShapes, readLayer, recordName, roomSolids, sceneSolids, sceneSpace, shapeRing, solidCorners, solidVolume, unitsPer, wallFootprints, wallFrames, wallHasOutline, wallPoint, wallTransform };
390
677
 
391
678
  //# sourceMappingURL=index.js.map