@mark1russell7/room-view 0.2.4 → 0.3.0
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 +36 -34
- package/build/{anchors-Ba3OUmhF.js → check-DI_B57qy.js} +10 -233
- package/build/check-DI_B57qy.js.map +1 -0
- package/build/index.d.ts +4 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -5
- package/build/index.js.map +1 -1
- package/build/{layers-B5nL_lVW.js → layers-CDNFVXds.js} +161 -5
- package/build/layers-CDNFVXds.js.map +1 -0
- package/build/{layers-BO_MMtQJ.d.ts → layers-CYZwt1bH.d.ts} +34 -9
- package/build/layers-CYZwt1bH.d.ts.map +1 -0
- package/build/{level-CXCIX08K.js → level-BERjgyrT.js} +11 -37
- package/build/level-BERjgyrT.js.map +1 -0
- package/build/{level-Cjcf3u20.d.ts → level-m-mJ_3Ok.d.ts} +11 -19
- package/build/level-m-mJ_3Ok.d.ts.map +1 -0
- package/build/marks.d.ts +2 -2
- package/build/marks.js +1 -2
- package/build/marks.js.map +1 -1
- package/build/sample.d.ts +4 -4
- package/build/sample.d.ts.map +1 -1
- package/build/sample.js +21 -217
- package/build/sample.js.map +1 -1
- package/build/schema.d.ts +59 -9
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +250 -91
- package/build/schema.js.map +1 -1
- package/build/{solids-S_j17vFJ.d.ts → solids-OiTlb_Pm.d.ts} +9 -54
- package/build/solids-OiTlb_Pm.d.ts.map +1 -0
- package/build/three.d.ts +8 -16
- package/build/three.d.ts.map +1 -1
- package/build/three.js +12 -106
- package/build/three.js.map +1 -1
- package/package.json +1 -1
- package/build/anchors-Ba3OUmhF.js.map +0 -1
- package/build/layers-B5nL_lVW.js.map +0 -1
- package/build/layers-BO_MMtQJ.d.ts.map +0 -1
- package/build/level-CXCIX08K.js.map +0 -1
- package/build/level-Cjcf3u20.d.ts.map +0 -1
- package/build/loads-CtHa4EHo.js +0 -103
- package/build/loads-CtHa4EHo.js.map +0 -1
- package/build/loads-Diy6-Ekz.d.ts +0 -73
- package/build/loads-Diy6-Ekz.d.ts.map +0 -1
- 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/
|
|
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
|
-
|
|
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/
|
|
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
|
|
94
|
-
- A side that shares the gap changes its length. Its openings and its
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
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
|
|
224
|
-
| `warning` | The record is possible, but it is probably a mistake. | Two objects that overlap, an object in a wall
|
|
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: "
|
|
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
|
-
-
|
|
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
|
|
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
|
|
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";
|
|
@@ -380,8 +372,8 @@ The option `cut` gives a floor plan: the plan keeps only the solids that start b
|
|
|
380
372
|
|
|
381
373
|
| Entry | What it has |
|
|
382
374
|
| --- | --- |
|
|
383
|
-
| `@mark1russell7/room-view` | The record types, the model, the plan, the checks, the
|
|
384
|
-
| `@mark1russell7/room-view/schema` | `
|
|
375
|
+
| `@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. |
|
|
376
|
+
| `@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
377
|
| `@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
378
|
| `@mark1russell7/room-view/marks` | `layerMarks` and the type `AddOnMarks`: the marks of the layers of a scene, as plain data for a viewer. |
|
|
387
379
|
| `@mark1russell7/room-view/three` | `createRoomViewer`, the themes and `solidGeometry`: the viewer in a page. It needs the package `three`. |
|
|
@@ -390,12 +382,22 @@ The schemas examine the form of a record: the fields and their types. The checks
|
|
|
390
382
|
|
|
391
383
|
```ts
|
|
392
384
|
import { checkScene } from "@mark1russell7/room-view";
|
|
393
|
-
import {
|
|
385
|
+
import { readRecord } from "@mark1russell7/room-view/schema";
|
|
394
386
|
|
|
395
|
-
const
|
|
396
|
-
|
|
387
|
+
const read = readRecord(JSON.parse(text), addOns);
|
|
388
|
+
if (read.ok && read.kind === "scene") {
|
|
389
|
+
const errors = checkScene(read.record).filter((finding) => finding.level === "error");
|
|
390
|
+
}
|
|
397
391
|
```
|
|
398
392
|
|
|
393
|
+
- `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.
|
|
394
|
+
- 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.
|
|
395
|
+
- A field of version 1 that no add-on of the list moves is a fault. `readRecord` does not throw.
|
|
396
|
+
- A record with a layer and the old fields of the same add-on keeps the layer. The finding `read-both` tells it.
|
|
397
|
+
- A `room/1` with old records becomes a `scene/2`, because a room record has no layers.
|
|
398
|
+
|
|
399
|
+
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.
|
|
400
|
+
|
|
399
401
|
## The geometry
|
|
400
402
|
|
|
401
403
|
`@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,5 +1,5 @@
|
|
|
1
1
|
import { quantity, valueIn } from "@mark1russell7/quantity";
|
|
2
|
-
import { boundsOf3, box3Corners, box3Volume, clipRing, composeTransforms3, convexOverlap, length3, pointInRing, regionArea,
|
|
2
|
+
import { boundsOf3, box3Corners, box3Volume, clipRing, composeTransforms3, convexOverlap, length3, pointInRing, regionArea, rotationAbout, transformPoint3 } from "@mark1russell7/layout-contract";
|
|
3
3
|
// src/units.ts
|
|
4
4
|
/** These are the units of length that a room record can use. */
|
|
5
5
|
const LENGTH_UNITS = [
|
|
@@ -285,19 +285,12 @@ const SOLID_KINDS = [
|
|
|
285
285
|
"floor",
|
|
286
286
|
"wall",
|
|
287
287
|
"glass",
|
|
288
|
-
"outlet",
|
|
289
288
|
"object"
|
|
290
289
|
];
|
|
291
290
|
/** The default depth of the floor, in meters. */
|
|
292
291
|
const FLOOR_DEPTH = .1;
|
|
293
292
|
/** The thickness of the glass of a window, in meters. */
|
|
294
293
|
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
294
|
/**
|
|
302
295
|
* The transform from the room, where the z axis points up, to a space where the y axis points up.
|
|
303
296
|
* 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 +415,7 @@ function wallSolids(room, frame, footprint, scale, depth) {
|
|
|
422
415
|
}
|
|
423
416
|
/**
|
|
424
417
|
* 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
|
|
418
|
+
* 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
419
|
*
|
|
427
420
|
* The function does not stop for a record with a fault. It skips each part that it cannot make.
|
|
428
421
|
* 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 +446,6 @@ function roomSolids(room, options = {}) {
|
|
|
453
446
|
frames.forEach((frame, index) => {
|
|
454
447
|
solids.push(...wallSolids(room, frame, footprints[index], scale, depth));
|
|
455
448
|
});
|
|
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
449
|
return solids;
|
|
482
450
|
}
|
|
483
451
|
/**
|
|
@@ -597,10 +565,7 @@ const RECORD_KINDS = [
|
|
|
597
565
|
"wall",
|
|
598
566
|
"opening",
|
|
599
567
|
"floor",
|
|
600
|
-
"
|
|
601
|
-
"circuit",
|
|
602
|
-
"object",
|
|
603
|
-
"load"
|
|
568
|
+
"object"
|
|
604
569
|
];
|
|
605
570
|
/**
|
|
606
571
|
* This function gives the name of a record: its kind, a colon and its `id`, for example `object:desk`.
|
|
@@ -637,20 +602,12 @@ const FINDING_CODES = [
|
|
|
637
602
|
"opening-range",
|
|
638
603
|
"opening-height",
|
|
639
604
|
"opening-overlap",
|
|
640
|
-
"outlet-wall",
|
|
641
|
-
"outlet-circuit",
|
|
642
|
-
"outlet-range",
|
|
643
|
-
"outlet-in-opening",
|
|
644
605
|
"floor-ring",
|
|
645
|
-
"circuit-limit",
|
|
646
606
|
"object-parent",
|
|
647
607
|
"object-cycle",
|
|
648
|
-
"object-outlet",
|
|
649
608
|
"object-outside",
|
|
650
609
|
"object-overlap",
|
|
651
|
-
"object-in-wall"
|
|
652
|
-
"load-circuit",
|
|
653
|
-
"load-watts"
|
|
610
|
+
"object-in-wall"
|
|
654
611
|
];
|
|
655
612
|
/** A length in meters at this value or less is 0 for the checks: a size must be above it. */
|
|
656
613
|
const SMALL = 1e-6;
|
|
@@ -715,22 +672,18 @@ function checkRoom(room, options = {}) {
|
|
|
715
672
|
/** This function tells if a size of the record is 0 for the checks. */
|
|
716
673
|
const none = (size) => !(size * scale > SMALL);
|
|
717
674
|
const openings = room.openings ?? [];
|
|
718
|
-
const outlets = room.outlets ?? [];
|
|
719
|
-
const circuits = room.circuits ?? [];
|
|
720
675
|
const floors = room.floors ?? [];
|
|
721
676
|
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
677
|
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
678
|
const lists = [
|
|
724
679
|
["wall", room.walls],
|
|
725
680
|
["opening", openings],
|
|
726
|
-
["floor", floors]
|
|
727
|
-
["outlet", outlets],
|
|
728
|
-
["circuit", circuits]
|
|
681
|
+
["floor", floors]
|
|
729
682
|
];
|
|
730
683
|
for (const [record, list] of lists) {
|
|
731
684
|
for (const item of list) {
|
|
732
685
|
if (holdsBadNumber(item)) error("number-not-finite", record, item.id, `A number of the ${record} "${item.id}" is not finite.`);
|
|
733
|
-
if (
|
|
686
|
+
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
687
|
}
|
|
735
688
|
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
689
|
}
|
|
@@ -791,32 +744,10 @@ function checkRoom(room, options = {}) {
|
|
|
791
744
|
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
745
|
}
|
|
793
746
|
}
|
|
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
747
|
for (const floor of floors) if (floor.ring.length < 3 || !(regionArea({
|
|
812
748
|
kind: "polygon",
|
|
813
749
|
points: floor.ring
|
|
814
750
|
}) * 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
751
|
return findings;
|
|
821
752
|
}
|
|
822
753
|
/** 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 +774,8 @@ function extentOf(object, transform, scale) {
|
|
|
843
774
|
};
|
|
844
775
|
}
|
|
845
776
|
/**
|
|
846
|
-
* This function gives each fault of a scene record: the faults of its room, then the faults of its placed objects
|
|
777
|
+
* This function gives each fault of a scene record: the faults of its room, then the faults of its placed objects.
|
|
778
|
+
* `checkLayers` examines the layers of the scene.
|
|
847
779
|
* A scene with no finding of the level `error` gives a full model.
|
|
848
780
|
*/
|
|
849
781
|
function checkScene(scene, options = {}) {
|
|
@@ -872,8 +804,6 @@ function checkScene(scene, options = {}) {
|
|
|
872
804
|
const scale = metersPer(room.unit);
|
|
873
805
|
const objects = scene.objects ?? [];
|
|
874
806
|
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
807
|
/** This function tells if each size of an object is above 0 for the checks. */
|
|
878
808
|
const hasSize = (object) => object.size.every((size) => size * scale > SMALL);
|
|
879
809
|
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 +830,6 @@ function checkScene(scene, options = {}) {
|
|
|
900
830
|
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
831
|
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
832
|
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
833
|
}
|
|
905
834
|
const transforms = objectTransforms(scene);
|
|
906
835
|
const extents = [];
|
|
@@ -927,10 +856,6 @@ function checkScene(scene, options = {}) {
|
|
|
927
856
|
if (!(Math.min(a.top, b.top) - Math.max(a.z, b.z) > SMALL) || !(convexOverlap(a.ring, b.ring) > SMALL)) continue;
|
|
928
857
|
warning("object-overlap", "object", a.object.id, `The objects "${a.object.id}" and "${b.object.id}" overlap.`, b.object.id);
|
|
929
858
|
}
|
|
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
859
|
return findings;
|
|
935
860
|
}
|
|
936
861
|
/** These are the codes of the faults of an anchor. */
|
|
@@ -1013,154 +938,6 @@ function checkAnchor(anchor, space, name = "The anchor") {
|
|
|
1013
938
|
message: `${name} is not ${word} a floor of the room.`
|
|
1014
939
|
}];
|
|
1015
940
|
}
|
|
1016
|
-
|
|
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 };
|
|
941
|
+
export { lengthsInRange as A, wallFootprints as C, wallTransform as D, wallPoint as E, unitsPer as M, LARGEST_LENGTH as O, 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, metersPer as j, LENGTH_UNITS as k, 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
942
|
|
|
1166
|
-
//# sourceMappingURL=
|
|
943
|
+
//# sourceMappingURL=check-DI_B57qy.js.map
|