kitchen-simulator 1.1.1-test.49 → 1.1.1-test.50

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 (358) hide show
  1. package/es/@history.js +2 -0
  2. package/es/AppContext.js +3 -0
  3. package/es/KitchenConfigurator.js +645 -0
  4. package/es/KitchenConfiguratorApp.js +480 -0
  5. package/es/actions/area-actions.js +14 -0
  6. package/es/actions/export.js +23 -0
  7. package/es/actions/groups-actions.js +89 -0
  8. package/es/actions/holes-actions.js +119 -0
  9. package/es/actions/items-actions.js +313 -0
  10. package/es/actions/lines-actions.js +81 -0
  11. package/es/actions/project-actions.js +281 -0
  12. package/es/actions/scene-actions.js +33 -0
  13. package/es/actions/vertices-actions.js +27 -0
  14. package/es/actions/viewer2d-actions.js +58 -0
  15. package/es/actions/viewer3d-actions.js +23 -0
  16. package/es/catalog/areas/area/planner-element.js +40 -0
  17. package/es/catalog/areas/area/textures/ceramic-tile.jpg +0 -0
  18. package/es/catalog/areas/area/textures/grass.jpg +0 -0
  19. package/es/catalog/areas/area/textures/parquet.jpg +0 -0
  20. package/es/catalog/areas/area/textures/strand-porcelain.jpg +0 -0
  21. package/es/catalog/areas/area/textures/tile1.jpg +0 -0
  22. package/es/catalog/catalog.js +277 -0
  23. package/es/catalog/envMap/nx.hdr +0 -0
  24. package/es/catalog/envMap/ny.hdr +0 -0
  25. package/es/catalog/envMap/nz.hdr +0 -0
  26. package/es/catalog/envMap/px.hdr +0 -0
  27. package/es/catalog/envMap/py.hdr +0 -0
  28. package/es/catalog/envMap/pz.hdr +0 -0
  29. package/es/catalog/factories/area-factory-3d.js +181 -0
  30. package/es/catalog/factories/area-factory.js +81 -0
  31. package/es/catalog/factories/export.js +7 -0
  32. package/es/catalog/factories/wall-factory-3d.js +202 -0
  33. package/es/catalog/factories/wall-factory.js +268 -0
  34. package/es/catalog/holes/door-closet/planner-element.js +222 -0
  35. package/es/catalog/holes/door-double/door_double.png +0 -0
  36. package/es/catalog/holes/door-double/planner-element.js +315 -0
  37. package/es/catalog/holes/door-exterior/planner-element.js +215 -0
  38. package/es/catalog/holes/door-interior/planner-element.js +227 -0
  39. package/es/catalog/holes/door-panic/panicDoor.png +0 -0
  40. package/es/catalog/holes/door-panic/planner-element.js +503 -0
  41. package/es/catalog/holes/door-panic-double/panicDoorDouble.png +0 -0
  42. package/es/catalog/holes/door-panic-double/planner-element.js +463 -0
  43. package/es/catalog/holes/door-sliding/planner-element.js +225 -0
  44. package/es/catalog/holes/doorway-framed/planner-element.js +145 -0
  45. package/es/catalog/holes/doorway-frameless/planner-element.js +104 -0
  46. package/es/catalog/holes/export.js +13 -0
  47. package/es/catalog/holes/gate/gate.jpg +0 -0
  48. package/es/catalog/holes/window-clear/planner-element.js +166 -0
  49. package/es/catalog/holes/window-clear/texture.png +0 -0
  50. package/es/catalog/holes/window-cross/planner-element.js +165 -0
  51. package/es/catalog/holes/window-cross/texture.png +0 -0
  52. package/es/catalog/holes/window-double-hung/planner-element.js +303 -0
  53. package/es/catalog/holes/window-double-hung/texture.png +0 -0
  54. package/es/catalog/holes/window-vertical/planner-element.js +276 -0
  55. package/es/catalog/holes/window-vertical/texture.png +0 -0
  56. package/es/catalog/lines/wall/planner-element.js +70 -0
  57. package/es/catalog/lines/wall/textures/bricks-normal.jpg +0 -0
  58. package/es/catalog/lines/wall/textures/bricks-normal2.jpg +0 -0
  59. package/es/catalog/lines/wall/textures/bricks.jpg +0 -0
  60. package/es/catalog/lines/wall/textures/bricks2.jpg +0 -0
  61. package/es/catalog/lines/wall/textures/bricks3.jpg +0 -0
  62. package/es/catalog/lines/wall/textures/morden-normal.jpg +0 -0
  63. package/es/catalog/lines/wall/textures/morden.jpg +0 -0
  64. package/es/catalog/lines/wall/textures/painted-normal.jpg +0 -0
  65. package/es/catalog/lines/wall/textures/painted.jpg +0 -0
  66. package/es/catalog/lines/wall/textures/plaster-normal.jpg +0 -0
  67. package/es/catalog/lines/wall/textures/plaster.jpg +0 -0
  68. package/es/catalog/lines/wall/wall.png +0 -0
  69. package/es/catalog/molding/molding-dcm/planner-element.js +28 -0
  70. package/es/catalog/molding/molding-dcm/texture.png +0 -0
  71. package/es/catalog/molding/molding-fbm/planner-element.js +28 -0
  72. package/es/catalog/molding/molding-fbm/texture.png +0 -0
  73. package/es/catalog/molding/molding-lrm/planner-element.js +28 -0
  74. package/es/catalog/molding/molding-lrm/texture.png +0 -0
  75. package/es/catalog/properties/export.js +21 -0
  76. package/es/catalog/properties/property-checkbox.js +116 -0
  77. package/es/catalog/properties/property-color.js +39 -0
  78. package/es/catalog/properties/property-enum.js +97 -0
  79. package/es/catalog/properties/property-hidden.js +19 -0
  80. package/es/catalog/properties/property-lenght-measure.js +101 -0
  81. package/es/catalog/properties/property-length-measure.js +134 -0
  82. package/es/catalog/properties/property-length-measure_hole.js +101 -0
  83. package/es/catalog/properties/property-number.js +48 -0
  84. package/es/catalog/properties/property-read-only.js +26 -0
  85. package/es/catalog/properties/property-string.js +48 -0
  86. package/es/catalog/properties/property-toggle.js +39 -0
  87. package/es/catalog/properties/shared-property-style.js +14 -0
  88. package/es/catalog/utils/FuseUtils.js +82 -0
  89. package/es/catalog/utils/exporter.js +148 -0
  90. package/es/catalog/utils/geom-utils.js +189 -0
  91. package/es/catalog/utils/item-loader.js +1521 -0
  92. package/es/catalog/utils/load-obj.js +91 -0
  93. package/es/catalog/utils/mtl-loader.js +358 -0
  94. package/es/catalog/utils/obj-loader.js +477 -0
  95. package/es/class/FuseUtils.js +82 -0
  96. package/es/class/area.js +145 -0
  97. package/es/class/export.js +24 -0
  98. package/es/class/group.js +440 -0
  99. package/es/class/guide.js +62 -0
  100. package/es/class/hole.js +929 -0
  101. package/es/class/item.js +1883 -0
  102. package/es/class/layer.js +667 -0
  103. package/es/class/line.js +1180 -0
  104. package/es/class/project.js +793 -0
  105. package/es/class/vertex.js +202 -0
  106. package/es/components/content.js +107 -0
  107. package/es/components/disclaimer/disclaimer.js +97 -0
  108. package/es/components/export.js +9 -0
  109. package/es/components/style/button.js +113 -0
  110. package/es/components/style/cancel-button.js +22 -0
  111. package/es/components/style/content-container.js +33 -0
  112. package/es/components/style/content-title.js +29 -0
  113. package/es/components/style/delete-button.js +25 -0
  114. package/es/components/style/export.js +31 -0
  115. package/es/components/style/form-block.js +24 -0
  116. package/es/components/style/form-color-input.js +27 -0
  117. package/es/components/style/form-label.js +26 -0
  118. package/es/components/style/form-number-input.js +213 -0
  119. package/es/components/style/form-number-input_2.js +206 -0
  120. package/es/components/style/form-select.js +68 -0
  121. package/es/components/style/form-slider.js +61 -0
  122. package/es/components/style/form-submit-button.js +26 -0
  123. package/es/components/style/form-text-input.js +95 -0
  124. package/es/components/viewer2d/area.js +81 -0
  125. package/es/components/viewer2d/export.js +31 -0
  126. package/es/components/viewer2d/grids/grid-horizontal-streak.js +37 -0
  127. package/es/components/viewer2d/grids/grid-streak.js +37 -0
  128. package/es/components/viewer2d/grids/grid-vertical-streak.js +37 -0
  129. package/es/components/viewer2d/grids/grids.js +35 -0
  130. package/es/components/viewer2d/group.js +53 -0
  131. package/es/components/viewer2d/item.js +513 -0
  132. package/es/components/viewer2d/layer.js +164 -0
  133. package/es/components/viewer2d/line.js +882 -0
  134. package/es/components/viewer2d/ruler.js +100 -0
  135. package/es/components/viewer2d/rulerDist.js +146 -0
  136. package/es/components/viewer2d/rulerX.js +151 -0
  137. package/es/components/viewer2d/rulerY.js +153 -0
  138. package/es/components/viewer2d/scene.js +140 -0
  139. package/es/components/viewer2d/snap.js +74 -0
  140. package/es/components/viewer2d/state.js +78 -0
  141. package/es/components/viewer2d/utils.js +198 -0
  142. package/es/components/viewer2d/vertex.js +65 -0
  143. package/es/components/viewer2d/viewer2d.js +1398 -0
  144. package/es/components/viewer3d/camera-controls-module/camera-controls.module.js +2592 -0
  145. package/es/components/viewer3d/dcm.js +401 -0
  146. package/es/components/viewer3d/fbm.js +414 -0
  147. package/es/components/viewer3d/front3D.js +66 -0
  148. package/es/components/viewer3d/grid-creator.js +25 -0
  149. package/es/components/viewer3d/grids/grid-horizontal-streak.js +36 -0
  150. package/es/components/viewer3d/grids/grid-streak.js +27 -0
  151. package/es/components/viewer3d/grids/grid-vertical-streak.js +36 -0
  152. package/es/components/viewer3d/libs/first-person-controls.js +67 -0
  153. package/es/components/viewer3d/libs/helvetiker_regular.typeface.js +1281 -0
  154. package/es/components/viewer3d/libs/mtl-loader.js +357 -0
  155. package/es/components/viewer3d/libs/obj-loader.js +462 -0
  156. package/es/components/viewer3d/libs/orbit-controls.js +699 -0
  157. package/es/components/viewer3d/libs/pointer-lock-controls.js +46 -0
  158. package/es/components/viewer3d/lrm.js +305 -0
  159. package/es/components/viewer3d/model.js +708 -0
  160. package/es/components/viewer3d/pointer-lock-navigation.js +115 -0
  161. package/es/components/viewer3d/ruler-utils/itemRect.js +61 -0
  162. package/es/components/viewer3d/ruler-utils/layer3D.js +495 -0
  163. package/es/components/viewer3d/ruler-utils/ruler3D.js +227 -0
  164. package/es/components/viewer3d/ruler-utils/scene3D.js +60 -0
  165. package/es/components/viewer3d/ruler-utils/state3D.js +18 -0
  166. package/es/components/viewer3d/scene-creator.js +3608 -0
  167. package/es/components/viewer3d/three-memory-cleaner.js +51 -0
  168. package/es/components/viewer3d/viewer3d-first-person.js +315 -0
  169. package/es/components/viewer3d/viewer3d.js +2527 -0
  170. package/es/constants.js +636 -0
  171. package/es/index.js +16 -0
  172. package/es/models.js +510 -0
  173. package/es/plugins/SVGLoader.js +1412 -0
  174. package/es/plugins/autosave.js +33 -0
  175. package/es/plugins/console-debugger.js +37 -0
  176. package/es/plugins/export.js +9 -0
  177. package/es/plugins/keyboard.js +101 -0
  178. package/es/reducers/areas-reducer.js +12 -0
  179. package/es/reducers/export.js +25 -0
  180. package/es/reducers/groups-reducer.js +38 -0
  181. package/es/reducers/holes-reducer.js +62 -0
  182. package/es/reducers/items-reducer.js +140 -0
  183. package/es/reducers/lines-reducer.js +45 -0
  184. package/es/reducers/project-reducer.js +129 -0
  185. package/es/reducers/reducer.js +19 -0
  186. package/es/reducers/scene-reducer.js +28 -0
  187. package/es/reducers/user-reducer.js +40 -0
  188. package/es/reducers/vertices-reducer.js +19 -0
  189. package/es/reducers/viewer2d-reducer.js +75 -0
  190. package/es/reducers/viewer3d-reducer.js +56 -0
  191. package/es/shared-style.js +66 -0
  192. package/es/styles/export.js +5 -0
  193. package/es/styles/tabs.css +40 -0
  194. package/es/translator/en.js +104 -0
  195. package/es/translator/it.js +79 -0
  196. package/es/translator/ru.js +79 -0
  197. package/es/translator/translator.js +84 -0
  198. package/es/utils/browser.js +33 -0
  199. package/es/utils/email-validator.js +4 -0
  200. package/es/utils/export.js +25 -0
  201. package/es/utils/geometry.js +2420 -0
  202. package/es/utils/get-edges-of-subgraphs.js +27 -0
  203. package/es/utils/graph-cycles.js +237 -0
  204. package/es/utils/graph-inner-cycles.js +46 -0
  205. package/es/utils/graph.js +150 -0
  206. package/es/utils/helper.js +268 -0
  207. package/es/utils/history.js +29 -0
  208. package/es/utils/id-broker.js +19 -0
  209. package/es/utils/logger.js +8 -0
  210. package/es/utils/math.js +50 -0
  211. package/es/utils/molding.js +871 -0
  212. package/es/utils/name-generator.js +18 -0
  213. package/es/utils/objects-utils.js +50 -0
  214. package/es/utils/phone-validator.js +4 -0
  215. package/es/utils/process-black-list.js +18 -0
  216. package/es/utils/react-if.js +18 -0
  217. package/es/utils/snap-scene.js +99 -0
  218. package/es/utils/snap.js +237 -0
  219. package/es/utils/summarizeCart.js +24 -0
  220. package/es/utils/threeCSG.es6.js +498 -0
  221. package/es/version.js +2 -0
  222. package/lib/catalog/properties/property-string.js +55 -0
  223. package/lib/catalog/properties/property-toggle.js +46 -0
  224. package/lib/catalog/properties/shared-property-style.js +20 -0
  225. package/lib/catalog/utils/FuseUtils.js +88 -0
  226. package/lib/catalog/utils/exporter.js +155 -0
  227. package/lib/catalog/utils/geom-utils.js +205 -0
  228. package/lib/catalog/utils/item-loader.js +1533 -0
  229. package/lib/catalog/utils/load-obj.js +99 -0
  230. package/lib/catalog/utils/mtl-loader.js +363 -0
  231. package/lib/catalog/utils/obj-loader.js +482 -0
  232. package/lib/class/FuseUtils.js +88 -0
  233. package/lib/class/area.js +150 -0
  234. package/lib/class/export.js +96 -0
  235. package/lib/class/group.js +445 -0
  236. package/lib/class/guide.js +67 -0
  237. package/lib/class/hole.js +934 -0
  238. package/lib/class/item.js +1889 -0
  239. package/lib/class/layer.js +672 -0
  240. package/lib/class/line.js +1186 -0
  241. package/lib/class/project.js +799 -0
  242. package/lib/class/vertex.js +207 -0
  243. package/lib/components/content.js +116 -0
  244. package/lib/components/disclaimer/disclaimer.js +105 -0
  245. package/lib/components/export.js +33 -0
  246. package/lib/components/style/button.js +120 -0
  247. package/lib/components/style/cancel-button.js +29 -0
  248. package/lib/components/style/content-container.js +40 -0
  249. package/lib/components/style/content-title.js +37 -0
  250. package/lib/components/style/delete-button.js +34 -0
  251. package/lib/components/style/export.js +121 -0
  252. package/lib/components/style/form-block.js +31 -0
  253. package/lib/components/style/form-color-input.js +34 -0
  254. package/lib/components/style/form-label.js +33 -0
  255. package/lib/components/style/form-number-input.js +220 -0
  256. package/lib/components/style/form-number-input_2.js +213 -0
  257. package/lib/components/style/form-select.js +75 -0
  258. package/lib/components/style/form-slider.js +68 -0
  259. package/lib/components/style/form-submit-button.js +35 -0
  260. package/lib/components/style/form-text-input.js +101 -0
  261. package/lib/components/viewer2d/area.js +88 -0
  262. package/lib/components/viewer2d/export.js +121 -0
  263. package/lib/components/viewer2d/grids/grid-horizontal-streak.js +44 -0
  264. package/lib/components/viewer2d/grids/grid-streak.js +44 -0
  265. package/lib/components/viewer2d/grids/grid-vertical-streak.js +44 -0
  266. package/lib/components/viewer2d/grids/grids.js +44 -0
  267. package/lib/components/viewer2d/group.js +62 -0
  268. package/lib/components/viewer2d/item.js +521 -0
  269. package/lib/components/viewer2d/layer.js +171 -0
  270. package/lib/components/viewer2d/line.js +892 -0
  271. package/lib/components/viewer2d/ruler.js +107 -0
  272. package/lib/components/viewer2d/rulerDist.js +153 -0
  273. package/lib/components/viewer2d/rulerX.js +158 -0
  274. package/lib/components/viewer2d/rulerY.js +160 -0
  275. package/lib/components/viewer2d/scene.js +147 -0
  276. package/lib/components/viewer2d/snap.js +83 -0
  277. package/lib/components/viewer2d/state.js +87 -0
  278. package/lib/components/viewer2d/utils.js +210 -0
  279. package/lib/components/viewer2d/vertex.js +74 -0
  280. package/lib/components/viewer2d/viewer2d.js +1405 -0
  281. package/lib/components/viewer3d/camera-controls-module/camera-controls.module.js +2597 -0
  282. package/lib/components/viewer3d/dcm.js +407 -0
  283. package/lib/components/viewer3d/fbm.js +420 -0
  284. package/lib/components/viewer3d/front3D.js +75 -0
  285. package/lib/components/viewer3d/grid-creator.js +34 -0
  286. package/lib/components/viewer3d/grids/grid-horizontal-streak.js +44 -0
  287. package/lib/components/viewer3d/grids/grid-streak.js +35 -0
  288. package/lib/components/viewer3d/grids/grid-vertical-streak.js +44 -0
  289. package/lib/components/viewer3d/libs/first-person-controls.js +74 -0
  290. package/lib/components/viewer3d/libs/helvetiker_regular.typeface.js +1287 -0
  291. package/lib/components/viewer3d/libs/mtl-loader.js +363 -0
  292. package/lib/components/viewer3d/libs/obj-loader.js +468 -0
  293. package/lib/components/viewer3d/libs/orbit-controls.js +705 -0
  294. package/lib/components/viewer3d/libs/pointer-lock-controls.js +52 -0
  295. package/lib/components/viewer3d/lrm.js +311 -0
  296. package/lib/components/viewer3d/model.js +714 -0
  297. package/lib/components/viewer3d/pointer-lock-navigation.js +122 -0
  298. package/lib/components/viewer3d/ruler-utils/itemRect.js +68 -0
  299. package/lib/components/viewer3d/ruler-utils/layer3D.js +502 -0
  300. package/lib/components/viewer3d/ruler-utils/ruler3D.js +234 -0
  301. package/lib/components/viewer3d/ruler-utils/scene3D.js +68 -0
  302. package/lib/components/viewer3d/ruler-utils/state3D.js +25 -0
  303. package/lib/components/viewer3d/scene-creator.js +3642 -0
  304. package/lib/components/viewer3d/three-memory-cleaner.js +60 -0
  305. package/lib/components/viewer3d/viewer3d-first-person.js +320 -0
  306. package/lib/components/viewer3d/viewer3d.js +2532 -0
  307. package/lib/constants.js +645 -0
  308. package/lib/index.js +96 -0
  309. package/lib/models.js +517 -0
  310. package/lib/plugins/SVGLoader.js +1417 -0
  311. package/lib/plugins/autosave.js +39 -0
  312. package/lib/plugins/console-debugger.js +44 -0
  313. package/lib/plugins/export.js +33 -0
  314. package/lib/plugins/keyboard.js +107 -0
  315. package/lib/reducers/areas-reducer.js +18 -0
  316. package/lib/reducers/export.js +97 -0
  317. package/lib/reducers/groups-reducer.js +44 -0
  318. package/lib/reducers/holes-reducer.js +68 -0
  319. package/lib/reducers/items-reducer.js +146 -0
  320. package/lib/reducers/lines-reducer.js +51 -0
  321. package/lib/reducers/project-reducer.js +135 -0
  322. package/lib/reducers/reducer.js +26 -0
  323. package/lib/reducers/scene-reducer.js +34 -0
  324. package/lib/reducers/user-reducer.js +46 -0
  325. package/lib/reducers/vertices-reducer.js +25 -0
  326. package/lib/reducers/viewer2d-reducer.js +82 -0
  327. package/lib/reducers/viewer3d-reducer.js +63 -0
  328. package/lib/shared-style.js +72 -0
  329. package/lib/styles/export.js +13 -0
  330. package/lib/translator/en.js +110 -0
  331. package/lib/translator/it.js +85 -0
  332. package/lib/translator/ru.js +85 -0
  333. package/lib/translator/translator.js +90 -0
  334. package/lib/utils/browser.js +40 -0
  335. package/lib/utils/email-validator.js +10 -0
  336. package/lib/utils/export.js +56 -0
  337. package/lib/utils/geometry.js +2516 -0
  338. package/lib/utils/get-edges-of-subgraphs.js +34 -0
  339. package/lib/utils/graph-cycles.js +240 -0
  340. package/lib/utils/graph-inner-cycles.js +54 -0
  341. package/lib/utils/graph.js +157 -0
  342. package/lib/utils/helper.js +291 -0
  343. package/lib/utils/history.js +36 -0
  344. package/lib/utils/id-broker.js +25 -0
  345. package/lib/utils/logger.js +14 -0
  346. package/lib/utils/math.js +57 -0
  347. package/lib/utils/molding.js +895 -0
  348. package/lib/utils/name-generator.js +23 -0
  349. package/lib/utils/objects-utils.js +60 -0
  350. package/lib/utils/phone-validator.js +10 -0
  351. package/lib/utils/process-black-list.js +24 -0
  352. package/lib/utils/react-if.js +24 -0
  353. package/lib/utils/snap-scene.js +105 -0
  354. package/lib/utils/snap.js +249 -0
  355. package/lib/utils/summarizeCart.js +30 -0
  356. package/lib/utils/threeCSG.es6.js +503 -0
  357. package/lib/version.js +8 -0
  358. package/package.json +3 -3
@@ -0,0 +1,2420 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
5
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
18
+ /** @description Determines the distance between two points
19
+ * @param {number} x0 Vertex 0 x
20
+ * @param {number} y0 Vertex 0 y
21
+ * @param {number} x1 Vertex 1 x
22
+ * @param {number} y1 Vertex 1 y
23
+ * @return {number}
24
+ */
25
+ import { toFixedFloat, fAbs } from "./math.js";
26
+ import { BASE_CABINET_LAYOUTPOS, EPSILON, LINE_THICKNESS, MEPSILON, OVERLAP_INCLUDED, OVERLAP_LINK, OVERLAP_NONE, OVERLAP_SAME, OVERLAP_SOME, WALL_CABINET_LAYOUTPOS, UNIT_ANGLE, MIN_ANGLE_DISALLOW_DRAW_WALL } from "../constants";
27
+ import convert from 'convert-units';
28
+ import * as Three from 'three';
29
+ import { returnReplaceableDeepSearchType } from "../components/viewer2d/utils.js";
30
+ import { isEmpty } from "./helper.js";
31
+ import { MathUtils } from "./export.js";
32
+ export function compareVertices(v0, v1) {
33
+ return v0.x === v1.x ? v0.y - v1.y : v0.x - v1.x;
34
+ }
35
+ export function minVertex(v0, v1) {
36
+ return compareVertices(v0, v1) > 0 ? v1 : v0;
37
+ }
38
+ export function maxVertex(v0, v1) {
39
+ return compareVertices(v0, v1) > 0 ? v0 : v1;
40
+ }
41
+ export function orderVertices(vertices) {
42
+ return vertices.sort(compareVertices);
43
+ }
44
+ export function pointsDistance(x0, y0, x1, y1) {
45
+ var diff_x = x0 - x1;
46
+ var diff_y = y0 - y1;
47
+ return Math.sqrt(diff_x * diff_x + diff_y * diff_y);
48
+ }
49
+ export function verticesDistance(v1, v2) {
50
+ var x0 = v1.x,
51
+ y0 = v1.y;
52
+ var x1 = v2.x,
53
+ y1 = v2.y;
54
+ return pointsDistance(x0, y0, x1, y1);
55
+ }
56
+ export function horizontalLine(y) {
57
+ return {
58
+ a: 0,
59
+ b: 1,
60
+ c: -y
61
+ };
62
+ }
63
+ export var almostEqual = function almostEqual(x, y) {
64
+ return Math.abs(x - y) < EPSILON;
65
+ };
66
+ export function verticalLine(x) {
67
+ return {
68
+ a: 1,
69
+ b: 0,
70
+ c: -x
71
+ };
72
+ }
73
+ export function upcrossLine(x, y) {
74
+ return {
75
+ a: 1,
76
+ b: 1,
77
+ c: -x - y
78
+ };
79
+ }
80
+ export function downcrossLine(x, y) {
81
+ return {
82
+ a: 1,
83
+ b: -1,
84
+ c: -x + y
85
+ };
86
+ }
87
+ export function linePassingThroughTwoPoints(x1, y1, x2, y2) {
88
+ if (x1 === x2 && y1 == y2) throw new Error('Geometry error');
89
+ //if (x1 === x2) return verticalLine(x1);
90
+ //if (y1 === y2) return horizontalLine(y1);
91
+
92
+ return {
93
+ a: y1 - y2,
94
+ b: x2 - x1,
95
+ c: y2 * x1 - x2 * y1
96
+ };
97
+ }
98
+ export function getNormaline(x1, y1, x2, y2) {
99
+ var lineFunction = linePassingThroughTwoPoints(x1, y1, x2, y2);
100
+ return {
101
+ x: lineFunction.a / Math.sqrt(lineFunction.a * lineFunction.a + lineFunction.b * lineFunction.b),
102
+ y: lineFunction.b / Math.sqrt(lineFunction.a * lineFunction.a + lineFunction.b * lineFunction.b)
103
+ };
104
+ }
105
+ export function distancePointFromLine(a, b, c, x, y) {
106
+ //https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
107
+ return fAbs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
108
+ }
109
+ export function closestPointFromLine(a, b, c, x, y) {
110
+ //https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
111
+ var denom = a * a + b * b;
112
+ return {
113
+ x: (b * (b * x - a * y) - a * c) / denom,
114
+ y: (a * -b * x + a * y - b * c) / denom
115
+ };
116
+ }
117
+
118
+ /** @description Get point of intersection between two lines using ax+by+c line's equation
119
+ * @param {number} a x coefficent of first line
120
+ * @param {number} b y coefficent of first line
121
+ * @param {number} c costant of first line
122
+ * @param {number} j x coefficent of second line
123
+ * @param {number} k y coefficent of second line
124
+ * @param {number} l costant of second line
125
+ * @return {object} {x,y} point's coordinates
126
+ */
127
+ export function twoLinesIntersection(a, b, c, j, k, l) {
128
+ var angularCoefficientsDiff = b * j - a * k;
129
+ if (angularCoefficientsDiff === 0) return undefined; //no intersection
130
+
131
+ var y = (a * l - c * j) / angularCoefficientsDiff;
132
+ var x = (c * k - b * l) / angularCoefficientsDiff;
133
+ return {
134
+ x: x,
135
+ y: y
136
+ };
137
+ }
138
+ export function twoLineSegmentsIntersection(p1, p2, p3, p4) {
139
+ return _twoLineSegmentsIntersection(p1, p2, p3.toJS(), p4.toJS());
140
+ }
141
+ export function _twoLineSegmentsIntersection(p1, p2, p3, p4) {
142
+ //https://github.com/psalaets/line-intersect/blob/master/lib/check-intersection.js
143
+
144
+ var x1 = p1.x,
145
+ y1 = p1.y;
146
+ var x2 = p2.x,
147
+ y2 = p2.y;
148
+ var x3 = p3.x,
149
+ y3 = p3.y;
150
+ var x4 = p4.x,
151
+ y4 = p4.y;
152
+ var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
153
+ var numA = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
154
+ var numB = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
155
+ if (fAbs(denom) <= EPSILON) {
156
+ if (fAbs(numA) <= EPSILON && fAbs(numB) <= EPSILON) {
157
+ var comparator = function comparator(pa, pb) {
158
+ return pa.x === pb.x ? pa.y - pb.y : pa.x - pb.x;
159
+ };
160
+ var line0 = [p1, p2].sort(comparator);
161
+ var line1 = [p3, p4].sort(comparator);
162
+ var _sort = [line0, line1].sort(function (lineA, lineB) {
163
+ return comparator(lineA[0], lineB[0]);
164
+ }),
165
+ _sort2 = _slicedToArray(_sort, 2),
166
+ lineSX = _sort2[0],
167
+ lineDX = _sort2[1];
168
+ comparator(lineSX[1], lineDX[0]) < 0 ? 'colinear' : 'none';
169
+ if (lineSX[1].x === lineDX[0].x) {
170
+ return {
171
+ type: lineDX[0].y <= lineSX[1].y ? 'colinear' : 'none'
172
+ };
173
+ } else {
174
+ return {
175
+ type: lineDX[0].x <= lineSX[1].x ? 'colinear' : 'none'
176
+ };
177
+ }
178
+ }
179
+ return {
180
+ type: 'parallel'
181
+ };
182
+ }
183
+ var uA = numA / denom;
184
+ var uB = numB / denom;
185
+ if (uA >= 0 - EPSILON && uA <= 1 + EPSILON && uB >= 0 - EPSILON && uB <= 1 + EPSILON) {
186
+ var _point = {
187
+ x: x1 + uA * (x2 - x1),
188
+ y: y1 + uA * (y2 - y1)
189
+ };
190
+ return {
191
+ type: 'intersecting',
192
+ point: _point
193
+ };
194
+ }
195
+ return {
196
+ type: 'none'
197
+ };
198
+ }
199
+ export function distancePointFromLineSegment(v1, v2, xp, yp) {
200
+ //http://stackoverflow.com/a/6853926/1398836
201
+ var x1 = v1.x,
202
+ y1 = v1.y;
203
+ var x2 = v2.x,
204
+ y2 = v2.y;
205
+ var A = xp - x1;
206
+ var B = yp - y1;
207
+ var C = x2 - x1;
208
+ var D = y2 - y1;
209
+ var dot = A * C + B * D;
210
+ var len_sq = C * C + D * D;
211
+ var param = -1;
212
+ if (len_sq != 0)
213
+ //in case of 0 length line
214
+ param = dot / len_sq;
215
+ var xx, yy;
216
+ if (param < 0) {
217
+ xx = x1;
218
+ yy = y1;
219
+ } else if (param > 1) {
220
+ xx = x2;
221
+ yy = y2;
222
+ } else {
223
+ xx = x1 + param * C;
224
+ yy = y1 + param * D;
225
+ }
226
+ var dx = xp - xx;
227
+ var dy = yp - yy;
228
+ return Math.sqrt(dx * dx + dy * dy);
229
+ }
230
+
231
+ /**
232
+ *
233
+ * @param x1 {number} x for first vertex of the segment
234
+ * @param y1 {number} y for first vertex of the segment
235
+ * @param x2 {number} x for second vertex of the segment
236
+ * @param y2 {number} y for second vertex of the segment
237
+ * @param xp {number} x for point we want to verify
238
+ * @param yp {number} y for point we want to verify
239
+ * @param maxDistance {number} the epsilon value used for comparisons
240
+ * @returns {boolean} true if the point lies on the line segment false otherwise
241
+ */
242
+ export function isPointOnLineSegment(x1, y1, x2, y2, xp, yp) {
243
+ var maxDistance = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : EPSILON;
244
+ return distancePointFromLineSegment({
245
+ x: x1,
246
+ y: y1
247
+ }, {
248
+ x: x2,
249
+ y: y2
250
+ }, xp, yp) <= maxDistance;
251
+ }
252
+ export function closestPointFromLineSegment(x1, y1, x2, y2, xp, yp) {
253
+ if (x1 === x2) return {
254
+ x: x1,
255
+ y: yp
256
+ };
257
+ if (y1 === y2) return {
258
+ x: xp,
259
+ y: y1
260
+ };
261
+ var m = (y2 - y1) / (x2 - x1);
262
+ var q = y1 - m * x1;
263
+ var mi = -1 / m;
264
+ var qi = yp - mi * xp;
265
+ var x = (qi - q) / (m - mi);
266
+ var y = m * x + q;
267
+ return {
268
+ x: x,
269
+ y: y
270
+ };
271
+ }
272
+ export function pointPositionOnLineSegment(x1, y1, x2, y2, xp, yp) {
273
+ var length = pointsDistance(x1, y1, x2, y2);
274
+ var distance = pointsDistance(x1, y1, xp, yp);
275
+ var offset = distance / length;
276
+ /*
277
+ if (x1 > x2) offset = 1 - offset;
278
+ if (y1 > y2) offset = 1 - offset;
279
+ */
280
+ return offset;
281
+ }
282
+ export function mapRange(value, low1, high1, low2, high2) {
283
+ return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
284
+ }
285
+ export function angleBetweenTwoPointsAndOrigin(x1, y1, x2, y2) {
286
+ return -Math.atan2(y1 - y2, x2 - x1) * 180 / Math.PI;
287
+ }
288
+ export function angleBetweenTwoPoints(x1, y1, x2, y2) {
289
+ return Math.atan2(y2 - y1, x2 - x1);
290
+ }
291
+ export function angleBetweenTwoLines(line, drawingLine, vertices) {
292
+ var points = [];
293
+
294
+ // safety guards
295
+ var lv = Array.isArray(line === null || line === void 0 ? void 0 : line.vertices) ? line.vertices : [];
296
+ var dv = Array.isArray(drawingLine === null || drawingLine === void 0 ? void 0 : drawingLine.vertices) ? drawingLine.vertices : [];
297
+
298
+ // 1) push common vertices (in order of line.vertices)
299
+ var _iterator = _createForOfIteratorHelper(lv),
300
+ _step;
301
+ try {
302
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
303
+ var vt = _step.value;
304
+ if (dv.includes(vt) && !points.includes(vt)) points.push(vt);
305
+ }
306
+
307
+ // 2) push remaining vertices from line.vertices
308
+ } catch (err) {
309
+ _iterator.e(err);
310
+ } finally {
311
+ _iterator.f();
312
+ }
313
+ var _iterator2 = _createForOfIteratorHelper(lv),
314
+ _step2;
315
+ try {
316
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
317
+ var _vt = _step2.value;
318
+ if (!points.includes(_vt)) points.push(_vt);
319
+ }
320
+
321
+ // 3) push remaining vertices from drawingLine.vertices
322
+ } catch (err) {
323
+ _iterator2.e(err);
324
+ } finally {
325
+ _iterator2.f();
326
+ }
327
+ var _iterator3 = _createForOfIteratorHelper(dv),
328
+ _step3;
329
+ try {
330
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
331
+ var _vt2 = _step3.value;
332
+ if (!points.includes(_vt2)) points.push(_vt2);
333
+ }
334
+
335
+ // If no points at all, nothing to compute — return 0 (safe fallback)
336
+ } catch (err) {
337
+ _iterator3.e(err);
338
+ } finally {
339
+ _iterator3.f();
340
+ }
341
+ if (points.length === 0) return 0;
342
+
343
+ // Ensure we have at least 3 entries (same behaviour as original)
344
+ while (points.length < 3) points.push(points[points.length - 1]);
345
+ var _points$slice$map = points.slice(0, 3).map(function (idx) {
346
+ var v = vertices === null || vertices === void 0 ? void 0 : vertices[idx];
347
+ return v ? new Three.Vector2(v.x, v.y) : new Three.Vector2(0, 0);
348
+ }),
349
+ _points$slice$map2 = _slicedToArray(_points$slice$map, 3),
350
+ c = _points$slice$map2[0],
351
+ p1 = _points$slice$map2[1],
352
+ p2 = _points$slice$map2[2];
353
+ var vec1 = p1.clone().sub(c).normalize();
354
+ var vec2 = p2.clone().sub(c).normalize();
355
+ return Math.floor(vec1.angle() * 180 / Math.PI - vec2.angle() * 180 / Math.PI + 0.5);
356
+ }
357
+ export var getRelatedLines = function getRelatedLines(tlines, drawingLine, vertices, lines) {
358
+ var exceptLineId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
359
+ if (!(drawingLine !== null && drawingLine !== void 0 && drawingLine.vertices) || !Array.isArray(drawingLine.vertices)) return;
360
+ var seen = new Set();
361
+ var _iterator4 = _createForOfIteratorHelper(drawingLine.vertices),
362
+ _step4;
363
+ try {
364
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
365
+ var vIdx = _step4.value;
366
+ var vertex = vertices === null || vertices === void 0 ? void 0 : vertices[vIdx];
367
+ if (!(vertex !== null && vertex !== void 0 && vertex.lines)) continue;
368
+ var _iterator5 = _createForOfIteratorHelper(vertex.lines),
369
+ _step5;
370
+ try {
371
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
372
+ var lineId = _step5.value;
373
+ if (lineId !== drawingLine.id && lineId !== exceptLineId && !isEmpty(lines === null || lines === void 0 ? void 0 : lines[lineId]) && !seen.has(lineId)) {
374
+ seen.add(lineId);
375
+ tlines.push(lines[lineId]);
376
+ }
377
+ }
378
+ } catch (err) {
379
+ _iterator5.e(err);
380
+ } finally {
381
+ _iterator5.f();
382
+ }
383
+ }
384
+ } catch (err) {
385
+ _iterator4.e(err);
386
+ } finally {
387
+ _iterator4.f();
388
+ }
389
+ };
390
+ export function snapAngleByUnit(lineAngle, vertices, drawingLine, x, y, dragVertexId) {
391
+ var tx, ty;
392
+ var absAngle = Math.abs(lineAngle);
393
+ // angle snapping as a value of UNIT_ANGLE
394
+ var rest = absAngle % UNIT_ANGLE;
395
+ var missAngle = UNIT_ANGLE - rest;
396
+ // the origin point of rotation(snapping)
397
+ var originVerId = drawingLine.vertices.findIndex(function (vertice) {
398
+ return vertice !== dragVertexId;
399
+ });
400
+ originVerId = originVerId < 0 ? drawingLine.vertices[0] : drawingLine.vertices[originVerId];
401
+ var ox = vertices[originVerId].x;
402
+ var oy = vertices[originVerId].y;
403
+ // check whether the line is snapped to before point.
404
+ if (rest <= UNIT_ANGLE / 2) {
405
+ // determine the direction of rotation.
406
+ rest = lineAngle > 0 ? rest : -rest;
407
+ // rotate the current point to last point around the first point of drawing line.
408
+ tx = rotatePointAroundPoint(x, y, ox, oy, rest).x;
409
+ ty = rotatePointAroundPoint(x, y, ox, oy, rest).y;
410
+ }
411
+ // check whether the line is snapped to next new point.
412
+ else if (rest > UNIT_ANGLE / 2) {
413
+ // determine the direction of rotation.
414
+ missAngle = lineAngle > 0 ? -missAngle : missAngle;
415
+ // rotate the current point to last point around the first point of drawing line.
416
+ tx = rotatePointAroundPoint(x, y, ox, oy, missAngle).x;
417
+ ty = rotatePointAroundPoint(x, y, ox, oy, missAngle).y;
418
+ }
419
+ var resPoint = {
420
+ x: tx,
421
+ y: ty
422
+ };
423
+ return resPoint;
424
+ }
425
+ export function absAngleBetweenTwoPoints(x1, y1, x2, y2) {
426
+ return Math.atan2(y2 - y1, Math.abs(x2 - x1));
427
+ }
428
+ export function samePoints(_ref, _ref2) {
429
+ var x1 = _ref.x,
430
+ y1 = _ref.y;
431
+ var x2 = _ref2.x,
432
+ y2 = _ref2.y;
433
+ return fAbs(x1 - x2) <= EPSILON && fAbs(y1 - y2) <= EPSILON;
434
+ }
435
+ export function sameDistances(dis1, dis2) {
436
+ return fAbs(dis1 - dis2) <= EPSILON;
437
+ }
438
+ export function sameMPoints(_ref3, _ref4) {
439
+ var x1 = _ref3.x,
440
+ y1 = _ref3.y;
441
+ var x2 = _ref4.x,
442
+ y2 = _ref4.y;
443
+ return fAbs(x1 - x2) <= MEPSILON && fAbs(y1 - y2) <= MEPSILON;
444
+ }
445
+ export function sameMDistances(dis1, dis2) {
446
+ return fAbs(dis1 - dis2) <= MEPSILON;
447
+ }
448
+ export function isPointInRect(rect, point) {
449
+ var result = true;
450
+ for (var i = 0; i < rect.length; i++) {
451
+ var pos1 = rect[i];
452
+ var pos2 = rect[(i + 1) % rect.length];
453
+ if (isPointOnLineSegment(pos1.x, pos1.y, pos2.x, pos2.y, point.x, point.y)) {
454
+ result = false;
455
+ }
456
+ }
457
+ return result;
458
+ }
459
+
460
+ /** @description Extend line based on coordinates and new line length
461
+ * @param {number} x1 Vertex 1 x
462
+ * @param {number} y1 Vertex 1 y
463
+ * @param {number} x2 Vertex 2 x
464
+ * @param {number} y2 Vertex 2 y
465
+ * @param {number} newDistance New line length
466
+ * @return {object}
467
+ */
468
+ export function extendLine(x1, y1, x2, y2, newDistance) {
469
+ var precision = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 6;
470
+ var rad = angleBetweenTwoPoints(x1, y1, x2, y2);
471
+ return {
472
+ x: toFixedFloat(x1 + Math.cos(rad) * newDistance, precision),
473
+ y: toFixedFloat(y1 + Math.sin(rad) * newDistance, precision)
474
+ };
475
+ }
476
+ export function roundVertex(vertex) {
477
+ var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
478
+ vertex.set('x', toFixedFloat(vertex.get('x'), precision));
479
+ vertex.set('y', toFixedFloat(vertex.get('y'), precision));
480
+ return vertex;
481
+ }
482
+
483
+ //https://github.com/MartyWallace/PolyK
484
+ export function ContainsPoint(polygon, pointX, pointY) {
485
+ var n = polygon.length >> 1;
486
+ var ax, lup;
487
+ var ay = polygon[2 * n - 3] - pointY;
488
+ var bx = polygon[2 * n - 2] - pointX;
489
+ var by = polygon[2 * n - 1] - pointY;
490
+ if (bx === 0 && by === 0) return false; // point on edge
491
+
492
+ // let lup = by > ay;
493
+ for (var ii = 0; ii < n; ii++) {
494
+ ax = bx;
495
+ ay = by;
496
+ bx = polygon[2 * ii] - pointX;
497
+ by = polygon[2 * ii + 1] - pointY;
498
+ if (bx === 0 && by === 0) return false; // point on edge
499
+ if (ay === by) continue;
500
+ lup = by > ay;
501
+ }
502
+ var depth = 0;
503
+ for (var i = 0; i < n; i++) {
504
+ ax = bx;
505
+ ay = by;
506
+ bx = polygon[2 * i] - pointX;
507
+ by = polygon[2 * i + 1] - pointY;
508
+ if (ay < 0 && by < 0) continue; // both 'up' or both 'down'
509
+ if (ay > 0 && by > 0) continue; // both 'up' or both 'down'
510
+ if (ax < 0 && bx < 0) continue; // both points on the left
511
+
512
+ if (ay === by && Math.min(ax, bx) < 0) return true;
513
+ if (ay === by) continue;
514
+ var lx = ax + (bx - ax) * -ay / (by - ay);
515
+ if (lx === 0) return false; // point on edge
516
+ if (lx > 0) depth++;
517
+ if (ay === 0 && lup && by > ay) depth--; // hit vertex, both up
518
+ if (ay === 0 && !lup && by < ay) depth--; // hit vertex, both down
519
+ lup = by > ay;
520
+ }
521
+ return (depth & 1) === 1;
522
+ }
523
+ export function cosWithThreshold(alpha, threshold) {
524
+ var cos = Math.cos(alpha);
525
+ return cos < threshold ? 0 : cos;
526
+ }
527
+ export function sinWithThreshold(alpha, threshold) {
528
+ var sin = Math.sin(alpha);
529
+ return sin < threshold ? 0 : sin;
530
+ }
531
+ export function midPoint(x1, y1, x2, y2) {
532
+ return {
533
+ x: (x1 + x2) / 2,
534
+ y: (y1 + y2) / 2
535
+ };
536
+ }
537
+ export function verticesMidPoint(verticesArray) {
538
+ var res = verticesArray.reduce(function (incr, vertex) {
539
+ return {
540
+ x: incr.x + vertex.x,
541
+ y: incr.y + vertex.y
542
+ };
543
+ }, {
544
+ x: 0,
545
+ y: 0
546
+ });
547
+ return {
548
+ x: res.x / verticesArray.length,
549
+ y: res.y / verticesArray.length
550
+ };
551
+ }
552
+ export function rotatePointAroundPoint(px, py, ox, oy, theta) {
553
+ var thetaRad = theta * Math.PI / 180;
554
+ var cos = Math.cos(thetaRad);
555
+ var sin = Math.sin(thetaRad);
556
+ var deltaX = px - ox;
557
+ var deltaY = py - oy;
558
+ return {
559
+ x: cos * deltaX - sin * deltaY + ox,
560
+ y: sin * deltaX + cos * deltaY + oy
561
+ };
562
+ }
563
+
564
+ // point: x,y
565
+ // itemrectInfo: pos(x,y),rotRad,size,layoutpos,is_corner
566
+ // calcRect: rect(point[4]),pos(x,y),rotRad,size,layoutpos,is_corner
567
+
568
+ function point(x, y) {
569
+ return {
570
+ x: x,
571
+ y: y
572
+ };
573
+ }
574
+ function itemrectInfo(x, y, rotRad, size, layoutpos, is_corner) {
575
+ return {
576
+ pos: {
577
+ x: x,
578
+ y: y
579
+ },
580
+ rotRad: rotRad,
581
+ size: size,
582
+ layoutpos: layoutpos,
583
+ is_corner: is_corner
584
+ };
585
+ }
586
+ export function getCalcRectFromItem(item) {
587
+ var itemInfo;
588
+ if (item === undefined) itemInfo = [];else itemInfo = item.item;
589
+ var x = item.pos.x;
590
+ var y = item.pos.y;
591
+ var rotRad = item.rotRad;
592
+ var w = item.size && item.size.width / 2;
593
+ var h = item.size && item.size.height / 2;
594
+ var mx = x - w * Math.cos(rotRad);
595
+ var my = y - w * Math.sin(rotRad);
596
+ var x0 = mx + h * Math.sin(rotRad);
597
+ var y0 = my - h * Math.cos(rotRad);
598
+ var x3 = mx * 2 - x0;
599
+ var y3 = my * 2 - y0;
600
+ var x1 = x * 2 - x3;
601
+ var y1 = y * 2 - y3;
602
+ var x2 = x * 2 - x0;
603
+ var y2 = y * 2 - y0;
604
+ return {
605
+ rect: [point(x0, y0), point(x1, y1), point(x2, y2), point(x3, y3)],
606
+ pos: point(x, y),
607
+ rotRad: rotRad,
608
+ size: item.size,
609
+ layoutpos: item.layoutpos,
610
+ is_corner: item.is_corner,
611
+ itemInfo: itemInfo
612
+ };
613
+ }
614
+ export function getCalcRectFromItem3D(item) {
615
+ var itemInfo;
616
+ if (item === undefined) itemInfo = [];else itemInfo = item.item;
617
+ var x = item.pos.x;
618
+ var y = item.pos.y;
619
+ var rotRad = item.rotRad;
620
+ var w = item.size.width / 2;
621
+ var h = item.size.depth / 2;
622
+ var mx = x - w * Math.cos(rotRad);
623
+ var my = y - w * Math.sin(rotRad);
624
+ var x0 = mx + h * Math.sin(rotRad);
625
+ var y0 = my - h * Math.cos(rotRad);
626
+ var x3 = mx * 2 - x0;
627
+ var y3 = my * 2 - y0;
628
+ var x1 = x * 2 - x3;
629
+ var y1 = y * 2 - y3;
630
+ var x2 = x * 2 - x0;
631
+ var y2 = y * 2 - y0;
632
+ return {
633
+ rect: [point(x0, y0), point(x1, y1), point(x2, y2), point(x3, y3)],
634
+ pos: point(x, y),
635
+ rotRad: rotRad,
636
+ size: item.size,
637
+ layoutpos: item.layoutpos,
638
+ is_corner: item.is_corner,
639
+ itemInfo: itemInfo
640
+ };
641
+ }
642
+ export function getAllItems(scene, catalog, allLineRects) {
643
+ var layerID = scene.selectedLayer;
644
+ var layer = scene.layers.get(layerID);
645
+ var curiteminfo;
646
+ var iteminfo = [];
647
+ var otherItems = [];
648
+ var selectedItem;
649
+ var currentItem;
650
+ if (layer.selected.items.size > 0) {
651
+ selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
652
+ var catid = selectedItem.type;
653
+ var cat = catalog.elements[catid];
654
+ if (!cat) cat = catalog.elements[returnReplaceableDeepSearchType(catid)];
655
+ currentItem = {
656
+ selectedItem: selectedItem,
657
+ cat: cat
658
+ };
659
+ }
660
+ layer.items.forEach(function (item) {
661
+ var val = {
662
+ pos: {
663
+ x: item.x,
664
+ y: item.y
665
+ },
666
+ rotRad: item.rotation / 180 * Math.PI
667
+ };
668
+ var catid = item.type;
669
+ var cat = catalog.elements[catid];
670
+ if (!cat) {
671
+ cat = catalog.elements[returnReplaceableDeepSearchType(catid)];
672
+ }
673
+ var sizeinfo = [];
674
+ var width, height, depth;
675
+ sizeinfo = {
676
+ width: item.properties.get('width').get('_length'),
677
+ height: item.properties.get('height').get('_length'),
678
+ depth: item.properties.get('depth').get('_length'),
679
+ widthUnit: item.properties.get('width').get('_unit'),
680
+ heightUnit: item.properties.get('height').get('_unit'),
681
+ depthUnit: item.properties.get('depth').get('_unit')
682
+ };
683
+ sizeinfo = _objectSpread(_objectSpread({}, sizeinfo), {}, {
684
+ layoutpos: cat && cat.info.layoutpos,
685
+ is_corner: cat && cat.info.is_corner
686
+ });
687
+ width = convert(sizeinfo.width).from(sizeinfo.widthUnit).to(scene.unit);
688
+ height = convert(sizeinfo.depth).from(sizeinfo.depthUnit).to(scene.unit);
689
+ depth = convert(sizeinfo.height).from(sizeinfo.heightUnit).to(scene.unit);
690
+ val.size = {
691
+ width: width,
692
+ height: height,
693
+ depth: depth
694
+ };
695
+ val.layoutpos = sizeinfo.layoutpos;
696
+ val.is_corner = sizeinfo.is_corner;
697
+ val.doorStyle = item.doorStyle;
698
+ val.item = item;
699
+ var otherItem = {
700
+ item: item,
701
+ cat: cat
702
+ };
703
+ if (!needSnap(currentItem, otherItem)) {
704
+ return;
705
+ }
706
+ if (item.selected) {
707
+ curiteminfo = getCalcRectFromItem(val);
708
+ } else {
709
+ var calcrect = getCalcRectFromItem(val);
710
+ calcrect.isSnappedLine = isSnappedLine(calcrect, allLineRects);
711
+ iteminfo.push(calcrect);
712
+ otherItems.push(otherItem);
713
+ }
714
+ });
715
+ return {
716
+ cur: curiteminfo,
717
+ others: iteminfo,
718
+ currentItem: currentItem,
719
+ otherItems: otherItems
720
+ };
721
+ }
722
+ export function getAllItemSpecified(scene, catalog, filter) {
723
+ var _scene$layers, _scene$layers$get;
724
+ var layerID = scene === null || scene === void 0 ? void 0 : scene.selectedLayer;
725
+ var layer = scene === null || scene === void 0 || (_scene$layers = scene.layers) === null || _scene$layers === void 0 || (_scene$layers$get = _scene$layers.get) === null || _scene$layers$get === void 0 ? void 0 : _scene$layers$get.call(_scene$layers, layerID);
726
+ if (!layer || !layer.items) return {
727
+ cur: null,
728
+ others: []
729
+ };
730
+ var curiteminfo;
731
+ var iteminfo = [];
732
+ layer.items.forEach(function (item) {
733
+ var _cat$obj;
734
+ if (!item) return;
735
+ var val = {
736
+ pos: {
737
+ x: item.x,
738
+ y: item.y
739
+ },
740
+ rotRad: item.rotation / 180 * Math.PI
741
+ };
742
+ var cat = item.type ? findCatalogElement(catalog, item.type) : null;
743
+ var info = cat === null || cat === void 0 ? void 0 : cat.info;
744
+ var props = item.properties;
745
+ var getSize = function getSize(key) {
746
+ var _props$getIn;
747
+ var length = props === null || props === void 0 || (_props$getIn = props.getIn) === null || _props$getIn === void 0 ? void 0 : _props$getIn.call(props, [key, '_length']);
748
+ return length != null ? convert(length).from('in').to(scene.unit) : 0;
749
+ };
750
+ val.size = {
751
+ width: getSize('width'),
752
+ height: getSize('height'),
753
+ depth: getSize('depth')
754
+ };
755
+ val.item = item;
756
+ if (info) {
757
+ val.layoutpos = info.layoutpos;
758
+ val.is_corner = info.is_corner;
759
+ }
760
+
761
+ // Filter check
762
+ if (Array.isArray(filter)) {
763
+ if (info && !filter.includes(info.layoutpos)) return;
764
+ } else if (info && (info.layoutpos !== filter || (cat === null || cat === void 0 ? void 0 : cat.type) === 'appliance' && ['Cook Top', 'Microwave'].includes(cat === null || cat === void 0 || (_cat$obj = cat.obj) === null || _cat$obj === void 0 ? void 0 : _cat$obj.category))) {
765
+ return;
766
+ }
767
+
768
+ // Current vs others
769
+ var rect = getCalcRectFromItem3D(val);
770
+ if (item.selected) {
771
+ curiteminfo = rect;
772
+ } else {
773
+ iteminfo.push(rect);
774
+ }
775
+ });
776
+ return {
777
+ cur: curiteminfo,
778
+ others: iteminfo
779
+ };
780
+ }
781
+ export function findCatalogElement(catalog, elementName) {
782
+ if (!elementName || !catalog) return null;
783
+ var variants = [elementName, elementName.toLowerCase()];
784
+ var deepVariants = variants.map(function (v) {
785
+ return returnReplaceableDeepSearchType(v);
786
+ }).filter(Boolean);
787
+ var allCandidates = [].concat(variants, _toConsumableArray(deepVariants));
788
+ var getElement = function getElement(catid) {
789
+ if (!catid) return null;
790
+
791
+ // Immutable.js Map
792
+ if (typeof catalog.getIn === 'function') {
793
+ return catalog.getIn(['elements', catid]);
794
+ }
795
+
796
+ // Plain JS object
797
+ if (catalog.elements && catalog.elements[catid]) {
798
+ return catalog.elements[catid];
799
+ }
800
+ return null;
801
+ };
802
+ var _iterator6 = _createForOfIteratorHelper(allCandidates),
803
+ _step6;
804
+ try {
805
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
806
+ var name = _step6.value;
807
+ var cat = getElement(name);
808
+ if (cat) return cat;
809
+ }
810
+ } catch (err) {
811
+ _iterator6.e(err);
812
+ } finally {
813
+ _iterator6.f();
814
+ }
815
+ return null;
816
+ }
817
+ export function isSnappedLine(calcrect, allLineRects) {
818
+ if (allLineRects === undefined) return false;
819
+ var r2 = calcrect.rect[2];
820
+ var r3 = calcrect.rect[3];
821
+ var result = allLineRects.some(function (linerect) {
822
+ var l2 = linerect.rect[2];
823
+ var l3 = linerect.rect[3];
824
+ var delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
825
+ if (delta < EPSILON) {
826
+ return true;
827
+ } else {
828
+ l2 = linerect.rect[3];
829
+ l3 = linerect.rect[2];
830
+ delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
831
+ return delta < EPSILON;
832
+ }
833
+ });
834
+ return result;
835
+ }
836
+ export function isSnappedSideLine(calcrect, allLineRects) {
837
+ if (allLineRects === undefined) return 0;
838
+ var r2 = calcrect.rect[1];
839
+ var r3 = calcrect.rect[2];
840
+ var result = allLineRects.some(function (linerect) {
841
+ var l2 = linerect.rect[2];
842
+ var l3 = linerect.rect[3];
843
+ var delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
844
+ return delta < EPSILON;
845
+ });
846
+ return result;
847
+ }
848
+
849
+ /** Calculate candidate positions */
850
+ export function getAllItemSnap(allItemRects) {
851
+ var allItemSnap = [];
852
+ var cur = allItemRects.cur;
853
+
854
+ // For development
855
+ var otherItems = allItemRects.otherItems,
856
+ currentItem = allItemRects.currentItem;
857
+ allItemRects.others.forEach(function (rect, index) {
858
+ var cw = cur && cur.size.width / 2;
859
+ var ch = cur && cur.size.height / 2;
860
+ var cos = Math.cos(rect.rotRad);
861
+ var sin = Math.sin(rect.rotRad);
862
+ var ox0 = cw * cos - ch * sin; // (cw, ch) rot
863
+ var oy0 = cw * sin + ch * cos;
864
+ var ox1 = -cw * cos - ch * sin; // (-cw, ch) rot
865
+ var oy1 = -cw * sin + ch * cos;
866
+ var ox2 = ch * sin - cw * cos;
867
+ var oy2 = -ch * cos - cw * sin;
868
+ var ox3 = ch * sin + cw * cos;
869
+ var oy3 = -ch * cos + cw * sin;
870
+ var nrot = rect.rotRad + Math.PI;
871
+ if (nrot >= Math.PI) nrot -= Math.PI * 2;
872
+ var snap1 = itemrectInfo(rect.rect[2].x + ox3, rect.rect[2].y + oy3, rect.rotRad, cur && cur.size, rect.layoutpos, rect.is_corner);
873
+ var snap2 = itemrectInfo(rect.rect[3].x + ox2, rect.rect[3].y + oy2, rect.rotRad, cur && cur.size, rect.layoutpos, rect.is_corner);
874
+ var snap3 = itemrectInfo(rect.rect[2].x + ox1, rect.rect[2].y + oy1, nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
875
+ var snap4 = itemrectInfo(rect.rect[3].x + ox0, rect.rect[3].y + oy0, nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
876
+ var sizeinfo = otherItems[index].cat && otherItems[index].cat.info.sizeinfo;
877
+ if (sizeinfo) {
878
+ var leftBlindLength = sizeinfo.leftBlindLength,
879
+ rightBlindLength = sizeinfo.rightBlindLength;
880
+ if (leftBlindLength > 0) {
881
+ var vx = leftBlindLength - ch;
882
+ var vy = cw;
883
+ var dx = vx * cos + vy * sin;
884
+ var dy = vx * sin - vy * cos;
885
+ var snap6 = itemrectInfo(rect.rect[0].x + dx, rect.rect[0].y + dy, rect.rotRad + Math.PI / 2, cur && cur.size, rect.layoutpos, rect.is_corner);
886
+ allItemSnap.push(snap6);
887
+ }
888
+ if (rightBlindLength > 0) {
889
+ var _vx = ch - rightBlindLength;
890
+ var _vy = cw;
891
+ var _dx = _vx * cos + _vy * sin;
892
+ var _dy = _vx * sin - _vy * cos;
893
+ var snap7 = itemrectInfo(rect.rect[1].x + _dx, rect.rect[1].y + _dy, rect.rotRad - Math.PI / 2, cur && cur.size, rect.layoutpos, rect.is_corner);
894
+ allItemSnap.push(snap7);
895
+ }
896
+ }
897
+ if (rect.isSnappedLine) {
898
+ snap1.isSnappedLine = true;
899
+ snap2.isSnappedLine = true;
900
+ }
901
+ if (rect.is_corner) {
902
+ var _nrot = rect.rotRad + Math.PI * 3 / 2;
903
+ if (_nrot >= Math.PI) _nrot -= Math.PI * 2;
904
+ var snap5 = itemrectInfo(rect.rect[1].x - oy1, rect.rect[1].y + ox1, _nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
905
+ allItemSnap.push(snap2);
906
+ allItemSnap.push(snap5);
907
+ } else {
908
+ allItemSnap.push(snap1);
909
+ allItemSnap.push(snap2);
910
+ allItemSnap.push(snap3);
911
+ allItemSnap.push(snap4);
912
+ }
913
+ });
914
+ return allItemSnap;
915
+ }
916
+ export function getAllArea(layer) {
917
+ var allAreaLines = [];
918
+ var allLines = [];
919
+ var verticesArray = [];
920
+ var vertexID_to_verticesArrayIndex = {};
921
+ layer.vertices.forEach(function (vertex) {
922
+ var verticesCount = verticesArray.push([vertex.x, vertex.y]);
923
+ var latestVertexIndex = verticesCount - 1;
924
+ vertexID_to_verticesArrayIndex[vertex.id] = latestVertexIndex;
925
+ });
926
+ layer.areas.forEach(function (area) {
927
+ allAreaLines.push(area.vertices);
928
+ });
929
+ allAreaLines.forEach(function (area) {
930
+ var pt = [];
931
+ area.forEach(function (element) {
932
+ pt.push({
933
+ x: verticesArray[vertexID_to_verticesArrayIndex[element]][0],
934
+ y: verticesArray[vertexID_to_verticesArrayIndex[element]][1]
935
+ });
936
+ });
937
+ allLines.push(pt);
938
+ });
939
+ return allLines;
940
+ }
941
+
942
+ /** Get all lines of the scene */
943
+ export function getAllLines(layer) {
944
+ var allAreaLines = getAllAreaLines(layer);
945
+ var allLines = [];
946
+ //let allNonAreaLines = [];
947
+ var thick = LINE_THICKNESS / 2;
948
+ layer.lines.forEach(function (line) {
949
+ var i = containLine(allAreaLines, line);
950
+ // let thick = line.properties.getIn(['thickness', 'length']);
951
+ if (i < 0) {
952
+ var vertices = line.vertices.toJS();
953
+ var tmp_vertices = {
954
+ x1: layer.vertices.get(vertices[0]).x,
955
+ y1: layer.vertices.get(vertices[0]).y,
956
+ x2: layer.vertices.get(vertices[1]).x,
957
+ y2: layer.vertices.get(vertices[1]).y
958
+ };
959
+ if (tmp_vertices.x1 == tmp_vertices.x2 && tmp_vertices.y1 == tmp_vertices.y2) return;
960
+ var addIdx = allLines.length;
961
+ var flag = 0;
962
+ allLines.forEach(function (element, idx) {
963
+ if (flag == 0) {
964
+ var el = element[0];
965
+ var tmp_el = {
966
+ x1: layer.vertices.get(el[0]).x,
967
+ y1: layer.vertices.get(el[0]).y,
968
+ x2: layer.vertices.get(el[1]).x,
969
+ y2: layer.vertices.get(el[1]).y
970
+ };
971
+ if (tmp_el.x1 == tmp_vertices.x1 && tmp_el.y1 == tmp_vertices.y1) {
972
+ var tmp = vertices[0];
973
+ vertices[0] = vertices[1];
974
+ vertices[1] = tmp;
975
+ addIdx = idx == 0 ? 0 : idx - 1;
976
+ flag = 1;
977
+ } else if (tmp_el.x2 == tmp_vertices.x1 && tmp_el.y2 == tmp_vertices.y1) {
978
+ addIdx = idx;
979
+ flag = 1;
980
+ } else if (tmp_el.x1 == tmp_vertices.x2 && tmp_el.y1 == tmp_vertices.y2) {
981
+ addIdx = idx == 0 ? 0 : idx - 1;
982
+ flag = 1;
983
+ } else if (tmp_el.x2 == tmp_vertices.x2 && tmp_el.y2 == tmp_vertices.y2) {
984
+ var _tmp = vertices[0];
985
+ vertices[0] = vertices[1];
986
+ vertices[1] = _tmp;
987
+ addIdx = idx;
988
+ flag = 1;
989
+ }
990
+ }
991
+ });
992
+ allLines.splice(addIdx, 0, [vertices, thick]);
993
+ } else {
994
+ allLines.push([allAreaLines[i], thick]);
995
+ }
996
+ });
997
+ return allLines;
998
+ }
999
+
1000
+ /** Get lines that wraps the area */
1001
+ export function getAllAreaLines(layer) {
1002
+ var areainfo = [];
1003
+ layer.areas.forEach(function (area) {
1004
+ var sz = area.vertices.size;
1005
+ for (var i = 0; i < sz; i++) {
1006
+ areainfo.push([area.vertices.get(i), area.vertices.get((i + 1) % sz)]);
1007
+ }
1008
+ });
1009
+ return areainfo;
1010
+ }
1011
+ export function containLine(lines, line) {
1012
+ // lines: [array]
1013
+ var sz = lines.length;
1014
+ for (var i = 0; i < sz; i++) {
1015
+ var l = lines[i];
1016
+ if (line.vertices.get(0) == l[0] && line.vertices.get(1) == l[1] || line.vertices.get(1) == l[0] && line.vertices.get(0) == l[1]) {
1017
+ return i;
1018
+ }
1019
+ }
1020
+ return -1;
1021
+ }
1022
+ export function buildRectFromLines(layer, lines) {
1023
+ var rect = [];
1024
+ lines.forEach(function (line) {
1025
+ var vxys = []; // 0: x0, 1: y0, 2: x1, 3: y1
1026
+ line[0].forEach(function (vertex) {
1027
+ var vert = layer.vertices.get(vertex);
1028
+ vxys.push(vert.x);
1029
+ vxys.push(vert.y);
1030
+ });
1031
+ var thick = line[1];
1032
+ var x0 = vxys[0];
1033
+ var y0 = vxys[1];
1034
+ var x1 = vxys[2];
1035
+ var y1 = vxys[3];
1036
+ rect.push(getCalcRectFromLine(x0, y0, x1, y1, thick, layer));
1037
+ });
1038
+ return rect;
1039
+ }
1040
+ export function getRelatedVertices(x0, y0, x1, y1, layer) {
1041
+ var verticesArray = [];
1042
+ var mapVertIDtoIndex = {};
1043
+ layer.vertices.forEach(function (vertex) {
1044
+ var verticesCount = verticesArray.push([vertex.x, vertex.y]);
1045
+ var latestVertexIndex = verticesCount - 1;
1046
+ mapVertIDtoIndex[vertex.id] = latestVertexIndex;
1047
+ });
1048
+ var relVerts = [];
1049
+ layer.lines.some(function (line) {
1050
+ var vertID0 = line.vertices.get(0);
1051
+ var vertID1 = line.vertices.get(1);
1052
+ var pt0 = {
1053
+ x: verticesArray[mapVertIDtoIndex[vertID0]][0],
1054
+ y: verticesArray[mapVertIDtoIndex[vertID0]][1]
1055
+ };
1056
+ var pt1 = {
1057
+ x: verticesArray[mapVertIDtoIndex[vertID1]][0],
1058
+ y: verticesArray[mapVertIDtoIndex[vertID1]][1]
1059
+ };
1060
+ if (Math.abs(pt0.x - x0) < EPSILON && Math.abs(pt0.y - y0) < EPSILON && Math.abs(pt1.x - x1) < EPSILON && Math.abs(pt1.y - y1) < EPSILON || Math.abs(pt0.x - x1) < EPSILON && Math.abs(pt0.y - y1) < EPSILON && Math.abs(pt1.x - x0) < EPSILON && Math.abs(pt1.y - y0) < EPSILON) {
1061
+ if (line.relatedVertices.size == 2) {
1062
+ var relPt0 = point(x0, y0);
1063
+ var relPt1 = point(x1, y1);
1064
+ line.relatedVertices.forEach(function (relatedVertice, index) {
1065
+ if (relatedVertice.index == undefined) relatedVertice = relatedVertice.toJSON();
1066
+ if (relatedVertice.index == 0) relPt0 = point(relatedVertice.point.x, relatedVertice.point.y);else relPt1 = point(relatedVertice.point.x, relatedVertice.point.y);
1067
+ });
1068
+ relVerts.push(relPt0);
1069
+ relVerts.push(relPt1);
1070
+ }
1071
+ return true;
1072
+ }
1073
+ });
1074
+ return relVerts;
1075
+ }
1076
+ export function getCalcRectFromLine(x0, y0, x1, y1, thick, layer) {
1077
+ // get line from vertex coordinate
1078
+ var relVerts = getRelatedVertices(x0, y0, x1, y1, layer);
1079
+ var dx = x1 - x0;
1080
+ var dy = y1 - y0;
1081
+ var dl = Math.sqrt(dx * dx + dy * dy);
1082
+ var ox = -dy / dl * thick;
1083
+ var oy = dx / dl * thick;
1084
+ var rot = Math.atan2(dy, dx);
1085
+ if (relVerts.length == 2) {
1086
+ var vN = point(ox, oy);
1087
+ var vR = point(relVerts[0].x - x0, relVerts[0].y - y0);
1088
+ if (dotprod(vN, vR) < 0) {
1089
+ ox = -ox;
1090
+ oy = -oy;
1091
+ } else {
1092
+ rot += Math.PI;
1093
+ }
1094
+ } else {
1095
+ var pt0 = point(x0 + ox, y0 + oy);
1096
+ var pt1 = point(x1 + ox, y1 + oy);
1097
+ var ptC = point((pt0.x + pt1.x) / 2, (pt0.y + pt1.y) / 2);
1098
+ var allArea = getAllArea(layer);
1099
+ if (isPointInArea(allArea, ptC)) {
1100
+ // try make rect under line
1101
+ var _pt0 = point(x0 - ox, y0 - oy);
1102
+ var _pt1 = point(x1 - ox, y1 - oy);
1103
+ var _ptC = point((_pt0.x + _pt1.x) / 2, (_pt0.y + _pt1.y) / 2);
1104
+ if (!isPointInArea(allArea, _ptC)) {
1105
+ // only under rect is not included in area, make rect under line
1106
+ ox = -ox;
1107
+ oy = -oy;
1108
+ }
1109
+ }
1110
+ }
1111
+ return {
1112
+ rectEnd: [point(x0 + ox / 2, y0 + oy / 2), point(x1 + ox / 2, y1 + oy / 2)],
1113
+ rect: [point(x0 + ox, y0 + oy), point(x1 + ox, y1 + oy), point(x1, y1), point(x0, y0)],
1114
+ pos: point((x0 + x1 + ox) / 2, (y0 + y1 + ox) / 2),
1115
+ rotRad: rot,
1116
+ size: {
1117
+ width: dl,
1118
+ height: thick / 2
1119
+ }
1120
+ };
1121
+ }
1122
+ export function getAllLineSnap(allLineRects, curItemRect) {
1123
+ var allLineSnap = [];
1124
+ var cur = curItemRect;
1125
+ if (cur === undefined || cur === null) return;else allLineRects.forEach(function (rect) {
1126
+ var cw = cur.size.width / 2;
1127
+ var ch = cur.size.height / 2;
1128
+ var cos = Math.cos(rect.rotRad);
1129
+ var sin = Math.sin(rect.rotRad);
1130
+ var ox0 = cw * cos - ch * sin; // (cw, ch) rot
1131
+ var oy0 = cw * sin + ch * cos;
1132
+ var ox1 = -cw * cos - ch * sin; // (-cw, ch) rot
1133
+ var oy1 = -cw * sin + ch * cos;
1134
+ var nrot = rect.rotRad + Math.PI;
1135
+ if (nrot >= Math.PI) nrot -= Math.PI * 2;
1136
+ var thick = rect.size.height;
1137
+ var snap3 = itemInfo(rect.rect[2].x + ox1, rect.rect[2].y + oy1, nrot, cur.size);
1138
+ var snap4 = itemInfo(rect.rect[3].x + ox0, rect.rect[3].y + oy0, nrot, cur.size);
1139
+ if (!cur.is_corner) {
1140
+ allLineSnap.push(snap3);
1141
+ }
1142
+ allLineSnap.push(snap4);
1143
+ });
1144
+ return allLineSnap;
1145
+ }
1146
+ export function validateSnaps(allSnaps, allRects) {
1147
+ var validSnaps = [];
1148
+ if (allSnaps !== undefined && allSnaps !== null && allSnaps.length > 0) allSnaps.forEach(function (snap) {
1149
+ if (validSnap(snap, allRects)) {
1150
+ validSnaps.push(snap);
1151
+ }
1152
+ });
1153
+ return validSnaps;
1154
+ }
1155
+ export function validateLineSnaps(allSnaps, allItemSnap, allLineSnap, allItemRects, allLineRects, allRects) {
1156
+ var validSnaps = [];
1157
+ allSnaps.forEach(function (snap) {
1158
+ if (validSnap(snap, allRects)) {
1159
+ validSnaps.push(snap);
1160
+ } else {
1161
+ allItemSnap.forEach(function (snap) {
1162
+ validSnaps.push(snap);
1163
+ });
1164
+ allLineSnap.forEach(function (snap) {
1165
+ validSnaps.push(snap);
1166
+ });
1167
+ }
1168
+ });
1169
+ return validSnaps;
1170
+ }
1171
+ export function validSnap(snap, rects) {
1172
+ var snaprect = getCalcRectFromItem(snap);
1173
+ return rects.every(function (rect) {
1174
+ return !intersectRect(rect.rect, snaprect.rect);
1175
+ });
1176
+ }
1177
+ export function itemInfo(x, y, rotRad, size) {
1178
+ return {
1179
+ pos: {
1180
+ x: x,
1181
+ y: y
1182
+ },
1183
+ rotRad: rotRad,
1184
+ size: size
1185
+ };
1186
+ }
1187
+ export function intersectRect(rect1, rect2) {
1188
+ var ret = false;
1189
+ rect1 = shrinkRect(rect1);
1190
+ rect2 = shrinkRect(rect2);
1191
+ ret = ret || getInterSect(rect1, rect2);
1192
+ ret = ret || rect1.some(function (pt) {
1193
+ return containPointInRect(pt, rect2);
1194
+ });
1195
+ ret = ret || rect2.some(function (pt) {
1196
+ return containPointInRect(pt, rect1);
1197
+ });
1198
+ return ret;
1199
+ }
1200
+ export function containPointInRect(point, rect) {
1201
+ // true: contain, false: not contain
1202
+ for (var i = 0; i < rect.length; i++) {
1203
+ var ni = (i + 1) % rect.length;
1204
+ if (crossprod(diff(point, rect[i]), diff(rect[i], rect[ni])) < 0) {
1205
+ return false;
1206
+ }
1207
+ }
1208
+ return true;
1209
+ }
1210
+ export function diff(v0, v1) {
1211
+ return {
1212
+ x: v0.x - v1.x,
1213
+ y: v0.y - v1.y
1214
+ };
1215
+ }
1216
+ export function crossprod(v0, v1) {
1217
+ return v0.x * v1.y - v0.y * v1.x;
1218
+ }
1219
+ export function shrinkRect(rect) {
1220
+ var v02x = rect[2].x - rect[0].x;
1221
+ var v02y = rect[2].y - rect[0].y;
1222
+ var d02 = Math.sqrt(v02x * v02x + v02y * v02y);
1223
+ var o02x = v02x / d02 * 0.1;
1224
+ var o02y = v02y / d02 * 0.1;
1225
+ var v13x = rect[3].x - rect[1].x;
1226
+ var v13y = rect[3].y - rect[1].y;
1227
+ var d13 = Math.sqrt(v02x * v02x + v02y * v02y);
1228
+ var o13x = v13x / d13 * 0.1;
1229
+ var o13y = v13y / d13 * 0.1;
1230
+ return [point(rect[0].x + o02x, rect[0].y + o02y), point(rect[1].x + o13x, rect[1].y + o13y), point(rect[2].x - o02x, rect[2].y - o02y), point(rect[3].x - o13x, rect[3].y - o13y)];
1231
+ }
1232
+ export function getInterSect(shape1, shape2) {
1233
+ // return result of intersect of two shape
1234
+ var count = 0;
1235
+ for (var i = 0; i < shape1.length; i++) {
1236
+ var sl1 = {
1237
+ x: shape1[i].x,
1238
+ y: shape1[i].y
1239
+ };
1240
+ var sl2 = {
1241
+ x: shape1[(i + 1) % shape1.length].x,
1242
+ y: shape1[(i + 1) % shape1.length].y
1243
+ };
1244
+ for (var j = 0; j < shape2.length; j++) {
1245
+ var el1 = {
1246
+ x: shape2[j].x,
1247
+ y: shape2[j].y
1248
+ };
1249
+ var el2 = {
1250
+ x: shape2[(j + 1) % shape2.length].x,
1251
+ y: shape2[(j + 1) % shape2.length].y
1252
+ };
1253
+ var flag = getLineInterSect(sl1.x, sl1.y, sl2.x, sl2.y, el1.x, el1.y, el2.x, el2.y);
1254
+ if (flag) {
1255
+ count++;
1256
+ if (count > 1) return true;
1257
+ }
1258
+ }
1259
+ }
1260
+ return false;
1261
+ }
1262
+ export function getLineInterSect(s1x, s1y, e1x, e1y, s2x, s2y, e2x, e2y) {
1263
+ var ax = s1x;
1264
+ var ay = s1y;
1265
+ var bx = e1x - s1x;
1266
+ var by = e1y - s1y;
1267
+ var cx = s2x;
1268
+ var cy = s2y;
1269
+ var dx = e2x - s2x;
1270
+ var dy = e2y - s2y;
1271
+ if (Math.abs(bx * dy - by * dx) < 0.00000001) {
1272
+ if (Math.abs((cx - ax) * by - (cy - ay) * bx) < 0.00000001) {
1273
+ var maxX = ax;
1274
+ var minX = ax;
1275
+ var maxY = ay;
1276
+ var minY = ay;
1277
+ if (maxX < e1x) maxX = e1x;
1278
+ if (maxX < cx) maxX = cx;
1279
+ if (maxX < e2x) maxX = e2x;
1280
+ if (minX > e1x) minX = e1x;
1281
+ if (minX > cx) minX = cx;
1282
+ if (minX > e2x) minX = e2x;
1283
+ if (maxY < e1y) maxY = e1y;
1284
+ if (maxY < cy) maxY = cy;
1285
+ if (maxY < e2y) maxY = e2y;
1286
+ if (minY > e1y) minY = e1y;
1287
+ if (minY > cy) minY = cy;
1288
+ if (minY > e2y) minX = e2y;
1289
+ var len = Math.sqrt((maxX - minX) * (maxX - minX) + (maxY - minY) * (maxY - minY));
1290
+ var len1 = Math.sqrt(bx * bx + by * by);
1291
+ var len2 = Math.sqrt(dx * dx + dy * dy);
1292
+ if (len < len1 + len2) {
1293
+ return true;
1294
+ } else {
1295
+ return false;
1296
+ }
1297
+ } else {
1298
+ return false;
1299
+ }
1300
+ } else {
1301
+ var t = (dx * (ay - cy) + dy * (cx - ax)) / (bx * dy - by * dx);
1302
+ var u = (bx * (cy - ay) + by * (ax - cx)) / (dx * by - dy * bx);
1303
+ var ret = u < 1 && u > 0 && t > 0 && t < 1;
1304
+ return ret;
1305
+ }
1306
+ }
1307
+ export function isPointInArea(allArea, pt) {
1308
+ var x = pt.x;
1309
+ var y = pt.y;
1310
+ var result = false;
1311
+ result = allArea.some(function (area) {
1312
+ var sum = 0,
1313
+ alpha = 0;
1314
+ for (var i = 0; i < area.length; i++) {
1315
+ var x0 = area[i].x;
1316
+ var y0 = area[i].y;
1317
+ var x1 = area[(i + 1) % area.length].x;
1318
+ var y1 = area[(i + 1) % area.length].y;
1319
+ var v0 = {
1320
+ x: x0 - x,
1321
+ y: y0 - y
1322
+ };
1323
+ var v1 = {
1324
+ x: x1 - x,
1325
+ y: y1 - y
1326
+ };
1327
+ if (Math.abs(v0.x) < EPSILON && Math.abs(v0.y) < EPSILON)
1328
+ // check if pt is area point
1329
+ return true;
1330
+
1331
+ // check if pt is in area line
1332
+ var lineLen = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
1333
+ var v0Len = Math.sqrt(v0.x * v0.x + v0.y * v0.y);
1334
+ var vPt = {
1335
+ x: -v0.x / v0Len,
1336
+ y: -v0.y / v0Len
1337
+ };
1338
+ var xE = x0 + vPt.x * lineLen;
1339
+ var yE = y0 + vPt.y * lineLen;
1340
+ if (v0Len <= lineLen && Math.abs(xE - x1) < EPSILON && Math.abs(yE - y1) < EPSILON) return true;
1341
+ alpha = Math.atan2(v0.x * v1.y - v1.x * v0.y, v0.x * v1.x + v0.y * v1.y);
1342
+ sum += alpha;
1343
+ }
1344
+ if (Math.abs(Math.abs(sum) - Math.PI * 2) < EPSILON) return true;
1345
+ });
1346
+ return result;
1347
+ }
1348
+ export function calcSnap(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allAreaLines) {
1349
+ return calcSnap2(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allAreaLines);
1350
+ }
1351
+ export function calcCreateSnap(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, polygonPoint) {
1352
+ // Validate required input and guard against missing `.cur`
1353
+ if (!allItemRect || !allItemRect.cur) return;
1354
+ var cur = allItemRect.cur; // safe alias
1355
+ var cx = x;
1356
+ var cy = y;
1357
+ var ndist = 5000;
1358
+ var rotRad = cur.rotRad;
1359
+
1360
+ // Get candidate snaps and validate them as before
1361
+ var allCurSnap = getAllCurSnap(allLineRects, x, y, cur);
1362
+ allCurSnap = validateLineSnaps(allCurSnap, allItemSnap, allLineSnap, allItemRect, allLineRects, allRect);
1363
+ var getSnap = false;
1364
+ var snapdist = [];
1365
+
1366
+ // Build distances for snaps that lie inside polygonPoint (if any)
1367
+ if (Array.isArray(allCurSnap)) {
1368
+ allCurSnap.forEach(function (snap) {
1369
+ if (!snap || !snap.pos) return;
1370
+ var inside = ContainsPoint(polygonPoint, snap.pos.x, snap.pos.y);
1371
+ if (inside) {
1372
+ var dx = snap.pos.x - x;
1373
+ var dy = snap.pos.y - y;
1374
+ snapdist.push(dx * dx + dy * dy);
1375
+ }
1376
+ });
1377
+ }
1378
+
1379
+ // Find minimum distance (Infinity if none)
1380
+ var edist = snapdist.length ? Math.min.apply(Math, snapdist) : Infinity;
1381
+
1382
+ // Choose the snap with distance === edist
1383
+ if (Array.isArray(allCurSnap)) {
1384
+ allCurSnap.forEach(function (snap) {
1385
+ if (!snap || !snap.pos) return;
1386
+ var dx = snap.pos.x - x;
1387
+ var dy = snap.pos.y - y;
1388
+ var dist = dx * dx + dy * dy;
1389
+ if (dist === edist) {
1390
+ var _snap$rotRad;
1391
+ ndist = dist;
1392
+ cx = snap.pos.x;
1393
+ cy = snap.pos.y;
1394
+ rotRad = (_snap$rotRad = snap.rotRad) !== null && _snap$rotRad !== void 0 ? _snap$rotRad : rotRad; // nullish coalescing
1395
+ getSnap = true;
1396
+ }
1397
+ });
1398
+ }
1399
+ var crot = rotRad / Math.PI * 180;
1400
+ return {
1401
+ cx: cx,
1402
+ cy: cy,
1403
+ crot: crot,
1404
+ rotRad: rotRad
1405
+ };
1406
+ }
1407
+
1408
+ ////////////
1409
+ export function calcSnap1(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y) {
1410
+ var cx = allItemRect.cur.pos.x;
1411
+ var cy = allItemRect.cur.pos.y;
1412
+ var nx = x;
1413
+ var ny = y;
1414
+ var cursize = allItemRect.cur.size;
1415
+ var ndist = cursize.width * cursize.width + cursize.height * cursize.height;
1416
+ ndist = ndist / 4;
1417
+ var rotRad = allItemRect.cur.rotRad;
1418
+ var allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
1419
+ allCurSnap = validateSnaps(allCurSnap, allRect);
1420
+ var getSnap = false;
1421
+ allCurSnap.forEach(function (snap) {
1422
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1423
+ if (dist < ndist) {
1424
+ ndist = dist;
1425
+ nx = snap.pos.x;
1426
+ ny = snap.pos.y;
1427
+ rotRad = snap.rotRad;
1428
+ getSnap = true;
1429
+ }
1430
+ });
1431
+ if (!getSnap) {
1432
+ allLineSnap.concat(allItemSnap).forEach(function (snap) {
1433
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1434
+ if (dist < ndist) {
1435
+ ndist = dist;
1436
+ nx = snap.pos.x;
1437
+ ny = snap.pos.y;
1438
+ rotRad = snap.rotRad;
1439
+ }
1440
+ });
1441
+ }
1442
+ var rot = rotRad / Math.PI * 180;
1443
+ var ret = {
1444
+ nx: nx,
1445
+ ny: ny,
1446
+ rot: rot,
1447
+ rotRad: rotRad
1448
+ };
1449
+ return ret;
1450
+ }
1451
+
1452
+ ////////////
1453
+ export function calcSnap2(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allArea) {
1454
+ var nx = x;
1455
+ var ny = y;
1456
+ var ndist = 20;
1457
+ var rotRad = allItemRect.cur && allItemRect.cur.rotRad;
1458
+ var val = {
1459
+ pos: {
1460
+ x: x,
1461
+ y: y
1462
+ },
1463
+ rotRad: rotRad
1464
+ };
1465
+ val.size = allItemRect.cur && allItemRect.cur.size;
1466
+ val.layoutpos = allItemRect.cur && allItemRect.cur.layoutpos;
1467
+ val.is_corner = allItemRect.cur && allItemRect.cur.is_corner;
1468
+ var curitem = getCalcRectFromItem(val);
1469
+ var allCurSnap = [];
1470
+ //if (!val.is_corner) {
1471
+ allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
1472
+ allCurSnap = validateSnaps(allCurSnap, allRect);
1473
+ //}
1474
+ var getSnap = false;
1475
+ var snapdist = [];
1476
+ //console.log("allItemSnap", allItemSnap.filter(e => e.isSnappedLine))
1477
+ //console.log("~~~~start~~~~");
1478
+ allItemSnap.filter(function (e) {
1479
+ return e.isSnappedLine;
1480
+ }).forEach(function (snap) {
1481
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1482
+ snapdist.push(dist);
1483
+ //console.log("dist", snap)
1484
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < 100) {
1485
+ ndist = dist;
1486
+ nx = snap.pos.x;
1487
+ ny = snap.pos.y;
1488
+ rotRad = snap.rotRad;
1489
+ getSnap = true;
1490
+
1491
+ //console.log("SUCCESS!!!!");
1492
+ }
1493
+ });
1494
+ //console.log("====end====");
1495
+ if (getSnap == false) {
1496
+ allCurSnap.forEach(function (snap) {
1497
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1498
+ snapdist.push(dist);
1499
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < ndist) {
1500
+ ndist = dist;
1501
+ nx = snap.pos.x;
1502
+ ny = snap.pos.y;
1503
+ rotRad = snap.rotRad;
1504
+ getSnap = true;
1505
+ //console.log("SUCCE!!!!");
1506
+ }
1507
+ });
1508
+ if (!getSnap && allLineRects.some(function (others) {
1509
+ return intersectRect(others.rect, curitem.rect);
1510
+ })) {
1511
+ var edist = Math.min.apply(null, snapdist);
1512
+ allCurSnap.forEach(function (snap) {
1513
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1514
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist === edist) {
1515
+ ndist = dist;
1516
+ nx = snap.pos.x;
1517
+ ny = snap.pos.y;
1518
+ rotRad = snap.rotRad;
1519
+ getSnap = true;
1520
+ }
1521
+ });
1522
+ }
1523
+ if (getSnap === false) {
1524
+ var nearRect = null;
1525
+ var minDist = Infinity;
1526
+ allLineRects.forEach(function (rect) {
1527
+ var e = rect.rectEnd[0];
1528
+ e = clone_point(e);
1529
+ e.x -= curitem.pos.x;
1530
+ e.y -= curitem.pos.y;
1531
+ var nRot = rect.rotRad + Math.PI / 2;
1532
+ var dist = Math.abs(e.x * Math.cos(nRot) + e.y * Math.sin(nRot));
1533
+ if (minDist > dist) {
1534
+ minDist = dist;
1535
+ nearRect = rect;
1536
+ }
1537
+ });
1538
+ var containrect = nearRect && intersectRect(nearRect.rect, curitem.rect);
1539
+ if (containrect) {
1540
+ var filter_func = function filter_func(snap) {
1541
+ var diff = Math.abs(snap.rotRad - nearRect.rotRad - Math.PI);
1542
+ return diff == 0 || diff == 2 * Math.PI;
1543
+ };
1544
+ var tempSnap = allLineSnap.filter(filter_func);
1545
+ tempSnap = tempSnap.concat(allLineSnap.filter(function (snap) {
1546
+ return !filter_func(snap);
1547
+ }));
1548
+ tempSnap.some(function (snap) {
1549
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1550
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < 5000) {
1551
+ nx = snap.pos.x;
1552
+ ny = snap.pos.y;
1553
+ rotRad = snap.rotRad;
1554
+ getSnap = true;
1555
+ return true;
1556
+ }
1557
+ return false;
1558
+ });
1559
+ }
1560
+ }
1561
+ if (allItemRect.others.some(function (others) {
1562
+ return intersectRect(others.rect, curitem.rect);
1563
+ })) {
1564
+ getSnap = false;
1565
+ }
1566
+ if (!getSnap) {
1567
+ var _snapdist = [];
1568
+ allItemSnap.forEach(function (snap) {
1569
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1570
+ _snapdist.push(dist);
1571
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < ndist) {
1572
+ ndist = dist;
1573
+ nx = snap.pos.x;
1574
+ ny = snap.pos.y;
1575
+ rotRad = snap.rotRad;
1576
+ getSnap = true;
1577
+ }
1578
+ });
1579
+ if (!getSnap && allItemRect.others.some(function (others) {
1580
+ return intersectRect(others.rect, curitem.rect);
1581
+ })) {
1582
+ var _edist = Math.min.apply(null, _snapdist);
1583
+ allItemSnap.forEach(function (snap) {
1584
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1585
+ if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist === _edist) {
1586
+ ndist = dist;
1587
+ nx = snap.pos.x;
1588
+ ny = snap.pos.y;
1589
+ rotRad = snap.rotRad;
1590
+ }
1591
+ });
1592
+ if (allItemRect.cur.itemInfo.name.includes('Cook Top')) {
1593
+ var intersects = allItemRect.others.filter(function (others) {
1594
+ return intersectRect(others.rect, curitem.rect);
1595
+ });
1596
+ intersects.forEach(function (rect) {
1597
+ if (isPointInArea(allArea, rect.itemInfo) || !allArea.length) if (rect.itemInfo.layoutpos.includes(BASE_CABINET_LAYOUTPOS)) {
1598
+ nx = rect.itemInfo.x;
1599
+ ny = rect.itemInfo.y;
1600
+ rotRad = rect.itemInfo.rotation * Math.PI / 180;
1601
+ }
1602
+ });
1603
+ }
1604
+ if (allItemRect.cur.itemInfo.name.includes('Hood') || allItemRect.cur.itemInfo.name.includes('Range') || allItemRect.cur.itemInfo.name.includes('Cook Top')) {
1605
+ var _intersects = allItemRect.others.filter(function (others) {
1606
+ return intersectRect(others.rect, curitem.rect);
1607
+ });
1608
+ _intersects.forEach(function (rect) {
1609
+ if (isPointInArea(allArea, rect.itemInfo) || !allArea.length) if (rect.itemInfo.name.includes('Hood') || rect.itemInfo.name.includes('Range') || rect.itemInfo.name.includes('Cook Top')) {
1610
+ nx = rect.itemInfo.x;
1611
+ ny = rect.itemInfo.y;
1612
+ rotRad = rect.itemInfo.rotation * Math.PI / 180;
1613
+ }
1614
+ });
1615
+ }
1616
+ }
1617
+ }
1618
+ }
1619
+ var rot = rotRad / Math.PI * 180;
1620
+
1621
+ //Check case.
1622
+ //If item is 'blind base cabinet', it must be pulled from other 3".
1623
+ if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.startsWith('BBC')) {
1624
+ var offset3inch = convert(3).from('in').to('cm');
1625
+ var tx = nx,
1626
+ ty = ny;
1627
+ if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.endsWith('-L')) {
1628
+ if (rot == 0 || rot == -180) {
1629
+ tx -= offset3inch * Math.cos(rotRad);
1630
+ }
1631
+ if (rot == 90 || rot == -90) {
1632
+ ty -= offset3inch * Math.sin(rotRad);
1633
+ }
1634
+ }
1635
+ if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.endsWith('-R')) {
1636
+ if (rot == 0 || rot == -180) {
1637
+ tx += offset3inch * Math.cos(rotRad);
1638
+ }
1639
+ if (rot == 90 || rot == -90) {
1640
+ ty += offset3inch * Math.sin(rotRad);
1641
+ }
1642
+ }
1643
+ var t_val = {
1644
+ pos: {
1645
+ x: tx,
1646
+ y: ty
1647
+ },
1648
+ rotRad: rotRad,
1649
+ size: allItemRect.cur.size,
1650
+ layoutpos: allItemRect.cur.layoutpos,
1651
+ is_corner: allItemRect.cur.is_corner
1652
+ };
1653
+ var isItemRectSect = validInterSect(allItemRect.others, t_val);
1654
+ var isWallRectSect = validInterSect(allLineRects, t_val);
1655
+ if (isItemRectSect && isWallRectSect) {
1656
+ nx = tx;
1657
+ ny = ty;
1658
+ }
1659
+ }
1660
+ return {
1661
+ nx: nx,
1662
+ ny: ny,
1663
+ rot: rot,
1664
+ rotRad: rotRad
1665
+ };
1666
+ }
1667
+
1668
+ ////////////
1669
+ export function calcSnap3(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y) {
1670
+ // let layer = scene.layers.get(layerID);
1671
+ // let cx = allItemRect.cur.pos.x;
1672
+ // let cy = allItemRect.cur.pos.y;
1673
+ var nx = x;
1674
+ var ny = y;
1675
+ var ndist = 20;
1676
+ var rotRad = allItemRect.cur.rotRad;
1677
+ var val = {
1678
+ pos: {
1679
+ x: x,
1680
+ y: y
1681
+ },
1682
+ rotRad: rotRad
1683
+ };
1684
+ val.size = allItemRect.cur.size;
1685
+ val.layoutpos = allItemRect.cur.layoutpos;
1686
+ val.is_corner = allItemRect.cur.is_corner;
1687
+ var curitem = getCalcRectFromItem3D(val);
1688
+ var allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
1689
+ allCurSnap = validateSnaps(allCurSnap, allRect);
1690
+ var getSnap = false;
1691
+ var snapdist = [];
1692
+ allCurSnap.forEach(function (snap) {
1693
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1694
+ snapdist.push(dist);
1695
+ if (dist < ndist) {
1696
+ ndist = dist;
1697
+ nx = snap.pos.x;
1698
+ ny = snap.pos.y;
1699
+ rotRad = snap.rotRad;
1700
+ getSnap = true;
1701
+ } else {
1702
+ var i = 0;
1703
+ allLineRects.forEach(function (others) {
1704
+ var containrect = intersectRect(others.rect, curitem.rect);
1705
+ if (containrect) {
1706
+ var edist = Math.min.apply(null, snapdist);
1707
+ allCurSnap.forEach(function (snap) {
1708
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1709
+ if (dist === edist) {
1710
+ ndist = dist;
1711
+ nx = snap.pos.x;
1712
+ ny = snap.pos.y;
1713
+ rotRad = snap.rotRad;
1714
+ getSnap = true;
1715
+ }
1716
+ });
1717
+ }
1718
+ });
1719
+ }
1720
+ });
1721
+ if (getSnap === false) {
1722
+ allLineRects.forEach(function (others) {
1723
+ var containrect = intersectRect(others.rect, curitem.rect);
1724
+ if (containrect) {
1725
+ allLineSnap.forEach(function (snap) {
1726
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1727
+ if (dist < 5000) {
1728
+ nx = snap.pos.x;
1729
+ ny = snap.pos.y;
1730
+ rotRad = snap.rotRad;
1731
+ getSnap = true;
1732
+ }
1733
+ });
1734
+ }
1735
+ });
1736
+ }
1737
+ allItemRect.others.forEach(function (others) {
1738
+ if (!(others.layoutpos === 'base' && allItemRect.cur.layoutpos === 'wall') || !(others.layoutpos === 'wall' && allItemRect.cur.layoutpos === 'base')) {
1739
+ var containrect = intersectRect(others.rect, curitem.rect);
1740
+ if (containrect) {
1741
+ getSnap = false;
1742
+ }
1743
+ }
1744
+ });
1745
+ if (!getSnap) {
1746
+ var _snapdist2 = [];
1747
+ allItemSnap.forEach(function (snap) {
1748
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1749
+ _snapdist2.push(dist);
1750
+ if (dist < ndist) {
1751
+ ndist = dist;
1752
+ nx = snap.pos.x;
1753
+ ny = snap.pos.y;
1754
+ rotRad = snap.rotRad;
1755
+ } else {
1756
+ allItemRect.others.forEach(function (others) {
1757
+ if (!(others.layoutpos === 'base' && allItemRect.cur.layoutpos === 'wall') || !(others.layoutpos === 'wall' && allItemRect.cur.layoutpos === 'base')) {
1758
+ var containrect = intersectRect(others.rect, curitem.rect);
1759
+ if (containrect) {
1760
+ var edist = Math.min.apply(null, _snapdist2);
1761
+ allItemSnap.forEach(function (snap) {
1762
+ var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
1763
+ if (dist === edist) {
1764
+ ndist = dist;
1765
+ nx = snap.pos.x;
1766
+ ny = snap.pos.y;
1767
+ rotRad = snap.rotRad;
1768
+ }
1769
+ });
1770
+ }
1771
+ }
1772
+ });
1773
+ }
1774
+ });
1775
+ }
1776
+ var rot = rotRad / Math.PI * 180;
1777
+ return {
1778
+ nx: nx,
1779
+ ny: ny,
1780
+ rot: rot,
1781
+ rotRad: rotRad
1782
+ };
1783
+ }
1784
+ export function getAllCurSnap(allLineRects, x, y, curItemRect) {
1785
+ if (!curItemRect) return;
1786
+ var allCurSnap = [];
1787
+ var thick = LINE_THICKNESS / 2;
1788
+ allLineRects.forEach(function (linerect) {
1789
+ //allLineRects:left, right, top, bottom line
1790
+ var p0 = clone_point(linerect.rect[2]); //point 2(x, y) inside of line
1791
+ var p1 = clone_point(linerect.rect[3]); //point 3(x, y) inside of line
1792
+ var q = point(x, y); // point of item
1793
+ var cos = Math.cos(linerect.rotRad);
1794
+ var sin = Math.sin(linerect.rotRad);
1795
+ p0.x -= cos * curItemRect.size.width / 2;
1796
+ p0.y -= sin * curItemRect.size.width / 2;
1797
+ p1.x += cos * curItemRect.size.width / 2;
1798
+ p1.y += sin * curItemRect.size.width / 2;
1799
+ var n = point(-sin, cos);
1800
+ var v3to0 = {
1801
+ x: linerect.rect[0].x - p1.x,
1802
+ y: linerect.rect[0].y - p1.y
1803
+ };
1804
+ var fDot = dotprod(n, v3to0);
1805
+ if (fDot > 0) {
1806
+ // normal vector is crossing the wall
1807
+ n.x = -n.x;
1808
+ n.y = -n.y;
1809
+ }
1810
+ var dist = dotprod(diff(p1, q), n);
1811
+ var h = point(q.x + dist * n.x, q.y + dist * n.y);
1812
+ var nrot = linerect.rotRad + Math.PI;
1813
+ if (nrot >= Math.PI) nrot -= Math.PI * 2;
1814
+ var o = itemrectInfo(h.x + n.x * (curItemRect && curItemRect.size.height / 2), h.y + n.y * (curItemRect && curItemRect.size.height / 2), nrot, curItemRect && curItemRect.size, curItemRect && curItemRect.layoutpos, curItemRect && curItemRect.is_corner);
1815
+ allCurSnap.push(o);
1816
+ nrot = nrot + Math.PI;
1817
+ o = itemrectInfo(h.x - n.x * (curItemRect && curItemRect.size.height / 2 + thick), h.y - n.y * (curItemRect && curItemRect.size.height / 2 + thick), nrot, curItemRect && curItemRect.size, curItemRect && curItemRect.layoutpos, curItemRect && curItemRect.is_corner);
1818
+ allCurSnap.push(o);
1819
+ });
1820
+ return allCurSnap;
1821
+ }
1822
+ export function clone_point(pt) {
1823
+ return point(pt.x, pt.y);
1824
+ }
1825
+ export function dotprod(v0, v1) {
1826
+ return v0.x * v1.x + v0.y * v1.y;
1827
+ }
1828
+
1829
+ //////////
1830
+ export function validInterSect(rect, val) {
1831
+ var curitem = getCalcRectFromItem(val);
1832
+ var datas = [];
1833
+ rect.forEach(function (line) {
1834
+ datas.push(line);
1835
+ });
1836
+ for (var i = 0; i < datas.length; i++) {
1837
+ var data = datas[i];
1838
+ var containrect = intersectRect(data.rect, curitem.rect);
1839
+ if (containrect) {
1840
+ return false;
1841
+ }
1842
+ }
1843
+ return true;
1844
+ }
1845
+ var lineRect = function lineRect(layer) {
1846
+ var areainfo = [];
1847
+ layer.areas.forEach(function (area) {
1848
+ var sz = area.vertices.size;
1849
+ for (var i = 0; i < sz; i++) {
1850
+ areainfo.push(area.vertices.get(i));
1851
+ }
1852
+ });
1853
+ var rect = [];
1854
+ areainfo.forEach(function (area) {
1855
+ var vert = layer.vertices.get(area);
1856
+ rect.push(vert.x, vert.y);
1857
+ });
1858
+ return rect;
1859
+ };
1860
+ export function getAllHoleRect(scene, val) {
1861
+ var layerID = scene.selectedLayer;
1862
+ var layer = scene.layers.get(layerID);
1863
+ var selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
1864
+ if (selectedItem !== undefined) {
1865
+ if (selectedItem.category != 'cabinet') {
1866
+ // If selected Item type is not `cabinet` then do not snap at windows
1867
+ return {
1868
+ isSect: true,
1869
+ snap: null
1870
+ };
1871
+ }
1872
+ } else {
1873
+ return {
1874
+ isSect: false,
1875
+ snap: null
1876
+ };
1877
+ }
1878
+ var holes = [];
1879
+ var itemRect = getCalcRectFromItem(val);
1880
+ layer.lines.forEach(function (line) {
1881
+ line.holes.forEach(function (holeID) {
1882
+ var hole = layer.holes.get(holeID);
1883
+ holes.push(hole);
1884
+ });
1885
+ });
1886
+ var i = 0;
1887
+ for (; i < holes.length; i++) {
1888
+ var twidth = holes[i].properties.getIn(['width', 'length']);
1889
+ var theight = holes[i].properties.getIn(['thickness', 'length']) + 1;
1890
+ var tdepth = holes[i].properties.getIn(['altitude', 'length']);
1891
+ //let trot = holes[i].rotation;
1892
+ var verticeIDs = scene.getIn(['layers', layerID, 'lines', holes[i].line, 'vertices'])._tail.array;
1893
+ var vertice0 = scene.getIn(['layers', layerID, 'vertices', verticeIDs[0]]);
1894
+ var vertice1 = scene.getIn(['layers', layerID, 'vertices', verticeIDs[1]]);
1895
+ var point0 = {
1896
+ x: vertice0.x,
1897
+ y: vertice0.y
1898
+ };
1899
+ var point1 = {
1900
+ x: vertice1.x,
1901
+ y: vertice1.y
1902
+ };
1903
+ var rotation = Math.atan2(point1.y - point0.y, point1.x - point0.x);
1904
+ var rectInfo = getCalcRectFromLine(point0.x, point0.y, point1.x, point1.y, LINE_THICKNESS, layer);
1905
+ var vN = point(rectInfo.rect[0].x - rectInfo.rect[3].x, rectInfo.rect[0].y - rectInfo.rect[3].y);
1906
+ var lenN = Math.sqrt(vN.x * vN.x + vN.y * vN.y);
1907
+ vN.x /= lenN;
1908
+ vN.y /= lenN;
1909
+ var hx = holes[i].x;
1910
+ var hy = holes[i].y;
1911
+ hx += theight / 2 * vN.x;
1912
+ hy += theight / 2 * vN.y;
1913
+ var tval = {
1914
+ pos: {
1915
+ x: hx,
1916
+ y: hy
1917
+ },
1918
+ rotRad: rotation
1919
+ };
1920
+ tval.size = {
1921
+ width: twidth,
1922
+ height: theight
1923
+ };
1924
+ var hole_rect = getCalcRectFromItem(tval);
1925
+ if (intersectRect(itemRect.rect, hole_rect.rect)) {
1926
+ if (tdepth > itemRect.size.depth && itemRect.layoutpos !== WALL_CABINET_LAYOUTPOS) {
1927
+ var dist = itemRect.size.height / 2 + theight / 2;
1928
+ var snap = [];
1929
+ var p0 = {
1930
+ x: hx + dist * Math.cos(rotation + Math.PI / 2),
1931
+ y: hy + dist * Math.sin(rotation + Math.PI / 2)
1932
+ };
1933
+ var p1 = {
1934
+ x: hx - dist * Math.cos(rotation + Math.PI / 2),
1935
+ y: hy - dist * Math.sin(rotation + Math.PI / 2)
1936
+ };
1937
+ var allArea = getAllArea(layer);
1938
+ if (isPointInArea(allArea, p0)) {
1939
+ snap.push(p0);
1940
+ }
1941
+ if (isPointInArea(allArea, p1)) {
1942
+ snap.push(p1);
1943
+ }
1944
+ return {
1945
+ isSect: true,
1946
+ snap: snap
1947
+ };
1948
+ } else return {
1949
+ isSect: false,
1950
+ snap: null
1951
+ };
1952
+ }
1953
+ }
1954
+ return {
1955
+ isSect: true,
1956
+ snap: null
1957
+ };
1958
+ }
1959
+ export function getHoleItems(layer) {
1960
+ var holeItems = [];
1961
+ layer.holes.map(function (hole) {
1962
+ var width = hole.properties.getIn(['width', 'length']);
1963
+ var altitude = hole.properties.getIn(['altitude', 'length']);
1964
+ holeItems.push({
1965
+ x: hole.x,
1966
+ y: hole.y,
1967
+ width: width,
1968
+ altitude: altitude
1969
+ });
1970
+ });
1971
+ return holeItems;
1972
+ }
1973
+ export function needSnap(curItem, othItem) {
1974
+ var blSnap = false;
1975
+ if (curItem == undefined || curItem == null) return false;
1976
+ var altitude = curItem.selectedItem.properties.get('altitude');
1977
+ var heightFromFloor = convert(altitude.get('_length')).from(altitude.get('_unit')).to('in');
1978
+ var height = curItem.cat.info.sizeinfo.height;
1979
+ var currentItem = {
1980
+ heightFromFloor: heightFromFloor,
1981
+ height: height
1982
+ };
1983
+ altitude = othItem.item.properties.get('altitude');
1984
+ heightFromFloor = convert(altitude.get('_length')).from(altitude.get('_unit')).to('in');
1985
+ height = othItem.cat && othItem.cat.info.sizeinfo.height;
1986
+ var otherItem = {
1987
+ heightFromFloor: heightFromFloor,
1988
+ height: height
1989
+ };
1990
+ var curFloor = currentItem.heightFromFloor;
1991
+ var otherFloor = otherItem.heightFromFloor;
1992
+ var delta;
1993
+ curFloor > otherFloor ? delta = otherItem.height : delta = currentItem.height;
1994
+ if (Math.abs(curFloor - otherFloor) < delta) blSnap = true;
1995
+ if (curItem.cat.hasOwnProperty('long_name') || othItem.cat && othItem.cat.hasOwnProperty('long_name')) {
1996
+ if (curItem.cat.long_name.includes('Hood') || othItem.cat && othItem.cat.long_name.includes('Hood')) blSnap = true;
1997
+ if (curItem.cat.long_name.includes('Hood') && othItem.cat && othItem.cat.long_name.includes('Base Cabinet') || curItem.cat.long_name.includes('Base Cabinet') && othItem.cat && othItem.cat.long_name.includes('Hood')) blSnap = false;
1998
+ if (curItem.cat.long_name.includes('Cook Top') && othItem.cat && othItem.cat.long_name.includes('Cabinet') || curItem.cat.long_name.includes('Cabinet') && othItem.cat && othItem.cat.long_name.includes('Cook Top')) blSnap = true;
1999
+ }
2000
+ return blSnap;
2001
+ }
2002
+ export function isFrontWall(v0, v1) {
2003
+ var x1 = v0.x,
2004
+ y1 = v0.y;
2005
+ var x2 = v1.x,
2006
+ y2 = v1.y;
2007
+ var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
2008
+ return almostEqual(y1, y2) && x1 < x2 || -Math.PI / 2 < alpha && alpha < Math.PI / 2;
2009
+ }
2010
+ export function isBackWall(v0, v1) {
2011
+ var x1 = v0.x,
2012
+ y1 = v0.y;
2013
+ var x2 = v1.x,
2014
+ y2 = v1.y;
2015
+ var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
2016
+ return almostEqual(y1, y2) && x1 > x2 || -Math.PI / 2 > alpha || alpha > Math.PI / 2;
2017
+ }
2018
+ export function isLeftWall(v0, v1) {
2019
+ var x1 = v0.x,
2020
+ y1 = v0.y;
2021
+ var x2 = v1.x,
2022
+ y2 = v1.y;
2023
+ var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
2024
+ return almostEqual(x1, x2) && y1 < y2 || Math.PI > alpha && alpha > 0;
2025
+ }
2026
+ export function isRightWall(v0, v1) {
2027
+ var x1 = v0.x,
2028
+ y1 = v0.y;
2029
+ var x2 = v1.x,
2030
+ y2 = v1.y;
2031
+ var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
2032
+ return almostEqual(x1, x2) && y1 > y2 || -Math.PI < alpha && alpha < 0;
2033
+ }
2034
+
2035
+ /**
2036
+ * Calculate the overlapping relationship of two lines
2037
+ * @param {*} srcLine // source line
2038
+ * @param {*} destLine // destination line
2039
+ * @returns overlapping status (OVERLAP_NONE | OVERLAP_SAME | OVERLAP_LINK | OVERLAP_INCLUDED | OVERLAP_SOME) and line segments of srcLine which broken with destLine
2040
+ * OVERLAP_NONE: two lines are not overlapped
2041
+ * OVERLAP_SAME: the start point and endpoint of two lines are same
2042
+ * OVERLAP_LINK: two lines are linked at the common point, so they can be merged to one line
2043
+ * OVERLAP_INCLUDED: destLine includes srcLine
2044
+ * OVERLAP_SOME: two lines are overlapped with some common range, then returns the trimmed segments of srcLine
2045
+ *
2046
+ * //////// test - start /////////////
2047
+ const p1 = { x1: 1413.1313131313132, y1: 1044.949494949495 };
2048
+ const p2 = { x1: 1476.2626262626263, y1: 1108.0808080808079 };
2049
+ const p3 = { x1: 1596.969696969697, y1: 1228.7878787878785 };
2050
+ const p4 = { x1: 1664.1414141414139, y1: 1295.9595959595958 };
2051
+ const tempRet = GeometryUtils.relationshipOfTwoOverlappedLines(
2052
+ { x1: p3.x1, y1: p3.y1, x2: p1.x1, y2: p1.y1 },
2053
+ { x1: p1.x1, y1: p1.y1, x2: p3.x1, y2: p3.y1 }
2054
+ );
2055
+ console.log(tempRet);
2056
+ //////// test - end /////////////
2057
+
2058
+ */
2059
+ export function relationshipOfTwoOverlappedLines(srcLine, destLine) {
2060
+ // let res1 = relationshipOfTwoOverlappedLines1(srcLine, destLine);
2061
+ var res2 = relationshipOfTwoOverlappedLines2(srcLine, destLine);
2062
+ // if (res1.result !== 0 || res2.result !== 0) {
2063
+ // console.group(res1.result);
2064
+ // console.log(res1);
2065
+ // console.log(res2);
2066
+ // console.log(srcLine, destLine);
2067
+ // console.groupEnd();
2068
+ // }
2069
+ return res2;
2070
+ }
2071
+ export function relationshipOfTwoOverlappedLines2(srcLine, destLine) {
2072
+ var p1 = {
2073
+ x: srcLine.x1,
2074
+ y: srcLine.y1
2075
+ };
2076
+ var p2 = {
2077
+ x: srcLine.x2,
2078
+ y: srcLine.y2
2079
+ };
2080
+ var p3 = {
2081
+ x: destLine.x1,
2082
+ y: destLine.y1
2083
+ };
2084
+ var p4 = {
2085
+ x: destLine.x2,
2086
+ y: destLine.y2
2087
+ };
2088
+ var x1 = p1.x,
2089
+ y1 = p1.y;
2090
+ var x2 = p2.x,
2091
+ y2 = p2.y;
2092
+ var x3 = p3.x,
2093
+ y3 = p3.y;
2094
+ var x4 = p4.x,
2095
+ y4 = p4.y;
2096
+ var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
2097
+ var numA = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
2098
+ var numB = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
2099
+ if (fAbs(denom) <= EPSILON) {
2100
+ if (fAbs(numA) <= EPSILON && fAbs(numB) <= EPSILON) {
2101
+ var comparator = function comparator(pa, pb) {
2102
+ return fAbs(pa.x - pb.x) <= EPSILON ? pa.y - pb.y : pa.x - pb.x;
2103
+ };
2104
+ var line0 = [p1, p2].sort(comparator);
2105
+ var line1 = [p3, p4].sort(comparator);
2106
+ var isReversedSrcLineDirection = false;
2107
+ if (line0[0].x === srcLine.x2 && line0[0].y === srcLine.y2) isReversedSrcLineDirection = true;
2108
+ var _sort3 = [line0, line1].sort(function (lineA, lineB) {
2109
+ return comparator(lineA[0], lineB[0]);
2110
+ }),
2111
+ _sort4 = _slicedToArray(_sort3, 2),
2112
+ lineSX = _sort4[0],
2113
+ lineDX = _sort4[1];
2114
+ var isReversedSrcLineIdx = false;
2115
+ if (lineSX[0].x === line1[0].x && lineSX[0].y === line1[0].y) isReversedSrcLineIdx = true;
2116
+ var compare0 = comparator(lineSX[0], lineDX[0]);
2117
+ var compare1 = comparator(lineSX[1], lineDX[0]);
2118
+ var compare2 = comparator(lineSX[1], lineDX[1]);
2119
+ if (MathUtils.fAbs(compare0) < EPSILON && MathUtils.fAbs(compare2) < EPSILON) {
2120
+ return {
2121
+ result: OVERLAP_SAME
2122
+ };
2123
+ } else if (MathUtils.fAbs(compare0) < EPSILON && compare2 < 0) {
2124
+ // lineDX includes lineSX
2125
+ if (!isReversedSrcLineIdx) {
2126
+ // dest === lineDX : dest includes src
2127
+ // return OVERLAP_INCLUDED; // lineSX[1] - lineDX[1]
2128
+ return {
2129
+ result: OVERLAP_INCLUDED
2130
+ };
2131
+ }
2132
+ // else {
2133
+ // // src includes dest
2134
+ // // return OVERLAP_SOME; // lineSX[1] - lineDX[1]
2135
+ // return {
2136
+ // result: OVERLAP_SOME,
2137
+ // trimmedSegs: {
2138
+ // x1: lineSX[1].x,
2139
+ // y1: lineSX[1].y,
2140
+ // x2: lineDX[1].x,
2141
+ // y2: lineDX[1].y
2142
+ // }
2143
+ // };
2144
+ // }
2145
+ }
2146
+ if (MathUtils.fAbs(compare1) < EPSILON) {
2147
+ // return OVERLAP_LINK; // lineSX[1]
2148
+ return {
2149
+ result: OVERLAP_LINK,
2150
+ linkedLine: {
2151
+ x1: isReversedSrcLineDirection ? lineDX[1].x : lineSX[0].x,
2152
+ y1: isReversedSrcLineDirection ? lineDX[1].y : lineSX[0].y,
2153
+ x2: isReversedSrcLineDirection ? lineSX[0].x : lineDX[1].x,
2154
+ y2: isReversedSrcLineDirection ? lineSX[0].y : lineDX[1].y
2155
+ }
2156
+ };
2157
+ } else if (compare1 < 0) {
2158
+ return {
2159
+ result: OVERLAP_NONE
2160
+ };
2161
+ } else {
2162
+ if (MathUtils.fAbs(compare2) < EPSILON || compare2 > 0) {
2163
+ // lineSX includes lineDX
2164
+ if (isReversedSrcLineIdx) {
2165
+ // dest === lineSX : dest includes src
2166
+ // return OVERLAP_INCLUDED; // lineDX[0] - lineDX[1]
2167
+ return {
2168
+ result: OVERLAP_INCLUDED
2169
+ };
2170
+ } else {
2171
+ // dest === lineDX : src includes dest
2172
+ var trimmedSegs = [];
2173
+ // return OVERLAP_SOME; // lineSX[0] - lineDX[0], lineDX[1] - lineSX[1]
2174
+ if (compare0 < 0) trimmedSegs.push({
2175
+ x1: isReversedSrcLineDirection ? lineDX[0].x : lineSX[0].x,
2176
+ y1: isReversedSrcLineDirection ? lineDX[0].y : lineSX[0].y,
2177
+ x2: isReversedSrcLineDirection ? lineSX[0].x : lineDX[0].x,
2178
+ y2: isReversedSrcLineDirection ? lineSX[0].y : lineDX[0].y
2179
+ });
2180
+ if (compare2 > 0) trimmedSegs.push({
2181
+ x1: isReversedSrcLineDirection ? lineSX[1].x : lineDX[1].x,
2182
+ y1: isReversedSrcLineDirection ? lineSX[1].y : lineDX[1].y,
2183
+ x2: isReversedSrcLineDirection ? lineDX[1].x : lineSX[1].x,
2184
+ y2: isReversedSrcLineDirection ? lineDX[1].y : lineSX[1].y
2185
+ });
2186
+ return {
2187
+ result: OVERLAP_SOME,
2188
+ trimmedSegs: trimmedSegs
2189
+ };
2190
+ }
2191
+ }
2192
+ if (compare2 < 0) {
2193
+ // return OVERLAP_SOME; // lineSX[0] - lineDX[0], lineSX[1] - lineDX[1]
2194
+ var _trimmedSegs = [];
2195
+ if (compare0 < 0 && !isReversedSrcLineIdx) _trimmedSegs.push({
2196
+ x1: isReversedSrcLineDirection ? lineDX[0].x : lineSX[0].x,
2197
+ y1: isReversedSrcLineDirection ? lineDX[0].y : lineSX[0].y,
2198
+ x2: isReversedSrcLineDirection ? lineSX[0].x : lineDX[0].x,
2199
+ y2: isReversedSrcLineDirection ? lineSX[0].y : lineDX[0].y
2200
+ });
2201
+ if (compare2 < 0 && isReversedSrcLineIdx) _trimmedSegs.push({
2202
+ x1: isReversedSrcLineDirection ? lineDX[1].x : lineSX[1].x,
2203
+ y1: isReversedSrcLineDirection ? lineDX[1].y : lineSX[1].y,
2204
+ x2: isReversedSrcLineDirection ? lineSX[1].x : lineDX[1].x,
2205
+ y2: isReversedSrcLineDirection ? lineSX[1].y : lineDX[1].y
2206
+ });
2207
+ return {
2208
+ result: OVERLAP_SOME,
2209
+ trimmedSegs: _trimmedSegs
2210
+ };
2211
+ }
2212
+ }
2213
+ }
2214
+ }
2215
+ return {
2216
+ result: OVERLAP_NONE
2217
+ };
2218
+ }
2219
+ export function relationshipOfTwoOverlappedLines1(srcLine, destLine) {
2220
+ var INFINITY = 1000000;
2221
+ var ZERO_DELTA = 0.01;
2222
+ // geometric equation of srcLine
2223
+ var dx1 = srcLine.x2 - srcLine.x1;
2224
+ dx1 = MathUtils.fAbs(dx1) < ZERO_DELTA ? 0 : dx1;
2225
+ var dy1 = srcLine.y2 - srcLine.y1;
2226
+ dy1 = MathUtils.fAbs(dy1) < ZERO_DELTA ? 0 : dy1;
2227
+ var a1 = dx1 === 0 ? INFINITY : dy1 / dx1;
2228
+ var b1 = a1 === INFINITY ? srcLine.x1 : srcLine.y1 - a1 * srcLine.x1;
2229
+ // geometric equation of destLine
2230
+ var dx2 = destLine.x2 - destLine.x1;
2231
+ dx2 = MathUtils.fAbs(dx2) < ZERO_DELTA ? 0 : dx2;
2232
+ var dy2 = destLine.y2 - destLine.y1;
2233
+ dy2 = MathUtils.fAbs(dy2) < ZERO_DELTA ? 0 : dy2;
2234
+ var a2 = dx2 === 0 ? INFINITY : dy2 / dx2;
2235
+ var b2 = a2 === INFINITY ? destLine.x1 : destLine.y1 - a2 * destLine.x1;
2236
+ if (MathUtils.fAbs(MathUtils.fAbs(a1) - MathUtils.fAbs(a2)) > ZERO_DELTA)
2237
+ // two lines are not parallel
2238
+ return {
2239
+ result: OVERLAP_NONE
2240
+ };
2241
+ if (MathUtils.fAbs(MathUtils.fAbs(b1) - MathUtils.fAbs(b2)) > ZERO_DELTA)
2242
+ // two lines are parallel but not overlap
2243
+ return {
2244
+ result: OVERLAP_NONE
2245
+ };
2246
+
2247
+ // parametric equation of destLine
2248
+ var sk1 = dx1 === 0 ? INFINITY : MathUtils.toFixedFloat((destLine.x1 - srcLine.x1) / dx1, 3);
2249
+ var sk2 = dy1 === 0 ? INFINITY : MathUtils.toFixedFloat((destLine.y1 - srcLine.y1) / dy1, 3);
2250
+ var ek1 = dx1 === 0 ? INFINITY : MathUtils.toFixedFloat((destLine.x2 - srcLine.x1) / dx1, 3);
2251
+ var ek2 = dy1 === 0 ? INFINITY : MathUtils.toFixedFloat((destLine.y2 - srcLine.y1) / dy1, 3);
2252
+ if (sk1 !== INFINITY && sk2 !== INFINITY && ek1 !== INFINITY && ek2 !== INFINITY && (sk1 !== sk2 || ek1 !== ek2))
2253
+ // destLine does not overlap with srcLine
2254
+ return {
2255
+ result: OVERLAP_NONE
2256
+ };
2257
+
2258
+ // parameter of destLine on the start and end points
2259
+ var sk = Math.min(sk1, sk2);
2260
+ if (Math.abs(sk) < 0.05) sk = 0;else if (Math.abs(Math.abs(sk) - 1) < 0.05) sk = 1;
2261
+ var ek = Math.abs(Math.min(ek1, ek2)) > 0.05 ? Math.min(ek1, ek2) : 0;
2262
+ if (Math.abs(ek) < 0.05) ek = 0;else if (Math.abs(Math.abs(ek) - 1) < 0.05) ek = 1;
2263
+ // let ek = Math.min(ek1, ek2);
2264
+
2265
+ // check the relationship between srcLine and destLine
2266
+ if (sk < 0 && ek < 0 || sk > 1 && ek > 1)
2267
+ // not overlap
2268
+ return {
2269
+ result: OVERLAP_NONE
2270
+ };
2271
+ if (sk === 0 && ek === 1 || sk === 1 && ek === 0)
2272
+ // same lines
2273
+ return {
2274
+ result: OVERLAP_SAME
2275
+ };
2276
+ if (sk <= 0 && ek >= 1 || sk >= 1 && ek <= 0)
2277
+ // destLine includes srcLine
2278
+ return {
2279
+ result: OVERLAP_INCLUDED
2280
+ };
2281
+ if (sk === 0 && ek < 0 || sk === 1 && ek > 1 || ek === 0 && sk < 0 || ek === 1 && sk > 1) {
2282
+ // linked with one common point
2283
+ var linkedLine;
2284
+ if (sk === 0 && ek < 0) {
2285
+ // destE destS srcS srcE
2286
+ // |----------|------------|
2287
+ linkedLine = {
2288
+ x1: destLine.x2,
2289
+ y1: destLine.y2,
2290
+ x2: srcLine.x2,
2291
+ y2: srcLine.y2
2292
+ };
2293
+ } else if (sk === 1 && ek > 1) {
2294
+ // srcS srcE destS destE
2295
+ // |----------|------------|
2296
+ linkedLine = {
2297
+ x1: srcLine.x1,
2298
+ y1: srcLine.y1,
2299
+ x2: destLine.x2,
2300
+ y2: destLine.y2
2301
+ };
2302
+ } else if (ek === 0 && sk < 0) {
2303
+ // destS destE srcS srcE
2304
+ // |----------|------------|
2305
+ linkedLine = {
2306
+ x1: destLine.x1,
2307
+ y1: destLine.y1,
2308
+ x2: srcLine.x2,
2309
+ y2: srcLine.y2
2310
+ };
2311
+ } else if (ek === 1 && sk > 1) {
2312
+ // srcS srcE destE destS
2313
+ // |----------|------------|
2314
+ linkedLine = {
2315
+ x1: srcLine.x1,
2316
+ y1: srcLine.y1,
2317
+ x2: destLine.x1,
2318
+ y2: destLine.y1
2319
+ };
2320
+ }
2321
+ return {
2322
+ result: OVERLAP_LINK,
2323
+ linkedLine: linkedLine
2324
+ };
2325
+ }
2326
+ var trimmedSegment1 = null;
2327
+ var trimmedSegment2 = null;
2328
+ var ret = {
2329
+ result: OVERLAP_SOME,
2330
+ trimmedSegs: []
2331
+ };
2332
+ if (0 <= sk && sk <= 1 && 0 <= ek && ek <= 1) {
2333
+ // srcLine includes destLine
2334
+ if (sk < ek) {
2335
+ // srcS destS destE srcE
2336
+ // |------|---------|-------|
2337
+ if (sk > 0) trimmedSegment1 = {
2338
+ x1: srcLine.x1,
2339
+ y1: srcLine.y1,
2340
+ x2: destLine.x1,
2341
+ y2: destLine.y1
2342
+ };
2343
+ if (ek < 1) trimmedSegment2 = {
2344
+ x1: destLine.x2,
2345
+ y1: destLine.y2,
2346
+ x2: srcLine.x2,
2347
+ y2: srcLine.y2
2348
+ };
2349
+ } else {
2350
+ // srcS destE destS srcE
2351
+ // |------|---------|-------|
2352
+ if (ek > 0) trimmedSegment1 = {
2353
+ x1: srcLine.x1,
2354
+ y1: srcLine.y1,
2355
+ x2: destLine.x2,
2356
+ y2: destLine.y2
2357
+ };
2358
+ if (sk < 1) trimmedSegment2 = {
2359
+ x1: destLine.x1,
2360
+ y1: destLine.y1,
2361
+ x2: srcLine.x2,
2362
+ y2: srcLine.y2
2363
+ };
2364
+ }
2365
+ } else {
2366
+ // srcLine and destLine are overlapped with some range
2367
+ if (sk < 0) {
2368
+ // destS srcS destE srcE
2369
+ // |------|---------|-------|
2370
+ trimmedSegment1 = {
2371
+ x1: destLine.x2,
2372
+ y1: destLine.y2,
2373
+ x2: srcLine.x2,
2374
+ y2: srcLine.y2
2375
+ };
2376
+ } else if (ek < 0) {
2377
+ // destE srcS destS srcE
2378
+ // |------|---------|-------|
2379
+ trimmedSegment1 = {
2380
+ x1: destLine.x1,
2381
+ y1: destLine.y1,
2382
+ x2: srcLine.x2,
2383
+ y2: srcLine.y2
2384
+ };
2385
+ } else if (sk > 1) {
2386
+ // srcS destE srcE destS
2387
+ // |------|---------|-------|
2388
+ trimmedSegment1 = {
2389
+ x1: srcLine.x1,
2390
+ y1: srcLine.y1,
2391
+ x2: destLine.x2,
2392
+ y2: destLine.y2
2393
+ };
2394
+ } else if (ek > 1) {
2395
+ // srcS destS srcE destE
2396
+ // |------|---------|-------|
2397
+ trimmedSegment1 = {
2398
+ x1: srcLine.x1,
2399
+ y1: srcLine.y1,
2400
+ x2: destLine.x1,
2401
+ y2: destLine.y1
2402
+ };
2403
+ }
2404
+ }
2405
+ if (trimmedSegment1 !== null) ret.trimmedSegs.push(trimmedSegment1);
2406
+ if (trimmedSegment2 !== null) ret.trimmedSegs.push(trimmedSegment2);
2407
+ return ret;
2408
+ }
2409
+
2410
+ /**
2411
+ *
2412
+ * @param {Array} points //points of polygon
2413
+ * @returns {Array} [centroid.x, centroid.y]
2414
+ */
2415
+ export function getCentroidOfPolygon(points) {
2416
+ var center = points.reduce(function (x, y) {
2417
+ return [x[0] + y[0] / points.length, x[1] + y[1] / points.length];
2418
+ }, [0, 0]);
2419
+ return center;
2420
+ }