@mark1russell7/room-view 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +28 -0
  2. package/build/{check-DI_B57qy.js → check-lFfxIUS3.js} +3 -29
  3. package/build/check-lFfxIUS3.js.map +1 -0
  4. package/build/index.d.ts +4 -3
  5. package/build/index.d.ts.map +1 -1
  6. package/build/index.js +5 -3
  7. package/build/index.js.map +1 -1
  8. package/build/{layers-CYZwt1bH.d.ts → layers-BiiyFJwZ.d.ts} +3 -2
  9. package/build/layers-BiiyFJwZ.d.ts.map +1 -0
  10. package/build/{layers-CDNFVXds.js → layers-DmTro5Ny.js} +5 -29
  11. package/build/layers-DmTro5Ny.js.map +1 -0
  12. package/build/{level-BERjgyrT.js → level-CvbiwvhH.js} +4 -3
  13. package/build/{level-BERjgyrT.js.map → level-CvbiwvhH.js.map} +1 -1
  14. package/build/{level-m-mJ_3Ok.d.ts → level-DmEftWYn.d.ts} +3 -3
  15. package/build/{level-m-mJ_3Ok.d.ts.map → level-DmEftWYn.d.ts.map} +1 -1
  16. package/build/marks.d.ts +2 -2
  17. package/build/marks.js +1 -1
  18. package/build/plan-import.d.ts +329 -0
  19. package/build/plan-import.d.ts.map +1 -0
  20. package/build/plan-import.js +864 -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 +2 -2
  27. package/build/schema.d.ts +3 -3
  28. package/build/schema.js +4 -3
  29. package/build/schema.js.map +1 -1
  30. package/build/{solids-OiTlb_Pm.d.ts → solids-CdJf0U39.d.ts} +3 -123
  31. package/build/solids-CdJf0U39.d.ts.map +1 -0
  32. package/build/three.d.ts +2 -1
  33. package/build/three.d.ts.map +1 -1
  34. package/build/three.js +2 -1
  35. package/build/three.js.map +1 -1
  36. package/build/units-BZmvVyu4.js +30 -0
  37. package/build/units-BZmvVyu4.js.map +1 -0
  38. package/package.json +7 -1
  39. package/build/check-DI_B57qy.js.map +0 -1
  40. package/build/layers-CDNFVXds.js.map +0 -1
  41. package/build/layers-CYZwt1bH.d.ts.map +0 -1
  42. package/build/solids-OiTlb_Pm.d.ts.map +0 -1
@@ -0,0 +1,329 @@
1
+ import { c as Room, i as OpeningKind, o as PlanPoint, y as LengthUnit } from "./room-BQua5eSs.js";
2
+ import { Ring } from "@mark1russell7/layout-contract";
3
+ /**
4
+ * A line of a sheet: one straight piece of a stroked path, in the coordinates of the sheet.
5
+ * The y axis of a sheet points down, as in a PDF page after the usual flip.
6
+ */
7
+ export interface SheetLine {
8
+ readonly from: PlanPoint;
9
+ readonly to: PlanPoint;
10
+ /** The width of the pen, in the units of the sheet. */
11
+ readonly width: number;
12
+ /** The color of the pen, for example `#000000`. */
13
+ readonly color: string;
14
+ /** This value is true when the line is one piece of a curve, for example of the swing of a door. */
15
+ readonly curve?: boolean | undefined;
16
+ }
17
+ /** A filled path of a sheet. The rings use the even-odd rule. The sequence of the fills is the paint sequence. */
18
+ export interface SheetFill {
19
+ readonly color: string;
20
+ readonly rings: readonly Ring[];
21
+ }
22
+ /** A text of a sheet. The point `at` is the start of its base line. */
23
+ export interface SheetText {
24
+ readonly text: string;
25
+ readonly at: PlanPoint;
26
+ /** The height of the text, in the units of the sheet. */
27
+ readonly height: number;
28
+ }
29
+ /**
30
+ * A sheet: the vector paths of one floor plan, for example from a page of a PDF file.
31
+ * The scale is the number of units of the sheet for one `unit` of the building. A PDF page at 1/8 inch to the foot has the scale 9 with the unit `ft`.
32
+ */
33
+ export interface Sheet {
34
+ /** The width of the sheet, in the units of the sheet. */
35
+ readonly width: number;
36
+ /** The height of the sheet, in the units of the sheet. */
37
+ readonly height: number;
38
+ readonly scale: number;
39
+ /** The unit of the building, and of each length of the result. */
40
+ readonly unit: LengthUnit;
41
+ readonly lines: readonly SheetLine[];
42
+ readonly fills?: readonly SheetFill[] | undefined;
43
+ readonly texts?: readonly SheetText[] | undefined;
44
+ }
45
+ /** This function gives the name of the pen of a line: its width, a bar, then its color. */
46
+ export declare function penOf(line: Pick<SheetLine, "width" | "color">): string;
47
+ /** This function gives the length of a line. */
48
+ export declare function lineLength(line: Pick<SheetLine, "from" | "to">): number;
49
+ /** A legend: the name of each fill color, and the fills that are the color samples of the legend. */
50
+ export interface Legend {
51
+ /** The name of each color. A color with two or more names has the names with a slash between them. */
52
+ readonly names: Readonly<Record<string, string>>;
53
+ /** The position of each sample in the fills of the sheet. A sample is not a room. */
54
+ readonly samples: readonly number[];
55
+ }
56
+ /** The options of `readLegend`. Each length is in the units of the sheet, and the defaults suit a sheet in points. */
57
+ export interface LegendOptions {
58
+ /** The smallest side of a sample. The default is 4. */
59
+ readonly smallest?: number | undefined;
60
+ /** The largest side of a sample. The default is 30. */
61
+ readonly largest?: number | undefined;
62
+ /** The largest distance from the right side of a sample to the start of its text. The default is 12. */
63
+ readonly reach?: number | undefined;
64
+ /** The smallest height of a text of the legend. The default is 2. */
65
+ readonly smallestText?: number | undefined;
66
+ }
67
+ /** This function gives the box of a fill: the smallest x, the smallest y, the largest x and the largest y. */
68
+ export declare function fillBox(fill: SheetFill): readonly [number, number, number, number];
69
+ /**
70
+ * This function reads the legend of a sheet. A sample is a small square fill with a text near its right side.
71
+ * The text is the name of the color of the sample.
72
+ */
73
+ export declare function readLegend(sheet: Pick<Sheet, "fills" | "texts">, options?: LegendOptions): Legend;
74
+ /** Two parallel lines at a distance from each other. */
75
+ export interface LinePair {
76
+ /** The position of the first line. */
77
+ readonly a: number;
78
+ /** The position of the second line. */
79
+ readonly b: number;
80
+ /** The distance between the two lines. */
81
+ readonly distance: number;
82
+ /** The length of the common part of the two lines, along their direction. */
83
+ readonly overlap: number;
84
+ }
85
+ /** The pairs of `parallelPairs`, and the number of partners on each side of each line. */
86
+ export interface PairSearch {
87
+ readonly pairs: readonly LinePair[];
88
+ /** The partners of line `i` on its left side are at `2 * i`, and on its right side at `2 * i + 1`. */
89
+ readonly sides: Int32Array;
90
+ }
91
+ /**
92
+ * This function finds the pairs of parallel lines with a distance from `nearest` to `farthest`, and a common part of `overlap` or more.
93
+ * Two lines are parallel when their directions differ by `tolerance` radians or less. The lines go in buckets by direction, so the search is fast.
94
+ */
95
+ export declare function parallelPairs(lines: readonly SheetLine[], nearest: number, farthest: number, overlap: number, tolerance?: number): PairSearch;
96
+ /** The options of the search for walls. Each length is in the unit of the sheet. */
97
+ export interface WallOptions {
98
+ /** The smallest thickness of a wall. The default is 0.25 ft. */
99
+ readonly thinnest?: number | undefined;
100
+ /** The largest thickness of a wall. The default is 1.5 ft. */
101
+ readonly thickest?: number | undefined;
102
+ /** The length of a long line of a pen. The pairs of the long lines tell if a pen is a wall pen. The default is 1.5 ft. */
103
+ readonly longLine?: number | undefined;
104
+ /** The smallest number of long lines of a wall pen. The default is 8. */
105
+ readonly fewestLines?: number | undefined;
106
+ /** The smallest sum of the lengths of the paired long lines of a wall pen. The default is 40 ft. */
107
+ readonly leastLength?: number | undefined;
108
+ /** The smallest common length of the two faces of one wall. The default is 1 ft. */
109
+ readonly shortestWall?: number | undefined;
110
+ }
111
+ /** The read of one pen of a sheet. */
112
+ export interface PenRead {
113
+ /** The name of the pen, as `penOf` gives it. */
114
+ readonly pen: string;
115
+ /** The number of long straight lines of the pen. */
116
+ readonly lines: number;
117
+ /** The part of the long lines with a parallel partner at the distance of a wall, from 0 to 1. */
118
+ readonly paired: number;
119
+ /** The part of the paired lines with partners on one side only, from 0 to 1. The face of a wall has a partner on one side. */
120
+ readonly oneSide: number;
121
+ /** The sum of the lengths of the paired lines, in the `unit` of the sheet. */
122
+ readonly length: number;
123
+ /** The part of the length of all the straight lines of the pen that is in the paired lines, from 0 to 1. A pen of short lines, as a hatch or text, has a small part. */
124
+ readonly lengthShare: number;
125
+ /** This value is true when the pen draws walls. */
126
+ readonly wall: boolean;
127
+ }
128
+ /** The limits of the search for walls, in the units of the sheet. */
129
+ export interface WallLimits {
130
+ readonly thinnest: number;
131
+ readonly thickest: number;
132
+ readonly longLine: number;
133
+ readonly fewestLines: number;
134
+ readonly leastLength: number;
135
+ readonly shortestWall: number;
136
+ }
137
+ /**
138
+ * This function reads each pen of the straight lines of a sheet.
139
+ * A pen is a wall pen when most of its long lines have a parallel partner at the distance of a wall thickness.
140
+ * Also, most of the paired lines of a wall pen have the partner on one side only.
141
+ * Also, the paired lines hold most of the length of all the straight lines of the pen. Thus a hatch with some paired lines is not a wall pen.
142
+ *
143
+ * The limits are in the units of the sheet. The pens with the most lines come first.
144
+ */
145
+ export declare function readPens(lines: readonly SheetLine[], limits: WallLimits, scale: number): readonly PenRead[];
146
+ /** A wall from two parallel lines of a wall pen: the center line of the common part, in the coordinates of the sheet. */
147
+ export interface WallPair {
148
+ readonly a: number;
149
+ readonly b: number;
150
+ readonly from: PlanPoint;
151
+ readonly to: PlanPoint;
152
+ /** The distance between the two faces, in the units of the sheet. */
153
+ readonly thickness: number;
154
+ }
155
+ /**
156
+ * This function gives the walls of the straight lines of the wall pens. Each line keeps its nearest partner, so a face has one wall.
157
+ * The wall is the center line of the common part of the two faces.
158
+ */
159
+ export declare function wallPairs(lines: readonly SheetLine[], limits: WallLimits): readonly WallPair[];
160
+ /** The options of the search for bridges. Each length is in the `unit` of the sheet. */
161
+ export interface BridgeOptions {
162
+ /** The smallest width of a gap in a wall. The default is 1.5 ft. */
163
+ readonly narrowest?: number | undefined;
164
+ /** The largest width of a gap in a wall. The default is 4.5 ft. */
165
+ readonly widest?: number | undefined;
166
+ /** The smallest length of the end line of a wall. The default is 0.2 ft. */
167
+ readonly shortestEnd?: number | undefined;
168
+ /** The largest length of the end line of a wall. The default is 1.6 ft. */
169
+ readonly longestEnd?: number | undefined;
170
+ /** Two lines touch when the distance between them is this value or less. The default is 0.225 ft. */
171
+ readonly touch?: number | undefined;
172
+ /** The largest angle between the direction of an open end and the direction to the other end, in degrees. The default is 25. */
173
+ readonly angle?: number | undefined;
174
+ }
175
+ /** The limits of the search for bridges, in the units of the sheet. */
176
+ export interface BridgeLimits {
177
+ readonly narrowest: number;
178
+ readonly widest: number;
179
+ readonly shortestEnd: number;
180
+ readonly longestEnd: number;
181
+ readonly touch: number;
182
+ readonly angle: number;
183
+ }
184
+ /** These are the sources of a bridge. `ends` is a pair of end lines of two walls. `open` is a pair of open ends of two lines. */
185
+ export declare const BRIDGE_SOURCES: readonly ["ends", "open"];
186
+ /** A source of a bridge. */
187
+ export type BridgeSource = (typeof BRIDGE_SOURCES)[number];
188
+ /** A bridge: a gap between two wall ends, in the coordinates of the sheet. A bridge closes a room, and the room record has it as an opening. */
189
+ export interface Bridge {
190
+ readonly source: BridgeSource;
191
+ /** The line of the bridge from the middle of one wall end to the middle of the other. */
192
+ readonly from: PlanPoint;
193
+ readonly to: PlanPoint;
194
+ /** The thickness of the wall at the bridge. A bridge from open ends has no thickness. */
195
+ readonly thickness: number | undefined;
196
+ /** The lines that close the gap, as the barrier of the rooms. */
197
+ readonly lines: readonly SheetLine[];
198
+ }
199
+ /**
200
+ * This function finds the bridges across the gaps in the walls. A gap is from `narrowest` to `widest`.
201
+ *
202
+ * - Two short end lines of walls can be parallel and face each other across a gap. They give two lines, one along each face of the wall.
203
+ * - An open end of a long line, with no other line near it, joins the nearest open end that faces it.
204
+ */
205
+ export declare function findBridges(lines: readonly SheetLine[], limits: BridgeLimits): readonly Bridge[];
206
+ /**
207
+ * A grid of square cells over a sheet. The cell at column `x` and row `y` has the position `y * columns + x` in each array of the grid.
208
+ * The plan import keeps its rasters here: each is specific to the method of the import.
209
+ */
210
+ interface Grid {
211
+ readonly columns: number;
212
+ readonly rows: number;
213
+ /** The side of a cell, in the units of the sheet. */
214
+ readonly cell: number;
215
+ }
216
+ /** The name of the side of an opening that is outside the building. */
217
+ export declare const OUTSIDE = "outside";
218
+ /** The options of `importPlan`. Each length is in the `unit` of the sheet, and each area is in that unit squared. */
219
+ export interface ImportOptions {
220
+ /** The legend of the sheet. Without it, the rooms have no use and the area gate has no rings. */
221
+ readonly legend?: Legend | undefined;
222
+ /** The wall pens. The default is each pen that `readPens` reads as a wall pen. */
223
+ readonly wallPens?: readonly string[] | undefined;
224
+ /** The pens of the doors, as barriers of the rooms. The default is the pen with the most curve lines: the pen of the door swings. */
225
+ readonly doorPens?: readonly string[] | undefined;
226
+ readonly walls?: WallOptions | undefined;
227
+ readonly bridges?: BridgeOptions | undefined;
228
+ /** The side of a cell of the grid. The default is 0.1 ft. */
229
+ readonly cell?: number | undefined;
230
+ /** The largest number of cells of the grid. A larger grid gets larger cells. The default is 40 000 000. */
231
+ readonly largestGrid?: number | undefined;
232
+ /** A free region with a smaller area is a speck, not a room. The default is 12 square ft. */
233
+ readonly smallestRoom?: number | undefined;
234
+ /** A free region with a smaller mean width is the space inside a wall, not a room. The mean width is two times the area over the perimeter. The default is 1.6 ft. */
235
+ readonly thinnestRoom?: number | undefined;
236
+ /** The height of each wall. The default is 8 ft. */
237
+ readonly height?: number | undefined;
238
+ /** The height of each opening. The default is 80 in. */
239
+ readonly openingHeight?: number | undefined;
240
+ /** A fill ring with a smaller area is not in the area gate. The default is 15 square ft. */
241
+ readonly smallestRing?: number | undefined;
242
+ /** The limits of the area gate, as parts of the area of a ring. The default is 0.05 and 0.1. */
243
+ readonly gateLimits?: readonly number[] | undefined;
244
+ }
245
+ /** One room of a plan import: a free region of the grid inside the building. */
246
+ export interface ImportedRoom {
247
+ /** The `id` of the room, and of its floor in the room record. */
248
+ readonly id: string;
249
+ /** The name of the fill color under most of the room, from the legend. */
250
+ readonly use?: string | undefined;
251
+ /** The fill color under most of the room. */
252
+ readonly color?: string | undefined;
253
+ /** The area of the cells of the room. */
254
+ readonly area: number;
255
+ /** The mean point of the cells of the room, in the plan. */
256
+ readonly center: PlanPoint;
257
+ }
258
+ /** One opening of a plan import: a bridge across a gap in a wall. */
259
+ export interface ImportedOpening {
260
+ /** The `id` of the opening in the room record. */
261
+ readonly id: string;
262
+ /** The `id` of the wall of the opening in the room record. */
263
+ readonly wall: string;
264
+ readonly kind: OpeningKind;
265
+ readonly source: Bridge["source"];
266
+ /** The room on each side of the opening, or `OUTSIDE`. An opening with no room or a room on the two sides has no sides. */
267
+ readonly sides?: readonly [string, string] | undefined;
268
+ }
269
+ /** The kinds of the free regions of the grid. */
270
+ export declare const REGION_KINDS: readonly ["outside", "speck", "core", "room"];
271
+ /** A kind of a free region of the grid. */
272
+ export type RegionKind = (typeof REGION_KINDS)[number];
273
+ /** One fill ring of the area gate, and the rooms that it holds. */
274
+ export interface RingFit {
275
+ /** The position of the fill in the fills of the sheet. */
276
+ readonly fill: number;
277
+ /** The position of the ring in the rings of the fill. */
278
+ readonly ring: number;
279
+ readonly use: string;
280
+ /** The area of the ring. */
281
+ readonly area: number;
282
+ /** The rooms that have most of their cells in the ring, and half of their cells or more. */
283
+ readonly rooms: readonly string[];
284
+ /** The sum of the areas of the rooms over the area of the ring, minus 1. A ring with no room has no error. */
285
+ readonly error?: number | undefined;
286
+ }
287
+ /** The area gate: each fill ring of a use of the legend against the rooms that it holds. */
288
+ export interface AreaGate {
289
+ readonly rings: readonly RingFit[];
290
+ /** The number of rings with an error of each limit or less, in the sequence of the limits. */
291
+ readonly within: readonly {
292
+ readonly limit: number;
293
+ readonly rings: number;
294
+ }[];
295
+ /** The median of the errors. A gate with no error has no median. */
296
+ readonly median?: number | undefined;
297
+ }
298
+ /** The result of a plan import. */
299
+ export interface PlanImport {
300
+ /**
301
+ * The room record of the level: the walls, one opening for each bridge, and one floor for each room.
302
+ * A wall from two faces has the `id` `wall-` and a number. The wall of a bridge has the `id` `bridge-` and the number of its opening.
303
+ */
304
+ readonly room: Room;
305
+ readonly rooms: readonly ImportedRoom[];
306
+ readonly openings: readonly ImportedOpening[];
307
+ /** The number of free regions of each kind. */
308
+ readonly regions: Readonly<Record<RegionKind, number>>;
309
+ readonly pens: readonly PenRead[];
310
+ readonly wallPens: readonly string[];
311
+ readonly doorPens: readonly string[];
312
+ /** The grid of the rooms. Its cell is in the `unit` of the sheet. */
313
+ readonly grid: Grid;
314
+ readonly gate: AreaGate;
315
+ }
316
+ /**
317
+ * This function turns the vector paths of a floor plan into a room record with rooms, walls and openings.
318
+ *
319
+ * 1. A wall pen has long lines with a parallel partner at the distance of a wall thickness. Two such lines give a wall.
320
+ * 2. A bridge closes each gap between two wall ends. The bridge is an opening of the room record.
321
+ * 3. The walls, the door pens and the bridges go on a grid. Each free region of the grid that does not touch the border is a room, a speck or the space in a wall.
322
+ * 4. A room gets the fill color under most of its cells, and its use from the legend.
323
+ * 5. The area gate compares each fill ring of the legend with the rooms that have most of their cells in it.
324
+ *
325
+ * The coordinates of the sheet have the y axis down. The plan of the result has the y axis up, with the bottom left corner of the sheet at the origin.
326
+ */
327
+ export declare function importPlan(sheet: Sheet, options?: ImportOptions): PlanImport;
328
+ export type { Grid };
329
+ //# sourceMappingURL=plan-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-import.d.ts","names":[],"sources":["../src/plan-import/sheet.ts","../src/plan-import/walls.ts","../src/plan-import/bridges.ts","../src/plan-import/raster.ts","../src/plan-import/importer.ts"],"mappings":";;;;;;iBAQiB;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;WAEA;;;iBAIM;WACN;WACA,gBAAgB;;;iBAIV;WACN;WACA,IAAI;;WAEJ;;;;;;iBAOM;;WAEN;;WAEA;WACA;;WAEA,MAAM;WACN,gBAAgB;WAChB,iBAAiB;WACjB,iBAAiB;;;wBAIZ,MAAM,MAAM,KAAK;;wBAKjB,WAAW,MAAM,KAAK;;iBAKrB;;WAEN,OAAO,SAAS;;WAEhB;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;wBAIK,QAAQ,MAAM;;;;;wBAoBd,WAAW,OAAO,KAAK,2BAA2B,UAAS,gBAAqB;;iBCjG/E;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN,gBAAgB;;WAEhB,OAAO;;;;;;wBA8BF,cAAc,gBAAgB,aAAa,iBAAiB,kBAAkB,iBAAiB,qBAAqB;;iBAyDnH;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN;WACA;WACA;WACA;WACA;WACA;;;;;;;;;;wBAWK,SAAS,gBAAgB,aAAa,QAAQ,YAAY,yBAAyB;;iBAwClF;WACN;WACA;WACA,MAAM;WACN,IAAI;;WAEJ;;;;;;wBAOK,UAAU,gBAAgB,aAAa,QAAQ,sBAAsB;;iBC7MpE;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN;WACA;WACA;WACA;WACA;WACA;;;qBAIE;;YAGD,uBAAuB;;iBAGlB;WACN,QAAQ;;WAER,MAAM;WACN,IAAI;;WAEJ;;WAEA,gBAAgB;;;;;;;;wBASX,YAAY,gBAAgB,aAAa,QAAQ,wBAAwB;;;;;UC9CxE;WACN;WACA;;WAEA;;;qBCFE;;iBAGI;;WAEN,SAAS;;WAET;;WAEA;WACA,QAAQ;WACR,UAAU;;WAEV;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,QAAQ;;;iBAIF;;WAEN;;WAEA;WACA,MAAM;WACN,QAAQ;;WAER;;;qBAIE;;YAGD,qBAAqB;;iBAGhB;;WAEN;;WAEA;WACA;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN,gBAAgB;;WAEhB;aAA4B;aAAwB;;;WAEpD;;;iBAIM;;;;;WAKN,MAAM;WACN,gBAAgB;WAChB,mBAAmB;;WAEnB,SAAS,SAAS,OAAO;WACzB,eAAe;WACf;WACA;;WAEA,MAAM;WACN,MAAM;;;;;;;;;;;;;wBAiBD,WAAW,OAAO,OAAO,UAAS,gBAAqB"}