@mark1russell7/room-view 0.1.0 → 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 +25 -1
- package/build/index.d.ts +174 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +308 -17
- package/build/index.js.map +1 -1
- package/build/{level-84nrw7oL.d.ts → level-Cgja5fXb.d.ts} +2 -2
- package/build/{level-84nrw7oL.d.ts.map → level-Cgja5fXb.d.ts.map} +1 -1
- package/build/{level-xTO7P1Fn.js → level-Cu8vgrwN.js} +9 -2
- package/build/level-Cu8vgrwN.js.map +1 -0
- package/build/{loads-H-VFEx6b.d.ts → loads-spBbQkb0.d.ts} +2 -2
- package/build/{loads-H-VFEx6b.d.ts.map → loads-spBbQkb0.d.ts.map} +1 -1
- package/build/{room-BUlXejkm.d.ts → room-x9FxGjGi.d.ts} +12 -2
- package/build/room-x9FxGjGi.d.ts.map +1 -0
- package/build/sample.d.ts +2 -2
- package/build/schema.d.ts +2 -2
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +3 -2
- package/build/schema.js.map +1 -1
- package/build/three.d.ts +2 -2
- package/package.json +1 -1
- package/build/level-xTO7P1Fn.js.map +0 -1
- package/build/room-BUlXejkm.d.ts.map +0 -1
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-
|
|
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",
|
|
@@ -146,22 +161,24 @@ function repeated(ids) {
|
|
|
146
161
|
*/
|
|
147
162
|
function checkRoom(room, options = {}) {
|
|
148
163
|
const findings = [];
|
|
149
|
-
const error = (code, record, at, message) => {
|
|
164
|
+
const error = (code, record, at, message, other) => {
|
|
150
165
|
findings.push({
|
|
151
166
|
level: "error",
|
|
152
167
|
code,
|
|
153
168
|
record,
|
|
154
169
|
at,
|
|
155
|
-
message
|
|
170
|
+
message,
|
|
171
|
+
...other === void 0 ? {} : { other }
|
|
156
172
|
});
|
|
157
173
|
};
|
|
158
|
-
const warning = (code, record, at, message) => {
|
|
174
|
+
const warning = (code, record, at, message, other) => {
|
|
159
175
|
findings.push({
|
|
160
176
|
level: "warning",
|
|
161
177
|
code,
|
|
162
178
|
record,
|
|
163
179
|
at,
|
|
164
|
-
message
|
|
180
|
+
message,
|
|
181
|
+
...other === void 0 ? {} : { other }
|
|
165
182
|
});
|
|
166
183
|
};
|
|
167
184
|
const scale = metersPer(room.unit);
|
|
@@ -243,7 +260,7 @@ function checkRoom(room, options = {}) {
|
|
|
243
260
|
for (let i = 1; i < list.length; i++) {
|
|
244
261
|
const before = list[i - 1];
|
|
245
262
|
const hole = list[i];
|
|
246
|
-
if (hole.from < before.to - SMALL) error("opening-overlap", "opening", hole.id, `The openings "${before.id}" and "${hole.id}" of the wall "${wall}" overlap
|
|
263
|
+
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);
|
|
247
264
|
}
|
|
248
265
|
}
|
|
249
266
|
const circuitIds = new Set(circuits.map((circuit) => circuit.id));
|
|
@@ -261,7 +278,7 @@ function checkRoom(room, options = {}) {
|
|
|
261
278
|
continue;
|
|
262
279
|
}
|
|
263
280
|
const hole = (holes.get(outlet.wall) ?? []).find((item) => along > item.from && along < item.to && height > item.sill && height < item.top);
|
|
264
|
-
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}"
|
|
281
|
+
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);
|
|
265
282
|
}
|
|
266
283
|
for (const floor of floors) if (floor.ring.length < 3 || !(regionArea({
|
|
267
284
|
kind: "polygon",
|
|
@@ -299,22 +316,24 @@ function extentOf(object, transform, scale) {
|
|
|
299
316
|
*/
|
|
300
317
|
function checkScene(scene, options = {}) {
|
|
301
318
|
const findings = [...checkRoom(scene.room, options)];
|
|
302
|
-
const error = (code, record, at, message) => {
|
|
319
|
+
const error = (code, record, at, message, other) => {
|
|
303
320
|
findings.push({
|
|
304
321
|
level: "error",
|
|
305
322
|
code,
|
|
306
323
|
record,
|
|
307
324
|
at,
|
|
308
|
-
message
|
|
325
|
+
message,
|
|
326
|
+
...other === void 0 ? {} : { other }
|
|
309
327
|
});
|
|
310
328
|
};
|
|
311
|
-
const warning = (code, record, at, message) => {
|
|
329
|
+
const warning = (code, record, at, message, other) => {
|
|
312
330
|
findings.push({
|
|
313
331
|
level: "warning",
|
|
314
332
|
code,
|
|
315
333
|
record,
|
|
316
334
|
at,
|
|
317
|
-
message
|
|
335
|
+
message,
|
|
336
|
+
...other === void 0 ? {} : { other }
|
|
318
337
|
});
|
|
319
338
|
};
|
|
320
339
|
const room = scene.room;
|
|
@@ -347,9 +366,9 @@ function checkScene(scene, options = {}) {
|
|
|
347
366
|
object.lift
|
|
348
367
|
], 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.`);
|
|
349
368
|
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.`);
|
|
350
|
-
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
|
|
369
|
+
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);
|
|
351
370
|
else if (holders(object) === void 0) error("object-cycle", "object", object.id, `The parents of the object "${object.id}" make a loop.`);
|
|
352
|
-
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
|
|
371
|
+
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);
|
|
353
372
|
}
|
|
354
373
|
const transforms = objectTransforms(scene);
|
|
355
374
|
const extents = [];
|
|
@@ -366,7 +385,7 @@ function checkScene(scene, options = {}) {
|
|
|
366
385
|
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.`);
|
|
367
386
|
footprints.forEach((footprint, index) => {
|
|
368
387
|
if (footprint.ring.length < 3 || !(extent.z < frames[index].height - SMALL) || !(convexOverlap(footprint.ring, extent.ring) > SMALL)) return;
|
|
369
|
-
warning("object-in-wall", "object", object.id, `The object "${object.id}" overlaps the wall "${footprint.wall}"
|
|
388
|
+
warning("object-in-wall", "object", object.id, `The object "${object.id}" overlaps the wall "${footprint.wall}".`, footprint.wall);
|
|
370
389
|
});
|
|
371
390
|
}
|
|
372
391
|
for (let i = 0; i < extents.length; i++) for (let j = i + 1; j < extents.length; j++) {
|
|
@@ -374,7 +393,7 @@ function checkScene(scene, options = {}) {
|
|
|
374
393
|
const b = extents[j];
|
|
375
394
|
if (holders(a.object)?.has(b.object.id) === true || holders(b.object)?.has(a.object.id) === true) continue;
|
|
376
395
|
if (!(Math.min(a.top, b.top) - Math.max(a.z, b.z) > SMALL) || !(convexOverlap(a.ring, b.ring) > SMALL)) continue;
|
|
377
|
-
warning("object-overlap", "object", a.object.id, `The objects "${a.object.id}" and "${b.object.id}" overlap
|
|
396
|
+
warning("object-overlap", "object", a.object.id, `The objects "${a.object.id}" and "${b.object.id}" overlap.`, b.object.id);
|
|
378
397
|
}
|
|
379
398
|
for (const load of scene.loads ?? []) {
|
|
380
399
|
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.`);
|
|
@@ -382,6 +401,278 @@ function checkScene(scene, options = {}) {
|
|
|
382
401
|
}
|
|
383
402
|
return findings;
|
|
384
403
|
}
|
|
385
|
-
|
|
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 };
|
|
386
677
|
|
|
387
678
|
//# sourceMappingURL=index.js.map
|