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

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