@mark1russell7/room-view 0.2.0 → 0.2.1

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.
@@ -1,7 +1,567 @@
1
- import { _ as wallPoint, g as wallHasOutline, h as wallFrames, m as wallFootprints, s as objectTransforms } from "./solids-BKb-izIP.js";
2
1
  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";
2
+ import { boundsOf3, box3Corners, box3Volume, clipRing, composeTransforms3, convexOverlap, length3, pointInRing, regionArea, rotatePoint3, rotationAbout, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
3
+ // src/frames.ts
4
+ /** This function gives the frame of one wall. `scale` is the length of the unit of the room in meters. */
5
+ function frameOf(room, wall, scale) {
6
+ const start = {
7
+ x: wall.from[0] * scale,
8
+ y: wall.from[1] * scale
9
+ };
10
+ const end = {
11
+ x: wall.to[0] * scale,
12
+ y: wall.to[1] * scale
13
+ };
14
+ const length = Math.hypot(end.x - start.x, end.y - start.y);
15
+ const along = length > 0 && Number.isFinite(length) ? {
16
+ x: (end.x - start.x) / length,
17
+ y: (end.y - start.y) / length
18
+ } : {
19
+ x: 1,
20
+ y: 0
21
+ };
22
+ const thickness = (wall.thickness ?? room.wallThickness) * scale;
23
+ const side = wall.side ?? "center";
24
+ const leftOffset = side === "left" ? thickness : side === "right" ? 0 : thickness / 2;
25
+ return {
26
+ id: wall.id,
27
+ start,
28
+ end,
29
+ along,
30
+ left: {
31
+ x: 0 - along.y,
32
+ y: along.x
33
+ },
34
+ length,
35
+ thickness,
36
+ height: (wall.height ?? room.height) * scale,
37
+ leftOffset,
38
+ rightOffset: leftOffset - thickness
39
+ };
40
+ }
41
+ /** This function gives the frame of each wall of a room, in the sequence of the walls. */
42
+ function wallFrames(room) {
43
+ const scale = metersPer(room.unit);
44
+ return room.walls.map((wall) => frameOf(room, wall, scale));
45
+ }
46
+ /**
47
+ * This function tells if a wall has an outline in the plan. Its ends and its thickness must be lengths in the range of the model,
48
+ * and its length and its thickness must be above 0. Only such a wall makes a corner, and the model makes only such a wall.
49
+ */
50
+ function wallHasOutline(frame) {
51
+ return lengthsInRange(frame.start.x, frame.start.y, frame.end.x, frame.end.y, frame.thickness) && frame.length > 0 && frame.thickness > 0;
52
+ }
53
+ /** This function gives the point of the plan at a distance along a wall and a distance across it, in meters. */
54
+ function wallPoint(frame, along, across) {
55
+ return {
56
+ x: frame.start.x + frame.along.x * along + frame.left.x * across,
57
+ y: frame.start.y + frame.along.y * along + frame.left.y * across
58
+ };
59
+ }
60
+ /**
61
+ * This function gives the transform from the frame of a wall to the room.
62
+ * In the frame of a wall, x is the distance along the wall and y is the distance across it. The height above the floor is z.
63
+ */
64
+ function wallTransform(frame) {
65
+ return {
66
+ position: {
67
+ x: frame.start.x,
68
+ y: frame.start.y,
69
+ z: 0
70
+ },
71
+ rotation: rotationAbout({
72
+ x: 0,
73
+ y: 0,
74
+ z: 1
75
+ }, Math.atan2(frame.along.y, frame.along.x))
76
+ };
77
+ }
78
+ // src/joins.ts
79
+ /** The default distance in meters at which two ends of walls make one corner. */
80
+ const JOIN_TOLERANCE = 1e-6;
81
+ /** The default limit of a sharp corner, in thicknesses. */
82
+ const MITER_LIMIT = 4;
83
+ /** Two unit vectors with a cross product below this value are parallel. */
84
+ const PARALLEL = 1e-9;
85
+ /** A corner of an outline with a turn of this value or less is flat, so the outline does not need it. */
86
+ const FLAT = 1e-12;
87
+ /** Two points at this distance or less are one point. A point at this distance or less from a face of a wall is on the face. */
88
+ const SAME = 1e-9;
89
+ /** This function gives an option, or its default when the option has no value or a value that is not finite. */
90
+ function finiteOr(value, fallback) {
91
+ return value !== void 0 && Number.isFinite(value) ? value : fallback;
92
+ }
93
+ /** This function gives the point at a distance across from the point of an end. */
94
+ function across(end, distance) {
95
+ return {
96
+ x: end.point.x + end.normal.x * distance,
97
+ y: end.point.y + end.normal.y * distance
98
+ };
99
+ }
100
+ /** This function makes the two ends of a wall, with square points. */
101
+ function endsOf(frame) {
102
+ const back = {
103
+ x: 0 - frame.along.x,
104
+ y: 0 - frame.along.y
105
+ };
106
+ const right = {
107
+ x: 0 - frame.left.x,
108
+ y: 0 - frame.left.y
109
+ };
110
+ const make = (point, out, normal, high, low) => {
111
+ const end = {
112
+ point,
113
+ out,
114
+ normal,
115
+ high,
116
+ low,
117
+ thickness: frame.thickness,
118
+ highPoint: point,
119
+ lowPoint: point,
120
+ joined: false
121
+ };
122
+ end.highPoint = across(end, high);
123
+ end.lowPoint = across(end, low);
124
+ return end;
125
+ };
126
+ return [make(frame.start, frame.along, frame.left, frame.leftOffset, frame.rightOffset), make(frame.end, back, right, 0 - frame.rightOffset, 0 - frame.leftOffset)];
127
+ }
128
+ /** This function gives the point where two lines meet, or `undefined` for parallel lines. Each line has a point and a unit direction. */
129
+ function meet(p, d, q, e) {
130
+ const cross = d.x * e.y - d.y * e.x;
131
+ if (Math.abs(cross) < PARALLEL) return void 0;
132
+ const t = ((q.x - p.x) * e.y - (q.y - p.y) * e.x) / cross;
133
+ return {
134
+ x: p.x + d.x * t,
135
+ y: p.y + d.y * t
136
+ };
137
+ }
138
+ /**
139
+ * This function makes the corner of the ends at one point. The ends are in sequence counter-clockwise.
140
+ * The left face of each end meets the right face of the next end.
141
+ */
142
+ function joinEnds(ends, miterLimit) {
143
+ if (ends.length < 2) return;
144
+ for (let i = 0; i < ends.length; i++) {
145
+ const end = ends[i];
146
+ const next = ends[(i + 1) % ends.length];
147
+ end.joined = true;
148
+ const corner = meet(across(end, end.high), end.out, across(next, next.low), next.out);
149
+ if (corner === void 0) continue;
150
+ if (Math.hypot(corner.x - end.point.x, corner.y - end.point.y) > miterLimit * Math.max(end.thickness, next.thickness)) continue;
151
+ end.highPoint = corner;
152
+ next.lowPoint = corner;
153
+ }
154
+ }
155
+ /** This function gives the part of a ring to the left of the line from `p` to `q`. Two points at one position give the full ring. */
156
+ function leftOf(ring, p, q) {
157
+ const length = Math.hypot(q.x - p.x, q.y - p.y);
158
+ if (length <= SAME) return ring;
159
+ const dx = (q.x - p.x) / length;
160
+ const dy = (q.y - p.y) / length;
161
+ return clipRing(ring, dy, 0 - dx, dy * p.x - dx * p.y);
162
+ }
163
+ /**
164
+ * This function cuts the outline of a wall at one end. An end with no corner gets a square cut.
165
+ * An end with a corner keeps the part between the two lines from the point of the corner to the points of the two faces.
166
+ */
167
+ function cut(ring, end) {
168
+ if (!end.joined) return leftOf(ring, end.highPoint, end.lowPoint);
169
+ return leftOf(leftOf(ring, end.highPoint, end.point), end.point, end.lowPoint);
170
+ }
171
+ /** This function removes each corner of a convex outline that is flat or that is a copy of the corner before it. Fewer than 3 corners give an empty outline. */
172
+ function withoutFlat(points) {
173
+ const ring = [...points];
174
+ let changed = true;
175
+ while (changed && ring.length >= 3) {
176
+ changed = false;
177
+ for (let i = 0; i < ring.length && ring.length >= 3; i++) {
178
+ const [ax, ay] = ring[(i + ring.length - 1) % ring.length];
179
+ const [bx, by] = ring[i];
180
+ const [cx, cy] = ring[(i + 1) % ring.length];
181
+ if ((bx - ax) * (cy - by) - (by - ay) * (cx - bx) > FLAT) continue;
182
+ ring.splice(i, 1);
183
+ changed = true;
184
+ i--;
185
+ }
186
+ }
187
+ return ring.length >= 3 ? ring : [];
188
+ }
189
+ /** This function gives the range of the distances along a wall of the corners of an outline that are on one face. */
190
+ function faceRange(frame, ring, offset) {
191
+ let from = 1e400;
192
+ let to = -1e400;
193
+ for (const [x, y] of ring) {
194
+ const dx = x - frame.start.x;
195
+ const dy = y - frame.start.y;
196
+ if (Math.abs(dx * frame.left.x + dy * frame.left.y - offset) > SAME) continue;
197
+ const along = dx * frame.along.x + dy * frame.along.y;
198
+ from = Math.min(from, along);
199
+ to = Math.max(to, along);
200
+ }
201
+ return [from, to];
202
+ }
203
+ /**
204
+ * This function gives the outline of each wall in the plan, in the sequence of the frames.
205
+ *
206
+ * Two or more ends of walls at one point make a corner. At a corner, the faces of the walls that are adjacent meet at a point.
207
+ * Each wall ends at the lines from the corner to those points. Thus two walls make a miter, and the walls of a corner do not overlap.
208
+ * An end with no other end at its point is square. An end on the face of a different wall is also square: the two walls touch.
209
+ * A wall with no outline (`wallHasOutline`) gets an empty outline, and it makes no corner.
210
+ */
211
+ function wallFootprints(frames, options = {}) {
212
+ const tolerance = finiteOr(options.tolerance, JOIN_TOLERANCE);
213
+ const miterLimit = Math.max(finiteOr(options.miterLimit, 4), 0);
214
+ const pairs = frames.map((frame) => wallHasOutline(frame) ? endsOf(frame) : void 0);
215
+ const corners = [];
216
+ for (const pair of pairs) for (const end of pair ?? []) {
217
+ const corner = corners.find((ends) => Math.hypot(ends[0].point.x - end.point.x, ends[0].point.y - end.point.y) <= tolerance);
218
+ if (corner === void 0) corners.push([end]);
219
+ else corner.push(end);
220
+ }
221
+ for (const ends of corners) {
222
+ ends.sort((a, b) => Math.atan2(a.out.y, a.out.x) - Math.atan2(b.out.y, b.out.x));
223
+ joinEnds(ends, miterLimit);
224
+ }
225
+ const thickest = frames.reduce((most, frame, index) => pairs[index] === void 0 ? most : Math.max(most, frame.thickness), 0);
226
+ const reach = (miterLimit + 1) * thickest;
227
+ return frames.map((frame, index) => {
228
+ const pair = pairs[index];
229
+ if (pair === void 0) return {
230
+ wall: frame.id,
231
+ ring: [],
232
+ clear: [0, 0]
233
+ };
234
+ const ring = withoutFlat(cut(cut([
235
+ wallPoint(frame, 0 - reach, frame.rightOffset),
236
+ wallPoint(frame, frame.length + reach, frame.rightOffset),
237
+ wallPoint(frame, frame.length + reach, frame.leftOffset),
238
+ wallPoint(frame, 0 - reach, frame.leftOffset)
239
+ ].map((point) => [point.x, point.y]), pair[0]), pair[1]));
240
+ if (!ring.every(([x, y]) => Number.isFinite(x) && Number.isFinite(y))) return {
241
+ wall: frame.id,
242
+ ring: [],
243
+ clear: [0, 0]
244
+ };
245
+ const leftFace = faceRange(frame, ring, frame.leftOffset);
246
+ const rightFace = faceRange(frame, ring, frame.rightOffset);
247
+ const from = Math.max(leftFace[0], rightFace[0]);
248
+ const to = Math.min(leftFace[1], rightFace[1]);
249
+ return {
250
+ wall: frame.id,
251
+ ring,
252
+ clear: from < to ? [from, to] : [0, 0]
253
+ };
254
+ });
255
+ }
256
+ // src/solids.ts
257
+ /** These are the kinds of a solid. */
258
+ const SOLID_KINDS = [
259
+ "floor",
260
+ "wall",
261
+ "glass",
262
+ "outlet",
263
+ "object"
264
+ ];
265
+ /** The default depth of the floor, in meters. */
266
+ const FLOOR_DEPTH = .1;
267
+ /** The thickness of the glass of a window, in meters. */
268
+ const GLASS_THICKNESS = .02;
269
+ /** The size of the plate of an outlet, in meters. The plate of a duplex outlet in North America is 70 mm by 115 mm. */
270
+ const OUTLET_PLATE = {
271
+ width: .07,
272
+ height: .115,
273
+ depth: .012
274
+ };
275
+ /**
276
+ * The transform from the room, where the z axis points up, to a space where the y axis points up.
277
+ * The glTF format and three.js have the y axis up. The x axis stays, and the y axis of the plan becomes the negative z axis.
278
+ */
279
+ const TO_Y_UP = {
280
+ position: {
281
+ x: 0,
282
+ y: 0,
283
+ z: 0
284
+ },
285
+ rotation: {
286
+ x: -Math.SQRT1_2,
287
+ y: 0,
288
+ z: 0,
289
+ w: Math.SQRT1_2
290
+ }
291
+ };
292
+ /** A length in meters at this value or less is empty: the model does not make a part of this size. */
293
+ const EMPTY = 1e-9;
294
+ /** An area in square meters at this value or less is empty. */
295
+ const EMPTY_AREA = 1e-12;
296
+ /** This function gives an outline, or an empty ring when the outline has no area or a number that is not finite. */
297
+ function solidRing(ring) {
298
+ if (ring.length < 3 || !ring.every(([x, y]) => Number.isFinite(x) && Number.isFinite(y))) return [];
299
+ return regionArea({
300
+ kind: "polygon",
301
+ points: ring
302
+ }) > EMPTY_AREA ? ring : [];
303
+ }
304
+ /** This function tells if the model makes a wall. Such a wall has an outline in the plan, and its height is above 0 and in the range of the model. */
305
+ function isMade(frame) {
306
+ return wallHasOutline(frame) && frame.height > 0 && lengthsInRange(frame.height);
307
+ }
308
+ /**
309
+ * This function gives the openings of one wall that the model can make, in sequence along the wall.
310
+ * It skips an opening with no size and an opening out of the straight part of the wall. It also skips an opening that overlaps the opening before it.
311
+ */
312
+ function holesOf(room, frame, footprint, scale) {
313
+ const [clearFrom, clearTo] = footprint.clear;
314
+ const holes = (room.openings ?? []).filter((opening) => opening.wall === frame.id).map((opening) => {
315
+ const sill = (opening.sill ?? 0) * scale;
316
+ return {
317
+ id: opening.id,
318
+ kind: opening.kind,
319
+ from: opening.offset * scale,
320
+ to: (opening.offset + opening.width) * scale,
321
+ sill,
322
+ top: Math.min(sill + opening.height * scale, frame.height)
323
+ };
324
+ }).filter((hole) => hole.to - hole.from > EMPTY && hole.sill >= 0 && hole.top - hole.sill > EMPTY && hole.from >= clearFrom - EMPTY && hole.to <= clearTo + EMPTY).sort((a, b) => a.from - b.from);
325
+ const kept = [];
326
+ let cursor = -1e400;
327
+ for (const hole of holes) {
328
+ if (hole.from < cursor - EMPTY) continue;
329
+ kept.push(hole);
330
+ cursor = hole.to;
331
+ }
332
+ return kept;
333
+ }
334
+ /** This function removes each corner of a ring that is at the position of the corner before it. */
335
+ function withoutRepeats(ring) {
336
+ return ring.filter(([x, y], index) => {
337
+ const [px, py] = ring[(index + ring.length - 1) % ring.length];
338
+ return ring.length === 1 || Math.hypot(x - px, y - py) > EMPTY;
339
+ });
340
+ }
341
+ /** This function gives the part of the outline of a wall between two distances along the wall. An empty part gives an empty ring. */
342
+ function slice(frame, ring, from, to) {
343
+ const base = frame.start.x * frame.along.x + frame.start.y * frame.along.y;
344
+ let part = ring;
345
+ if (Number.isFinite(from)) part = clipRing(part, 0 - frame.along.x, 0 - frame.along.y, 0 - (base + from));
346
+ if (Number.isFinite(to)) part = clipRing(part, frame.along.x, frame.along.y, base + to);
347
+ return solidRing(withoutRepeats(part));
348
+ }
349
+ /** This function gives the solids of one wall: the parts between, below and above its openings, and the glass of each window. */
350
+ function wallSolids(room, frame, footprint, scale, depth) {
351
+ if (footprint.ring.length < 3 || !isMade(frame)) return [];
352
+ const walls = [];
353
+ const glass = [];
354
+ const add = (ring, z, top) => {
355
+ if (ring.length < 3 || top - z <= EMPTY) return;
356
+ walls.push({
357
+ id: `wall:${frame.id}:${String(walls.length)}`,
358
+ kind: "wall",
359
+ source: frame.id,
360
+ shape: {
361
+ kind: "prism",
362
+ ring,
363
+ z,
364
+ d: top - z
365
+ }
366
+ });
367
+ };
368
+ let cursor = -1e400;
369
+ for (const hole of holesOf(room, frame, footprint, scale)) {
370
+ add(slice(frame, footprint.ring, cursor, hole.from), 0 - depth, frame.height);
371
+ const part = slice(frame, footprint.ring, hole.from, hole.to);
372
+ add(part, 0 - depth, hole.sill);
373
+ add(part, hole.top, frame.height);
374
+ cursor = hole.to;
375
+ if (hole.kind !== "window") continue;
376
+ glass.push({
377
+ id: `glass:${hole.id}`,
378
+ kind: "glass",
379
+ source: hole.id,
380
+ shape: {
381
+ kind: "box",
382
+ box: {
383
+ x: hole.from,
384
+ y: (frame.leftOffset + frame.rightOffset - GLASS_THICKNESS) / 2,
385
+ z: hole.sill,
386
+ w: hole.to - hole.from,
387
+ h: GLASS_THICKNESS,
388
+ d: hole.top - hole.sill
389
+ },
390
+ transform: wallTransform(frame)
391
+ }
392
+ });
393
+ }
394
+ add(slice(frame, footprint.ring, cursor, 1e400), 0 - depth, frame.height);
395
+ return [...walls, ...glass];
396
+ }
397
+ /**
398
+ * This function gives the 3D model of a room as a list of solids.
399
+ * The solids are the floors, the walls with their openings, the glass of the windows and the outlets.
400
+ *
401
+ * The function does not stop for a record with a fault. It skips each part that it cannot make.
402
+ * One example is a wall with no length. A second example is an opening on a wall that the room does not have.
403
+ * A third example is a part with a number that is not finite or not in the range of the model (`LARGEST_LENGTH`). `checkRoom` tells each fault.
404
+ */
405
+ function roomSolids(room, options = {}) {
406
+ const scale = metersPer(room.unit);
407
+ const given = options.floorDepth ?? .1;
408
+ const depth = Number.isFinite(given) ? Math.min(Math.max(given, 0), LARGEST_LENGTH) : FLOOR_DEPTH;
409
+ const frames = wallFrames(room);
410
+ const footprints = wallFootprints(frames, options.joins);
411
+ const solids = [];
412
+ for (const floor of room.floors ?? []) {
413
+ const ring = solidRing(floor.ring.map(([x, y]) => [x * scale, y * scale]));
414
+ if (ring.length < 3 || depth <= EMPTY || !ring.every(([x, y]) => lengthsInRange(x, y))) continue;
415
+ solids.push({
416
+ id: `floor:${floor.id}`,
417
+ kind: "floor",
418
+ source: floor.id,
419
+ shape: {
420
+ kind: "prism",
421
+ ring,
422
+ z: 0 - depth,
423
+ d: depth
424
+ }
425
+ });
426
+ }
427
+ frames.forEach((frame, index) => {
428
+ solids.push(...wallSolids(room, frame, footprints[index], scale, depth));
429
+ });
430
+ const byId = new Map(frames.map((frame) => [frame.id, frame]));
431
+ for (const outlet of room.outlets ?? []) {
432
+ const frame = byId.get(outlet.wall);
433
+ if (frame === void 0 || !isMade(frame)) continue;
434
+ const along = outlet.offset * scale;
435
+ const height = outlet.height * scale;
436
+ if (!lengthsInRange(along, height)) continue;
437
+ solids.push({
438
+ id: `outlet:${outlet.id}`,
439
+ kind: "outlet",
440
+ source: outlet.id,
441
+ shape: {
442
+ kind: "box",
443
+ box: {
444
+ x: along - OUTLET_PLATE.width / 2,
445
+ y: outlet.face === "left" ? frame.leftOffset : frame.rightOffset - OUTLET_PLATE.depth,
446
+ z: height - OUTLET_PLATE.height / 2,
447
+ w: OUTLET_PLATE.width,
448
+ h: OUTLET_PLATE.depth,
449
+ d: OUTLET_PLATE.height
450
+ },
451
+ transform: wallTransform(frame)
452
+ }
453
+ });
454
+ }
455
+ return solids;
456
+ }
457
+ /**
458
+ * This function gives the transform of each placed object of a scene, from the frame of the object to the room, in meters.
459
+ * The origin of the frame of an object is the center of its bottom. An object with a parent gets the transform of the parent first.
460
+ * An object has no transform when a parent is not in the scene, or when its parents make a loop.
461
+ * An object also has no transform when one value of its place is not finite or not in the range of the model.
462
+ */
463
+ function objectTransforms(scene) {
464
+ const scale = metersPer(scene.room.unit);
465
+ const objects = new Map((scene.objects ?? []).map((object) => [object.id, object]));
466
+ const done = /* @__PURE__ */ new Map();
467
+ const open = /* @__PURE__ */ new Set();
468
+ const resolve = (object) => {
469
+ const known = done.get(object.id);
470
+ if (known !== void 0) return known;
471
+ if (open.has(object.id)) return void 0;
472
+ const turn = object.turn ?? 0;
473
+ const position = {
474
+ x: object.at[0] * scale,
475
+ y: object.at[1] * scale,
476
+ z: (object.lift ?? 0) * scale
477
+ };
478
+ if (!Number.isFinite(turn) || !lengthsInRange(position.x, position.y, position.z)) return void 0;
479
+ const local = {
480
+ position,
481
+ rotation: rotationAbout({
482
+ x: 0,
483
+ y: 0,
484
+ z: 1
485
+ }, turn % 360 * Math.PI / 180)
486
+ };
487
+ let world = local;
488
+ if (object.parent !== void 0) {
489
+ open.add(object.id);
490
+ const parent = objects.get(object.parent);
491
+ const outer = parent === void 0 ? void 0 : resolve(parent);
492
+ world = outer === void 0 ? void 0 : composeTransforms3(outer, local);
493
+ open.delete(object.id);
494
+ }
495
+ if (world !== void 0) done.set(object.id, world);
496
+ return world;
497
+ };
498
+ for (const object of scene.objects ?? []) resolve(object);
499
+ return done;
500
+ }
501
+ /**
502
+ * This function gives the 3D model of a scene: the solids of its room, then one box for each placed object.
503
+ * It skips an object that has no transform, no size, or a size that is not in the range of the model. `checkScene` tells each fault.
504
+ */
505
+ function sceneSolids(scene, options = {}) {
506
+ const scale = metersPer(scene.room.unit);
507
+ const transforms = objectTransforms(scene);
508
+ const solids = [...roomSolids(scene.room, options)];
509
+ for (const object of scene.objects ?? []) {
510
+ const transform = transforms.get(object.id);
511
+ const w = object.size[0] * scale;
512
+ const h = object.size[1] * scale;
513
+ const d = object.size[2] * scale;
514
+ if (transform === void 0 || ![
515
+ w,
516
+ h,
517
+ d
518
+ ].every((size) => size > EMPTY && size <= 1e6)) continue;
519
+ solids.push({
520
+ id: `object:${object.id}`,
521
+ kind: "object",
522
+ source: object.id,
523
+ shape: {
524
+ kind: "box",
525
+ box: {
526
+ x: 0 - w / 2,
527
+ y: 0 - h / 2,
528
+ z: 0,
529
+ w,
530
+ h,
531
+ d
532
+ },
533
+ transform
534
+ }
535
+ });
536
+ }
537
+ return solids;
538
+ }
539
+ /** This function gives the corners of a solid in the room. A box has 8, and a prism has 2 for each corner of its outline. */
540
+ function solidCorners(solid) {
541
+ const shape = solid.shape;
542
+ if (shape.kind === "box") return box3Corners(shape.box).map((corner) => transformPoint3(shape.transform, corner));
543
+ return shape.ring.flatMap(([x, y]) => [{
544
+ x,
545
+ y,
546
+ z: shape.z
547
+ }, {
548
+ x,
549
+ y,
550
+ z: shape.z + shape.d
551
+ }]);
552
+ }
553
+ /** This function gives the smallest box along the axes that holds each solid, or `undefined` for no solids. */
554
+ function boundsOfSolids(solids) {
555
+ return boundsOf3(solids.flatMap((solid) => solidCorners(solid)));
556
+ }
557
+ /** This function gives the volume of a solid in cubic meters. */
558
+ function solidVolume(solid) {
559
+ const shape = solid.shape;
560
+ return shape.kind === "box" ? box3Volume(shape.box) : regionArea({
561
+ kind: "polygon",
562
+ points: shape.ring
563
+ }) * shape.d;
564
+ }
5
565
  // src/check.ts
6
566
  /** 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
567
  const FINDING_LEVELS = ["error", "warning"];
@@ -23,6 +583,13 @@ const RECORD_KINDS = [
23
583
  function recordName(kind, id) {
24
584
  return `${kind}:${id}`;
25
585
  }
586
+ /**
587
+ * This function gives the name of the record of a solid, as `recordName` gives it. `source` is the field `source` of the solid.
588
+ * The glass of a window is a solid of its opening, so its name has the kind `opening`.
589
+ */
590
+ function solidRecord(kind, source) {
591
+ return recordName(kind === "glass" ? "opening" : kind, source);
592
+ }
26
593
  /** 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
594
  function parseRecordName(name) {
28
595
  const colon = name.indexOf(":");
@@ -540,91 +1107,6 @@ function sceneSpace(scene) {
540
1107
  frame
541
1108
  };
542
1109
  }
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 };
1110
+ export { wallTransform as A, solidVolume as C, wallFrames as D, wallFootprints as E, wallHasOutline as O, solidCorners as S, MITER_LIMIT as T, TO_Y_UP as _, FINDING_LEVELS as a, roomSolids as b, checkRoom as c, recordName as d, solidRecord as f, SOLID_KINDS as g, OUTLET_PLATE as h, FINDING_CODES as i, wallPoint as k, checkScene as l, GLASS_THICKNESS as m, sceneSpace as n, RECORD_KINDS as o, FLOOR_DEPTH as p, ANCHOR_CODES as r, checkAnchor as s, ANCHOR_SURFACES as t, parseRecordName as u, boundsOfSolids as v, JOIN_TOLERANCE as w, sceneSolids as x, objectTransforms as y };
629
1111
 
630
- //# sourceMappingURL=layers-bgJ3OTId.js.map
1112
+ //# sourceMappingURL=anchors-J6mcUeJn.js.map