@threekit-tools/treble 0.0.92 → 0.0.94-next-01

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 (69) hide show
  1. package/dist/Treble/Treble.d.ts +2 -2
  2. package/dist/Treble/Treble.js +2 -2
  3. package/dist/Treble/index.d.ts +1 -1
  4. package/dist/Treble/index.js +1 -1
  5. package/dist/Treble/snapshot.d.ts +2 -2
  6. package/dist/Treble/snapshot.js +1 -1
  7. package/dist/hooks/useNestedConfigurator/index.js +1 -2
  8. package/dist/hooks/useSnapshot/index.d.ts +1 -1
  9. package/dist/hooks/useSpaces/SpacesState.d.ts +15 -2
  10. package/dist/hooks/useSpaces/SpacesState.js +85 -22
  11. package/dist/hooks/useSpaces/constants.d.ts +17 -2
  12. package/dist/hooks/useSpaces/constants.js +58 -37
  13. package/dist/hooks/useSpaces/dataHandlers.d.ts +22 -4
  14. package/dist/hooks/useSpaces/dataHandlers.js +197 -40
  15. package/dist/hooks/useSpaces/draw/drawDoors.js +1 -1
  16. package/dist/hooks/useSpaces/draw/drawGrid.d.ts +1 -1
  17. package/dist/hooks/useSpaces/draw/drawGrid.js +4 -1
  18. package/dist/hooks/useSpaces/draw/drawWalls.d.ts +3 -2
  19. package/dist/hooks/useSpaces/draw/drawWalls.js +6 -4
  20. package/dist/hooks/useSpaces/index.d.ts +13 -0
  21. package/dist/hooks/useSpaces/index.js +269 -126
  22. package/dist/hooks/useSpaces/types.d.ts +52 -13
  23. package/dist/icons/Boundary.d.ts +3 -0
  24. package/dist/icons/{Ruler copy.js → Boundary.js} +7 -8
  25. package/dist/icons/Draw.js +3 -3
  26. package/dist/icons/RulerBlank.js +2 -2
  27. package/dist/icons/RulerDetailed.js +2 -2
  28. package/dist/icons/Window.js +4 -4
  29. package/dist/icons/index.js +28 -0
  30. package/dist/index.d.ts +17 -2
  31. package/dist/index.js +35 -5
  32. package/dist/store/attributes.d.ts +2 -1
  33. package/dist/store/index.d.ts +41 -10
  34. package/dist/store/index.js +3 -1
  35. package/dist/store/product.js +4 -7
  36. package/dist/store/spaces.d.ts +32 -5
  37. package/dist/store/spaces.js +164 -7
  38. package/dist/store/treble.d.ts +1 -1
  39. package/dist/store/treble.js +14 -21
  40. package/dist/store/wishlist.d.ts +2 -20
  41. package/dist/types.d.ts +3 -1
  42. package/package.json +1 -2
  43. package/dist/Treble/snapshots.d.ts +0 -22
  44. package/dist/Treble/snapshots.js +0 -247
  45. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +0 -95
  46. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +0 -1237
  47. package/dist/hooks/useRoomBuilder/constants.d.ts +0 -41
  48. package/dist/hooks/useRoomBuilder/constants.js +0 -48
  49. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +0 -18
  50. package/dist/hooks/useRoomBuilder/dataHandlers.js +0 -187
  51. package/dist/hooks/useRoomBuilder/draw.d.ts +0 -55
  52. package/dist/hooks/useRoomBuilder/draw.js +0 -573
  53. package/dist/hooks/useRoomBuilder/findLoops.d.ts +0 -5
  54. package/dist/hooks/useRoomBuilder/findLoops.js +0 -99
  55. package/dist/hooks/useRoomBuilder/geometry.d.ts +0 -33
  56. package/dist/hooks/useRoomBuilder/geometry.js +0 -325
  57. package/dist/hooks/useRoomBuilder/index.d.ts +0 -40
  58. package/dist/hooks/useRoomBuilder/index.js +0 -303
  59. package/dist/hooks/useRoomBuilder/messaging.d.ts +0 -8
  60. package/dist/hooks/useRoomBuilder/messaging.js +0 -18
  61. package/dist/hooks/useRoomBuilder/themes.d.ts +0 -12
  62. package/dist/hooks/useRoomBuilder/themes.js +0 -273
  63. package/dist/hooks/useRoomBuilder/types.d.ts +0 -238
  64. package/dist/hooks/useRoomBuilder/types.js +0 -36
  65. package/dist/hooks/useRoomBuilder/validators.d.ts +0 -36
  66. package/dist/hooks/useRoomBuilder/validators.js +0 -362
  67. package/dist/icons/Ruler copy.d.ts +0 -3
  68. package/dist/icons/RulerDetailed copy.d.ts +0 -3
  69. package/dist/icons/RulerDetailed copy.js +0 -27
@@ -1,573 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.drawRoom = exports.drawElements = exports.drawOpenings = exports.drawDoors = exports.drawWindows = exports.drawDimensions = exports.drawVertices = exports.drawWalls = exports.drawNewWall = exports.drawVertex = exports.drawFloor = exports.drawGrid = exports.drawBackground = exports.clearCanvas = void 0;
13
- var types_1 = require("./types");
14
- var types_2 = require("./types");
15
- var geometry_1 = require("./geometry");
16
- var debug = false;
17
- function clearCanvas(canvas) {
18
- var ctx = canvas.getContext('2d');
19
- if (!ctx)
20
- return;
21
- ctx.clearRect(0, 0, canvas.width, canvas.height);
22
- }
23
- exports.clearCanvas = clearCanvas;
24
- function drawBackground(canvas, color) {
25
- if (!color)
26
- return;
27
- var ctx = canvas.getContext('2d');
28
- if (!ctx)
29
- return;
30
- ctx.fillStyle = color;
31
- ctx.fillRect(0, 0, canvas.width, canvas.height);
32
- }
33
- exports.drawBackground = drawBackground;
34
- function drawGrid(canvas, styles) {
35
- var ctx = canvas.getContext('2d');
36
- if (!ctx)
37
- return;
38
- ctx.strokeStyle = styles.lineColor;
39
- var numHorizontalLines = Math.ceil(canvas.width / styles.gridStepGap);
40
- var numVerticalLines = Math.ceil(canvas.height / styles.gridStepGap);
41
- for (var i = 0; i < numHorizontalLines; i++) {
42
- var y = i * styles.gridStepGap;
43
- ctx.lineWidth =
44
- styles.secondaryLineIncrement !== undefined &&
45
- i % styles.secondaryLineIncrement === 0
46
- ? styles.secondaryLineThickness
47
- : styles.lineThickness;
48
- ctx.beginPath();
49
- ctx.moveTo(0, y);
50
- ctx.lineTo(canvas.width, y);
51
- ctx.stroke();
52
- }
53
- for (var i = 0; i < numVerticalLines; i++) {
54
- var x = i * styles.gridStepGap;
55
- ctx.lineWidth =
56
- styles.secondaryLineIncrement !== undefined &&
57
- i % styles.secondaryLineIncrement === 0
58
- ? styles.secondaryLineThickness
59
- : styles.lineThickness;
60
- ctx.beginPath();
61
- ctx.moveTo(x, 0);
62
- ctx.lineTo(x, canvas.height);
63
- ctx.stroke();
64
- }
65
- }
66
- exports.drawGrid = drawGrid;
67
- function drawFloor(canvas, enclosedSpaces, styles) {
68
- var ctx = canvas.getContext('2d');
69
- if (!ctx)
70
- return;
71
- if (!enclosedSpaces.length)
72
- return;
73
- for (var _i = 0, enclosedSpaces_1 = enclosedSpaces; _i < enclosedSpaces_1.length; _i++) {
74
- var enclosedSpace = enclosedSpaces_1[_i];
75
- var loop = enclosedSpace.loop;
76
- ctx.fillStyle = styles.color;
77
- if (debug)
78
- ctx.fillStyle = 'rgba(255,0,0,.2)';
79
- ctx.beginPath();
80
- ctx.moveTo.apply(ctx, loop[0]);
81
- for (var i = 1; i < loop.length; i++)
82
- ctx.lineTo.apply(ctx, loop[i]);
83
- ctx.fill();
84
- }
85
- }
86
- exports.drawFloor = drawFloor;
87
- function drawWall(canvas, wall, style, mode) {
88
- var _a;
89
- var ctx = canvas.getContext('2d');
90
- if (!ctx)
91
- return;
92
- var path = (_a = wall.path) !== null && _a !== void 0 ? _a : (0, geometry_1.addThicknessToLine)(wall.line, style.thickness);
93
- var stroke = style.stroke, fill = style.fill, strokeWidth = style.strokeWidth;
94
- if (mode) {
95
- stroke = style[mode].stroke;
96
- fill = style[mode].fill;
97
- }
98
- ctx.strokeStyle = stroke || fill;
99
- ctx.fillStyle = fill;
100
- ctx.lineWidth = strokeWidth || 1;
101
- ctx.beginPath();
102
- ctx.moveTo.apply(ctx, path[0]);
103
- for (var i = 1; i < path.length; i++) {
104
- ctx.lineTo.apply(ctx, path[i]);
105
- }
106
- ctx.lineTo.apply(ctx, path[0]);
107
- ctx.fill();
108
- if (style.stroke && style.strokeWidth)
109
- ctx.stroke();
110
- }
111
- function drawFloorArea(canvas, enclosedSpaces, styles) {
112
- var ctx = canvas.getContext('2d');
113
- if (!ctx)
114
- return;
115
- if (!enclosedSpaces.length)
116
- return;
117
- for (var _i = 0, enclosedSpaces_2 = enclosedSpaces; _i < enclosedSpaces_2.length; _i++) {
118
- var enclosedSpace = enclosedSpaces_2[_i];
119
- var center = enclosedSpace.center, area = enclosedSpace.area;
120
- ctx.font = '20px Arial';
121
- ctx.fillStyle = styles.textColor;
122
- ctx.fillText(area, center[0], center[1]);
123
- }
124
- }
125
- function drawDimension(canvas, line, styles, message) {
126
- var ctx = canvas.getContext('2d');
127
- if (!ctx)
128
- return;
129
- var dimensionsBoxHeight = styles.fontSize + 6;
130
- var dimensionsHeight = dimensionsBoxHeight + 6;
131
- var line1 = (0, geometry_1.getParallelLineSegmentAtDistance)(line, styles.padding);
132
- var line2 = (0, geometry_1.getParallelLineSegmentAtDistance)(line, styles.padding + dimensionsHeight / 2);
133
- var line3 = (0, geometry_1.getParallelLineSegmentAtDistance)(line, styles.padding + dimensionsHeight);
134
- var textLine = (0, geometry_1.getParallelLineSegmentAtDistance)(line, styles.padding + dimensionsHeight / 2 - dimensionsBoxHeight / 2);
135
- var textCoordinates = (0, geometry_1.getMidpointOfLineSegment)(textLine);
136
- var textAngle = (0, geometry_1.getAngleOfLineSegment)(textLine);
137
- ctx.strokeStyle = styles.lineColor;
138
- ctx.lineWidth = 1;
139
- ctx.beginPath();
140
- ctx.moveTo.apply(ctx, line2[0]);
141
- ctx.lineTo.apply(ctx, line2[1]);
142
- ctx.stroke();
143
- ctx.beginPath();
144
- ctx.moveTo.apply(ctx, line1[0]);
145
- ctx.lineTo.apply(ctx, line3[0]);
146
- ctx.stroke();
147
- ctx.beginPath();
148
- ctx.moveTo.apply(ctx, line1[1]);
149
- ctx.lineTo.apply(ctx, line3[1]);
150
- ctx.stroke();
151
- ctx.beginPath();
152
- ctx.font = "".concat(styles.fontSize, "px ").concat(styles.font);
153
- ctx.font = "".concat(styles.fontSize, "px ").concat(styles.font);
154
- ctx.translate.apply(ctx, textCoordinates);
155
- ctx.rotate(textAngle);
156
- ctx.fillStyle = styles.textBackgroundColor;
157
- var textWidth = ctx.measureText(message).width + 12;
158
- ctx.fillRect(-(textWidth / 2), -((dimensionsBoxHeight * 3) / 4), textWidth, dimensionsBoxHeight);
159
- ctx.fillStyle = styles.textColor;
160
- ctx.textAlign = 'center';
161
- ctx.fillText(message, 0, 0);
162
- ctx.resetTransform();
163
- }
164
- function drawVertex(canvas, point, style, mode) {
165
- var ctx = canvas.getContext('2d');
166
- if (!ctx)
167
- return;
168
- var stroke = style.stroke, innerFill = style.innerFill, outerFill = style.outerFill, strokeWidth = style.strokeWidth, outerRadius = style.outerRadius;
169
- if (mode) {
170
- stroke = style[mode].stroke;
171
- innerFill = style[mode].innerFill;
172
- outerFill = style[mode].outerFill;
173
- }
174
- ctx.lineWidth = strokeWidth || 1;
175
- ctx.strokeStyle = stroke || innerFill;
176
- ctx.fillStyle = outerFill;
177
- if (outerRadius) {
178
- ctx.beginPath();
179
- ctx.arc(point[0], point[1], outerRadius, 0, 2 * Math.PI);
180
- if (style.strokeWidth)
181
- ctx.stroke();
182
- ctx.fill();
183
- }
184
- ctx.lineWidth = strokeWidth || 1;
185
- ctx.fillStyle = innerFill;
186
- ctx.strokeStyle = stroke || innerFill;
187
- ctx.beginPath();
188
- ctx.arc(point[0], point[1], style.innerRadius, 0, 2 * Math.PI);
189
- ctx.fill();
190
- if (!outerRadius && strokeWidth)
191
- ctx.stroke();
192
- if (debug) {
193
- ctx.font = '20px Arial';
194
- ctx.fillStyle = 'red';
195
- ctx.fillText.apply(ctx, __spreadArray([Math.round(point[0]) + ',' + Math.round(point[1])], point, false));
196
- }
197
- }
198
- exports.drawVertex = drawVertex;
199
- function drawWindow(canvas, wall, offset, length, style, mode) {
200
- var ctx = canvas.getContext('2d');
201
- if (!ctx)
202
- return;
203
- var windowLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, offset, length);
204
- var windowRectangleLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, offset + style.thickness / 2, length - style.thickness);
205
- var points = (0, geometry_1.addThicknessToLine)(windowLine, style.thickness);
206
- var rectanglePoints = (0, geometry_1.addThicknessToLine)(windowRectangleLine, style.thickness);
207
- var stroke = style.stroke, fill = style.fill, strokeWidth = style.strokeWidth;
208
- if (mode) {
209
- stroke = style[mode].stroke;
210
- fill = style[mode].fill;
211
- }
212
- ctx.fillStyle = 'white';
213
- ctx.beginPath();
214
- ctx.moveTo.apply(ctx, points[0]);
215
- for (var i = 1; i < points.length; i++) {
216
- ctx.lineTo.apply(ctx, points[i]);
217
- }
218
- ctx.lineTo.apply(ctx, points[0]);
219
- ctx.fill();
220
- ctx.closePath();
221
- ctx.strokeStyle = stroke || fill;
222
- ctx.fillStyle = fill;
223
- ctx.lineWidth = strokeWidth || 1;
224
- ctx.moveTo.apply(ctx, rectanglePoints[0]);
225
- ctx.beginPath();
226
- for (var i = 1; i < points.length; i++) {
227
- ctx.lineTo.apply(ctx, rectanglePoints[i]);
228
- }
229
- ctx.lineTo.apply(ctx, rectanglePoints[0]);
230
- ctx.fill();
231
- ctx.closePath();
232
- ctx.beginPath();
233
- ctx.moveTo.apply(ctx, windowLine[0]);
234
- ctx.lineTo.apply(ctx, windowLine[1]);
235
- if (style.stroke)
236
- ctx.stroke();
237
- ctx.closePath();
238
- var angle = (0, geometry_1.getAngleOfLineSegment)(windowLine);
239
- ctx.beginPath();
240
- ctx.arc(windowLine[0][0], windowLine[0][1], style.thickness / 2, angle - Math.PI / 2, angle + Math.PI / 2);
241
- ctx.fill();
242
- ctx.closePath();
243
- ctx.beginPath();
244
- ctx.arc(windowLine[1][0], windowLine[1][1], style.thickness / 2, angle + Math.PI / 2, angle - Math.PI / 2);
245
- ctx.fill();
246
- }
247
- function drawDoor(canvas, wall, offset, length, style, mode) {
248
- var ctx = canvas.getContext('2d');
249
- if (!ctx)
250
- return;
251
- var doorLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, offset, length);
252
- var points = (0, geometry_1.addThicknessToLine)(doorLine, style.thickness);
253
- var stroke = style.stroke, fill = style.fill, strokeWidth = style.strokeWidth;
254
- if (mode) {
255
- stroke = style[mode].stroke;
256
- fill = style[mode].fill;
257
- }
258
- ctx.strokeStyle = stroke || fill;
259
- ctx.fillStyle = fill;
260
- ctx.lineWidth = strokeWidth || 1;
261
- ctx.beginPath();
262
- ctx.moveTo.apply(ctx, points[0]);
263
- for (var i = 1; i < points.length; i++) {
264
- ctx.lineTo.apply(ctx, points[i]);
265
- }
266
- ctx.lineTo.apply(ctx, points[0]);
267
- ctx.fill();
268
- if (style.stroke)
269
- ctx.stroke();
270
- }
271
- function drawOpening(canvas, wall, offset, length, style, mode) {
272
- var ctx = canvas.getContext('2d');
273
- if (!ctx)
274
- return;
275
- var openingLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, offset, length);
276
- var points = (0, geometry_1.addThicknessToLine)(openingLine, style.thickness);
277
- var stroke = style.stroke, fill = style.fill, strokeWidth = style.strokeWidth;
278
- if (mode) {
279
- stroke = style[mode].stroke;
280
- fill = style[mode].fill;
281
- }
282
- ctx.fillStyle = 'white';
283
- ctx.beginPath();
284
- ctx.moveTo.apply(ctx, points[0]);
285
- for (var i = 1; i < points.length; i++) {
286
- ctx.lineTo.apply(ctx, points[i]);
287
- }
288
- ctx.lineTo.apply(ctx, points[0]);
289
- ctx.fill();
290
- ctx.beginPath();
291
- ctx.strokeStyle = stroke || fill;
292
- ctx.fillStyle = fill;
293
- ctx.lineWidth = strokeWidth || 1;
294
- ctx.setLineDash([10, 10]);
295
- ctx.moveTo.apply(ctx, openingLine[0]);
296
- ctx.lineTo.apply(ctx, openingLine[1]);
297
- ctx.stroke();
298
- ctx.closePath();
299
- ctx.beginPath();
300
- ctx.setLineDash([]);
301
- var angle = (0, geometry_1.getAngleOfLineSegment)(openingLine);
302
- ctx.arc(openingLine[0][0], openingLine[0][1], style.thickness / 2, angle - Math.PI / 2, angle + Math.PI / 2);
303
- ctx.fill();
304
- ctx.closePath();
305
- ctx.beginPath();
306
- ctx.arc(openingLine[1][0], openingLine[1][1], style.thickness / 2, angle + Math.PI / 2, angle - Math.PI / 2);
307
- ctx.fill();
308
- }
309
- function drawNewWall(canvas, line, styles, mode) {
310
- drawWall(canvas, {
311
- line: line,
312
- path: (0, geometry_1.addThicknessToLine)(line, styles.wall.thickness),
313
- }, styles.wall, mode !== null && mode !== void 0 ? mode : types_1.IElementStyleModes.ACTIVE);
314
- line.forEach(function (point) {
315
- return drawVertex(canvas, point, styles.vertex, mode !== null && mode !== void 0 ? mode : types_1.IElementStyleModes.HIGHLIGHT);
316
- });
317
- }
318
- exports.drawNewWall = drawNewWall;
319
- function drawWalls(canvas, walls, selections, styles) {
320
- var styled = [
321
- selections.active,
322
- selections.highlighted,
323
- selections.error,
324
- selections.hidden,
325
- ];
326
- var defaultOpenings = walls.reduce(function (output, _, i) {
327
- if (!styled.flat().includes(i))
328
- output.push(i);
329
- return output;
330
- }, []);
331
- var wallsMap = [
332
- [types_1.IElementStyleModes.ACTIVE, selections.active],
333
- [types_1.IElementStyleModes.HIGHLIGHT, selections.highlighted],
334
- [types_1.IElementStyleModes.ERROR, selections.error],
335
- [undefined, defaultOpenings],
336
- ];
337
- wallsMap.forEach(function (_a) {
338
- var mode = _a[0], wallIndexes = _a[1];
339
- return wallIndexes.forEach(function (index) { return drawWall(canvas, walls[index], styles, mode); });
340
- });
341
- }
342
- exports.drawWalls = drawWalls;
343
- function drawVertices(canvas, vertices, selections, styles) {
344
- var styled = [
345
- selections.active,
346
- selections.highlighted,
347
- selections.error,
348
- selections.hidden,
349
- ];
350
- var defaultOpenings = vertices.reduce(function (output, _, i) {
351
- if (!styled.flat().includes(i))
352
- output.push(i);
353
- return output;
354
- }, []);
355
- var verticesMap = [
356
- [types_1.IElementStyleModes.ACTIVE, selections.active],
357
- [types_1.IElementStyleModes.HIGHLIGHT, selections.highlighted],
358
- [types_1.IElementStyleModes.ERROR, selections.error],
359
- [undefined, defaultOpenings],
360
- ];
361
- verticesMap.forEach(function (_a) {
362
- var mode = _a[0], vertexIndexes = _a[1];
363
- return vertexIndexes.forEach(function (index) {
364
- var point = vertices[index].point;
365
- drawVertex(canvas, point, styles, mode);
366
- });
367
- });
368
- }
369
- exports.drawVertices = drawVertices;
370
- function drawDimensions(canvas, dimensions, config) {
371
- dimensions.forEach(function (_a) {
372
- var line = _a.line, label = _a.label;
373
- drawDimension(canvas, line, config.styles.dimensions, label);
374
- });
375
- }
376
- exports.drawDimensions = drawDimensions;
377
- function drawWindows(canvas, walls, windows, selections, styles) {
378
- var styled = [
379
- selections.active,
380
- selections.highlighted,
381
- selections.error,
382
- selections.hidden,
383
- ];
384
- var defaultOpenings = windows.reduce(function (output, _, i) {
385
- if (!styled.flat().includes(i))
386
- output.push(i);
387
- return output;
388
- }, []);
389
- var windowsMap = [
390
- [types_1.IElementStyleModes.ACTIVE, selections.active],
391
- [types_1.IElementStyleModes.HIGHLIGHT, selections.highlighted],
392
- [types_1.IElementStyleModes.ERROR, selections.error],
393
- [undefined, defaultOpenings],
394
- ];
395
- windowsMap.forEach(function (_a) {
396
- var mode = _a[0], windowIndexes = _a[1];
397
- return windowIndexes.forEach(function (index) {
398
- var window = windows[index];
399
- if (!(window === null || window === void 0 ? void 0 : window.connectedTo.length))
400
- return;
401
- var wallIndex = window.connectedTo[1];
402
- drawWindow(canvas, walls[wallIndex], window.offset, window.length, styles.feature, mode);
403
- });
404
- });
405
- }
406
- exports.drawWindows = drawWindows;
407
- function drawDoors(canvas, walls, doors, selections, styles) {
408
- var styled = [
409
- selections.active,
410
- selections.highlighted,
411
- selections.error,
412
- selections.hidden,
413
- ];
414
- var defaultOpenings = doors.reduce(function (output, _, i) {
415
- if (!styled.flat().includes(i))
416
- output.push(i);
417
- return output;
418
- }, []);
419
- var doorsMap = [
420
- [types_1.IElementStyleModes.ACTIVE, selections.active],
421
- [types_1.IElementStyleModes.HIGHLIGHT, selections.highlighted],
422
- [types_1.IElementStyleModes.ERROR, selections.error],
423
- [undefined, defaultOpenings],
424
- ];
425
- doorsMap.forEach(function (_a) {
426
- var mode = _a[0], doorsIndexes = _a[1];
427
- return doorsIndexes.forEach(function (index) {
428
- var door = doors[index];
429
- if (!(door === null || door === void 0 ? void 0 : door.connectedTo.length))
430
- return;
431
- var wallIndex = door.connectedTo[1];
432
- drawDoor(canvas, walls[wallIndex], door.offset, door.length, styles.feature, mode);
433
- });
434
- });
435
- }
436
- exports.drawDoors = drawDoors;
437
- function drawOpenings(canvas, walls, openings, selections, styles) {
438
- var styled = [
439
- selections.active,
440
- selections.highlighted,
441
- selections.error,
442
- selections.hidden,
443
- ];
444
- var defaultOpenings = openings.reduce(function (output, _, i) {
445
- if (!styled.flat().includes(i))
446
- output.push(i);
447
- return output;
448
- }, []);
449
- var openingsMap = [
450
- [types_1.IElementStyleModes.ACTIVE, selections.active],
451
- [types_1.IElementStyleModes.HIGHLIGHT, selections.highlighted],
452
- [types_1.IElementStyleModes.ERROR, selections.error],
453
- [undefined, defaultOpenings],
454
- ];
455
- openingsMap.forEach(function (_a) {
456
- var mode = _a[0], openingsIndexes = _a[1];
457
- return openingsIndexes.forEach(function (index) {
458
- var opening = openings[index];
459
- if (!(opening === null || opening === void 0 ? void 0 : opening.connectedTo.length))
460
- return;
461
- var wallIndex = opening.connectedTo[1];
462
- drawOpening(canvas, walls[wallIndex], opening.offset, opening.length, styles.feature, mode);
463
- });
464
- });
465
- }
466
- exports.drawOpenings = drawOpenings;
467
- function drawElements(canvas, walls, vertices, features, selections, styles) {
468
- var wallSelections = {
469
- active: [],
470
- highlighted: [],
471
- hidden: [],
472
- error: [],
473
- };
474
- var verticesSelections = {
475
- active: [],
476
- highlighted: [],
477
- hidden: [],
478
- error: [],
479
- };
480
- var windowSelections = {
481
- active: [],
482
- highlighted: [],
483
- hidden: [],
484
- error: [],
485
- };
486
- var doorSelections = {
487
- active: [],
488
- highlighted: [],
489
- hidden: [],
490
- error: [],
491
- };
492
- var openingSelections = {
493
- active: [],
494
- highlighted: [],
495
- hidden: [],
496
- error: [],
497
- };
498
- selections.active.forEach(function (address) {
499
- if (address.type === types_2.IElements.WALL)
500
- wallSelections.active.push(address.index);
501
- else if (address.type === types_2.IElements.VERTEX)
502
- verticesSelections.active.push(address.index);
503
- else if (address.type === types_2.IElements.WINDOW)
504
- windowSelections.active.push(address.index);
505
- else if (address.type === types_2.IElements.DOOR)
506
- doorSelections.active.push(address.index);
507
- else if (address.type === types_2.IElements.OPENING)
508
- openingSelections.active.push(address.index);
509
- });
510
- selections.highlighted.forEach(function (address) {
511
- if (address.type === types_2.IElements.WALL)
512
- wallSelections.highlighted.push(address.index);
513
- else if (address.type === types_2.IElements.VERTEX)
514
- verticesSelections.highlighted.push(address.index);
515
- else if (address.type === types_2.IElements.WINDOW)
516
- windowSelections.highlighted.push(address.index);
517
- else if (address.type === types_2.IElements.DOOR)
518
- doorSelections.highlighted.push(address.index);
519
- else if (address.type === types_2.IElements.OPENING)
520
- openingSelections.highlighted.push(address.index);
521
- });
522
- selections.hidden.forEach(function (address) {
523
- if (address.type === types_2.IElements.WALL)
524
- wallSelections.hidden.push(address.index);
525
- else if (address.type === types_2.IElements.VERTEX)
526
- verticesSelections.hidden.push(address.index);
527
- else if (address.type === types_2.IElements.WINDOW)
528
- windowSelections.hidden.push(address.index);
529
- else if (address.type === types_2.IElements.DOOR)
530
- doorSelections.hidden.push(address.index);
531
- else if (address.type === types_2.IElements.OPENING)
532
- openingSelections.hidden.push(address.index);
533
- });
534
- selections.error.forEach(function (address) {
535
- if (address.type === types_2.IElements.WALL)
536
- wallSelections.error.push(address.index);
537
- else if (address.type === types_2.IElements.VERTEX)
538
- verticesSelections.error.push(address.index);
539
- else if (address.type === types_2.IElements.WINDOW)
540
- windowSelections.error.push(address.index);
541
- else if (address.type === types_2.IElements.DOOR)
542
- doorSelections.error.push(address.index);
543
- else if (address.type === types_2.IElements.OPENING)
544
- openingSelections.error.push(address.index);
545
- });
546
- drawWalls(canvas, walls, wallSelections, styles.wall);
547
- drawVertices(canvas, vertices, verticesSelections, styles.vertex);
548
- if (features[types_2.IElements.WINDOW])
549
- drawWindows(canvas, walls, features[types_2.IElements.WINDOW] || [], windowSelections, styles);
550
- if (features[types_2.IElements.DOOR])
551
- drawDoors(canvas, walls, features[types_2.IElements.DOOR] || [], doorSelections, styles);
552
- if (features[types_2.IElements.OPENING])
553
- drawOpenings(canvas, walls, features[types_2.IElements.OPENING] || [], openingSelections, styles);
554
- }
555
- exports.drawElements = drawElements;
556
- function drawRoom(canvas, enclosedSpaces, walls, vertices, features, dimensions, selections, config) {
557
- var preppedSelections = {
558
- active: [(selections === null || selections === void 0 ? void 0 : selections.active) || []].flat(),
559
- highlighted: [(selections === null || selections === void 0 ? void 0 : selections.highlighted) || []].flat(),
560
- error: [(selections === null || selections === void 0 ? void 0 : selections.error) || []].flat(),
561
- hidden: [(selections === null || selections === void 0 ? void 0 : selections.hidden) || []].flat(),
562
- };
563
- clearCanvas(canvas);
564
- drawBackground(canvas, config.styles.grid.backgroundColor);
565
- drawGrid(canvas, config.styles.grid);
566
- drawFloor(canvas, enclosedSpaces, config.styles.floor);
567
- drawElements(canvas, walls, vertices, features, preppedSelections, config.styles);
568
- if (dimensions) {
569
- drawDimensions(canvas, dimensions, config);
570
- drawFloorArea(canvas, enclosedSpaces, config.styles.floor);
571
- }
572
- }
573
- exports.drawRoom = drawRoom;
@@ -1,5 +0,0 @@
1
- import type { ICoordinate2D, ICoordinatesLine } from './types';
2
- export declare function findLoops(lines: Array<ICoordinatesLine>): {
3
- inner: Array<ICoordinate2D[]>;
4
- outer: Array<ICoordinate2D[]>;
5
- };
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.findLoops = void 0;
13
- var geometry_1 = require("./geometry");
14
- var areSidesEqual = function (_a, _b) {
15
- var lineIndex0 = _a[0], fromPoint0 = _a[1];
16
- var lineIndex1 = _b[0], fromPoint1 = _b[1];
17
- return lineIndex0 === lineIndex1 && (0, geometry_1.arePointsEqual)(fromPoint0, fromPoint1);
18
- };
19
- var composeSideKey = function (_a) {
20
- var lineIndex = _a[0], point = _a[1];
21
- return "".concat(lineIndex, ":").concat(JSON.stringify(point));
22
- };
23
- var decomposeSideKey = function (key) {
24
- var _a = key.split(':'), lineIndexStr = _a[0], fromVertStr = _a[1];
25
- return [Number(lineIndexStr), JSON.parse(fromVertStr)];
26
- };
27
- function calcPointToLineAdjacency(lines) {
28
- return lines.reduce(function (output, line, lineIndex) {
29
- line.forEach(function (point) {
30
- var pointStr = JSON.stringify(point);
31
- if (output[pointStr])
32
- output[pointStr].push(lineIndex);
33
- else
34
- output[pointStr] = [lineIndex];
35
- });
36
- return output;
37
- }, {});
38
- }
39
- function findLoops(lines) {
40
- var pointToLinesIndices = calcPointToLineAdjacency(lines);
41
- var unvisitedSides = new Set(__spreadArray(__spreadArray([], lines.map(function (line, i) { return composeSideKey([i, line[0]]); }), true), lines.map(function (line, i) { return composeSideKey([i, line[1]]); }), true));
42
- var sumCurvature = 0;
43
- function nextAdjacentWallSide(side) {
44
- var lineIndex = side[0], fromPoint = side[1];
45
- var line = lines[lineIndex];
46
- var toPoint = (0, geometry_1.getLineOtherPoint)(line, fromPoint);
47
- var lineAng = (0, geometry_1.getAngleOfLineSegment)([fromPoint, toPoint]);
48
- var adjacentLineIndices = pointToLinesIndices[JSON.stringify(toPoint)];
49
- var nextLineIndex;
50
- if (adjacentLineIndices.length === 0)
51
- throw new Error();
52
- if (adjacentLineIndices.length === 1) {
53
- nextLineIndex = adjacentLineIndices[0];
54
- sumCurvature += Math.PI;
55
- }
56
- else {
57
- var smallestAngDiff = Infinity;
58
- for (var _i = 0, adjacentLineIndices_1 = adjacentLineIndices; _i < adjacentLineIndices_1.length; _i++) {
59
- var adjacentLineIndex = adjacentLineIndices_1[_i];
60
- if (adjacentLineIndex === lineIndex)
61
- continue;
62
- var adjacentLine = lines[adjacentLineIndex];
63
- var adjacentPoint = (0, geometry_1.getLineOtherPoint)(adjacentLine, toPoint);
64
- var adjacentLineAng = (0, geometry_1.getAngleOfLineSegment)([toPoint, adjacentPoint]);
65
- var angDiff = (0, geometry_1.euclideanMod)(lineAng - adjacentLineAng + Math.PI, Math.PI * 2);
66
- if (angDiff < smallestAngDiff) {
67
- smallestAngDiff = angDiff;
68
- nextLineIndex = adjacentLineIndex;
69
- }
70
- }
71
- sumCurvature += smallestAngDiff - Math.PI;
72
- }
73
- return [nextLineIndex, toPoint];
74
- }
75
- function traverseLoop(start) {
76
- var path = new Array();
77
- var curr = start;
78
- do {
79
- path.push(curr[1]);
80
- unvisitedSides.delete(composeSideKey(curr));
81
- curr = nextAdjacentWallSide(curr);
82
- } while (!areSidesEqual(start, curr));
83
- return path;
84
- }
85
- var innerLoops = new Array();
86
- var outerLoops = new Array();
87
- while (unvisitedSides.size > 0) {
88
- sumCurvature = 0;
89
- var start = decomposeSideKey(unvisitedSides.values().next().value);
90
- var path = traverseLoop(start);
91
- var isClockwise = sumCurvature < 0;
92
- (isClockwise ? innerLoops : outerLoops).push(path);
93
- }
94
- return {
95
- inner: innerLoops,
96
- outer: outerLoops,
97
- };
98
- }
99
- exports.findLoops = findLoops;