@mark1russell7/room-view 0.2.4 → 0.3.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.
Files changed (53) hide show
  1. package/README.md +64 -34
  2. package/build/{anchors-Ba3OUmhF.js → check-lFfxIUS3.js} +11 -260
  3. package/build/check-lFfxIUS3.js.map +1 -0
  4. package/build/index.d.ts +5 -5
  5. package/build/index.js +6 -5
  6. package/build/index.js.map +1 -1
  7. package/build/{layers-BO_MMtQJ.d.ts → layers-BiiyFJwZ.d.ts} +35 -9
  8. package/build/layers-BiiyFJwZ.d.ts.map +1 -0
  9. package/build/{layers-B5nL_lVW.js → layers-DmTro5Ny.js} +158 -26
  10. package/build/layers-DmTro5Ny.js.map +1 -0
  11. package/build/{level-CXCIX08K.js → level-CvbiwvhH.js} +12 -37
  12. package/build/level-CvbiwvhH.js.map +1 -0
  13. package/build/{level-Cjcf3u20.d.ts → level-DmEftWYn.d.ts} +11 -19
  14. package/build/level-DmEftWYn.d.ts.map +1 -0
  15. package/build/marks.d.ts +2 -2
  16. package/build/marks.js +1 -2
  17. package/build/marks.js.map +1 -1
  18. package/build/plan-import.d.ts +325 -0
  19. package/build/plan-import.d.ts.map +1 -0
  20. package/build/plan-import.js +855 -0
  21. package/build/plan-import.js.map +1 -0
  22. package/build/room-BQua5eSs.d.ts +124 -0
  23. package/build/room-BQua5eSs.d.ts.map +1 -0
  24. package/build/room-CiVZ_07s.js +29 -0
  25. package/build/room-CiVZ_07s.js.map +1 -0
  26. package/build/sample.d.ts +4 -4
  27. package/build/sample.d.ts.map +1 -1
  28. package/build/sample.js +21 -217
  29. package/build/sample.js.map +1 -1
  30. package/build/schema.d.ts +59 -9
  31. package/build/schema.d.ts.map +1 -1
  32. package/build/schema.js +251 -91
  33. package/build/schema.js.map +1 -1
  34. package/build/solids-CdJf0U39.d.ts +148 -0
  35. package/build/solids-CdJf0U39.d.ts.map +1 -0
  36. package/build/three.d.ts +9 -16
  37. package/build/three.d.ts.map +1 -1
  38. package/build/three.js +13 -106
  39. package/build/three.js.map +1 -1
  40. package/build/units-BZmvVyu4.js +30 -0
  41. package/build/units-BZmvVyu4.js.map +1 -0
  42. package/package.json +7 -1
  43. package/build/anchors-Ba3OUmhF.js.map +0 -1
  44. package/build/layers-B5nL_lVW.js.map +0 -1
  45. package/build/layers-BO_MMtQJ.d.ts.map +0 -1
  46. package/build/level-CXCIX08K.js.map +0 -1
  47. package/build/level-Cjcf3u20.d.ts.map +0 -1
  48. package/build/loads-CtHa4EHo.js +0 -103
  49. package/build/loads-CtHa4EHo.js.map +0 -1
  50. package/build/loads-Diy6-Ekz.d.ts +0 -73
  51. package/build/loads-Diy6-Ekz.d.ts.map +0 -1
  52. package/build/solids-S_j17vFJ.d.ts +0 -313
  53. package/build/solids-S_j17vFJ.d.ts.map +0 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ A tape measure gives the length of each wall, the position of each door and the
20
20
  import { checkRoom, roomSolids, type Room } from "@mark1russell7/room-view";
21
21
 
22
22
  const room: Room = {
23
- schema: "room/1",
23
+ schema: "room/2",
24
24
  unit: "ft",
25
25
  height: 8,
26
26
  wallThickness: 0.4,
@@ -51,9 +51,10 @@ roomSolids(room); // => the floor, and the parts of each wall around the door
51
51
  - A **wall** is a straight line in the plan, with a thickness and a height. The field `side` tells which side of the line has the wall.
52
52
  - An **opening** is a door, a window or a gap in a wall.
53
53
  - A **floor** is one area of the plan.
54
- - An **outlet** is a point on a face of a wall. A **circuit** gives power to outlets, and it has a limit in watts. A circuit can also keep the rating of its breaker in amperes and its voltage. The limit does not change with them.
55
54
 
56
- A scene is one room with its placed objects and the loads of its circuits. A placed object is a box: a desk, a rack, a computer. An object can have a parent, and then its position is relative to the parent.
55
+ The room record has only space. The records of a topic, for example outlets, are in a layer of an add-on. Refer to [Anchors and layers](#anchors-and-layers).
56
+
57
+ A scene is one room with its placed objects and its layers. A placed object is a box: a desk, a rack, a computer. An object can have a parent, and then its position is relative to the parent.
57
58
 
58
59
  ## A survey: the room from a tape measure
59
60
 
@@ -63,7 +64,7 @@ A person with a tape measure does not know the coordinates of a corner. The pers
63
64
  import { checkRoom, expandSurvey, type Survey } from "@mark1russell7/room-view";
64
65
 
65
66
  const survey: Survey = {
66
- schema: "survey/1",
67
+ schema: "survey/2",
67
68
  unit: "ft",
68
69
  height: 8,
69
70
  wallThickness: 0.4,
@@ -90,8 +91,8 @@ checkRoom(room); // => []
90
91
  - `expandSurvey` shares a small gap between the sides. A room with square corners keeps its square corners.
91
92
  - A walk with a mistake is not closed, for example a walk with a wrong turn. Its room has the walls of the walk and no floor, so a drawing shows the mistake.
92
93
  - A **check** is a measured distance between two corners, for example a diagonal. The result has its difference from the room record.
93
- - An opening and an outlet give their `offset` from the first corner of their side, as the tape measure shows it.
94
- - A side that shares the gap changes its length. Its openings and its outlets keep their place: each `offset` and each `width` changes in the same proportion.
94
+ - An opening gives its `offset` from the first corner of its side, as the tape measure shows it.
95
+ - A side that shares the gap changes its length. Its openings and the wall anchors of its layers keep their place: each `offset` and each `width` changes in the same proportion.
95
96
 
96
97
  The walk goes along the inner faces, so each wall is on the outer side of its line. A survey has one room. A wall in the middle of a room is not a side of the walk, for example the short wall of a nook. Add such a wall to the room record.
97
98
 
@@ -103,7 +104,7 @@ A person measures a desk or a rack from a wall. A survey can have these measurem
103
104
  import { checkScene, expandSurvey, type Scene, type Survey } from "@mark1russell7/room-view";
104
105
 
105
106
  const survey: Survey = {
106
- schema: "survey/1",
107
+ schema: "survey/2",
107
108
  unit: "m",
108
109
  height: 2.5,
109
110
  wallThickness: 0.15,
@@ -122,7 +123,7 @@ const survey: Survey = {
122
123
  const { room, objects } = expandSurvey(survey);
123
124
  objects[0]; // => { id: "desk", kind: "desk", size: [1.6, 0.8, 0.75], at: [2.2, 2.6], turn: 180 }, with rounded numbers
124
125
  objects[1]; // => { id: "display", kind: "display", size: [0.6, 0.2, 0.4], at: [0, -0.2], lift: 0.75, parent: "desk" }, with rounded numbers
125
- const scene: Scene = { schema: "scene/1", room, objects };
126
+ const scene: Scene = { schema: "scene/2", room, objects };
126
127
  checkScene(scene); // => []
127
128
  ```
128
129
 
@@ -132,7 +133,6 @@ checkScene(scene); // => []
132
133
  - An object with `on` is on a different object or in it. That object is its **holder**: a desk for a display, a rack for a computer.
133
134
  - With a holder, `offset` and `gap` start at the edge and the back of the holder. The holder becomes the parent of the placed object.
134
135
  - `lift` is the height of the bottom above the floor. With a holder, the default is the top of the holder.
135
- - `outlet` names the outlet that gives power to the object.
136
136
  - An object keeps its size on a side that shares the gap. Only its place changes.
137
137
  - An object with no place is not in the result. For example, its side is not in the survey, or a size is not above 0.
138
138
 
@@ -144,7 +144,7 @@ A survey has one room, with its own first corner. A level record has the survey
144
144
  import { checkRoom, expandLevel, type Level, type Survey } from "@mark1russell7/room-view";
145
145
 
146
146
  const hall: Survey = {
147
- schema: "survey/1",
147
+ schema: "survey/2",
148
148
  name: "Hall",
149
149
  unit: "m",
150
150
  height: 2.5,
@@ -158,7 +158,7 @@ const hall: Survey = {
158
158
  openings: [{ id: "to-study", wall: "east", kind: "door", offset: 0.2, width: 0.8, height: 2.05 }],
159
159
  };
160
160
  const study: Survey = {
161
- schema: "survey/1",
161
+ schema: "survey/2",
162
162
  name: "Study",
163
163
  unit: "m",
164
164
  height: 2.5,
@@ -173,7 +173,7 @@ const study: Survey = {
173
173
  };
174
174
 
175
175
  const level: Level = {
176
- schema: "level/1",
176
+ schema: "level/2",
177
177
  unit: "m",
178
178
  rooms: [
179
179
  { id: "hall", survey: hall },
@@ -196,7 +196,7 @@ checkRoom(room); // => []
196
196
  - A connection between two rooms that have a place examines the measurements. Its `gap` and its `turn` tell a mistake, and `fits` tells if they are in the limits.
197
197
  - A connection with a fault has the use `none` and a `fault`. For example, an end names an opening that its room does not have.
198
198
  - A room with no path of connections to the first room has the place `apart`. Its place is not known, so its group goes to the right of the groups before it.
199
- - The result has one room record with each room. The `id` of a wall, an opening or an outlet is the `id` of its room, then `/`, then its own `id`.
199
+ - The result has one room record with each room. The `id` of a wall or an opening is the `id` of its room, then `/`, then its own `id`.
200
200
  - `objects` has the objects of each survey, at the place of their room. The `id` of an object has the same form.
201
201
  - Each closed room gives one floor, with the `id` and the name of the room.
202
202
  - A survey can have a different unit than the level. `convertSurvey` changes the unit of a survey.
@@ -220,8 +220,8 @@ Two rooms have one wall between them, but each survey gives the full thickness t
220
220
 
221
221
  | Level | Meaning | Examples |
222
222
  | --- | --- | --- |
223
- | `error` | The model cannot show the record correctly. | An opening that is longer than its wall, an outlet on a wall that the room does not have. |
224
- | `warning` | The record is possible, but it is probably a mistake. | Two objects that overlap, an object in a wall, an outlet in a door. |
223
+ | `error` | The model cannot show the record correctly. | An opening that is longer than its wall, an object on an object that the scene does not have. |
224
+ | `warning` | The record is possible, but it is probably a mistake. | Two objects that overlap, an object in a wall. |
225
225
 
226
226
  Each finding has a code, the kind and the `id` of the record, and a message with the values. `FINDING_CODES` has each code. A fault between two records also has the `id` of the second record in `other`. An example is the other object of an overlap.
227
227
 
@@ -304,12 +304,6 @@ const findings = [...result.layerFindings, ...checkLayers(resultScene(result), a
304
304
 
305
305
  `ANCHOR_CODES`, `LAYER_CODES` and `FORM_CODES` have the codes of the core. The design of the add-ons is in `docs/ADD-ONS.md` of the repository.
306
306
 
307
- ## The loads of the circuits
308
-
309
- `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.
310
-
311
- `outletLevels` gives the level of the circuit of each outlet. `levelShape` gives the shape of the sign of a level. The shapes are a disc for `ok`, a triangle for `near`, a square for `over` and a ring for `unknown`. Thus a person who does not see a color reads the level from the shape. `SHAPE_OUTLINES` and `shapeRing` give the outline of each sign, so each drawing shows the same signs.
312
-
313
307
  ## The viewer
314
308
 
315
309
  The entry `@mark1russell7/room-view/three` shows a scene in a page with three.js. Install `three` 0.187 or later with this package. For the types, install `@types/three` too.
@@ -324,7 +318,7 @@ const viewer = createRoomViewer(container, {
324
318
  });
325
319
 
326
320
  viewer?.setTheme(DARK_THEME);
327
- viewer?.highlight([{ kind: "outlet", source: "nook-1" }]);
321
+ viewer?.highlight([{ kind: "object", source: "desk" }]);
328
322
  viewer?.setView("top");
329
323
  ```
330
324
 
@@ -334,20 +328,18 @@ viewer?.setView("top");
334
328
  - A click selects the record of a solid or of a sign. `onSelect` gets the kind and the `id` of the record.
335
329
  - With the keyboard, the arrow keys turn the model, and `+` and `-` change the distance. `Home` shows the first view, and `T` shows the plan.
336
330
  - The stage and the signs come from `@mark1russell7/visuals`. Thus each viewer on that package shows the same signs.
337
- - Each outlet has a sign with the color and the shape of the level of its circuit. A sign keeps its size in the picture.
338
- - A sign behind a wall or a machine stays in the picture, and it is less clear.
331
+ - The signs are the marks of the layers, from the option `marks`. With no marks, the picture has only the solids.
332
+ - A sign keeps its size in the picture. A sign behind a wall or a machine stays in the picture, and it is less clear.
339
333
  - The pointer finds a sign before each solid, also behind a solid. `onHover` and `onSelect` get its mark as their second parameter.
340
- - `highlight` and `select` mark records from your page: the outlets of a circuit, or the row of a table.
341
- - A marked outlet or object shows a line from the outlet to each object that takes its power from it.
342
- - The option `loads` has the options of `circuitStates`, for example the part of the limit where the level `near` starts.
334
+ - `highlight` and `select` mark records from your page, for example the record of the row of a table.
343
335
  - The viewer draws a frame only after a change.
344
336
  - `createRoomViewer` gives `undefined` in a browser with no WebGL 2. It does not throw.
345
337
 
346
- `LIGHT_THEME` and `DARK_THEME` are the colors, and a theme is plain data. The field `levels` of a theme has the color of each level. `solidGeometry` gives the three.js geometry of one solid, for your own three.js scene.
338
+ `LIGHT_THEME` and `DARK_THEME` are the colors, and a theme is plain data. The field `levels` of a theme has the color of each level of a mark. `solidGeometry` gives the three.js geometry of one solid, for your own three.js scene.
347
339
 
348
340
  ### The marks of the add-ons
349
341
 
350
- The option `marks` gives the marks of a scene to the viewer. The viewer draws them in place of the signs of the outlets:
342
+ The option `marks` gives the marks of a scene to the viewer. The viewer draws them as signs:
351
343
 
352
344
  ```ts
353
345
  import { layerMarks } from "@mark1russell7/room-view/marks";
@@ -376,26 +368,64 @@ viewer?.showMarks((mark) => mark.kind === "outlet");
376
368
 
377
369
  The option `cut` gives a floor plan: the plan keeps only the solids that start below the height of the cut. Thus a door becomes a gap in its wall. Use the plan for a drawing in SVG, or for a browser with no WebGL 2.
378
370
 
371
+ ## A floor plan from a drawing
372
+
373
+ The entry `@mark1russell7/room-view/import` reads the vector paths of a floor plan drawing, for example the lines of a page of a PDF file. It gives a room record with the walls, the openings and one floor for each room.
374
+
375
+ ```ts
376
+ import { importPlan, readLegend, type Sheet } from "@mark1russell7/room-view/import";
377
+
378
+ // The lines, the fills and the texts of one page, in points. The scale 1/8 inch to the foot gives 9 points for each foot.
379
+ const sheet: Sheet = { width, height, scale: 9, unit: "ft", lines, fills, texts };
380
+ const result = importPlan(sheet, { legend: readLegend(sheet) });
381
+ console.log(result.rooms.length, result.gate.within);
382
+ ```
383
+
384
+ The import has five steps:
385
+
386
+ 1. `readPens` finds the wall pens. A wall pen has long lines, and each line has a parallel partner at the distance of a wall thickness.
387
+ 2. `findBridges` closes each gap between two wall ends. The bridge of a gap is an opening of the room record.
388
+ 3. The walls, the door swings and the bridges go on a grid. Each free region inside the building is a room.
389
+ 4. Each room gets the fill color under most of its cells. `readLegend` gives the name of each color.
390
+ 5. The area gate compares the area of each fill of the legend with the rooms in it.
391
+
392
+ - A free region with a small area is a speck. A thin free region is the space inside a wall. They are not rooms.
393
+ - The sheet has the y axis down. The plan of the result has the y axis up.
394
+ - Each option has a default in feet. The import changes the default to the unit of the sheet.
395
+ - An opening is a `door` when a door swing is near it. Each other opening is a `gap`.
396
+ - The import does not read the windows or the heights. The room record has the default heights.
397
+
379
398
  ## The entries
380
399
 
381
400
  | Entry | What it has |
382
401
  | --- | --- |
383
- | `@mark1russell7/room-view` | The record types, the model, the plan, the checks, the loads, the survey and the level. It has no schema library. |
384
- | `@mark1russell7/room-view/schema` | `roomSchema`, `sceneSchema`, `surveySchema`, `levelSchema` and `anchorSchema`: the zod schemas that examine the form of a JSON record. |
402
+ | `@mark1russell7/room-view` | The record types, the model, the plan, the checks, the survey, the level, the anchors and the layers. It has no schema library. |
403
+ | `@mark1russell7/room-view/schema` | `readRecord`, the schemas of the records and of an anchor in `zod/mini`, and `READ_CONTEXT`: the read of a JSON record. |
385
404
  | `@mark1russell7/room-view/sample` | `SAMPLE_ROOM`, `SAMPLE_SCENE`, `SAMPLE_SURVEY` and `SAMPLE_LEVEL`: a room with a rack and an apartment of four rooms, for demos and tests. |
386
405
  | `@mark1russell7/room-view/marks` | `layerMarks` and the type `AddOnMarks`: the marks of the layers of a scene, as plain data for a viewer. |
406
+ | `@mark1russell7/room-view/import` | `importPlan`, `readLegend`, `readPens`, `wallPairs` and `findBridges`: a room record from the vector paths of a floor plan drawing. |
387
407
  | `@mark1russell7/room-view/three` | `createRoomViewer`, the themes and `solidGeometry`: the viewer in a page. It needs the package `three`. |
388
408
 
389
409
  The schemas examine the form of a record: the fields and their types. The checks examine its meaning. Use the two for a record from a file:
390
410
 
391
411
  ```ts
392
412
  import { checkScene } from "@mark1russell7/room-view";
393
- import { sceneSchema } from "@mark1russell7/room-view/schema";
413
+ import { readRecord } from "@mark1russell7/room-view/schema";
394
414
 
395
- const scene = sceneSchema.parse(JSON.parse(text));
396
- const errors = checkScene(scene).filter((finding) => finding.level === "error");
415
+ const read = readRecord(JSON.parse(text), addOns);
416
+ if (read.ok && read.kind === "scene") {
417
+ const errors = checkScene(read.record).filter((finding) => finding.level === "error");
418
+ }
397
419
  ```
398
420
 
421
+ - `readRecord` reads a room, a scene, a survey or a level, in version 1 or in version 2. It gives the record in version 2, its kind and the version of the file.
422
+ - A record of version 1 kept the records of some topics in fields of its own. An add-on with the read `v1` moves its fields to its layer.
423
+ - A field of version 1 that no add-on of the list moves is a fault. `readRecord` does not throw.
424
+ - A record with a layer and the old fields of the same add-on keeps the layer. The finding `read-both` tells it.
425
+ - A `room/1` with old records becomes a `scene/2`, because a room record has no layers.
426
+
427
+ The schemas use `zod/mini`, so a page gets only the parts of zod that the schemas use. `READ_CONTEXT` gives the English messages of zod to each read. An add-on gives it to the read of its layer too.
428
+
399
429
  ## The geometry
400
430
 
401
431
  `@mark1russell7/layout-contract` gives the points, the boxes, the transforms and the polygon functions. `@mark1russell7/quantity` gives the length units. This package keeps only the room, the scene and their model.
@@ -1,31 +1,5 @@
1
- import { quantity, valueIn } from "@mark1russell7/quantity";
2
- import { boundsOf3, box3Corners, box3Volume, clipRing, composeTransforms3, convexOverlap, length3, pointInRing, regionArea, rotatePoint3, rotationAbout, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
3
- // src/units.ts
4
- /** These are the units of length that a room record can use. */
5
- const LENGTH_UNITS = [
6
- "m",
7
- "cm",
8
- "mm",
9
- "ft",
10
- "in"
11
- ];
12
- /** This function gives the length of one unit in meters. The factor comes from `@mark1russell7/quantity`. */
13
- function metersPer(unit) {
14
- return valueIn(quantity(1, unit), "m");
15
- }
16
- /** This function gives the length of one unit in a different unit. For example, one foot is 12 inches. */
17
- function unitsPer(unit, other) {
18
- return valueIn(quantity(1, unit), other);
19
- }
20
- /**
21
- * The largest length in meters that the model can use: 1 000 km. A larger number in a room record is a mistake.
22
- * With this limit, each calculation of the model gives a finite number.
23
- */
24
- const LARGEST_LENGTH = 1e6;
25
- /** This function tells if the model can use each value as a length. Such a value is a finite number of meters, with a size of `LARGEST_LENGTH` or less. */
26
- function lengthsInRange(...meters) {
27
- return meters.every((value) => Math.abs(value) <= LARGEST_LENGTH);
28
- }
1
+ import { i as metersPer, r as lengthsInRange, t as LARGEST_LENGTH } from "./units-BZmvVyu4.js";
2
+ import { boundsOf3, box3Corners, box3Volume, clipRing, composeTransforms3, convexOverlap, length3, pointInRing, regionArea, rotationAbout, transformPoint3 } from "@mark1russell7/layout-contract";
29
3
  // src/frames.ts
30
4
  /** This function gives the frame of one wall. `scale` is the length of the unit of the room in meters. */
31
5
  function frameOf(room, wall, scale) {
@@ -285,19 +259,12 @@ const SOLID_KINDS = [
285
259
  "floor",
286
260
  "wall",
287
261
  "glass",
288
- "outlet",
289
262
  "object"
290
263
  ];
291
264
  /** The default depth of the floor, in meters. */
292
265
  const FLOOR_DEPTH = .1;
293
266
  /** The thickness of the glass of a window, in meters. */
294
267
  const GLASS_THICKNESS = .02;
295
- /** 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. */
296
- const OUTLET_PLATE = {
297
- width: .07,
298
- height: .115,
299
- depth: .012
300
- };
301
268
  /**
302
269
  * The transform from the room, where the z axis points up, to a space where the y axis points up.
303
270
  * 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.
@@ -422,7 +389,7 @@ function wallSolids(room, frame, footprint, scale, depth) {
422
389
  }
423
390
  /**
424
391
  * This function gives the 3D model of a room as a list of solids.
425
- * The solids are the floors, the walls with their openings, the glass of the windows and the outlets.
392
+ * The solids are the floors, the walls with their openings and the glass of the windows. The marks of the layers show the records of the add-ons.
426
393
  *
427
394
  * The function does not stop for a record with a fault. It skips each part that it cannot make.
428
395
  * One example is a wall with no length. A second example is an opening on a wall that the room does not have.
@@ -453,31 +420,6 @@ function roomSolids(room, options = {}) {
453
420
  frames.forEach((frame, index) => {
454
421
  solids.push(...wallSolids(room, frame, footprints[index], scale, depth));
455
422
  });
456
- const byId = new Map(frames.map((frame) => [frame.id, frame]));
457
- for (const outlet of room.outlets ?? []) {
458
- const frame = byId.get(outlet.wall);
459
- if (frame === void 0 || !isMade(frame)) continue;
460
- const along = outlet.offset * scale;
461
- const height = outlet.height * scale;
462
- if (!lengthsInRange(along, height)) continue;
463
- solids.push({
464
- id: `outlet:${outlet.id}`,
465
- kind: "outlet",
466
- source: outlet.id,
467
- shape: {
468
- kind: "box",
469
- box: {
470
- x: along - OUTLET_PLATE.width / 2,
471
- y: outlet.face === "left" ? frame.leftOffset : frame.rightOffset - OUTLET_PLATE.depth,
472
- z: height - OUTLET_PLATE.height / 2,
473
- w: OUTLET_PLATE.width,
474
- h: OUTLET_PLATE.depth,
475
- d: OUTLET_PLATE.height
476
- },
477
- transform: wallTransform(frame)
478
- }
479
- });
480
- }
481
423
  return solids;
482
424
  }
483
425
  /**
@@ -597,10 +539,7 @@ const RECORD_KINDS = [
597
539
  "wall",
598
540
  "opening",
599
541
  "floor",
600
- "outlet",
601
- "circuit",
602
- "object",
603
- "load"
542
+ "object"
604
543
  ];
605
544
  /**
606
545
  * This function gives the name of a record: its kind, a colon and its `id`, for example `object:desk`.
@@ -637,20 +576,12 @@ const FINDING_CODES = [
637
576
  "opening-range",
638
577
  "opening-height",
639
578
  "opening-overlap",
640
- "outlet-wall",
641
- "outlet-circuit",
642
- "outlet-range",
643
- "outlet-in-opening",
644
579
  "floor-ring",
645
- "circuit-limit",
646
580
  "object-parent",
647
581
  "object-cycle",
648
- "object-outlet",
649
582
  "object-outside",
650
583
  "object-overlap",
651
- "object-in-wall",
652
- "load-circuit",
653
- "load-watts"
584
+ "object-in-wall"
654
585
  ];
655
586
  /** A length in meters at this value or less is 0 for the checks: a size must be above it. */
656
587
  const SMALL = 1e-6;
@@ -715,22 +646,18 @@ function checkRoom(room, options = {}) {
715
646
  /** This function tells if a size of the record is 0 for the checks. */
716
647
  const none = (size) => !(size * scale > SMALL);
717
648
  const openings = room.openings ?? [];
718
- const outlets = room.outlets ?? [];
719
- const circuits = room.circuits ?? [];
720
649
  const floors = room.floors ?? [];
721
650
  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.");
722
651
  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.`);
723
652
  const lists = [
724
653
  ["wall", room.walls],
725
654
  ["opening", openings],
726
- ["floor", floors],
727
- ["outlet", outlets],
728
- ["circuit", circuits]
655
+ ["floor", floors]
729
656
  ];
730
657
  for (const [record, list] of lists) {
731
658
  for (const item of list) {
732
659
  if (holdsBadNumber(item)) error("number-not-finite", record, item.id, `A number of the ${record} "${item.id}" is not finite.`);
733
- 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.`);
660
+ if (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.`);
734
661
  }
735
662
  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}".`);
736
663
  }
@@ -791,32 +718,10 @@ function checkRoom(room, options = {}) {
791
718
  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);
792
719
  }
793
720
  }
794
- const circuitIds = new Set(circuits.map((circuit) => circuit.id));
795
- for (const outlet of outlets) {
796
- 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.`);
797
- const found = frameOf.get(outlet.wall);
798
- if (found === void 0) {
799
- error("outlet-wall", "outlet", outlet.id, `The outlet "${outlet.id}" is on the wall "${outlet.wall}", which the room does not have.`);
800
- continue;
801
- }
802
- const along = outlet.offset * scale;
803
- const height = outlet.height * scale;
804
- if (!(along >= 0 && along <= found.frame.length + SMALL && height >= 0 && height <= found.frame.height + SMALL)) {
805
- 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)}.`);
806
- continue;
807
- }
808
- const hole = (holes.get(outlet.wall) ?? []).find((item) => along > item.from && along < item.to && height > item.sill && height < item.top);
809
- 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);
810
- }
811
721
  for (const floor of floors) if (floor.ring.length < 3 || !(regionArea({
812
722
  kind: "polygon",
813
723
  points: floor.ring
814
724
  }) * 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.`);
815
- for (const circuit of circuits) {
816
- 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.`);
817
- 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.`);
818
- 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.`);
819
- }
820
725
  return findings;
821
726
  }
822
727
  /** 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. */
@@ -843,7 +748,8 @@ function extentOf(object, transform, scale) {
843
748
  };
844
749
  }
845
750
  /**
846
- * This function gives each fault of a scene record: the faults of its room, then the faults of its placed objects and its loads.
751
+ * This function gives each fault of a scene record: the faults of its room, then the faults of its placed objects.
752
+ * `checkLayers` examines the layers of the scene.
847
753
  * A scene with no finding of the level `error` gives a full model.
848
754
  */
849
755
  function checkScene(scene, options = {}) {
@@ -872,8 +778,6 @@ function checkScene(scene, options = {}) {
872
778
  const scale = metersPer(room.unit);
873
779
  const objects = scene.objects ?? [];
874
780
  const byId = new Map(objects.map((object) => [object.id, object]));
875
- const outletIds = new Set((room.outlets ?? []).map((outlet) => outlet.id));
876
- const circuitIds = new Set((room.circuits ?? []).map((circuit) => circuit.id));
877
781
  /** This function tells if each size of an object is above 0 for the checks. */
878
782
  const hasSize = (object) => object.size.every((size) => size * scale > SMALL);
879
783
  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}".`);
@@ -900,7 +804,6 @@ function checkScene(scene, options = {}) {
900
804
  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.`);
901
805
  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);
902
806
  else if (holders(object) === void 0) error("object-cycle", "object", object.id, `The parents of the object "${object.id}" make a loop.`);
903
- 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);
904
807
  }
905
808
  const transforms = objectTransforms(scene);
906
809
  const extents = [];
@@ -927,10 +830,6 @@ function checkScene(scene, options = {}) {
927
830
  if (!(Math.min(a.top, b.top) - Math.max(a.z, b.z) > SMALL) || !(convexOverlap(a.ring, b.ring) > SMALL)) continue;
928
831
  warning("object-overlap", "object", a.object.id, `The objects "${a.object.id}" and "${b.object.id}" overlap.`, b.object.id);
929
832
  }
930
- for (const load of scene.loads ?? []) {
931
- 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.`);
932
- 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.`);
933
- }
934
833
  return findings;
935
834
  }
936
835
  /** These are the codes of the faults of an anchor. */
@@ -1013,154 +912,6 @@ function checkAnchor(anchor, space, name = "The anchor") {
1013
912
  message: `${name} is not ${word} a floor of the room.`
1014
913
  }];
1015
914
  }
1016
- // src/anchors.ts
1017
- /** These are the surfaces that an anchor can be on. */
1018
- const ANCHOR_SURFACES = [
1019
- "wall",
1020
- "floor",
1021
- "ceiling",
1022
- "object"
1023
- ];
1024
- const UP = {
1025
- x: 0,
1026
- y: 0,
1027
- z: 1
1028
- };
1029
- const DOWN = {
1030
- x: 0,
1031
- y: 0,
1032
- z: -1
1033
- };
1034
- /** This function tells if each value of a point is a length in the range of the model. */
1035
- function inRange(point) {
1036
- return Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z) && lengthsInRange(point.x, point.y, point.z);
1037
- }
1038
- /** This function gives a point with no negative zero. JSON has no negative zero, so a frame goes through JSON with no change. */
1039
- function plainPoint(point) {
1040
- return {
1041
- x: point.x + 0,
1042
- y: point.y + 0,
1043
- z: point.z + 0
1044
- };
1045
- }
1046
- /** This function gives the space of a scene. The transforms of the objects are calculated one time, at the first use. */
1047
- function sceneSpace(scene) {
1048
- const scale = metersPer(scene.room.unit);
1049
- const walls = new Map(wallFrames(scene.room).map((frame) => [frame.id, frame]));
1050
- const objects = new Map((scene.objects ?? []).map((object) => [object.id, object]));
1051
- let transforms;
1052
- const transform = (id) => {
1053
- transforms ??= objectTransforms(scene);
1054
- return transforms.get(id);
1055
- };
1056
- const frame = (anchor) => {
1057
- let found;
1058
- if (anchor.on === "wall") {
1059
- const wall = walls.get(anchor.wall);
1060
- if (wall === void 0) return void 0;
1061
- const point = wallPoint(wall, anchor.offset * scale, anchor.face === "left" ? wall.leftOffset : wall.rightOffset);
1062
- const sign = anchor.face === "left" ? 1 : -1;
1063
- found = {
1064
- at: {
1065
- x: point.x,
1066
- y: point.y,
1067
- z: anchor.height * scale
1068
- },
1069
- out: {
1070
- x: wall.left.x * sign,
1071
- y: wall.left.y * sign,
1072
- z: 0
1073
- }
1074
- };
1075
- } else if (anchor.on === "floor") found = {
1076
- at: {
1077
- x: anchor.at[0] * scale,
1078
- y: anchor.at[1] * scale,
1079
- z: 0
1080
- },
1081
- out: UP
1082
- };
1083
- else if (anchor.on === "ceiling") found = {
1084
- at: {
1085
- x: anchor.at[0] * scale,
1086
- y: anchor.at[1] * scale,
1087
- z: scene.room.height * scale
1088
- },
1089
- out: DOWN
1090
- };
1091
- else {
1092
- const object = objects.get(anchor.object);
1093
- const place = transform(anchor.object);
1094
- if (object === void 0 || place === void 0) return void 0;
1095
- const [x, y, z] = anchor.at ?? [
1096
- 0,
1097
- 0,
1098
- object.size[2]
1099
- ];
1100
- const [ox, oy, oz] = anchor.out ?? [
1101
- 0,
1102
- 0,
1103
- 1
1104
- ];
1105
- const out = {
1106
- x: ox,
1107
- y: oy,
1108
- z: oz
1109
- };
1110
- const size = length3(out);
1111
- if (!(size > 0) || !Number.isFinite(size)) return void 0;
1112
- found = {
1113
- at: transformPoint3(place, {
1114
- x: x * scale,
1115
- y: y * scale,
1116
- z: z * scale
1117
- }),
1118
- out: rotatePoint3(place.rotation, scalePoint3(out, 1 / size))
1119
- };
1120
- }
1121
- const plain = {
1122
- at: plainPoint(found.at),
1123
- out: plainPoint(found.out)
1124
- };
1125
- return inRange(plain.at) && inRange(plain.out) ? plain : void 0;
1126
- };
1127
- return {
1128
- scene,
1129
- scale,
1130
- wall: (id) => walls.get(id),
1131
- object: (id) => objects.get(id),
1132
- transform,
1133
- frame
1134
- };
1135
- }
1136
- /**
1137
- * This function gives an anchor with each length times a factor. A direction stays, because it has no unit.
1138
- * `convertSurvey` uses it to change the unit of the anchors of a layer.
1139
- */
1140
- function scaleAnchor(anchor, factor) {
1141
- if (anchor.on === "wall") return {
1142
- ...anchor,
1143
- offset: anchor.offset * factor,
1144
- height: anchor.height * factor
1145
- };
1146
- if (anchor.on === "object") {
1147
- if (anchor.at === void 0) return anchor;
1148
- const [x, y, z] = anchor.at;
1149
- return {
1150
- ...anchor,
1151
- at: [
1152
- x * factor,
1153
- y * factor,
1154
- z * factor
1155
- ]
1156
- };
1157
- }
1158
- const [x, y] = anchor.at;
1159
- return {
1160
- ...anchor,
1161
- at: [x * factor, y * factor]
1162
- };
1163
- }
1164
- export { wallPoint as A, solidCorners as C, wallFootprints as D, MITER_LIMIT as E, metersPer as F, unitsPer as I, LARGEST_LENGTH as M, LENGTH_UNITS as N, wallFrames as O, lengthsInRange as P, sceneSolids as S, JOIN_TOLERANCE as T, SOLID_KINDS as _, FINDING_CODES as a, objectTransforms as b, checkAnchor as c, parseRecordName as d, recordName as f, OUTLET_PLATE as g, GLASS_THICKNESS as h, ANCHOR_CODES as i, wallTransform as j, wallHasOutline as k, checkRoom as l, FLOOR_DEPTH as m, scaleAnchor as n, FINDING_LEVELS as o, solidRecord as p, sceneSpace as r, RECORD_KINDS as s, ANCHOR_SURFACES as t, checkScene as u, TO_Y_UP as v, solidVolume as w, roomSolids as x, boundsOfSolids as y };
915
+ export { wallFootprints as C, wallTransform as D, wallPoint as E, MITER_LIMIT as S, wallHasOutline as T, roomSolids as _, checkAnchor as a, solidVolume as b, parseRecordName as c, FLOOR_DEPTH as d, GLASS_THICKNESS as f, objectTransforms as g, boundsOfSolids as h, RECORD_KINDS as i, recordName as l, TO_Y_UP as m, FINDING_CODES as n, checkRoom as o, SOLID_KINDS as p, FINDING_LEVELS as r, checkScene as s, ANCHOR_CODES as t, solidRecord as u, sceneSolids as v, wallFrames as w, JOIN_TOLERANCE as x, solidCorners as y };
1165
916
 
1166
- //# sourceMappingURL=anchors-Ba3OUmhF.js.map
917
+ //# sourceMappingURL=check-lFfxIUS3.js.map