@mark1russell7/room-view 0.1.3 → 0.1.5

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 (40) hide show
  1. package/README.md +15 -1
  2. package/build/anchors-BEnxNnSV.d.ts +75 -0
  3. package/build/anchors-BEnxNnSV.d.ts.map +1 -0
  4. package/build/frames-BYMK5ZId.d.ts +39 -0
  5. package/build/frames-BYMK5ZId.d.ts.map +1 -0
  6. package/build/index.d.ts +7 -211
  7. package/build/index.d.ts.map +1 -1
  8. package/build/index.js +6 -613
  9. package/build/index.js.map +1 -1
  10. package/build/joins-2p01wnr_.d.ts +39 -0
  11. package/build/joins-2p01wnr_.d.ts.map +1 -0
  12. package/build/layers-CKx0dcM0.d.ts +143 -0
  13. package/build/layers-CKx0dcM0.d.ts.map +1 -0
  14. package/build/layers-bgJ3OTId.js +630 -0
  15. package/build/layers-bgJ3OTId.js.map +1 -0
  16. package/build/{level-Cu8vgrwN.js → level-5Nb9rq5L.js} +3 -28
  17. package/build/level-5Nb9rq5L.js.map +1 -0
  18. package/build/{loads-C3Nrj3Gd.d.ts → loads-CriZuwcu.d.ts} +4 -73
  19. package/build/loads-CriZuwcu.d.ts.map +1 -0
  20. package/build/loads-CtHa4EHo.js +103 -0
  21. package/build/loads-CtHa4EHo.js.map +1 -0
  22. package/build/marks.d.ts +29 -0
  23. package/build/marks.d.ts.map +1 -0
  24. package/build/marks.js +34 -0
  25. package/build/marks.js.map +1 -0
  26. package/build/room-DrXMmX_h.js +29 -0
  27. package/build/room-DrXMmX_h.js.map +1 -0
  28. package/build/schema.d.ts +6 -0
  29. package/build/schema.d.ts.map +1 -1
  30. package/build/schema.js +37 -2
  31. package/build/schema.js.map +1 -1
  32. package/build/{loads-Br73kIsQ.js → solids-BKb-izIP.js} +2 -102
  33. package/build/solids-BKb-izIP.js.map +1 -0
  34. package/build/three.d.ts +1 -1
  35. package/build/three.js +2 -1
  36. package/build/three.js.map +1 -1
  37. package/package.json +7 -1
  38. package/build/level-Cu8vgrwN.js.map +0 -1
  39. package/build/loads-Br73kIsQ.js.map +0 -1
  40. package/build/loads-C3Nrj3Gd.d.ts.map +0 -1
@@ -0,0 +1,630 @@
1
+ import { _ as wallPoint, g as wallHasOutline, h as wallFrames, m as wallFootprints, s as objectTransforms } from "./solids-BKb-izIP.js";
2
+ import { i as metersPer, r as lengthsInRange, t as LARGEST_LENGTH } from "./units-BZmvVyu4.js";
3
+ import { o as isLayerName } from "./room-DrXMmX_h.js";
4
+ import { convexOverlap, length3, pointInRing, regionArea, rotatePoint3, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
5
+ // src/check.ts
6
+ /** 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. */
7
+ const FINDING_LEVELS = ["error", "warning"];
8
+ /** These are the kinds of the records that a finding can name. */
9
+ const RECORD_KINDS = [
10
+ "room",
11
+ "wall",
12
+ "opening",
13
+ "floor",
14
+ "outlet",
15
+ "circuit",
16
+ "object",
17
+ "load"
18
+ ];
19
+ /**
20
+ * This function gives the name of a record: its kind, a colon and its `id`, for example `object:desk`.
21
+ * 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.
22
+ */
23
+ function recordName(kind, id) {
24
+ return `${kind}:${id}`;
25
+ }
26
+ /** 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. */
27
+ function parseRecordName(name) {
28
+ const colon = name.indexOf(":");
29
+ return colon < 1 ? void 0 : {
30
+ kind: name.slice(0, colon),
31
+ id: name.slice(colon + 1)
32
+ };
33
+ }
34
+ /** These are the codes of the findings. */
35
+ const FINDING_CODES = [
36
+ "number-not-finite",
37
+ "number-too-large",
38
+ "id-duplicate",
39
+ "size-not-positive",
40
+ "wall-length",
41
+ "wall-short",
42
+ "wall-overlap",
43
+ "opening-wall",
44
+ "opening-range",
45
+ "opening-height",
46
+ "opening-overlap",
47
+ "outlet-wall",
48
+ "outlet-circuit",
49
+ "outlet-range",
50
+ "outlet-in-opening",
51
+ "floor-ring",
52
+ "circuit-limit",
53
+ "object-parent",
54
+ "object-cycle",
55
+ "object-outlet",
56
+ "object-outside",
57
+ "object-overlap",
58
+ "object-in-wall",
59
+ "load-circuit",
60
+ "load-watts"
61
+ ];
62
+ /** A length in meters at this value or less is 0 for the checks: a size must be above it. */
63
+ const SMALL = 1e-6;
64
+ /** This function gives a number with 3 decimals at most. */
65
+ function show(value) {
66
+ return String(Math.round(value * 1e3) / 1e3);
67
+ }
68
+ /** This function tells if a value is a number that is not finite, or if it holds such a number. */
69
+ function holdsBadNumber(value) {
70
+ if (typeof value === "number") return !Number.isFinite(value);
71
+ if (Array.isArray(value)) return value.some((item) => holdsBadNumber(item));
72
+ if (typeof value === "object" && value !== null) return Object.values(value).some((item) => holdsBadNumber(item));
73
+ return false;
74
+ }
75
+ /** This function tells if a value is a finite number with a size above a limit, or if it holds such a number. */
76
+ function holdsLargeNumber(value, limit) {
77
+ if (typeof value === "number") return Number.isFinite(value) && Math.abs(value) > limit;
78
+ if (Array.isArray(value)) return value.some((item) => holdsLargeNumber(item, limit));
79
+ if (typeof value === "object" && value !== null) return Object.values(value).some((item) => holdsLargeNumber(item, limit));
80
+ return false;
81
+ }
82
+ /** This function gives each value that a list has two or more times. */
83
+ function repeated(ids) {
84
+ const seen = /* @__PURE__ */ new Set();
85
+ const twice = /* @__PURE__ */ new Set();
86
+ for (const id of ids) {
87
+ if (seen.has(id)) twice.add(id);
88
+ seen.add(id);
89
+ }
90
+ return [...twice];
91
+ }
92
+ /**
93
+ * This function gives each fault of a room record. A room with no finding of the level `error` gives a full model.
94
+ *
95
+ * The function examines the meaning of the record: for example, an opening must be in its wall. The schema examines the form of the record.
96
+ */
97
+ function checkRoom(room, options = {}) {
98
+ const findings = [];
99
+ const error = (code, record, at, message, other) => {
100
+ findings.push({
101
+ level: "error",
102
+ code,
103
+ record,
104
+ at,
105
+ message,
106
+ ...other === void 0 ? {} : { other }
107
+ });
108
+ };
109
+ const warning = (code, record, at, message, other) => {
110
+ findings.push({
111
+ level: "warning",
112
+ code,
113
+ record,
114
+ at,
115
+ message,
116
+ ...other === void 0 ? {} : { other }
117
+ });
118
+ };
119
+ const scale = metersPer(room.unit);
120
+ /** The largest length of the model, in the unit of the room. */
121
+ const largest = LARGEST_LENGTH / scale;
122
+ /** This function tells if a size of the record is 0 for the checks. */
123
+ const none = (size) => !(size * scale > SMALL);
124
+ const openings = room.openings ?? [];
125
+ const outlets = room.outlets ?? [];
126
+ const circuits = room.circuits ?? [];
127
+ const floors = room.floors ?? [];
128
+ if (holdsBadNumber([room.height, room.wallThickness])) error("number-not-finite", "room", "", "The height or the wall thickness of the room is not a finite number.");
129
+ if (holdsLargeNumber([room.height, room.wallThickness], largest)) error("number-too-large", "room", "", `The height or the wall thickness of the room is above 1 000 km, the largest length of the model.`);
130
+ const lists = [
131
+ ["wall", room.walls],
132
+ ["opening", openings],
133
+ ["floor", floors],
134
+ ["outlet", outlets],
135
+ ["circuit", circuits]
136
+ ];
137
+ for (const [record, list] of lists) {
138
+ for (const item of list) {
139
+ if (holdsBadNumber(item)) error("number-not-finite", record, item.id, `A number of the ${record} "${item.id}" is not finite.`);
140
+ if (record !== "circuit" && holdsLargeNumber(item, largest)) error("number-too-large", record, item.id, `A length of the ${record} "${item.id}" is above 1 000 km, the largest length of the model.`);
141
+ }
142
+ for (const id of repeated(list.map((item) => item.id))) error("id-duplicate", record, id, `Two or more records of the kind ${record} have the id "${id}".`);
143
+ }
144
+ if (none(room.height)) error("size-not-positive", "room", "", `The height of the room is ${show(room.height)}. It must be above 0.`);
145
+ if (none(room.wallThickness)) error("size-not-positive", "room", "", `The wall thickness of the room is ${show(room.wallThickness)}. It must be above 0.`);
146
+ const frames = wallFrames(room);
147
+ const footprints = wallFootprints(frames, options.joins);
148
+ frames.forEach((frame, index) => {
149
+ const wall = room.walls[index];
150
+ if (wall.thickness !== void 0 && none(wall.thickness)) error("size-not-positive", "wall", wall.id, `The thickness of the wall "${wall.id}" is ${show(wall.thickness)}. It must be above 0.`);
151
+ if (wall.height !== void 0 && none(wall.height)) error("size-not-positive", "wall", wall.id, `The height of the wall "${wall.id}" is ${show(wall.height)}. It must be above 0.`);
152
+ const [clearFrom, clearTo] = footprints[index].clear;
153
+ if (!(frame.length > SMALL)) error("wall-length", "wall", wall.id, `The wall "${wall.id}" has the length 0: its two ends are one point.`);
154
+ else if (wallHasOutline(frame) && !(clearTo - clearFrom > SMALL)) warning("wall-short", "wall", wall.id, `The wall "${wall.id}" is too short for the corners at its ends: no part of it has its full thickness.`);
155
+ });
156
+ for (let i = 0; i < footprints.length; i++) for (let j = i + 1; j < footprints.length; j++) {
157
+ const a = footprints[i];
158
+ const b = footprints[j];
159
+ if (a.ring.length < 3 || b.ring.length < 3 || !(convexOverlap(a.ring, b.ring) > SMALL)) continue;
160
+ warning("wall-overlap", "wall", a.wall, `The walls "${a.wall}" and "${b.wall}" overlap. Walls connect only at their ends: divide a wall at the point where a different wall crosses it.`);
161
+ }
162
+ const frameOf = new Map(frames.map((frame, index) => [frame.id, {
163
+ frame,
164
+ footprint: footprints[index]
165
+ }]));
166
+ const holes = /* @__PURE__ */ new Map();
167
+ for (const opening of openings) {
168
+ const found = frameOf.get(opening.wall);
169
+ if (found === void 0) {
170
+ error("opening-wall", "opening", opening.id, `The opening "${opening.id}" is on the wall "${opening.wall}", which the room does not have.`);
171
+ continue;
172
+ }
173
+ if (none(opening.width)) error("size-not-positive", "opening", opening.id, `The width of the opening "${opening.id}" is ${show(opening.width)}. It must be above 0.`);
174
+ if (none(opening.height)) error("size-not-positive", "opening", opening.id, `The height of the opening "${opening.id}" is ${show(opening.height)}. It must be above 0.`);
175
+ if (none(opening.width) || none(opening.height)) continue;
176
+ const from = opening.offset * scale;
177
+ const to = (opening.offset + opening.width) * scale;
178
+ const sill = (opening.sill ?? 0) * scale;
179
+ const top = sill + opening.height * scale;
180
+ const [clearFrom, clearTo] = found.footprint.clear;
181
+ if (from < clearFrom - SMALL || to > clearTo + SMALL) error("opening-range", "opening", opening.id, `The opening "${opening.id}" is from ${show(opening.offset)} to ${show(opening.offset + opening.width)} along the wall "${opening.wall}". The straight part of that wall is from ${show(clearFrom / scale)} to ${show(clearTo / scale)}.`);
182
+ if (sill < 0 || top > found.frame.height + SMALL) error("opening-height", "opening", opening.id, `The opening "${opening.id}" is from the height ${show(sill / scale)} to ${show(top / scale)}. The wall "${opening.wall}" is from 0 to ${show(found.frame.height / scale)}.`);
183
+ const list = holes.get(opening.wall) ?? [];
184
+ list.push({
185
+ id: opening.id,
186
+ from,
187
+ to,
188
+ sill,
189
+ top
190
+ });
191
+ holes.set(opening.wall, list);
192
+ }
193
+ for (const [wall, list] of holes) {
194
+ list.sort((a, b) => a.from - b.from);
195
+ for (let i = 1; i < list.length; i++) {
196
+ const before = list[i - 1];
197
+ const hole = list[i];
198
+ if (hole.from < before.to - SMALL) error("opening-overlap", "opening", hole.id, `The openings "${before.id}" and "${hole.id}" of the wall "${wall}" overlap.`, before.id);
199
+ }
200
+ }
201
+ const circuitIds = new Set(circuits.map((circuit) => circuit.id));
202
+ for (const outlet of outlets) {
203
+ if (outlet.circuit !== void 0 && !circuitIds.has(outlet.circuit)) error("outlet-circuit", "outlet", outlet.id, `The outlet "${outlet.id}" is on the circuit "${outlet.circuit}", which the room does not have.`);
204
+ const found = frameOf.get(outlet.wall);
205
+ if (found === void 0) {
206
+ error("outlet-wall", "outlet", outlet.id, `The outlet "${outlet.id}" is on the wall "${outlet.wall}", which the room does not have.`);
207
+ continue;
208
+ }
209
+ const along = outlet.offset * scale;
210
+ const height = outlet.height * scale;
211
+ if (!(along >= 0 && along <= found.frame.length + SMALL && height >= 0 && height <= found.frame.height + SMALL)) {
212
+ error("outlet-range", "outlet", outlet.id, `The outlet "${outlet.id}" is at ${show(outlet.offset)} along the wall "${outlet.wall}" and at the height ${show(outlet.height)}. The wall has the length ${show(found.frame.length / scale)} and the height ${show(found.frame.height / scale)}.`);
213
+ continue;
214
+ }
215
+ const hole = (holes.get(outlet.wall) ?? []).find((item) => along > item.from && along < item.to && height > item.sill && height < item.top);
216
+ if (hole !== void 0) warning("outlet-in-opening", "outlet", outlet.id, `The outlet "${outlet.id}" is in the opening "${hole.id}" of the wall "${outlet.wall}".`, hole.id);
217
+ }
218
+ for (const floor of floors) if (floor.ring.length < 3 || !(regionArea({
219
+ kind: "polygon",
220
+ points: floor.ring
221
+ }) * scale * scale > SMALL * SMALL)) error("floor-ring", "floor", floor.id, `The floor "${floor.id}" has no area. Its ring must have 3 or more corners that are not on one line.`);
222
+ for (const circuit of circuits) {
223
+ if (!(circuit.limit > 0)) error("circuit-limit", "circuit", circuit.id, `The limit of the circuit "${circuit.id}" is ${show(circuit.limit)} W. It must be above 0.`);
224
+ if (circuit.breaker !== void 0 && !(circuit.breaker > 0)) error("circuit-limit", "circuit", circuit.id, `The breaker of the circuit "${circuit.id}" is ${show(circuit.breaker)} A. It must be above 0.`);
225
+ if (circuit.voltage !== void 0 && !(circuit.voltage > 0)) error("circuit-limit", "circuit", circuit.id, `The voltage of the circuit "${circuit.id}" is ${show(circuit.voltage)} V. It must be above 0.`);
226
+ }
227
+ return findings;
228
+ }
229
+ /** This function gives the extent of a placed object from its transform. The turn of each object is about the vertical axis, so the outline is a rectangle. */
230
+ function extentOf(object, transform, scale) {
231
+ const w = object.size[0] * scale / 2;
232
+ const h = object.size[1] * scale / 2;
233
+ return {
234
+ object,
235
+ ring: [
236
+ [0 - w, 0 - h],
237
+ [w, 0 - h],
238
+ [w, h],
239
+ [0 - w, h]
240
+ ].map(([x, y]) => {
241
+ const point = transformPoint3(transform, {
242
+ x,
243
+ y,
244
+ z: 0
245
+ });
246
+ return [point.x, point.y];
247
+ }),
248
+ z: transform.position.z,
249
+ top: transform.position.z + object.size[2] * scale
250
+ };
251
+ }
252
+ /**
253
+ * This function gives each fault of a scene record: the faults of its room, then the faults of its placed objects and its loads.
254
+ * A scene with no finding of the level `error` gives a full model.
255
+ */
256
+ function checkScene(scene, options = {}) {
257
+ const findings = [...checkRoom(scene.room, options)];
258
+ const error = (code, record, at, message, other) => {
259
+ findings.push({
260
+ level: "error",
261
+ code,
262
+ record,
263
+ at,
264
+ message,
265
+ ...other === void 0 ? {} : { other }
266
+ });
267
+ };
268
+ const warning = (code, record, at, message, other) => {
269
+ findings.push({
270
+ level: "warning",
271
+ code,
272
+ record,
273
+ at,
274
+ message,
275
+ ...other === void 0 ? {} : { other }
276
+ });
277
+ };
278
+ const room = scene.room;
279
+ const scale = metersPer(room.unit);
280
+ const objects = scene.objects ?? [];
281
+ const byId = new Map(objects.map((object) => [object.id, object]));
282
+ const outletIds = new Set((room.outlets ?? []).map((outlet) => outlet.id));
283
+ const circuitIds = new Set((room.circuits ?? []).map((circuit) => circuit.id));
284
+ /** This function tells if each size of an object is above 0 for the checks. */
285
+ const hasSize = (object) => object.size.every((size) => size * scale > SMALL);
286
+ for (const id of repeated(objects.map((object) => object.id))) error("id-duplicate", "object", id, `Two or more records of the kind object have the id "${id}".`);
287
+ /** The objects that hold an object, from its parent up. A loop of parents gives `undefined`. */
288
+ const holders = (object) => {
289
+ const seen = /* @__PURE__ */ new Set([object.id]);
290
+ const above = /* @__PURE__ */ new Set();
291
+ let parent = object.parent === void 0 ? void 0 : byId.get(object.parent);
292
+ while (parent !== void 0) {
293
+ if (seen.has(parent.id)) return void 0;
294
+ seen.add(parent.id);
295
+ above.add(parent.id);
296
+ parent = parent.parent === void 0 ? void 0 : byId.get(parent.parent);
297
+ }
298
+ return above;
299
+ };
300
+ for (const object of objects) {
301
+ if (holdsBadNumber(object)) error("number-not-finite", "object", object.id, `A number of the object "${object.id}" is not finite.`);
302
+ if (holdsLargeNumber([
303
+ object.size,
304
+ object.at,
305
+ object.lift
306
+ ], 1e6 / scale)) error("number-too-large", "object", object.id, `A length of the object "${object.id}" is above 1 000 km, the largest length of the model.`);
307
+ if (!hasSize(object)) error("size-not-positive", "object", object.id, `The size of the object "${object.id}" is ${object.size.map(show).join(" by ")}. Each number must be above 0.`);
308
+ if (object.parent !== void 0 && !byId.has(object.parent)) error("object-parent", "object", object.id, `The object "${object.id}" is on the object "${object.parent}", which the scene does not have.`, object.parent);
309
+ else if (holders(object) === void 0) error("object-cycle", "object", object.id, `The parents of the object "${object.id}" make a loop.`);
310
+ if (object.outlet !== void 0 && !outletIds.has(object.outlet)) error("object-outlet", "object", object.id, `The object "${object.id}" uses the outlet "${object.outlet}", which the room does not have.`, object.outlet);
311
+ }
312
+ const transforms = objectTransforms(scene);
313
+ const extents = [];
314
+ for (const object of objects) {
315
+ const transform = transforms.get(object.id);
316
+ if (transform !== void 0 && hasSize(object)) extents.push(extentOf(object, transform, scale));
317
+ }
318
+ const floors = (room.floors ?? []).filter((floor) => floor.ring.length >= 3).map((floor) => floor.ring.map(([x, y]) => [x * scale, y * scale]));
319
+ const frames = wallFrames(room);
320
+ const footprints = wallFootprints(frames, options.joins);
321
+ for (const extent of extents) {
322
+ const { object } = extent;
323
+ const transform = transforms.get(object.id);
324
+ if (object.parent === void 0 && floors.length > 0 && !floors.some((ring) => pointInRing(transform.position.x, transform.position.y, ring))) warning("object-outside", "object", object.id, `The center of the object "${object.id}" is not on a floor of the room.`);
325
+ footprints.forEach((footprint, index) => {
326
+ if (footprint.ring.length < 3 || !(extent.z < frames[index].height - SMALL) || !(convexOverlap(footprint.ring, extent.ring) > SMALL)) return;
327
+ warning("object-in-wall", "object", object.id, `The object "${object.id}" overlaps the wall "${footprint.wall}".`, footprint.wall);
328
+ });
329
+ }
330
+ for (let i = 0; i < extents.length; i++) for (let j = i + 1; j < extents.length; j++) {
331
+ const a = extents[i];
332
+ const b = extents[j];
333
+ if (holders(a.object)?.has(b.object.id) === true || holders(b.object)?.has(a.object.id) === true) continue;
334
+ if (!(Math.min(a.top, b.top) - Math.max(a.z, b.z) > SMALL) || !(convexOverlap(a.ring, b.ring) > SMALL)) continue;
335
+ warning("object-overlap", "object", a.object.id, `The objects "${a.object.id}" and "${b.object.id}" overlap.`, b.object.id);
336
+ }
337
+ for (const load of scene.loads ?? []) {
338
+ if (!circuitIds.has(load.circuit)) error("load-circuit", "load", load.circuit, `A load is on the circuit "${load.circuit}", which the room does not have.`);
339
+ if (!(load.watts >= 0 && Number.isFinite(load.watts))) error("load-watts", "load", load.circuit, `A load of the circuit "${load.circuit}" is ${show(load.watts)} W. It must be a finite number, 0 or more.`);
340
+ }
341
+ return findings;
342
+ }
343
+ /** These are the codes of the faults of an anchor. */
344
+ const ANCHOR_CODES = [
345
+ "anchor-not-finite",
346
+ "anchor-wall",
347
+ "anchor-object",
348
+ "anchor-floor",
349
+ "anchor-range",
350
+ "anchor-direction",
351
+ "anchor-in-opening",
352
+ "anchor-outside"
353
+ ];
354
+ /**
355
+ * This function gives the faults of an anchor in the space of a scene. `name` starts each message.
356
+ * An error tells that the anchor has no position. A warning tells a fault that the model can show.
357
+ */
358
+ function checkAnchor(anchor, space, name = "The anchor") {
359
+ const error = (code, message) => [{
360
+ level: "error",
361
+ code,
362
+ message: `${name} ${message}`
363
+ }];
364
+ const { scene, scale } = space;
365
+ if (holdsBadNumber(anchor)) return error("anchor-not-finite", "has a number that is not finite.");
366
+ if (anchor.on === "wall") {
367
+ const wall = space.wall(anchor.wall);
368
+ if (wall === void 0) return error("anchor-wall", `is on the wall "${anchor.wall}", which the room does not have.`);
369
+ const along = anchor.offset * scale;
370
+ const height = anchor.height * scale;
371
+ 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)}.`);
372
+ const hole = (scene.room.openings ?? []).find((opening) => {
373
+ const sill = (opening.sill ?? 0) * scale;
374
+ return opening.wall === anchor.wall && along > opening.offset * scale && along < (opening.offset + opening.width) * scale && height > sill && height < sill + opening.height * scale;
375
+ });
376
+ return hole === void 0 ? [] : [{
377
+ level: "warning",
378
+ code: "anchor-in-opening",
379
+ message: `${name} is in the opening "${hole.id}" of the wall "${anchor.wall}".`,
380
+ other: hole.id
381
+ }];
382
+ }
383
+ if (anchor.on === "object") {
384
+ const object = space.object(anchor.object);
385
+ if (object === void 0) return error("anchor-object", `is on the object "${anchor.object}", which the scene does not have.`);
386
+ if (space.transform(anchor.object) === void 0) return error("anchor-object", `is on the object "${anchor.object}", which has no place in the room.`);
387
+ const small = SMALL / scale;
388
+ if (anchor.at !== void 0) {
389
+ const [x, y, z] = anchor.at;
390
+ const [width, depth, height] = object.size;
391
+ 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 ")}.`);
392
+ }
393
+ if (anchor.out !== void 0) {
394
+ const [x, y, z] = anchor.out;
395
+ if (!(length3({
396
+ x,
397
+ y,
398
+ z
399
+ }) > 0)) return error("anchor-direction", "has a direction with the length 0. A direction must have a length above 0.");
400
+ }
401
+ return [];
402
+ }
403
+ const [x, y] = anchor.at;
404
+ if (!lengthsInRange(x * scale, y * scale)) return error("anchor-range", "is at a point above 1 000 km, the largest length of the model.");
405
+ const word = anchor.on === "floor" ? "on" : "above";
406
+ const floors = scene.room.floors ?? [];
407
+ if (anchor.floor !== void 0) {
408
+ const floor = floors.find((item) => item.id === anchor.floor);
409
+ if (floor === void 0) return error("anchor-floor", `is ${word} the floor "${anchor.floor}", which the room does not have.`);
410
+ return pointInRing(x, y, floor.ring) ? [] : [{
411
+ level: "warning",
412
+ code: "anchor-outside",
413
+ message: `${name} is not ${word} the floor "${anchor.floor}".`
414
+ }];
415
+ }
416
+ if (floors.length === 0 || floors.some((floor) => pointInRing(x, y, floor.ring))) return [];
417
+ return [{
418
+ level: "warning",
419
+ code: "anchor-outside",
420
+ message: `${name} is not ${word} a floor of the room.`
421
+ }];
422
+ }
423
+ // src/anchors.ts
424
+ /** These are the surfaces that an anchor can be on. */
425
+ const ANCHOR_SURFACES = [
426
+ "wall",
427
+ "floor",
428
+ "ceiling",
429
+ "object"
430
+ ];
431
+ const UP = {
432
+ x: 0,
433
+ y: 0,
434
+ z: 1
435
+ };
436
+ const DOWN = {
437
+ x: 0,
438
+ y: 0,
439
+ z: -1
440
+ };
441
+ /** This function tells if each value of a point is a length in the range of the model. */
442
+ function inRange(point) {
443
+ return Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z) && lengthsInRange(point.x, point.y, point.z);
444
+ }
445
+ /** This function gives a point with no negative zero. JSON has no negative zero, so a frame goes through JSON with no change. */
446
+ function plainPoint(point) {
447
+ return {
448
+ x: point.x + 0,
449
+ y: point.y + 0,
450
+ z: point.z + 0
451
+ };
452
+ }
453
+ /** This function gives the space of a scene. The transforms of the objects are calculated one time, at the first use. */
454
+ function sceneSpace(scene) {
455
+ const scale = metersPer(scene.room.unit);
456
+ const walls = new Map(wallFrames(scene.room).map((frame) => [frame.id, frame]));
457
+ const objects = new Map((scene.objects ?? []).map((object) => [object.id, object]));
458
+ let transforms;
459
+ const transform = (id) => {
460
+ transforms ??= objectTransforms(scene);
461
+ return transforms.get(id);
462
+ };
463
+ const frame = (anchor) => {
464
+ let found;
465
+ if (anchor.on === "wall") {
466
+ const wall = walls.get(anchor.wall);
467
+ if (wall === void 0) return void 0;
468
+ const point = wallPoint(wall, anchor.offset * scale, anchor.face === "left" ? wall.leftOffset : wall.rightOffset);
469
+ const sign = anchor.face === "left" ? 1 : -1;
470
+ found = {
471
+ at: {
472
+ x: point.x,
473
+ y: point.y,
474
+ z: anchor.height * scale
475
+ },
476
+ out: {
477
+ x: wall.left.x * sign,
478
+ y: wall.left.y * sign,
479
+ z: 0
480
+ }
481
+ };
482
+ } else if (anchor.on === "floor") found = {
483
+ at: {
484
+ x: anchor.at[0] * scale,
485
+ y: anchor.at[1] * scale,
486
+ z: 0
487
+ },
488
+ out: UP
489
+ };
490
+ else if (anchor.on === "ceiling") found = {
491
+ at: {
492
+ x: anchor.at[0] * scale,
493
+ y: anchor.at[1] * scale,
494
+ z: scene.room.height * scale
495
+ },
496
+ out: DOWN
497
+ };
498
+ else {
499
+ const object = objects.get(anchor.object);
500
+ const place = transform(anchor.object);
501
+ if (object === void 0 || place === void 0) return void 0;
502
+ const [x, y, z] = anchor.at ?? [
503
+ 0,
504
+ 0,
505
+ object.size[2]
506
+ ];
507
+ const [ox, oy, oz] = anchor.out ?? [
508
+ 0,
509
+ 0,
510
+ 1
511
+ ];
512
+ const out = {
513
+ x: ox,
514
+ y: oy,
515
+ z: oz
516
+ };
517
+ const size = length3(out);
518
+ if (!(size > 0) || !Number.isFinite(size)) return void 0;
519
+ found = {
520
+ at: transformPoint3(place, {
521
+ x: x * scale,
522
+ y: y * scale,
523
+ z: z * scale
524
+ }),
525
+ out: rotatePoint3(place.rotation, scalePoint3(out, 1 / size))
526
+ };
527
+ }
528
+ const plain = {
529
+ at: plainPoint(found.at),
530
+ out: plainPoint(found.out)
531
+ };
532
+ return inRange(plain.at) && inRange(plain.out) ? plain : void 0;
533
+ };
534
+ return {
535
+ scene,
536
+ scale,
537
+ wall: (id) => walls.get(id),
538
+ object: (id) => objects.get(id),
539
+ transform,
540
+ frame
541
+ };
542
+ }
543
+ // src/order.ts
544
+ /** This function compares two texts by their code points, so the order does not change with the language of a computer. */
545
+ function compareText(a, b) {
546
+ return a < b ? -1 : a > b ? 1 : 0;
547
+ }
548
+ // src/layers.ts
549
+ /** These are the codes of the faults of a layer that the core finds. */
550
+ const LAYER_CODES = [
551
+ "layer-name",
552
+ "layer-unknown",
553
+ "layer-form"
554
+ ];
555
+ /** This function gives the add-on of each schema name. The first add-on of a name is used. */
556
+ function addOnsByName(addOns) {
557
+ const byName = /* @__PURE__ */ new Map();
558
+ for (const addOn of addOns) if (!byName.has(addOn.schema)) byName.set(addOn.schema, addOn);
559
+ return byName;
560
+ }
561
+ /** 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. */
562
+ function readLayer(scene, addOn) {
563
+ const layers = scene.layers ?? {};
564
+ return Object.hasOwn(layers, addOn.schema) ? addOn.parse(layers[addOn.schema]) : void 0;
565
+ }
566
+ /**
567
+ * This function gives the findings of the layers of a scene, with a list of add-ons.
568
+ * 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.
569
+ * The findings are in the order of the layer keys, then of the record keys. Thus equal inputs give equal findings.
570
+ *
571
+ * The name of the record of a finding is `recordName(finding.layer, finding.at)`, so a finding selects its mark.
572
+ * `checkScene` examines the core, and this function examines the layers.
573
+ */
574
+ function checkLayers(scene, addOns) {
575
+ const byName = addOnsByName(addOns);
576
+ const layers = scene.layers ?? {};
577
+ const findings = [];
578
+ let space;
579
+ for (const name of Object.keys(layers).sort(compareText)) {
580
+ if (!isLayerName(name)) {
581
+ findings.push({
582
+ level: "error",
583
+ code: "layer-name",
584
+ layer: name,
585
+ at: "",
586
+ message: `The layer "${name}" has a name that is not a word, a slash and a version, for example "electrical/1".`
587
+ });
588
+ continue;
589
+ }
590
+ const addOn = byName.get(name);
591
+ if (addOn === void 0) {
592
+ findings.push({
593
+ level: "warning",
594
+ code: "layer-unknown",
595
+ layer: name,
596
+ at: "",
597
+ message: `The scene has the layer "${name}", and no add-on of the check reads it. The scene keeps the layer.`
598
+ });
599
+ continue;
600
+ }
601
+ const read = addOn.parse(layers[name]);
602
+ if (!read.ok) {
603
+ for (const message of read.errors) findings.push({
604
+ level: "error",
605
+ code: "layer-form",
606
+ layer: name,
607
+ at: "",
608
+ message
609
+ });
610
+ continue;
611
+ }
612
+ space ??= sceneSpace(scene);
613
+ const own = [];
614
+ 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({
615
+ ...fault,
616
+ layer: name,
617
+ at: key
618
+ });
619
+ for (const fault of addOn.check(read.layer, space)) own.push({
620
+ ...fault,
621
+ layer: name
622
+ });
623
+ own.sort((a, b) => compareText(a.at, b.at));
624
+ findings.push(...own);
625
+ }
626
+ return findings;
627
+ }
628
+ export { ANCHOR_SURFACES as a, FINDING_CODES as c, checkAnchor as d, checkRoom as f, recordName as h, compareText as i, FINDING_LEVELS as l, parseRecordName as m, checkLayers as n, sceneSpace as o, checkScene as p, readLayer as r, ANCHOR_CODES as s, LAYER_CODES as t, RECORD_KINDS as u };
629
+
630
+ //# sourceMappingURL=layers-bgJ3OTId.js.map