@threekit-tools/treble 0.0.91 → 0.0.92-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 (189) 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/components/ThreekitProvider/index.js +3 -2
  6. package/dist/connection.d.ts +4 -1
  7. package/dist/connection.js +16 -53
  8. package/dist/hooks/useAttribute/index.js +1 -5
  9. package/dist/hooks/useNestedConfigurator/index.js +1 -2
  10. package/dist/hooks/useSpaces/SpacesLayout.d.ts +11 -0
  11. package/dist/hooks/useSpaces/SpacesLayout.js +74 -0
  12. package/dist/hooks/useSpaces/SpacesState.d.ts +177 -0
  13. package/dist/hooks/useSpaces/SpacesState.js +1814 -0
  14. package/dist/hooks/useSpaces/constants.d.ts +79 -0
  15. package/dist/hooks/useSpaces/constants.js +130 -0
  16. package/dist/hooks/useSpaces/dataHandlers.d.ts +38 -0
  17. package/dist/hooks/useSpaces/dataHandlers.js +407 -0
  18. package/dist/hooks/useSpaces/draw/clearCanvas.d.ts +2 -0
  19. package/dist/hooks/useSpaces/draw/clearCanvas.js +9 -0
  20. package/dist/hooks/useSpaces/draw/drawBackground.d.ts +2 -0
  21. package/dist/hooks/useSpaces/draw/drawBackground.js +12 -0
  22. package/dist/hooks/useSpaces/draw/drawDimensions.d.ts +3 -0
  23. package/dist/hooks/useSpaces/draw/drawDimensions.js +53 -0
  24. package/dist/hooks/useSpaces/draw/drawDoors.d.ts +9 -0
  25. package/dist/hooks/useSpaces/draw/drawDoors.js +99 -0
  26. package/dist/hooks/useSpaces/draw/drawFloor.d.ts +3 -0
  27. package/dist/hooks/useSpaces/draw/drawFloor.js +36 -0
  28. package/dist/hooks/useSpaces/draw/drawGrid.d.ts +3 -0
  29. package/dist/hooks/useSpaces/draw/drawGrid.js +36 -0
  30. package/dist/hooks/useSpaces/draw/drawGuides.d.ts +3 -0
  31. package/dist/hooks/useSpaces/draw/drawGuides.js +23 -0
  32. package/dist/hooks/useSpaces/draw/drawOpenings.d.ts +9 -0
  33. package/dist/hooks/useSpaces/draw/drawOpenings.js +72 -0
  34. package/dist/hooks/useSpaces/draw/drawVertices.d.ts +8 -0
  35. package/dist/hooks/useSpaces/draw/drawVertices.js +61 -0
  36. package/dist/hooks/useSpaces/draw/drawWalls.d.ts +11 -0
  37. package/dist/hooks/useSpaces/draw/drawWalls.js +90 -0
  38. package/dist/hooks/useSpaces/draw/drawWindows.d.ts +9 -0
  39. package/dist/hooks/useSpaces/draw/drawWindows.js +82 -0
  40. package/dist/hooks/useSpaces/draw/index.d.ts +11 -0
  41. package/dist/hooks/useSpaces/draw/index.js +129 -0
  42. package/dist/hooks/useSpaces/geometry/addThicknessToLine.d.ts +3 -0
  43. package/dist/hooks/useSpaces/geometry/addThicknessToLine.js +13 -0
  44. package/dist/hooks/useSpaces/geometry/areLinesEqual.d.ts +3 -0
  45. package/dist/hooks/useSpaces/geometry/areLinesEqual.js +17 -0
  46. package/dist/hooks/useSpaces/geometry/arePointsEqual.d.ts +3 -0
  47. package/dist/hooks/useSpaces/geometry/arePointsEqual.js +8 -0
  48. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.d.ts +3 -0
  49. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.js +11 -0
  50. package/dist/hooks/useSpaces/geometry/closestPointOnLine.d.ts +3 -0
  51. package/dist/hooks/useSpaces/geometry/closestPointOnLine.js +13 -0
  52. package/dist/hooks/useSpaces/geometry/doLinesOverlap.d.ts +2 -0
  53. package/dist/hooks/useSpaces/geometry/doLinesOverlap.js +16 -0
  54. package/dist/hooks/useSpaces/geometry/euclideanMod.d.ts +2 -0
  55. package/dist/hooks/useSpaces/geometry/euclideanMod.js +6 -0
  56. package/dist/hooks/useSpaces/geometry/findLoops.d.ts +6 -0
  57. package/dist/hooks/{useRoomBuilder → useSpaces/geometry}/findLoops.js +31 -13
  58. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.d.ts +6 -0
  59. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.js +23 -0
  60. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.d.ts +3 -0
  61. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.js +7 -0
  62. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.d.ts +3 -0
  63. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.js +17 -0
  64. package/dist/hooks/useSpaces/geometry/getDistanceToLine.d.ts +3 -0
  65. package/dist/hooks/useSpaces/geometry/getDistanceToLine.js +10 -0
  66. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.d.ts +3 -0
  67. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.js +7 -0
  68. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.d.ts +3 -0
  69. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.js +17 -0
  70. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.d.ts +3 -0
  71. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.js +11 -0
  72. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.d.ts +3 -0
  73. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.js +43 -0
  74. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.d.ts +3 -0
  75. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.js +9 -0
  76. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.d.ts +3 -0
  77. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.js +20 -0
  78. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.d.ts +3 -0
  79. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.js +11 -0
  80. package/dist/hooks/useSpaces/geometry/getPolygonArea.d.ts +3 -0
  81. package/dist/hooks/useSpaces/geometry/getPolygonArea.js +15 -0
  82. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.d.ts +3 -0
  83. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.js +16 -0
  84. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.d.ts +6 -0
  85. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.js +17 -0
  86. package/dist/hooks/useSpaces/geometry/getTriangleArea.d.ts +3 -0
  87. package/dist/hooks/useSpaces/geometry/getTriangleArea.js +9 -0
  88. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.d.ts +3 -0
  89. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.js +12 -0
  90. package/dist/hooks/useSpaces/geometry/index.d.ts +30 -0
  91. package/dist/hooks/useSpaces/geometry/index.js +64 -0
  92. package/dist/hooks/useSpaces/geometry/isPointInPolygon.d.ts +3 -0
  93. package/dist/hooks/useSpaces/geometry/isPointInPolygon.js +21 -0
  94. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.d.ts +3 -0
  95. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.js +25 -0
  96. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.d.ts +3 -0
  97. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.js +11 -0
  98. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.d.ts +3 -0
  99. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.js +12 -0
  100. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.d.ts +3 -0
  101. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.js +9 -0
  102. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.d.ts +3 -0
  103. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.js +28 -0
  104. package/dist/hooks/useSpaces/index.d.ts +95 -0
  105. package/dist/hooks/useSpaces/index.js +557 -0
  106. package/dist/hooks/useSpaces/themes/blueprint.d.ts +3 -0
  107. package/dist/hooks/useSpaces/themes/blueprint.js +96 -0
  108. package/dist/hooks/useSpaces/themes/default.d.ts +3 -0
  109. package/dist/hooks/useSpaces/themes/default.js +96 -0
  110. package/dist/hooks/{useRoomBuilder/themes.d.ts → useSpaces/themes/index.d.ts} +3 -4
  111. package/dist/hooks/useSpaces/themes/index.js +21 -0
  112. package/dist/hooks/useSpaces/themes/light.d.ts +3 -0
  113. package/dist/hooks/useSpaces/themes/light.js +96 -0
  114. package/dist/hooks/useSpaces/types.d.ts +378 -0
  115. package/dist/hooks/{useRoomBuilder → useSpaces}/types.js +19 -1
  116. package/dist/hooks/useSpaces/validators/areWallsDuplicated.d.ts +3 -0
  117. package/dist/hooks/useSpaces/validators/areWallsDuplicated.js +61 -0
  118. package/dist/hooks/useSpaces/validators/areWallsIntersecting.d.ts +3 -0
  119. package/dist/hooks/useSpaces/validators/areWallsIntersecting.js +42 -0
  120. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.d.ts +3 -0
  121. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.js +52 -0
  122. package/dist/hooks/useSpaces/validators/areWallsTooShort.d.ts +3 -0
  123. package/dist/hooks/useSpaces/validators/areWallsTooShort.js +37 -0
  124. package/dist/hooks/useSpaces/validators/index.d.ts +15 -0
  125. package/dist/hooks/useSpaces/validators/index.js +40 -0
  126. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.d.ts +3 -0
  127. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.js +31 -0
  128. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.d.ts +3 -0
  129. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.js +19 -0
  130. package/dist/hooks/useSpaces/validators/isLineTooShort.d.ts +3 -0
  131. package/dist/hooks/useSpaces/validators/isLineTooShort.js +26 -0
  132. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.d.ts +4 -0
  133. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.js +19 -0
  134. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.d.ts +3 -0
  135. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.js +19 -0
  136. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.d.ts +3 -0
  137. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.js +41 -0
  138. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.d.ts +3 -0
  139. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.js +54 -0
  140. package/dist/hooks/useSpaces/validators/isWallTooShort.d.ts +3 -0
  141. package/dist/hooks/useSpaces/validators/isWallTooShort.js +10 -0
  142. package/dist/hooks/{useRoomBuilder → useSpaces/validators}/messaging.js +1 -1
  143. package/dist/icons/Boundary.d.ts +3 -0
  144. package/dist/icons/Boundary.js +21 -0
  145. package/dist/icons/Draw.js +3 -3
  146. package/dist/icons/Player3D.d.ts +3 -0
  147. package/dist/icons/Player3D.js +21 -0
  148. package/dist/icons/RulerBlank.d.ts +3 -0
  149. package/dist/icons/RulerBlank.js +25 -0
  150. package/dist/icons/RulerDetailed.d.ts +3 -0
  151. package/dist/icons/RulerDetailed.js +27 -0
  152. package/dist/icons/Window.js +4 -4
  153. package/dist/icons/index.js +28 -0
  154. package/dist/icons/types.d.ts +1 -1
  155. package/dist/index.d.ts +17 -2
  156. package/dist/index.js +35 -5
  157. package/dist/store/attributes.d.ts +2 -1
  158. package/dist/store/index.d.ts +17 -31
  159. package/dist/store/index.js +3 -1
  160. package/dist/store/product.js +4 -7
  161. package/dist/store/spaces.d.ts +74 -0
  162. package/dist/store/spaces.js +354 -0
  163. package/dist/store/treble.d.ts +4 -2
  164. package/dist/store/treble.js +58 -50
  165. package/dist/store/wishlist.d.ts +20 -2
  166. package/dist/types.d.ts +14 -3
  167. package/package.json +2 -1
  168. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +0 -95
  169. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +0 -1237
  170. package/dist/hooks/useRoomBuilder/constants.d.ts +0 -41
  171. package/dist/hooks/useRoomBuilder/constants.js +0 -48
  172. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +0 -18
  173. package/dist/hooks/useRoomBuilder/dataHandlers.js +0 -187
  174. package/dist/hooks/useRoomBuilder/draw.d.ts +0 -55
  175. package/dist/hooks/useRoomBuilder/draw.js +0 -573
  176. package/dist/hooks/useRoomBuilder/findLoops.d.ts +0 -5
  177. package/dist/hooks/useRoomBuilder/geometry.d.ts +0 -33
  178. package/dist/hooks/useRoomBuilder/geometry.js +0 -325
  179. package/dist/hooks/useRoomBuilder/index.d.ts +0 -40
  180. package/dist/hooks/useRoomBuilder/index.js +0 -303
  181. package/dist/hooks/useRoomBuilder/themes.js +0 -273
  182. package/dist/hooks/useRoomBuilder/types.d.ts +0 -238
  183. package/dist/hooks/useRoomBuilder/validators.d.ts +0 -36
  184. package/dist/hooks/useRoomBuilder/validators.js +0 -362
  185. package/dist/hooks/useSpaces/Canvas.d.ts +0 -37
  186. package/dist/hooks/useSpaces/Canvas.js +0 -199
  187. /package/dist/Treble/{snapshots.d.ts → snapshot.d.ts} +0 -0
  188. /package/dist/Treble/{snapshots.js → snapshot.js} +0 -0
  189. /package/dist/hooks/{useRoomBuilder → useSpaces/validators}/messaging.d.ts +0 -0
@@ -1,362 +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.runValidators = exports.isVertexLandingOnFeature = exports.areWallsDuplicated = exports.areWallsOrphaningFeatures = exports.areWallsIntersecting = exports.areWallsTooShort = exports.isFeatureCollidingWithExistingFeature = exports.isFeatureOutsideWallBounds = exports.isWallEndingOnFeature = exports.isWallOverlappingExisitingWalls = exports.isWallIntersectingFeature = exports.isWallTooShort = void 0;
13
- var types_1 = require("./types");
14
- var geometry_1 = require("./geometry");
15
- var messaging_1 = require("./messaging");
16
- var constants_1 = require("./constants");
17
- function isLineTooShort(wallOrLine) {
18
- var minLength = constants_1.MIN_WALL_LENGTH;
19
- var line = Array.isArray(wallOrLine) ? wallOrLine : wallOrLine.line;
20
- var tooClose = geometry_1.arePointsWithinProximity.apply(void 0, __spreadArray(__spreadArray([], line, false), [minLength], false));
21
- if (tooClose)
22
- return {
23
- message: messaging_1.errorMessages.wallTooShort(),
24
- type: types_1.IErrorTypes.HARD,
25
- };
26
- return false;
27
- }
28
- function isWallTooShort(input) {
29
- return isLineTooShort(input.newWall.line);
30
- }
31
- exports.isWallTooShort = isWallTooShort;
32
- function isWallIntersectingFeature(input) {
33
- var _a;
34
- var newWall = input.newWall, walls = input.walls, features = input.features;
35
- if (!walls.length || !Object.values(features).flat().length)
36
- return false;
37
- var intersectingFeature;
38
- for (var i = 0; i < walls.length && !intersectingFeature; i++) {
39
- if (!walls[i].connections)
40
- continue;
41
- var intersectionPoint = (0, geometry_1.getLineSegmentsIntersection)(newWall.line, walls[i].line);
42
- if (!intersectionPoint)
43
- continue;
44
- var intersectionOffset = (0, geometry_1.getLengthOfLineSegment)([
45
- walls[i].line[0],
46
- intersectionPoint,
47
- ]);
48
- for (var j = 0; j < walls[i].connections.length && !intersectingFeature; j++) {
49
- var _b = walls[i].connections[j], type = _b[0], index = _b[1];
50
- var feature = (_a = features[type]) === null || _a === void 0 ? void 0 : _a[index];
51
- if (!feature)
52
- continue;
53
- if (feature.offset < intersectionOffset &&
54
- intersectionOffset < feature.offset + feature.length)
55
- intersectingFeature = { type: type, index: index };
56
- }
57
- }
58
- if (!intersectingFeature)
59
- return false;
60
- return ({
61
- address: intersectingFeature,
62
- message: messaging_1.errorMessages.addWallCollidingWithFeature(intersectingFeature.type),
63
- type: types_1.IErrorTypes.SOFT,
64
- } || false);
65
- }
66
- exports.isWallIntersectingFeature = isWallIntersectingFeature;
67
- function isWallOverlappingExisitingWalls(input) {
68
- var newWall = input.newWall, walls = input.walls;
69
- var snapStartTo = newWall.snapStartTo, snapEndTo = newWall.snapEndTo;
70
- if ((snapStartTo === null || snapStartTo === void 0 ? void 0 : snapStartTo.type) === types_1.IElements.WALL &&
71
- (snapEndTo === null || snapEndTo === void 0 ? void 0 : snapEndTo.type) === types_1.IElements.WALL &&
72
- snapStartTo.index === snapEndTo.index) {
73
- return {
74
- address: {
75
- type: types_1.IElements.WALL,
76
- index: snapStartTo.index,
77
- },
78
- type: types_1.IErrorTypes.SOFT,
79
- message: messaging_1.errorMessages.wallsNotUnique(),
80
- };
81
- }
82
- var overlappingIndex = walls.findIndex(function (wall, i) {
83
- var line = wall.line;
84
- if ((0, geometry_1.areLinesEqual)(line, newWall.line))
85
- return true;
86
- if ((snapStartTo === null || snapStartTo === void 0 ? void 0 : snapStartTo.type) === types_1.IElements.VERTEX &&
87
- ((0, geometry_1.arePointsEqual)(snapStartTo.point, line[0]) ||
88
- (0, geometry_1.arePointsEqual)(snapStartTo.point, line[1])) &&
89
- (snapEndTo === null || snapEndTo === void 0 ? void 0 : snapEndTo.type) === types_1.IElements.WALL &&
90
- snapEndTo.index === i) {
91
- return true;
92
- }
93
- if ((snapEndTo === null || snapEndTo === void 0 ? void 0 : snapEndTo.type) === types_1.IElements.VERTEX &&
94
- ((0, geometry_1.arePointsEqual)(snapEndTo.point, line[0]) ||
95
- (0, geometry_1.arePointsEqual)(snapEndTo.point, line[1])) &&
96
- (snapStartTo === null || snapStartTo === void 0 ? void 0 : snapStartTo.type) === types_1.IElements.WALL &&
97
- snapStartTo.index === i) {
98
- return true;
99
- }
100
- return false;
101
- });
102
- if (overlappingIndex !== -1) {
103
- return {
104
- address: {
105
- type: types_1.IElements.WALL,
106
- index: overlappingIndex,
107
- },
108
- type: types_1.IErrorTypes.SOFT,
109
- message: messaging_1.errorMessages.wallsNotUnique(),
110
- };
111
- }
112
- return false;
113
- }
114
- exports.isWallOverlappingExisitingWalls = isWallOverlappingExisitingWalls;
115
- function isWallEndingOnFeature(input) {
116
- var snapPoint = input.newWall.snapEndTo;
117
- if (!snapPoint)
118
- return false;
119
- if (snapPoint.type === types_1.IElements.WINDOW ||
120
- snapPoint.type === types_1.IElements.DOOR ||
121
- snapPoint.type === types_1.IElements.OPENING)
122
- return {
123
- address: snapPoint,
124
- message: messaging_1.errorMessages.addWallCollidingWithFeature(snapPoint.type),
125
- type: types_1.IErrorTypes.SOFT,
126
- };
127
- return false;
128
- }
129
- exports.isWallEndingOnFeature = isWallEndingOnFeature;
130
- function isFeatureOutsideWallBounds(input) {
131
- var wall = input.wall, updatedFeature = input.updatedFeature;
132
- var padding = constants_1.WALL_PADDING_FOR_FEATURE;
133
- var wallLength = (0, geometry_1.getLengthOfLineSegment)(wall.line);
134
- if (updatedFeature.offset < padding ||
135
- updatedFeature.offset + updatedFeature.length > wallLength - padding)
136
- return {
137
- address: updatedFeature.address,
138
- type: types_1.IErrorTypes.HARD,
139
- message: messaging_1.errorMessages.featureOutsideWallBounds(),
140
- };
141
- return false;
142
- }
143
- exports.isFeatureOutsideWallBounds = isFeatureOutsideWallBounds;
144
- function isFeatureCollidingWithExistingFeature(input) {
145
- var _a, _b;
146
- var features = input.features, wall = input.wall, updatedFeature = input.updatedFeature;
147
- if (!features || !((_a = wall.connections) === null || _a === void 0 ? void 0 : _a.length))
148
- return false;
149
- if (!Object.values(updatedFeature).flat().length)
150
- return false;
151
- for (var i = 0; i < wall.connections.length; i++) {
152
- var _c = wall.connections[i], type = _c[0], index = _c[1];
153
- if (updatedFeature.address.type === type &&
154
- updatedFeature.address.index === index)
155
- continue;
156
- var existingFeature = (_b = features[type]) === null || _b === void 0 ? void 0 : _b[index];
157
- if (!existingFeature)
158
- continue;
159
- if ((0, geometry_1.doLinesOverlap)([updatedFeature.offset, updatedFeature.length], [existingFeature.offset, existingFeature.length]))
160
- return {
161
- address: { type: type, index: index },
162
- type: types_1.IErrorTypes.SOFT,
163
- message: messaging_1.errorMessages.featuresColliding(type),
164
- };
165
- }
166
- return false;
167
- }
168
- exports.isFeatureCollidingWithExistingFeature = isFeatureCollidingWithExistingFeature;
169
- function areWallsTooShort(input) {
170
- var walls = input.walls, vertex = input.vertex, updatedPosition = input.updatedPosition;
171
- var _a = vertex.connections.reduce(function (output, connection) {
172
- var _a;
173
- var wallIndex = connection[0], vertexIndex = connection[1];
174
- output.wallIndexes.push(wallIndex);
175
- output.updatedVerticesMap = Object.assign(output.updatedVerticesMap, (_a = {},
176
- _a[wallIndex] = vertexIndex,
177
- _a));
178
- return output;
179
- }, {
180
- wallIndexes: [],
181
- updatedVerticesMap: {},
182
- }), wallIndexes = _a.wallIndexes, updatedVerticesMap = _a.updatedVerticesMap;
183
- for (var _i = 0, wallIndexes_1 = wallIndexes; _i < wallIndexes_1.length; _i++) {
184
- var index = wallIndexes_1[_i];
185
- var line = walls[index].line;
186
- line[updatedVerticesMap[index]] = updatedPosition.point;
187
- if (isLineTooShort(line))
188
- return {
189
- address: { type: types_1.IElements.WALL, index: index },
190
- message: messaging_1.errorMessages.wallTooShort(),
191
- type: types_1.IErrorTypes.HARD,
192
- };
193
- }
194
- return false;
195
- }
196
- exports.areWallsTooShort = areWallsTooShort;
197
- function areWallsIntersecting(input) {
198
- var walls = input.walls, vertex = input.vertex, updatedPosition = input.updatedPosition;
199
- var _a = vertex.connections.reduce(function (output, connection) {
200
- var _a;
201
- var wallIndex = connection[0], vertexIndex = connection[1];
202
- output.wallIndexes.add(wallIndex);
203
- output.updatedVerticesMap = Object.assign(output.updatedVerticesMap, (_a = {},
204
- _a[wallIndex] = vertexIndex,
205
- _a));
206
- return output;
207
- }, {
208
- wallIndexes: new Set([]),
209
- updatedVerticesMap: {},
210
- }), wallIndexes = _a.wallIndexes, updatedVerticesMap = _a.updatedVerticesMap;
211
- for (var _i = 0, _b = Array.from(wallIndexes); _i < _b.length; _i++) {
212
- var validateWallIndex = _b[_i];
213
- var line = walls[validateWallIndex].line;
214
- line[updatedVerticesMap[validateWallIndex]] = updatedPosition.point;
215
- for (var i = 0; i < walls.length; i++) {
216
- if (wallIndexes.has(i))
217
- continue;
218
- var wall = walls[i];
219
- if (!wall)
220
- continue;
221
- var intersectionPoint = (0, geometry_1.getLineSegmentsIntersection)(line, wall.line);
222
- if (intersectionPoint)
223
- return {
224
- address: { type: types_1.IElements.WALL, index: i },
225
- message: messaging_1.errorMessages.addWallCollidingWithWall(),
226
- type: types_1.IErrorTypes.SOFT,
227
- };
228
- }
229
- }
230
- return false;
231
- }
232
- exports.areWallsIntersecting = areWallsIntersecting;
233
- function areWallsOrphaningFeatures(input) {
234
- var _a;
235
- var walls = input.walls, vertex = input.vertex, features = input.features, updatedPosition = input.updatedPosition;
236
- var _b = vertex.connections.reduce(function (output, connection) {
237
- var _a;
238
- var wallIndex = connection[0], vertexIndex = connection[1];
239
- output.wallIndexes.add(wallIndex);
240
- output.updatedVerticesMap = Object.assign(output.updatedVerticesMap, (_a = {},
241
- _a[wallIndex] = vertexIndex,
242
- _a));
243
- return output;
244
- }, {
245
- wallIndexes: new Set([]),
246
- updatedVerticesMap: {},
247
- }), wallIndexes = _b.wallIndexes, updatedVerticesMap = _b.updatedVerticesMap;
248
- for (var _i = 0, _c = Array.from(wallIndexes); _i < _c.length; _i++) {
249
- var wallIdx = _c[_i];
250
- var wall = walls[wallIdx];
251
- if (!wall.connections.length)
252
- continue;
253
- var updatedLine = JSON.parse(JSON.stringify(wall.line));
254
- updatedLine[updatedVerticesMap[wallIdx]] = updatedPosition.point;
255
- var currentWallLength = (0, geometry_1.getLengthOfLineSegment)(wall.line);
256
- var updatedWallLength = (0, geometry_1.getLengthOfLineSegment)(updatedLine);
257
- var wallLengthDelta = updatedWallLength - currentWallLength;
258
- for (var i = 0; i < wall.connections.length; i++) {
259
- var _d = wall.connections[i], type = _d[0], index = _d[1];
260
- var feat = (_a = features[type]) === null || _a === void 0 ? void 0 : _a[index];
261
- if (!feat)
262
- continue;
263
- var error = {
264
- address: { type: type, index: index },
265
- message: 'feature collision',
266
- type: types_1.IErrorTypes.HARD,
267
- };
268
- if (updatedVerticesMap[wallIdx] === 0 &&
269
- feat.offset - wallLengthDelta < constants_1.WALL_PADDING_FOR_FEATURE)
270
- return error;
271
- else if (feat.offset + feat.length >
272
- updatedWallLength - constants_1.WALL_PADDING_FOR_FEATURE) {
273
- return error;
274
- }
275
- }
276
- }
277
- return false;
278
- }
279
- exports.areWallsOrphaningFeatures = areWallsOrphaningFeatures;
280
- function areWallsDuplicated(input) {
281
- var _a, _b, _c;
282
- var walls = input.walls, vertex = input.vertex, updatedPosition = input.updatedPosition;
283
- var point = (_b = (_a = updatedPosition.snapTo) === null || _a === void 0 ? void 0 : _a.point) !== null && _b !== void 0 ? _b : updatedPosition.point;
284
- var _d = vertex.connections.reduce(function (output, connection) {
285
- var _a;
286
- var wallIndex = connection[0], vertexIndex = connection[1];
287
- output.wallIndexes.add(wallIndex);
288
- output.updatedVerticesMap = Object.assign(output.updatedVerticesMap, (_a = {},
289
- _a[wallIndex] = vertexIndex,
290
- _a));
291
- return output;
292
- }, {
293
- wallIndexes: new Set([]),
294
- updatedVerticesMap: {},
295
- }), wallIndexes = _d.wallIndexes, updatedVerticesMap = _d.updatedVerticesMap;
296
- for (var _i = 0, _e = Array.from(wallIndexes); _i < _e.length; _i++) {
297
- var wallIdx = _e[_i];
298
- var wall = walls[wallIdx];
299
- var updatedLine = JSON.parse(JSON.stringify(wall.line));
300
- updatedLine[updatedVerticesMap[wallIdx]] = point;
301
- if (((_c = updatedPosition.snapTo) === null || _c === void 0 ? void 0 : _c.type) === types_1.IElements.WALL &&
302
- updatedPosition.snapTo.index !== wallIdx) {
303
- var _f = walls[updatedPosition.snapTo.index].line, xTest = _f[0], yTest = _f[1];
304
- var unmovedPoint = updatedLine[updatedVerticesMap[wallIdx] === 1 ? 0 : 1];
305
- if ((0, geometry_1.arePointsEqual)(unmovedPoint, xTest) ||
306
- (0, geometry_1.arePointsEqual)(unmovedPoint, yTest))
307
- return {
308
- address: {
309
- type: types_1.IElements.WALL,
310
- index: updatedPosition.snapTo.index,
311
- },
312
- type: types_1.IErrorTypes.SOFT,
313
- message: messaging_1.errorMessages.wallsNotUnique(),
314
- };
315
- }
316
- for (var i = 0; i < walls.length; i++) {
317
- if (wallIdx === i)
318
- continue;
319
- var existingWall = walls[i];
320
- var error = {
321
- address: { type: types_1.IElements.WALL, index: i },
322
- type: types_1.IErrorTypes.SOFT,
323
- message: messaging_1.errorMessages.wallsNotUnique(),
324
- };
325
- if (((0, geometry_1.arePointsEqual)(existingWall[0], wall.line[0]) &&
326
- (0, geometry_1.arePointsEqual)(existingWall[1], wall.line[1])) ||
327
- ((0, geometry_1.arePointsEqual)(existingWall[0], wall.line[1]) &&
328
- (0, geometry_1.arePointsEqual)(existingWall[1], wall.line[0]))) {
329
- return error;
330
- }
331
- }
332
- }
333
- return false;
334
- }
335
- exports.areWallsDuplicated = areWallsDuplicated;
336
- function isVertexLandingOnFeature(input) {
337
- var snapPoint = input.updatedPosition.snapTo;
338
- if (!snapPoint)
339
- return false;
340
- if (snapPoint.type === types_1.IElements.WINDOW ||
341
- snapPoint.type === types_1.IElements.DOOR ||
342
- snapPoint.type === types_1.IElements.OPENING)
343
- return {
344
- address: snapPoint,
345
- message: messaging_1.errorMessages.addWallCollidingWithFeature(snapPoint.type),
346
- type: types_1.IErrorTypes.SOFT,
347
- };
348
- return false;
349
- }
350
- exports.isVertexLandingOnFeature = isVertexLandingOnFeature;
351
- function runValidators(validators, input) {
352
- var errors = validators.reduce(function (output, validate) {
353
- var error = validate(input);
354
- if (error)
355
- output.push(error);
356
- return output;
357
- }, []);
358
- if (errors.length)
359
- return errors;
360
- return null;
361
- }
362
- exports.runValidators = runValidators;
@@ -1,37 +0,0 @@
1
- import { ICoordinate2D, ICoordinatesLine, IGridToDraw, IUnits } from './types';
2
- declare class Canvas {
3
- private _scale;
4
- private _dimensions;
5
- private _zoom;
6
- private _zoomLimits;
7
- private _translate;
8
- private _translateLimits;
9
- private _unit;
10
- constructor(scale: number, dimensions: ICoordinate2D, zoom: number, translate: ICoordinate2D, unit: IUnits);
11
- get dimensions(): ICoordinate2D;
12
- set dimensions(dimensions: ICoordinate2D);
13
- get width(): ICoordinate2D;
14
- get height(): ICoordinate2D;
15
- get zoom(): number;
16
- set zoom(delta: number);
17
- get zoomFactor(): number;
18
- set zoomFactor(val: number);
19
- get zoomMin(): ICoordinate2D;
20
- get zoomMax(): ICoordinate2D;
21
- get translate(): ICoordinate2D;
22
- get translateMin(): ICoordinatesLine;
23
- get translateMax(): ICoordinatesLine;
24
- set translate(position: ICoordinate2D);
25
- get unit(): IUnits;
26
- set unit(unit: IUnits);
27
- get gridUnitLength(): number;
28
- get gridUnitLengthToDraw(): number;
29
- get gridOffset(): ICoordinate2D;
30
- get gridToDraw(): IGridToDraw;
31
- transformLengthFromCanvas(length: number): number;
32
- transformLengthToCanvas(length: number): number;
33
- transformPointToCanvas(point: ICoordinate2D): ICoordinate2D;
34
- transformPointFromCanvas(point: ICoordinate2D): ICoordinate2D;
35
- transformLineToCanvas(line: ICoordinatesLine): ICoordinatesLine;
36
- }
37
- export default Canvas;
@@ -1,199 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("./constants");
4
- var dataHandlers_1 = require("./dataHandlers");
5
- var types_1 = require("./types");
6
- var Canvas = (function () {
7
- function Canvas(scale, dimensions, zoom, translate, unit) {
8
- this._scale = scale;
9
- this._dimensions = dimensions;
10
- this._zoom = zoom;
11
- this._zoomLimits = [constants_1.ZOOM_MIN, constants_1.ZOOM_MAX];
12
- this._translate = translate;
13
- this._translateLimits = [constants_1.TRANSLATE_MIN, constants_1.TRANSLATE_MAX];
14
- this._unit = unit;
15
- }
16
- Object.defineProperty(Canvas.prototype, "dimensions", {
17
- get: function () {
18
- return this._dimensions;
19
- },
20
- set: function (dimensions) {
21
- this._dimensions = dimensions;
22
- },
23
- enumerable: false,
24
- configurable: true
25
- });
26
- Object.defineProperty(Canvas.prototype, "width", {
27
- get: function () {
28
- return this._dimensions[0];
29
- },
30
- enumerable: false,
31
- configurable: true
32
- });
33
- Object.defineProperty(Canvas.prototype, "height", {
34
- get: function () {
35
- return this._dimensions[1];
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
40
- Object.defineProperty(Canvas.prototype, "zoom", {
41
- get: function () {
42
- return this._zoom;
43
- },
44
- set: function (delta) {
45
- var newZoom = this.zoom + delta;
46
- var preppedZoom = newZoom < this.zoomMin
47
- ? this.zoomMin
48
- : newZoom > this.zoomMax
49
- ? this.zoomMax
50
- : newZoom;
51
- if (preppedZoom === this.zoom)
52
- return;
53
- this._zoom = preppedZoom;
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- Object.defineProperty(Canvas.prototype, "zoomFactor", {
59
- get: function () {
60
- return this._zoom / this.zoomMin;
61
- },
62
- set: function (val) {
63
- var updatedZoom = val * this.zoomMin;
64
- if (updatedZoom < this.zoomMin)
65
- this._zoom = this.zoomMin;
66
- else if (updatedZoom > this.zoomMax)
67
- this._zoom = this.zoomMax;
68
- else
69
- this._zoom = updatedZoom;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Object.defineProperty(Canvas.prototype, "zoomMin", {
75
- get: function () {
76
- return this._zoomLimits[0];
77
- },
78
- enumerable: false,
79
- configurable: true
80
- });
81
- Object.defineProperty(Canvas.prototype, "zoomMax", {
82
- get: function () {
83
- return this._zoomLimits[1];
84
- },
85
- enumerable: false,
86
- configurable: true
87
- });
88
- Object.defineProperty(Canvas.prototype, "translate", {
89
- get: function () {
90
- return this._translate;
91
- },
92
- set: function (position) {
93
- var zoomFactor = this._zoom / this.zoomMin;
94
- var delta = [
95
- (position[0] - this._translate[0]) / zoomFactor,
96
- (position[1] - this._translate[1]) / zoomFactor,
97
- ];
98
- this._translate = [
99
- this._translate[0] + delta[0],
100
- this._translate[1] + delta[1],
101
- ];
102
- },
103
- enumerable: false,
104
- configurable: true
105
- });
106
- Object.defineProperty(Canvas.prototype, "translateMin", {
107
- get: function () {
108
- return this._translateLimits[0];
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- Object.defineProperty(Canvas.prototype, "translateMax", {
114
- get: function () {
115
- return this._translateLimits[1];
116
- },
117
- enumerable: false,
118
- configurable: true
119
- });
120
- Object.defineProperty(Canvas.prototype, "unit", {
121
- get: function () {
122
- return this._unit;
123
- },
124
- set: function (unit) {
125
- this._unit = unit;
126
- },
127
- enumerable: false,
128
- configurable: true
129
- });
130
- Object.defineProperty(Canvas.prototype, "gridUnitLength", {
131
- get: function () {
132
- var length = [types_1.IUnits.FEET, types_1.IUnits.INCH].includes(this.unit)
133
- ? (0, dataHandlers_1.convertLengthUnit)(1, types_1.IUnits.FEET, types_1.IUnits.METER)
134
- : 1;
135
- return length / this._scale;
136
- },
137
- enumerable: false,
138
- configurable: true
139
- });
140
- Object.defineProperty(Canvas.prototype, "gridUnitLengthToDraw", {
141
- get: function () {
142
- return this.transformLengthToCanvas(this.gridUnitLength);
143
- },
144
- enumerable: false,
145
- configurable: true
146
- });
147
- Object.defineProperty(Canvas.prototype, "gridOffset", {
148
- get: function () {
149
- var gridLength = this.gridUnitLengthToDraw;
150
- var translate = this.transformPointToCanvas([0, 0]);
151
- return [translate[0] % gridLength, translate[1] % gridLength];
152
- },
153
- enumerable: false,
154
- configurable: true
155
- });
156
- Object.defineProperty(Canvas.prototype, "gridToDraw", {
157
- get: function () {
158
- return {
159
- unitLength: this.gridUnitLengthToDraw,
160
- offset: this.gridOffset,
161
- subdivisions: [types_1.IUnits.FEET, types_1.IUnits.INCH].includes(this.unit) ? 4 : 5,
162
- };
163
- },
164
- enumerable: false,
165
- configurable: true
166
- });
167
- Canvas.prototype.transformLengthFromCanvas = function (length) {
168
- return length / this.zoomFactor;
169
- };
170
- Canvas.prototype.transformLengthToCanvas = function (length) {
171
- return length * this.zoomFactor;
172
- };
173
- Canvas.prototype.transformPointToCanvas = function (point) {
174
- var widthOffset = this.width / 2;
175
- var heightOffset = this.height / 2;
176
- return [
177
- this.transformLengthToCanvas(point[0] + this.translate[0]) -
178
- widthOffset * (this.zoomFactor - 1),
179
- this.transformLengthToCanvas(point[1] + this.translate[1]) -
180
- heightOffset * (this.zoomFactor - 1),
181
- ];
182
- };
183
- Canvas.prototype.transformPointFromCanvas = function (point) {
184
- var widthOffset = this.width / 2;
185
- var heightOffset = this.height / 2;
186
- return [
187
- this.transformLengthFromCanvas(point[0] + widthOffset * (this.zoomFactor - 1)) - this.translate[0],
188
- this.transformLengthFromCanvas(point[1] + heightOffset * (this.zoomFactor - 1)) - this.translate[1],
189
- ];
190
- };
191
- Canvas.prototype.transformLineToCanvas = function (line) {
192
- return [
193
- this.transformPointToCanvas(line[0]),
194
- this.transformPointToCanvas(line[1]),
195
- ];
196
- };
197
- return Canvas;
198
- }());
199
- exports.default = Canvas;
File without changes
File without changes