kitchen-simulator 11.0.0-react.18 → 11.0.0
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.
- package/es/AppContext.js +1 -4
- package/es/LiteKitchenConfigurator.js +67 -23
- package/es/LiteRenderer.js +15 -64
- package/es/actions/export.js +25 -12
- package/es/actions/items-actions.js +18 -2
- package/es/analytics/ga4.js +188 -0
- package/es/analytics/posthog.js +60 -0
- package/es/assets/Window.hdr +2100 -0
- package/es/assets/img/default/maple.jpg +0 -0
- package/es/assets/img/default/steel.jpg +0 -0
- package/es/assets/img/loading/loading.gif +0 -0
- package/es/catalog/cabinet/cabinet-assembly-order.js +36 -0
- package/es/catalog/catalog.js +0 -2
- package/es/catalog/factories/area-factory-3d.js +1 -5
- package/es/catalog/factories/wall-factory.js +1 -1
- package/es/catalog/holes/door-double/door_double.png +0 -0
- package/es/catalog/holes/door-panic/panicDoor.png +0 -0
- package/es/catalog/holes/door-panic-double/panicDoorDouble.png +0 -0
- package/es/catalog/holes/gate/gate.jpg +0 -0
- package/es/catalog/holes/window-clear/texture.png +0 -0
- package/es/catalog/holes/window-cross/texture.png +0 -0
- package/es/catalog/holes/window-double-hung/texture.png +0 -0
- package/es/catalog/holes/window-vertical/texture.png +0 -0
- package/es/catalog/utils/exporter.js +4 -0
- package/es/catalog/utils/item-loader.js +12 -25
- package/es/class/area.js +0 -1
- package/es/class/export.js +1 -3
- package/es/class/item.js +207 -89
- package/es/class/line.js +1 -3
- package/es/class/project.js +15 -19
- package/es/components/content.js +20 -6
- package/es/components/export.js +3 -5
- package/es/components/style/export.js +2 -28
- package/es/components/style/form-number-input.js +34 -43
- package/es/components/viewer2d/group.js +12 -7
- package/es/components/viewer2d/item.js +159 -168
- package/es/components/viewer2d/line.js +18 -51
- package/es/components/viewer2d/rulerX.js +3 -0
- package/es/components/viewer2d/rulerY.js +3 -0
- package/es/components/viewer2d/scene.js +67 -47
- package/es/components/viewer2d/state.js +1 -1
- package/es/components/viewer2d/utils.js +0 -6
- package/es/components/viewer2d/viewer2d.js +566 -508
- package/es/components/viewer3d/front3D.js +1 -2
- package/es/components/viewer3d/pointer-lock-navigation.js +0 -90
- package/es/components/viewer3d/ruler-utils/layer3D.js +2 -2
- package/es/components/viewer3d/scene-creator.js +113 -120
- package/es/components/viewer3d/three-memory-cleaner.js +0 -14
- package/es/components/viewer3d/viewer3d-first-person.js +132 -134
- package/es/components/viewer3d/viewer3d.js +40 -28
- package/es/constants/catalog/skinPanel.js +9 -0
- package/es/constants.js +19 -8
- package/es/{WorkSpaceOriginal.js → devLiteRenderer.js} +241 -173
- package/es/events/external/handleExternalEvent.js +141 -0
- package/es/events/external/handleExternalEvent.util.js +1099 -0
- package/es/events/external/handlers.addItem.js +47 -0
- package/es/events/external/handlers.changeDoorStyle.js +140 -0
- package/es/events/external/handlers.elementOps.js +8 -0
- package/es/events/external/handlers.finishing.js +26 -0
- package/es/events/external/handlers.hole.js +4 -0
- package/es/events/external/handlers.loadProject.js +128 -0
- package/es/events/external/handlers.molding.js +24 -0
- package/es/events/external/handlers.projectLifecycle.js +11 -0
- package/es/events/external/handlers.projectSettings.js +32 -0
- package/es/events/external/handlers.replaceCabinet.js +41 -0
- package/es/events/external/handlers.roomShape.js +8 -0
- package/es/events/external/handlers.syncScene.js +21 -0
- package/es/events/external/handlers.updateSelectedElements.js +11 -0
- package/es/events/external/handlers.viewMode.js +11 -0
- package/es/events/external/handlers.viewerNavigation.js +108 -0
- package/es/events/external/handlers.wall.js +7 -0
- package/es/index.js +36 -76
- package/es/mappings/external-events/mapExternalEventPayload.js +28 -0
- package/es/mappings/external-events/mappers/addItemMapper.js +97 -0
- package/es/mappings/external-events/mappers/ccdfMapper.js +100 -0
- package/es/mappings/external-events/mappers/ccdfToCDSMapper.js +49 -0
- package/es/mappings/external-events/mappers/changeDoorStyleMapper.js +37 -0
- package/es/mappings/external-events/mappers/loadProjectMapper.js +62 -0
- package/es/mappings/holesToCatalog.js +139 -0
- package/es/models.js +16 -1
- package/es/plugins/keyboard.js +1 -1
- package/es/reducers/export.js +2 -4
- package/es/reducers/items-reducer.js +4 -2
- package/es/reducers/project-reducer.js +1 -1
- package/es/reducers/reducer.js +2 -3
- package/es/reducers/viewer2d-reducer.js +0 -2
- package/es/shared/domain/cabinet-warning.js +15 -0
- package/es/shared/objects/immutable.js +3 -0
- package/es/utils/geometry.js +418 -95
- package/es/utils/helper.js +41 -35
- package/es/utils/history.js +2 -2
- package/es/utils/molding.js +12 -241
- package/es/utils/name-generator.js +0 -3
- package/es/utils/skinPanelEngine.js +522 -0
- package/lib/@history.js +11 -0
- package/lib/AppContext.js +11 -0
- package/lib/LiteKitchenConfigurator.js +527 -0
- package/lib/LiteRenderer.js +323 -0
- package/lib/actions/area-actions.js +21 -0
- package/lib/actions/export.js +36 -0
- package/lib/actions/groups-actions.js +107 -0
- package/lib/actions/holes-actions.js +140 -0
- package/lib/actions/items-actions.js +383 -0
- package/lib/actions/lines-actions.js +98 -0
- package/lib/actions/project-actions.js +351 -0
- package/lib/actions/scene-actions.js +43 -0
- package/lib/actions/vertices-actions.js +35 -0
- package/lib/actions/viewer2d-actions.js +73 -0
- package/lib/actions/viewer3d-actions.js +32 -0
- package/lib/analytics/ga4.js +194 -0
- package/lib/analytics/posthog.js +68 -0
- package/lib/assets/Window.hdr +2100 -0
- package/lib/assets/brown_photostudio_02_1k.hdr +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Black Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Black.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Bold Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Bold.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Book Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Book.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard ExtraBold Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard ExtraBold.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard ExtraLight Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard ExtraLight.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Hairline Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Hairline.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Heavy Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Heavy.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Light Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Light.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Medium Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Medium.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard SemiBold Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard SemiBold.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Thin Italic.woff +0 -0
- package/lib/assets/fonts/Rene Bieder Milliard Thin.woff +0 -0
- package/lib/assets/fonts/style.css +177 -0
- package/lib/assets/gltf/door_closet.gltf +1 -0
- package/lib/assets/gltf/door_exterior.gltf +1 -0
- package/lib/assets/gltf/door_interior.gltf +1 -0
- package/lib/assets/gltf/door_sliding.gltf +1 -0
- package/lib/assets/gltf/doorway_framed.bin +0 -0
- package/lib/assets/gltf/doorway_framed.fbx +0 -0
- package/lib/assets/gltf/doorway_framed.gltf +1 -0
- package/lib/assets/gltf/window_clear.bin +0 -0
- package/lib/assets/gltf/window_clear.fbx +0 -0
- package/lib/assets/gltf/window_clear.gltf +1 -0
- package/lib/assets/gltf/window_cross.bin +0 -0
- package/lib/assets/gltf/window_cross.fbx +0 -0
- package/lib/assets/gltf/window_cross.gltf +1 -0
- package/lib/assets/gltf/window_double_hung.bin +0 -0
- package/lib/assets/gltf/window_double_hung.fbx +0 -0
- package/lib/assets/gltf/window_double_hung.gltf +1 -0
- package/lib/assets/gltf/window_vertical.bin +0 -0
- package/lib/assets/gltf/window_vertical.fbx +0 -0
- package/lib/assets/gltf/window_vertical.gltf +1 -0
- package/lib/assets/img/TKC_thumbnail.png +0 -0
- package/lib/assets/img/Toggle.png +0 -0
- package/lib/assets/img/default/maple.jpg +0 -0
- package/lib/assets/img/default/steel.jpg +0 -0
- package/lib/assets/img/loading/loading.gif +0 -0
- package/lib/assets/img/loading/loading_1.svg +11 -0
- package/lib/assets/img/loading_large.gif +0 -0
- package/lib/assets/img/png/door/closet.png +0 -0
- package/lib/assets/img/png/door/doorwaysframed.png +0 -0
- package/lib/assets/img/png/door/doorwaysframeles.png +0 -0
- package/lib/assets/img/png/door/doorwaysframeless.png +0 -0
- package/lib/assets/img/png/door/exterior.png +0 -0
- package/lib/assets/img/png/door/interior.png +0 -0
- package/lib/assets/img/png/door/sliding.png +0 -0
- package/lib/assets/img/png/helper/outcome.png +0 -0
- package/lib/assets/img/project_img.png +0 -0
- package/lib/assets/img/rta/rta_logo_box_blue.jpg +0 -0
- package/lib/assets/img/rta/rta_logo_box_blue_ico.jpg +0 -0
- package/lib/assets/img/rta/rta_logo_box_blue_ico.svg +55 -0
- package/lib/assets/img/rta/rta_logo_box_darkGray.jpg +0 -0
- package/lib/assets/img/rta/rta_logo_box_lightblue.png +0 -0
- package/lib/assets/img/rta/rta_logo_box_lightmaroon.png +0 -0
- package/lib/assets/img/rta/rta_logo_box_maroon.png +0 -0
- package/lib/assets/img/rta/rta_logo_box_white.png +0 -0
- package/lib/assets/img/rta_menu.png +0 -0
- package/lib/assets/img/step2.jpg +0 -0
- package/lib/assets/img/step3.jpg +0 -0
- package/lib/assets/img/step4.jpg +0 -0
- package/lib/assets/img/step5.jpg +0 -0
- package/lib/assets/img/step6.jpg +0 -0
- package/lib/assets/img/step7.jpg +0 -0
- package/lib/assets/img/step8.jpg +0 -0
- package/lib/assets/img/svg/2d_delete_object.svg +33 -0
- package/lib/assets/img/svg/2d_delete_object1.svg +33 -0
- package/lib/assets/img/svg/2d_lock_object.svg +33 -0
- package/lib/assets/img/svg/3d_item_move.svg +106 -0
- package/lib/assets/img/svg/3d_item_rotation.svg +76 -0
- package/lib/assets/img/svg/3d_item_warning_edit.svg +77 -0
- package/lib/assets/img/svg/3d_item_warning_info.svg +81 -0
- package/lib/assets/img/svg/accessories.svg +4 -0
- package/lib/assets/img/svg/angle_icon.svg +39 -0
- package/lib/assets/img/svg/blank_div.svg +14 -0
- package/lib/assets/img/svg/bottombar/2d3d_button.svg +3 -0
- package/lib/assets/img/svg/bottombar/2d3d_button_active.svg +3 -0
- package/lib/assets/img/svg/bottombar/2d3d_toggle.svg +4 -0
- package/lib/assets/img/svg/bottombar/2d3d_toggle_active.svg +4 -0
- package/lib/assets/img/svg/bottombar/arrow-down.svg +3 -0
- package/lib/assets/img/svg/bottombar/arrow-left.svg +3 -0
- package/lib/assets/img/svg/bottombar/arrow-minus.svg +3 -0
- package/lib/assets/img/svg/bottombar/arrow-plus.svg +11 -0
- package/lib/assets/img/svg/bottombar/arrow-right.svg +3 -0
- package/lib/assets/img/svg/bottombar/arrow-up.svg +3 -0
- package/lib/assets/img/svg/bottombar/collapse.svg +3 -0
- package/lib/assets/img/svg/bottombar/elevation-back.svg +6 -0
- package/lib/assets/img/svg/bottombar/elevation-front.svg +6 -0
- package/lib/assets/img/svg/bottombar/elevation-left.svg +6 -0
- package/lib/assets/img/svg/bottombar/elevation-right.svg +7 -0
- package/lib/assets/img/svg/bottombar/elevation.svg +13 -0
- package/lib/assets/img/svg/bottombar/expand.svg +3 -0
- package/lib/assets/img/svg/bottombar/help.svg +72 -0
- package/lib/assets/img/svg/bottombar/incm_toggle.svg +39 -0
- package/lib/assets/img/svg/bottombar/pan_1.svg +57 -0
- package/lib/assets/img/svg/bottombar/pan_2.svg +27 -0
- package/lib/assets/img/svg/bottombar/pan_3.svg +27 -0
- package/lib/assets/img/svg/bottombar/pan_4.svg +27 -0
- package/lib/assets/img/svg/bottombar/pan_5.svg +27 -0
- package/lib/assets/img/svg/bottombar/settings.svg +23 -0
- package/lib/assets/img/svg/bottombar/spin-down.svg +76 -0
- package/lib/assets/img/svg/bottombar/spin-left.svg +75 -0
- package/lib/assets/img/svg/bottombar/spin-right.svg +75 -0
- package/lib/assets/img/svg/bottombar/spin-up.svg +76 -0
- package/lib/assets/img/svg/bottombar/spin_1.svg +48 -0
- package/lib/assets/img/svg/bottombar/spin_2.svg +31 -0
- package/lib/assets/img/svg/bottombar/spin_3.svg +31 -0
- package/lib/assets/img/svg/bottombar/spin_4.svg +31 -0
- package/lib/assets/img/svg/bottombar/spin_5.svg +31 -0
- package/lib/assets/img/svg/bottombar/zoomin.svg +29 -0
- package/lib/assets/img/svg/bottombar/zoomout.svg +26 -0
- package/lib/assets/img/svg/check.svg +10 -0
- package/lib/assets/img/svg/close.svg +11 -0
- package/lib/assets/img/svg/color/Black.svg +3 -0
- package/lib/assets/img/svg/color/Blue.svg +3 -0
- package/lib/assets/img/svg/color/Cream.svg +3 -0
- package/lib/assets/img/svg/color/Gray.svg +3 -0
- package/lib/assets/img/svg/color/Green.svg +3 -0
- package/lib/assets/img/svg/color/White.svg +3 -0
- package/lib/assets/img/svg/color/White.svg.bak +3 -0
- package/lib/assets/img/svg/color/stone2.jpg +0 -0
- package/lib/assets/img/svg/color/wood2.jpg +0 -0
- package/lib/assets/img/svg/copy.svg +11 -0
- package/lib/assets/img/svg/delete.svg +3 -0
- package/lib/assets/img/svg/detail.svg +77 -0
- package/lib/assets/img/svg/disclaimer/background.svg +758 -0
- package/lib/assets/img/svg/disclaimer/logo-dots.svg +11 -0
- package/lib/assets/img/svg/door/Closet.svg +11 -0
- package/lib/assets/img/svg/door/Exterior.svg +5 -0
- package/lib/assets/img/svg/door/Framed_dorway.svg +5 -0
- package/lib/assets/img/svg/door/Frameless_dorway.svg +5 -0
- package/lib/assets/img/svg/door/Interior.svg +7 -0
- package/lib/assets/img/svg/door/Sliding.svg +5 -0
- package/lib/assets/img/svg/doors_closet.svg +47 -0
- package/lib/assets/img/svg/doors_exterior.svg +25 -0
- package/lib/assets/img/svg/doors_interior.svg +29 -0
- package/lib/assets/img/svg/doors_patio.svg +26 -0
- package/lib/assets/img/svg/duplicate.svg +11 -0
- package/lib/assets/img/svg/duplicate_object_left.svg +32 -0
- package/lib/assets/img/svg/duplicate_object_right.svg +32 -0
- package/lib/assets/img/svg/filtersActive.svg +19 -0
- package/lib/assets/img/svg/firstsetting/L.svg +3 -0
- package/lib/assets/img/svg/firstsetting/L2.svg +3 -0
- package/lib/assets/img/svg/firstsetting/Open.svg +3 -0
- package/lib/assets/img/svg/firstsetting/Square.svg +3 -0
- package/lib/assets/img/svg/firstsetting/bar-active.svg +9 -0
- package/lib/assets/img/svg/firstsetting/bar-normal.svg +3 -0
- package/lib/assets/img/svg/firstsetting/bullet-current.svg +3 -0
- package/lib/assets/img/svg/firstsetting/bullet-done.svg +3 -0
- package/lib/assets/img/svg/firstsetting/bullet-not-done.svg +3 -0
- package/lib/assets/img/svg/firstsetting/check-active.svg +3 -0
- package/lib/assets/img/svg/firstsetting/check-normal.svg +3 -0
- package/lib/assets/img/svg/firstsetting/pencil.svg +11 -0
- package/lib/assets/img/svg/green_checkmark.svg +27 -0
- package/lib/assets/img/svg/headerbar/assist.svg +3 -0
- package/lib/assets/img/svg/headerbar/cart.svg +3 -0
- package/lib/assets/img/svg/headerbar/check.svg +10 -0
- package/lib/assets/img/svg/headerbar/consult_designer.svg +45 -0
- package/lib/assets/img/svg/headerbar/edit_name.svg +26 -0
- package/lib/assets/img/svg/headerbar/file-dollar.svg +13 -0
- package/lib/assets/img/svg/headerbar/hamburger_menu.svg +32 -0
- package/lib/assets/img/svg/headerbar/plus.svg +11 -0
- package/lib/assets/img/svg/headerbar/review_quote.svg +44 -0
- package/lib/assets/img/svg/headerbar/ruler-measure.svg +11 -0
- package/lib/assets/img/svg/headerbar/save.svg +3 -0
- package/lib/assets/img/svg/headerbar/setting.svg +75 -0
- package/lib/assets/img/svg/help/check.svg +10 -0
- package/lib/assets/img/svg/help/search.svg +76 -0
- package/lib/assets/img/svg/intro/1-start-with-floorplan-whole.svg +27 -0
- package/lib/assets/img/svg/intro/1-start-with-floorplan.svg +26 -0
- package/lib/assets/img/svg/intro/2-start-from-scratch-whole.svg +28 -0
- package/lib/assets/img/svg/intro/2-start-from-scratch.svg +27 -0
- package/lib/assets/img/svg/intro/3-retrieve-project-whole.svg +19 -0
- package/lib/assets/img/svg/intro/3-retrieve-project.svg +18 -0
- package/lib/assets/img/svg/invert.svg +127 -0
- package/lib/assets/img/svg/lefttoolbar/appliance-active.svg +13 -0
- package/lib/assets/img/svg/lefttoolbar/appliance.svg +13 -0
- package/lib/assets/img/svg/lefttoolbar/cabinet-active.svg +10 -0
- package/lib/assets/img/svg/lefttoolbar/cabinet-category.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/cabinet-one.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/cabinet.svg +10 -0
- package/lib/assets/img/svg/lefttoolbar/disigner_assistance.svg +89 -0
- package/lib/assets/img/svg/lefttoolbar/door-style-active.svg +20 -0
- package/lib/assets/img/svg/lefttoolbar/door-style.svg +20 -0
- package/lib/assets/img/svg/lefttoolbar/door.svg +12 -0
- package/lib/assets/img/svg/lefttoolbar/error_icon.svg +81 -0
- package/lib/assets/img/svg/lefttoolbar/finishing-active.svg +13 -0
- package/lib/assets/img/svg/lefttoolbar/finishing.svg +13 -0
- package/lib/assets/img/svg/lefttoolbar/reviewforquote-active.svg +86 -0
- package/lib/assets/img/svg/lefttoolbar/reviewforquote.svg +12 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-L.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-active.svg +18 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-custom.svg +12 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-irregular.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-open.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape-square.svg +3 -0
- package/lib/assets/img/svg/lefttoolbar/room-shape.svg +18 -0
- package/lib/assets/img/svg/lefttoolbar/search.svg +76 -0
- package/lib/assets/img/svg/lefttoolbar/view_more.svg +86 -0
- package/lib/assets/img/svg/lefttoolbar/warning_icon.svg +81 -0
- package/lib/assets/img/svg/lefttoolbar/window.svg +12 -0
- package/lib/assets/img/svg/logo.svg +11 -0
- package/lib/assets/img/svg/logo_with_text.svg +25 -0
- package/lib/assets/img/svg/menubar/login.svg +84 -0
- package/lib/assets/img/svg/menubar/my_projects.svg +85 -0
- package/lib/assets/img/svg/menubar/new_project.svg +110 -0
- package/lib/assets/img/svg/menubar/save_project.svg +84 -0
- package/lib/assets/img/svg/options.svg +3 -0
- package/lib/assets/img/svg/positioning.svg +3 -0
- package/lib/assets/img/svg/rotate.png +0 -0
- package/lib/assets/img/svg/rotate.svg +17 -0
- package/lib/assets/img/svg/rotate_object_clockwise.svg +26 -0
- package/lib/assets/img/svg/rotate_object_counterclockwise.svg +26 -0
- package/lib/assets/img/svg/toggleFilters.svg +19 -0
- package/lib/assets/img/svg/toolbar/add_appliances_active.svg +64 -0
- package/lib/assets/img/svg/toolbar/add_appliances_inactive.svg +52 -0
- package/lib/assets/img/svg/toolbar/add_button.svg +36 -0
- package/lib/assets/img/svg/toolbar/add_cabinets_active.svg +59 -0
- package/lib/assets/img/svg/toolbar/add_cabinets_inactive.svg +49 -0
- package/lib/assets/img/svg/toolbar/add_items_doors.svg +25 -0
- package/lib/assets/img/svg/toolbar/add_items_doorways.svg +24 -0
- package/lib/assets/img/svg/toolbar/add_items_refrigerator.svg +32 -0
- package/lib/assets/img/svg/toolbar/add_items_windows.svg +28 -0
- package/lib/assets/img/svg/toolbar/apply_button.svg +38 -0
- package/lib/assets/img/svg/toolbar/arrow-plus.svg +11 -0
- package/lib/assets/img/svg/toolbar/backsplash.svg +8 -0
- package/lib/assets/img/svg/toolbar/cancel_button.svg +37 -0
- package/lib/assets/img/svg/toolbar/consult_a_designer_button.svg +47 -0
- package/lib/assets/img/svg/toolbar/countertop.svg +7 -0
- package/lib/assets/img/svg/toolbar/dcm.png +0 -0
- package/lib/assets/img/svg/toolbar/dcm_off.svg +12 -0
- package/lib/assets/img/svg/toolbar/dcm_on.svg +474 -0
- package/lib/assets/img/svg/toolbar/delete_button.svg +37 -0
- package/lib/assets/img/svg/toolbar/download.svg +77 -0
- package/lib/assets/img/svg/toolbar/draw_custom_floor.svg +31 -0
- package/lib/assets/img/svg/toolbar/edit_button.svg +75 -0
- package/lib/assets/img/svg/toolbar/email_quote_button.svg +44 -0
- package/lib/assets/img/svg/toolbar/fbm.png +0 -0
- package/lib/assets/img/svg/toolbar/finishing_touches_active.svg +54 -0
- package/lib/assets/img/svg/toolbar/finishing_touches_inactive.svg +42 -0
- package/lib/assets/img/svg/toolbar/floorstyle.svg +9 -0
- package/lib/assets/img/svg/toolbar/fmb.png +0 -0
- package/lib/assets/img/svg/toolbar/fmb_off.svg +12 -0
- package/lib/assets/img/svg/toolbar/fmb_on.svg +489 -0
- package/lib/assets/img/svg/toolbar/furnishings_icon.svg +6 -0
- package/lib/assets/img/svg/toolbar/get_started_button.svg +41 -0
- package/lib/assets/img/svg/toolbar/handles.svg +5 -0
- package/lib/assets/img/svg/toolbar/lighting.svg +7 -0
- package/lib/assets/img/svg/toolbar/lrm.png +0 -0
- package/lib/assets/img/svg/toolbar/lrm_off.svg +12 -0
- package/lib/assets/img/svg/toolbar/lrm_on.svg +470 -0
- package/lib/assets/img/svg/toolbar/make_floorplan_active.svg +66 -0
- package/lib/assets/img/svg/toolbar/make_floorplan_inactive.svg +52 -0
- package/lib/assets/img/svg/toolbar/predefined_room_l_shaped.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_layout.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_long_narrow.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_open_l_shape.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_open_pentagon.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_open_rectangle.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_open_rectangle_2.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_pentagon.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_rectangle.svg +20 -0
- package/lib/assets/img/svg/toolbar/predefined_room_rectangle_with_alcove.svg +20 -0
- package/lib/assets/img/svg/toolbar/redo_button.svg +75 -0
- package/lib/assets/img/svg/toolbar/redo_button1.svg +75 -0
- package/lib/assets/img/svg/toolbar/review_quote_active.svg +14 -0
- package/lib/assets/img/svg/toolbar/review_quote_inactive.svg +44 -0
- package/lib/assets/img/svg/toolbar/save_project_button.svg +44 -0
- package/lib/assets/img/svg/toolbar/select_doorstyle_active.svg +67 -0
- package/lib/assets/img/svg/toolbar/select_doorstyle_inactive.svg +57 -0
- package/lib/assets/img/svg/toolbar/shopping-cart.svg +13 -0
- package/lib/assets/img/svg/toolbar/style_change_button.svg +47 -0
- package/lib/assets/img/svg/toolbar/take_picture.svg +75 -0
- package/lib/assets/img/svg/toolbar/undo_button.svg +76 -0
- package/lib/assets/img/svg/toolbar/undo_button1.svg +76 -0
- package/lib/assets/img/svg/toolbar/use_button.svg +37 -0
- package/lib/assets/img/svg/toolbar/wall_color_icon.svg +6 -0
- package/lib/assets/img/svg/topbar/edit_active.svg +10 -0
- package/lib/assets/img/svg/topbar/edit_inactive.svg +10 -0
- package/lib/assets/img/svg/topbar/redo_active.svg +42 -0
- package/lib/assets/img/svg/topbar/redo_inactive.svg +23 -0
- package/lib/assets/img/svg/topbar/select_all_active.svg +50 -0
- package/lib/assets/img/svg/topbar/select_all_inactive.svg +32 -0
- package/lib/assets/img/svg/topbar/take_picture_active.svg +51 -0
- package/lib/assets/img/svg/topbar/take_picture_inactive.svg +26 -0
- package/lib/assets/img/svg/topbar/undo_active.svg +42 -0
- package/lib/assets/img/svg/topbar/undo_inactive.svg +23 -0
- package/lib/assets/img/svg/warning_info_2d.svg +81 -0
- package/lib/assets/img/svg/window/Clear.svg +3 -0
- package/lib/assets/img/svg/window/Cross.svg +5 -0
- package/lib/assets/img/svg/window/Double_hung.svg +4 -0
- package/lib/assets/img/svg/window/Vertical.svg +4 -0
- package/lib/assets/img/svg/windows_clear.svg +23 -0
- package/lib/assets/img/svg/windows_cross.svg +28 -0
- package/lib/assets/img/svg/windows_double_hung.svg +24 -0
- package/lib/assets/img/svg/windows_vertical.svg +24 -0
- package/lib/assets/img/svg/wizardstep/Custom.svg +3 -0
- package/lib/assets/img/svg/wizardstep/Dashed_line.svg +3 -0
- package/lib/assets/img/svg/wizardstep/L.svg +3 -0
- package/lib/assets/img/svg/wizardstep/L2.svg +3 -0
- package/lib/assets/img/svg/wizardstep/Open.svg +3 -0
- package/lib/assets/img/svg/wizardstep/Square.svg +3 -0
- package/lib/assets/img/svg/wizardstep/bar-active.svg +9 -0
- package/lib/assets/img/svg/wizardstep/bar-normal.svg +3 -0
- package/lib/assets/img/svg/wizardstep/bullet-current.svg +3 -0
- package/lib/assets/img/svg/wizardstep/bullet-done.svg +3 -0
- package/lib/assets/img/svg/wizardstep/bullet-not-done.svg +3 -0
- package/lib/assets/img/svg/wizardstep/check-active.svg +3 -0
- package/lib/assets/img/svg/wizardstep/check-normal.svg +3 -0
- package/lib/assets/img/svg/wizardstep/detail_view.svg +87 -0
- package/lib/assets/img/svg/wizardstep/pencil.svg +11 -0
- package/lib/assets/img/svg/wizardstep/tile_view.svg +95 -0
- package/lib/assets/img/texture/glass.jpg +0 -0
- package/lib/assets/img/texture/steel.jpg +0 -0
- package/lib/assets/img/texture/white1px.jpg +0 -0
- package/lib/assets/img/texture/wood.jpg +0 -0
- package/lib/assets/model/DCM.bin +0 -0
- package/lib/assets/model/DCM.fbx +0 -0
- package/lib/assets/model/DCM.gltf +1 -0
- package/lib/assets/model/FBM.bin +0 -0
- package/lib/assets/model/FBM.fbx +0 -0
- package/lib/assets/model/FBM.gltf +1 -0
- package/lib/assets/model/LRM.bin +0 -0
- package/lib/assets/model/LRM.fbx +0 -0
- package/lib/assets/model/LRM.gltf +1 -0
- package/lib/assets/rtastore_logo.png +0 -0
- package/lib/catalog/areas/area/planner-element.js +53 -0
- package/lib/catalog/areas/area/textures/ceramic-tile.jpg +0 -0
- package/lib/catalog/areas/area/textures/grass.jpg +0 -0
- package/lib/catalog/areas/area/textures/parquet.jpg +0 -0
- package/lib/catalog/areas/area/textures/strand-porcelain.jpg +0 -0
- package/lib/catalog/areas/area/textures/tile1.jpg +0 -0
- package/lib/catalog/back.png +0 -0
- package/lib/catalog/cabinet/cabinet-assembly-order.js +42 -0
- package/lib/catalog/catalog.js +270 -0
- package/lib/catalog/doors.png +0 -0
- package/lib/catalog/doorways.png +0 -0
- package/lib/catalog/envMap/nx.hdr +0 -0
- package/lib/catalog/envMap/ny.hdr +0 -0
- package/lib/catalog/envMap/nz.hdr +0 -0
- package/lib/catalog/envMap/px.hdr +0 -0
- package/lib/catalog/envMap/py.hdr +0 -0
- package/lib/catalog/envMap/pz.hdr +0 -0
- package/lib/catalog/export.js +1 -0
- package/lib/catalog/factories/area-factory-3d.js +187 -0
- package/lib/catalog/factories/area-factory.js +88 -0
- package/lib/catalog/factories/export.js +25 -0
- package/lib/catalog/factories/wall-factory-3d.js +212 -0
- package/lib/catalog/factories/wall-factory.js +279 -0
- package/lib/catalog/holes/door-closet/planner-element.js +232 -0
- package/lib/catalog/holes/door-double/door_double.png +0 -0
- package/lib/catalog/holes/door-double/planner-element.js +325 -0
- package/lib/catalog/holes/door-exterior/planner-element.js +225 -0
- package/lib/catalog/holes/door-interior/planner-element.js +237 -0
- package/lib/catalog/holes/door-panic/panicDoor.png +0 -0
- package/lib/catalog/holes/door-panic/planner-element.js +513 -0
- package/lib/catalog/holes/door-panic-double/panicDoorDouble.png +0 -0
- package/lib/catalog/holes/door-panic-double/planner-element.js +473 -0
- package/lib/catalog/holes/door-sliding/planner-element.js +235 -0
- package/lib/catalog/holes/doorway-framed/planner-element.js +155 -0
- package/lib/catalog/holes/doorway-frameless/planner-element.js +114 -0
- package/lib/catalog/holes/export.js +97 -0
- package/lib/catalog/holes/gate/gate.jpg +0 -0
- package/lib/catalog/holes/window-clear/planner-element.js +176 -0
- package/lib/catalog/holes/window-clear/texture.png +0 -0
- package/lib/catalog/holes/window-cross/planner-element.js +175 -0
- package/lib/catalog/holes/window-cross/texture.png +0 -0
- package/lib/catalog/holes/window-double-hung/planner-element.js +313 -0
- package/lib/catalog/holes/window-double-hung/texture.png +0 -0
- package/lib/catalog/holes/window-vertical/planner-element.js +286 -0
- package/lib/catalog/holes/window-vertical/texture.png +0 -0
- package/lib/catalog/lines/wall/planner-element.js +87 -0
- package/lib/catalog/lines/wall/textures/bricks-normal.jpg +0 -0
- package/lib/catalog/lines/wall/textures/bricks.jpg +0 -0
- package/lib/catalog/lines/wall/textures/bricks2.jpg +0 -0
- package/lib/catalog/lines/wall/textures/morden-normal.jpg +0 -0
- package/lib/catalog/lines/wall/textures/morden.jpg +0 -0
- package/lib/catalog/lines/wall/textures/painted.jpg +0 -0
- package/lib/catalog/lines/wall/textures/plaster-normal.jpg +0 -0
- package/lib/catalog/lines/wall/textures/plaster.jpg +0 -0
- package/lib/catalog/lines/wall/wall.png +0 -0
- package/lib/catalog/molding/molding-dcm/planner-element.js +33 -0
- package/lib/catalog/molding/molding-dcm/texture.png +0 -0
- package/lib/catalog/molding/molding-fbm/planner-element.js +33 -0
- package/lib/catalog/molding/molding-fbm/texture.png +0 -0
- package/lib/catalog/molding/molding-lrm/planner-element.js +33 -0
- package/lib/catalog/molding/molding-lrm/texture.png +0 -0
- package/lib/catalog/utils/exporter.js +173 -0
- package/lib/catalog/utils/geom-utils.js +205 -0
- package/lib/catalog/utils/item-loader.js +1603 -0
- package/lib/catalog/utils/load-obj.js +99 -0
- package/lib/catalog/utils/mtl-loader.js +366 -0
- package/lib/catalog/utils/obj-loader.js +486 -0
- package/lib/catalog/windows.png +0 -0
- package/lib/class/area.js +147 -0
- package/lib/class/export.js +88 -0
- package/lib/class/group.js +438 -0
- package/lib/class/guide.js +64 -0
- package/lib/class/hole.js +930 -0
- package/lib/class/item.js +2009 -0
- package/lib/class/layer.js +670 -0
- package/lib/class/line.js +1236 -0
- package/lib/class/project.js +949 -0
- package/lib/class/vertex.js +205 -0
- package/lib/components/content.js +160 -0
- package/lib/components/export.js +7 -0
- package/lib/components/style/export.js +17 -0
- package/lib/components/style/form-number-input.js +192 -0
- package/lib/components/style/form-submit-button.js +35 -0
- package/lib/components/viewer2d/area.js +89 -0
- package/lib/components/viewer2d/export.js +121 -0
- package/lib/components/viewer2d/grids/grid-horizontal-streak.js +44 -0
- package/lib/components/viewer2d/grids/grid-streak.js +44 -0
- package/lib/components/viewer2d/grids/grid-vertical-streak.js +44 -0
- package/lib/components/viewer2d/grids/grids.js +40 -0
- package/lib/components/viewer2d/group.js +63 -0
- package/lib/components/viewer2d/item.js +244 -0
- package/lib/components/viewer2d/layer.js +172 -0
- package/lib/components/viewer2d/line.js +975 -0
- package/lib/components/viewer2d/ruler.js +92 -0
- package/lib/components/viewer2d/rulerDist.js +110 -0
- package/lib/components/viewer2d/rulerX.js +154 -0
- package/lib/components/viewer2d/rulerY.js +156 -0
- package/lib/components/viewer2d/scene.js +137 -0
- package/lib/components/viewer2d/snap.js +84 -0
- package/lib/components/viewer2d/state.js +83 -0
- package/lib/components/viewer2d/utils.js +200 -0
- package/lib/components/viewer2d/vertex.js +76 -0
- package/lib/components/viewer2d/viewer2d.js +1472 -0
- package/lib/components/viewer3d/camera-controls-module/camera-controls.module.js +2591 -0
- package/lib/components/viewer3d/dcm.js +408 -0
- package/lib/components/viewer3d/fbm.js +421 -0
- package/lib/components/viewer3d/front3D.js +71 -0
- package/lib/components/viewer3d/grid-creator.js +35 -0
- package/lib/components/viewer3d/grids/grid-horizontal-streak.js +45 -0
- package/lib/components/viewer3d/grids/grid-streak.js +36 -0
- package/lib/components/viewer3d/grids/grid-vertical-streak.js +45 -0
- package/lib/components/viewer3d/libs/first-person-controls.js +74 -0
- package/lib/components/viewer3d/libs/helvetiker_regular.typeface.js +1287 -0
- package/lib/components/viewer3d/libs/mtl-loader.js +366 -0
- package/lib/components/viewer3d/libs/obj-loader.js +471 -0
- package/lib/components/viewer3d/libs/orbit-controls.js +706 -0
- package/lib/components/viewer3d/libs/pointer-lock-controls.js +53 -0
- package/lib/components/viewer3d/lrm.js +312 -0
- package/lib/components/viewer3d/model.js +714 -0
- package/lib/components/viewer3d/pointer-lock-navigation.js +32 -0
- package/lib/components/viewer3d/ruler-utils/itemRect.js +69 -0
- package/lib/components/viewer3d/ruler-utils/layer3D.js +503 -0
- package/lib/components/viewer3d/ruler-utils/ruler3D.js +232 -0
- package/lib/components/viewer3d/ruler-utils/scene3D.js +67 -0
- package/lib/components/viewer3d/ruler-utils/state3D.js +26 -0
- package/lib/components/viewer3d/scene-creator.js +3850 -0
- package/lib/components/viewer3d/three-memory-cleaner.js +46 -0
- package/lib/components/viewer3d/viewer3d-first-person.js +316 -0
- package/lib/components/viewer3d/viewer3d.js +2673 -0
- package/lib/constants/catalog/skinPanel.js +15 -0
- package/lib/constants.js +791 -0
- package/lib/devLiteRenderer.js +917 -0
- package/lib/events/external/handleExternalEvent.js +148 -0
- package/lib/events/external/handleExternalEvent.util.js +1110 -0
- package/lib/events/external/handlers.addItem.js +54 -0
- package/lib/events/external/handlers.changeDoorStyle.js +147 -0
- package/lib/events/external/handlers.elementOps.js +15 -0
- package/lib/events/external/handlers.finishing.js +32 -0
- package/lib/events/external/handlers.hole.js +10 -0
- package/lib/events/external/handlers.loadProject.js +135 -0
- package/lib/events/external/handlers.molding.js +31 -0
- package/lib/events/external/handlers.projectLifecycle.js +19 -0
- package/lib/events/external/handlers.projectSettings.js +38 -0
- package/lib/events/external/handlers.replaceCabinet.js +48 -0
- package/lib/events/external/handlers.roomShape.js +14 -0
- package/lib/events/external/handlers.syncScene.js +27 -0
- package/lib/events/external/handlers.updateSelectedElements.js +17 -0
- package/lib/events/external/handlers.viewMode.js +19 -0
- package/lib/events/external/handlers.viewerNavigation.js +117 -0
- package/lib/events/external/handlers.wall.js +13 -0
- package/lib/index.js +637 -0
- package/lib/mappings/external-events/mapExternalEventPayload.js +33 -0
- package/lib/mappings/external-events/mappers/addItemMapper.js +103 -0
- package/lib/mappings/external-events/mappers/ccdfMapper.js +107 -0
- package/lib/mappings/external-events/mappers/ccdfToCDSMapper.js +55 -0
- package/lib/mappings/external-events/mappers/changeDoorStyleMapper.js +44 -0
- package/lib/mappings/external-events/mappers/loadProjectMapper.js +70 -0
- package/lib/mappings/holesToCatalog.js +148 -0
- package/lib/models.js +534 -0
- package/lib/plugins/SVGLoader.js +1419 -0
- package/lib/plugins/console-debugger.js +42 -0
- package/lib/plugins/export.js +25 -0
- package/lib/plugins/keyboard.js +117 -0
- package/lib/reducers/areas-reducer.js +19 -0
- package/lib/reducers/export.js +89 -0
- package/lib/reducers/groups-reducer.js +45 -0
- package/lib/reducers/holes-reducer.js +69 -0
- package/lib/reducers/items-reducer.js +152 -0
- package/lib/reducers/lines-reducer.js +52 -0
- package/lib/reducers/project-reducer.js +143 -0
- package/lib/reducers/reducer.js +25 -0
- package/lib/reducers/scene-reducer.js +35 -0
- package/lib/reducers/vertices-reducer.js +26 -0
- package/lib/reducers/viewer2d-reducer.js +84 -0
- package/lib/reducers/viewer3d-reducer.js +65 -0
- package/lib/shared/domain/cabinet-warning.js +20 -0
- package/lib/shared/objects/immutable.js +9 -0
- package/lib/shared-style.js +72 -0
- package/lib/translator/en.js +111 -0
- package/lib/translator/it.js +86 -0
- package/lib/translator/ru.js +86 -0
- package/lib/translator/translator.js +87 -0
- package/lib/utils/browser.js +40 -0
- package/lib/utils/convert-units-lite.js +44 -0
- package/lib/utils/email-validator.js +10 -0
- package/lib/utils/export.js +56 -0
- package/lib/utils/geometry.js +3230 -0
- package/lib/utils/get-edges-of-subgraphs.js +33 -0
- package/lib/utils/graph-cycles.js +239 -0
- package/lib/utils/graph-inner-cycles.js +54 -0
- package/lib/utils/graph.js +153 -0
- package/lib/utils/helper.js +480 -0
- package/lib/utils/history.js +48 -0
- package/lib/utils/id-broker.js +22 -0
- package/lib/utils/logger.js +14 -0
- package/lib/utils/math.js +57 -0
- package/lib/utils/molding.js +1146 -0
- package/lib/utils/name-generator.js +21 -0
- package/lib/utils/objects-utils.js +62 -0
- package/lib/utils/phone-validator.js +10 -0
- package/lib/utils/process-black-list.js +22 -0
- package/lib/utils/react-if.js +25 -0
- package/lib/utils/ruler.js +63 -0
- package/lib/utils/skinPanelEngine.js +530 -0
- package/lib/utils/snap-scene.js +101 -0
- package/lib/utils/snap.js +245 -0
- package/lib/utils/summarizeCart.js +30 -0
- package/lib/utils/threeCSG.es6.js +504 -0
- package/lib/version.js +7 -0
- package/package.json +29 -24
- package/es/WorkSpace.js +0 -30
- package/es/WorkSpaceHostMimic.js +0 -132
- package/es/assets/gltf/door_closet.bin +0 -0
- package/es/assets/gltf/door_closet.fbx +0 -0
- package/es/assets/gltf/door_exterior.bin +0 -0
- package/es/assets/gltf/door_exterior.fbx +0 -0
- package/es/assets/gltf/door_interior.bin +0 -0
- package/es/assets/gltf/door_interior.fbx +0 -0
- package/es/assets/gltf/door_sliding.bin +0 -0
- package/es/assets/gltf/door_sliding.fbx +0 -0
- package/es/assets/img/png/helper/video_preview_3d.png +0 -0
- package/es/assets/img/png/helper/video_preview_start.png +0 -0
- package/es/assets/img/svg/color/Brown.svg +0 -9
- package/es/assets/img/svg/color/Dark.svg +0 -9
- package/es/assets/img/svg/color/Light.svg +0 -9
- package/es/assets/img/svg/color/Medium.svg +0 -9
- package/es/assets/img/svg/color/Unfinished.svg +0 -9
- package/es/catalog/lines/wall/textures/bricks3.jpg +0 -0
- package/es/catalog/properties/export.js +0 -21
- package/es/catalog/properties/property-checkbox.js +0 -68
- package/es/catalog/properties/property-color.js +0 -39
- package/es/catalog/properties/property-enum.js +0 -50
- package/es/catalog/properties/property-hidden.js +0 -19
- package/es/catalog/properties/property-lenght-measure.js +0 -96
- package/es/catalog/properties/property-length-measure.js +0 -80
- package/es/catalog/properties/property-length-measure_hole.js +0 -96
- package/es/catalog/properties/property-number.js +0 -48
- package/es/catalog/properties/property-read-only.js +0 -26
- package/es/catalog/properties/property-string.js +0 -48
- package/es/catalog/properties/property-toggle.js +0 -39
- package/es/catalog/properties/shared-property-style.js +0 -14
- package/es/catalog/utils/FuseUtils.js +0 -79
- package/es/class/FuseUtils.js +0 -79
- package/es/components/style/button.js +0 -106
- package/es/components/style/cancel-button.js +0 -21
- package/es/components/style/content-container.js +0 -30
- package/es/components/style/content-title.js +0 -25
- package/es/components/style/delete-button.js +0 -24
- package/es/components/style/form-block.js +0 -20
- package/es/components/style/form-color-input.js +0 -26
- package/es/components/style/form-label.js +0 -22
- package/es/components/style/form-number-input_2.js +0 -238
- package/es/components/style/form-select.js +0 -19
- package/es/components/style/form-slider.js +0 -60
- package/es/components/style/form-text-input.js +0 -69
- package/es/index.html.ejs +0 -264
- package/es/reducers/user-reducer.js +0 -41
- package/es/utils/isolate-event-handler.js +0 -1622
- /package/{es/catalog/lines/wall/textures/bricks-normal2.jpg → lib/catalog/lines/wall/textures/painted-normal.jpg} +0 -0
|
@@ -0,0 +1,3230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ContainsPoint = ContainsPoint;
|
|
9
|
+
exports._twoLineSegmentsIntersection = _twoLineSegmentsIntersection;
|
|
10
|
+
exports.absAngleBetweenTwoPoints = absAngleBetweenTwoPoints;
|
|
11
|
+
exports.almostEqual = void 0;
|
|
12
|
+
exports.angleBetweenTwoLines = angleBetweenTwoLines;
|
|
13
|
+
exports.angleBetweenTwoPoints = angleBetweenTwoPoints;
|
|
14
|
+
exports.angleBetweenTwoPointsAndOrigin = angleBetweenTwoPointsAndOrigin;
|
|
15
|
+
exports.buildRectFromLines = buildRectFromLines;
|
|
16
|
+
exports.calcCreateSnap = calcCreateSnap;
|
|
17
|
+
exports.calcDistancesFromHoleToNearestOneOrWall = calcDistancesFromHoleToNearestOneOrWall;
|
|
18
|
+
exports.calcDistancesFromItemToWalls = calcDistancesFromItemToWalls;
|
|
19
|
+
exports.calcSnap = calcSnap;
|
|
20
|
+
exports.calcSnap1 = calcSnap1;
|
|
21
|
+
exports.calcSnap2 = calcSnap2;
|
|
22
|
+
exports.calcSnap3 = calcSnap3;
|
|
23
|
+
exports.clone_point = clone_point;
|
|
24
|
+
exports.closestPointFromLine = closestPointFromLine;
|
|
25
|
+
exports.closestPointFromLineSegment = closestPointFromLineSegment;
|
|
26
|
+
exports.compareVertices = compareVertices;
|
|
27
|
+
exports.containLine = containLine;
|
|
28
|
+
exports.containPointInRect = containPointInRect;
|
|
29
|
+
exports.cosWithThreshold = cosWithThreshold;
|
|
30
|
+
exports.crossprod = crossprod;
|
|
31
|
+
exports.diff = diff;
|
|
32
|
+
exports.distancePointFromLine = distancePointFromLine;
|
|
33
|
+
exports.distancePointFromLineSegment = distancePointFromLineSegment;
|
|
34
|
+
exports.dotprod = dotprod;
|
|
35
|
+
exports.downcrossLine = downcrossLine;
|
|
36
|
+
exports.extendLine = extendLine;
|
|
37
|
+
exports.findCatalogElement = findCatalogElement;
|
|
38
|
+
exports.getAllArea = getAllArea;
|
|
39
|
+
exports.getAllAreaLines = getAllAreaLines;
|
|
40
|
+
exports.getAllCurSnap = getAllCurSnap;
|
|
41
|
+
exports.getAllHoleRect = getAllHoleRect;
|
|
42
|
+
exports.getAllItemSnap = getAllItemSnap;
|
|
43
|
+
exports.getAllItemSpecified = getAllItemSpecified;
|
|
44
|
+
exports.getAllItems = getAllItems;
|
|
45
|
+
exports.getAllLineSnap = getAllLineSnap;
|
|
46
|
+
exports.getAllLines = getAllLines;
|
|
47
|
+
exports.getCalcRectFromItem = getCalcRectFromItem;
|
|
48
|
+
exports.getCalcRectFromItem3D = getCalcRectFromItem3D;
|
|
49
|
+
exports.getCalcRectFromLine = getCalcRectFromLine;
|
|
50
|
+
exports.getCentroidOfPolygon = getCentroidOfPolygon;
|
|
51
|
+
exports.getHoleItems = getHoleItems;
|
|
52
|
+
exports.getInterSect = getInterSect;
|
|
53
|
+
exports.getLineInterSect = getLineInterSect;
|
|
54
|
+
exports.getLineSnapPointsOfItem = getLineSnapPointsOfItem;
|
|
55
|
+
exports.getNormaline = getNormaline;
|
|
56
|
+
exports.getPoylgonPoints = getPoylgonPoints;
|
|
57
|
+
exports.getRelatedLines = void 0;
|
|
58
|
+
exports.getRelatedVertices = getRelatedVertices;
|
|
59
|
+
exports.getSnappedWallLines = getSnappedWallLines;
|
|
60
|
+
exports.horizontalLine = horizontalLine;
|
|
61
|
+
exports.intersectRect = intersectRect;
|
|
62
|
+
exports.isBackWall = isBackWall;
|
|
63
|
+
exports.isFrontWall = isFrontWall;
|
|
64
|
+
exports.isLeftWall = isLeftWall;
|
|
65
|
+
exports.isOverlappedTwoItemsOnOneLine = isOverlappedTwoItemsOnOneLine;
|
|
66
|
+
exports.isPointInArea = isPointInArea;
|
|
67
|
+
exports.isPointInRect = isPointInRect;
|
|
68
|
+
exports.isPointOnLineSegment = isPointOnLineSegment;
|
|
69
|
+
exports.isRightWall = isRightWall;
|
|
70
|
+
exports.isSnappedLine = isSnappedLine;
|
|
71
|
+
exports.isSnappedSideLine = isSnappedSideLine;
|
|
72
|
+
exports.itemInfo = itemInfo;
|
|
73
|
+
exports.linePassingThroughTwoPoints = linePassingThroughTwoPoints;
|
|
74
|
+
exports.mapRange = mapRange;
|
|
75
|
+
exports.maxVertex = maxVertex;
|
|
76
|
+
exports.midPoint = midPoint;
|
|
77
|
+
exports.minVertex = minVertex;
|
|
78
|
+
exports.needSnap = needSnap;
|
|
79
|
+
exports.orderVertices = orderVertices;
|
|
80
|
+
exports.pointPositionOnLineSegment = pointPositionOnLineSegment;
|
|
81
|
+
exports.pointsDistance = pointsDistance;
|
|
82
|
+
exports.relationshipOfTwoOverlappedLines = relationshipOfTwoOverlappedLines;
|
|
83
|
+
exports.relationshipOfTwoOverlappedLines1 = relationshipOfTwoOverlappedLines1;
|
|
84
|
+
exports.relationshipOfTwoOverlappedLines2 = relationshipOfTwoOverlappedLines2;
|
|
85
|
+
exports.rotatePointAroundPoint = rotatePointAroundPoint;
|
|
86
|
+
exports.roundVertex = roundVertex;
|
|
87
|
+
exports.sameDistances = sameDistances;
|
|
88
|
+
exports.sameMDistances = sameMDistances;
|
|
89
|
+
exports.sameMPoints = sameMPoints;
|
|
90
|
+
exports.samePoints = samePoints;
|
|
91
|
+
exports.shrinkRect = shrinkRect;
|
|
92
|
+
exports.sinWithThreshold = sinWithThreshold;
|
|
93
|
+
exports.snapAngleByUnit = snapAngleByUnit;
|
|
94
|
+
exports.twoLineSegmentsIntersection = twoLineSegmentsIntersection;
|
|
95
|
+
exports.twoLinesIntersection = twoLinesIntersection;
|
|
96
|
+
exports.upcrossLine = upcrossLine;
|
|
97
|
+
exports.validInterSect = validInterSect;
|
|
98
|
+
exports.validRect = validRect;
|
|
99
|
+
exports.validSnap = validSnap;
|
|
100
|
+
exports.validateLineSnaps = validateLineSnaps;
|
|
101
|
+
exports.validateSnaps = validateSnaps;
|
|
102
|
+
exports.verticalLine = verticalLine;
|
|
103
|
+
exports.verticesDistance = verticesDistance;
|
|
104
|
+
exports.verticesMidPoint = verticesMidPoint;
|
|
105
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
106
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
107
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
108
|
+
var _math = require("./math.js");
|
|
109
|
+
var _constants = require("../constants");
|
|
110
|
+
var _convertUnitsLite = require("./convert-units-lite");
|
|
111
|
+
var Three = _interopRequireWildcard(require("three"));
|
|
112
|
+
var _utils = require("../components/viewer2d/utils.js");
|
|
113
|
+
var _helper = require("./helper.js");
|
|
114
|
+
var _export = require("./export.js");
|
|
115
|
+
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); }
|
|
116
|
+
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; }
|
|
117
|
+
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) { (0, _defineProperty2["default"])(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; }
|
|
118
|
+
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; } } }; }
|
|
119
|
+
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; } }
|
|
120
|
+
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; } /** @description Determines the distance between two points
|
|
121
|
+
* @param {number} x0 Vertex 0 x
|
|
122
|
+
* @param {number} y0 Vertex 0 y
|
|
123
|
+
* @param {number} x1 Vertex 1 x
|
|
124
|
+
* @param {number} y1 Vertex 1 y
|
|
125
|
+
* @return {number}
|
|
126
|
+
*/
|
|
127
|
+
function compareVertices(v0, v1) {
|
|
128
|
+
return v0.x === v1.x ? v0.y - v1.y : v0.x - v1.x;
|
|
129
|
+
}
|
|
130
|
+
function minVertex(v0, v1) {
|
|
131
|
+
return compareVertices(v0, v1) > 0 ? v1 : v0;
|
|
132
|
+
}
|
|
133
|
+
function maxVertex(v0, v1) {
|
|
134
|
+
return compareVertices(v0, v1) > 0 ? v0 : v1;
|
|
135
|
+
}
|
|
136
|
+
function orderVertices(vertices) {
|
|
137
|
+
return vertices.sort(compareVertices);
|
|
138
|
+
}
|
|
139
|
+
function pointsDistance(x0, y0, x1, y1) {
|
|
140
|
+
var diff_x = x0 - x1;
|
|
141
|
+
var diff_y = y0 - y1;
|
|
142
|
+
return Math.sqrt(diff_x * diff_x + diff_y * diff_y);
|
|
143
|
+
}
|
|
144
|
+
function verticesDistance(v1, v2) {
|
|
145
|
+
var x0 = v1.x,
|
|
146
|
+
y0 = v1.y;
|
|
147
|
+
var x1 = v2.x,
|
|
148
|
+
y1 = v2.y;
|
|
149
|
+
return pointsDistance(x0, y0, x1, y1);
|
|
150
|
+
}
|
|
151
|
+
function horizontalLine(y) {
|
|
152
|
+
return {
|
|
153
|
+
a: 0,
|
|
154
|
+
b: 1,
|
|
155
|
+
c: -y
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
var almostEqual = exports.almostEqual = function almostEqual(x, y) {
|
|
159
|
+
return Math.abs(x - y) < _constants.EPSILON;
|
|
160
|
+
};
|
|
161
|
+
function verticalLine(x) {
|
|
162
|
+
return {
|
|
163
|
+
a: 1,
|
|
164
|
+
b: 0,
|
|
165
|
+
c: -x
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function upcrossLine(x, y) {
|
|
169
|
+
return {
|
|
170
|
+
a: 1,
|
|
171
|
+
b: 1,
|
|
172
|
+
c: -x - y
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function downcrossLine(x, y) {
|
|
176
|
+
return {
|
|
177
|
+
a: 1,
|
|
178
|
+
b: -1,
|
|
179
|
+
c: -x + y
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function linePassingThroughTwoPoints(x1, y1, x2, y2) {
|
|
183
|
+
if (x1 === x2 && y1 == y2) throw new Error('Geometry error');
|
|
184
|
+
//if (x1 === x2) return verticalLine(x1);
|
|
185
|
+
//if (y1 === y2) return horizontalLine(y1);
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
a: y1 - y2,
|
|
189
|
+
b: x2 - x1,
|
|
190
|
+
c: y2 * x1 - x2 * y1
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function getNormaline(x1, y1, x2, y2) {
|
|
194
|
+
var lineFunction = linePassingThroughTwoPoints(x1, y1, x2, y2);
|
|
195
|
+
return {
|
|
196
|
+
x: lineFunction.a / Math.sqrt(lineFunction.a * lineFunction.a + lineFunction.b * lineFunction.b),
|
|
197
|
+
y: lineFunction.b / Math.sqrt(lineFunction.a * lineFunction.a + lineFunction.b * lineFunction.b)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function distancePointFromLine(a, b, c, x, y) {
|
|
201
|
+
//https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
|
202
|
+
return (0, _math.fAbs)(a * x + b * y + c) / Math.sqrt(a * a + b * b);
|
|
203
|
+
}
|
|
204
|
+
function closestPointFromLine(a, b, c, x, y) {
|
|
205
|
+
//https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
|
206
|
+
var denom = a * a + b * b;
|
|
207
|
+
return {
|
|
208
|
+
x: (b * (b * x - a * y) - a * c) / denom,
|
|
209
|
+
y: (a * -b * x + a * y - b * c) / denom
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @description Get point of intersection between two lines using ax+by+c line's equation
|
|
214
|
+
* @param {number} a x coefficent of first line
|
|
215
|
+
* @param {number} b y coefficent of first line
|
|
216
|
+
* @param {number} c costant of first line
|
|
217
|
+
* @param {number} j x coefficent of second line
|
|
218
|
+
* @param {number} k y coefficent of second line
|
|
219
|
+
* @param {number} l costant of second line
|
|
220
|
+
* @return {object} {x,y} point's coordinates
|
|
221
|
+
*/
|
|
222
|
+
function twoLinesIntersection(a, b, c, j, k, l) {
|
|
223
|
+
var angularCoefficientsDiff = b * j - a * k;
|
|
224
|
+
if (angularCoefficientsDiff === 0) return undefined; //no intersection
|
|
225
|
+
|
|
226
|
+
var y = (a * l - c * j) / angularCoefficientsDiff;
|
|
227
|
+
var x = (c * k - b * l) / angularCoefficientsDiff;
|
|
228
|
+
return {
|
|
229
|
+
x: x,
|
|
230
|
+
y: y
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function twoLineSegmentsIntersection(p1, p2, p3, p4) {
|
|
234
|
+
return _twoLineSegmentsIntersection(p1, p2, p3.toJS(), p4.toJS());
|
|
235
|
+
}
|
|
236
|
+
function _twoLineSegmentsIntersection(p1, p2, p3, p4) {
|
|
237
|
+
//https://github.com/psalaets/line-intersect/blob/master/lib/check-intersection.js
|
|
238
|
+
|
|
239
|
+
var x1 = p1.x,
|
|
240
|
+
y1 = p1.y;
|
|
241
|
+
var x2 = p2.x,
|
|
242
|
+
y2 = p2.y;
|
|
243
|
+
var x3 = p3.x,
|
|
244
|
+
y3 = p3.y;
|
|
245
|
+
var x4 = p4.x,
|
|
246
|
+
y4 = p4.y;
|
|
247
|
+
var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
248
|
+
var numA = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
|
|
249
|
+
var numB = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
|
250
|
+
if ((0, _math.fAbs)(denom) <= _constants.EPSILON) {
|
|
251
|
+
if ((0, _math.fAbs)(numA) <= _constants.EPSILON && (0, _math.fAbs)(numB) <= _constants.EPSILON) {
|
|
252
|
+
var comparator = function comparator(pa, pb) {
|
|
253
|
+
return pa.x === pb.x ? pa.y - pb.y : pa.x - pb.x;
|
|
254
|
+
};
|
|
255
|
+
var line0 = [p1, p2].sort(comparator);
|
|
256
|
+
var line1 = [p3, p4].sort(comparator);
|
|
257
|
+
var _sort = [line0, line1].sort(function (lineA, lineB) {
|
|
258
|
+
return comparator(lineA[0], lineB[0]);
|
|
259
|
+
}),
|
|
260
|
+
_sort2 = (0, _slicedToArray2["default"])(_sort, 2),
|
|
261
|
+
lineSX = _sort2[0],
|
|
262
|
+
lineDX = _sort2[1];
|
|
263
|
+
comparator(lineSX[1], lineDX[0]) < 0 ? 'colinear' : 'none';
|
|
264
|
+
if (lineSX[1].x === lineDX[0].x) {
|
|
265
|
+
return {
|
|
266
|
+
type: lineDX[0].y <= lineSX[1].y ? 'colinear' : 'none'
|
|
267
|
+
};
|
|
268
|
+
} else {
|
|
269
|
+
return {
|
|
270
|
+
type: lineDX[0].x <= lineSX[1].x ? 'colinear' : 'none'
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
type: 'parallel'
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
var uA = numA / denom;
|
|
279
|
+
var uB = numB / denom;
|
|
280
|
+
if (uA >= 0 - _constants.EPSILON && uA <= 1 + _constants.EPSILON && uB >= 0 - _constants.EPSILON && uB <= 1 + _constants.EPSILON) {
|
|
281
|
+
var _point = {
|
|
282
|
+
x: x1 + uA * (x2 - x1),
|
|
283
|
+
y: y1 + uA * (y2 - y1)
|
|
284
|
+
};
|
|
285
|
+
return {
|
|
286
|
+
type: 'intersecting',
|
|
287
|
+
point: _point
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
type: 'none'
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function distancePointFromLineSegment(v1, v2, xp, yp) {
|
|
295
|
+
//http://stackoverflow.com/a/6853926/1398836
|
|
296
|
+
var x1 = v1.x,
|
|
297
|
+
y1 = v1.y;
|
|
298
|
+
var x2 = v2.x,
|
|
299
|
+
y2 = v2.y;
|
|
300
|
+
var A = xp - x1;
|
|
301
|
+
var B = yp - y1;
|
|
302
|
+
var C = x2 - x1;
|
|
303
|
+
var D = y2 - y1;
|
|
304
|
+
var dot = A * C + B * D;
|
|
305
|
+
var len_sq = C * C + D * D;
|
|
306
|
+
var param = -1;
|
|
307
|
+
if (len_sq != 0)
|
|
308
|
+
//in case of 0 length line
|
|
309
|
+
param = dot / len_sq;
|
|
310
|
+
var xx, yy;
|
|
311
|
+
if (param < 0) {
|
|
312
|
+
xx = x1;
|
|
313
|
+
yy = y1;
|
|
314
|
+
} else if (param > 1) {
|
|
315
|
+
xx = x2;
|
|
316
|
+
yy = y2;
|
|
317
|
+
} else {
|
|
318
|
+
xx = x1 + param * C;
|
|
319
|
+
yy = y1 + param * D;
|
|
320
|
+
}
|
|
321
|
+
var dx = xp - xx;
|
|
322
|
+
var dy = yp - yy;
|
|
323
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
*
|
|
328
|
+
* @param x1 {number} x for first vertex of the segment
|
|
329
|
+
* @param y1 {number} y for first vertex of the segment
|
|
330
|
+
* @param x2 {number} x for second vertex of the segment
|
|
331
|
+
* @param y2 {number} y for second vertex of the segment
|
|
332
|
+
* @param xp {number} x for point we want to verify
|
|
333
|
+
* @param yp {number} y for point we want to verify
|
|
334
|
+
* @param maxDistance {number} the epsilon value used for comparisons
|
|
335
|
+
* @returns {boolean} true if the point lies on the line segment false otherwise
|
|
336
|
+
*/
|
|
337
|
+
function isPointOnLineSegment(x1, y1, x2, y2, xp, yp) {
|
|
338
|
+
var maxDistance = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : _constants.EPSILON;
|
|
339
|
+
return distancePointFromLineSegment({
|
|
340
|
+
x: x1,
|
|
341
|
+
y: y1
|
|
342
|
+
}, {
|
|
343
|
+
x: x2,
|
|
344
|
+
y: y2
|
|
345
|
+
}, xp, yp) <= maxDistance;
|
|
346
|
+
}
|
|
347
|
+
function closestPointFromLineSegment(x1, y1, x2, y2, xp, yp) {
|
|
348
|
+
if (x1 === x2) return {
|
|
349
|
+
x: x1,
|
|
350
|
+
y: yp
|
|
351
|
+
};
|
|
352
|
+
if (y1 === y2) return {
|
|
353
|
+
x: xp,
|
|
354
|
+
y: y1
|
|
355
|
+
};
|
|
356
|
+
var m = (y2 - y1) / (x2 - x1);
|
|
357
|
+
var q = y1 - m * x1;
|
|
358
|
+
var mi = -1 / m;
|
|
359
|
+
var qi = yp - mi * xp;
|
|
360
|
+
var x = (qi - q) / (m - mi);
|
|
361
|
+
var y = m * x + q;
|
|
362
|
+
return {
|
|
363
|
+
x: x,
|
|
364
|
+
y: y
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function pointPositionOnLineSegment(x1, y1, x2, y2, xp, yp) {
|
|
368
|
+
var length = pointsDistance(x1, y1, x2, y2);
|
|
369
|
+
var distance = pointsDistance(x1, y1, xp, yp);
|
|
370
|
+
var offset = distance / length;
|
|
371
|
+
/*
|
|
372
|
+
if (x1 > x2) offset = 1 - offset;
|
|
373
|
+
if (y1 > y2) offset = 1 - offset;
|
|
374
|
+
*/
|
|
375
|
+
return offset;
|
|
376
|
+
}
|
|
377
|
+
function mapRange(value, low1, high1, low2, high2) {
|
|
378
|
+
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
|
|
379
|
+
}
|
|
380
|
+
function angleBetweenTwoPointsAndOrigin(x1, y1, x2, y2) {
|
|
381
|
+
return -Math.atan2(y1 - y2, x2 - x1) * 180 / Math.PI;
|
|
382
|
+
}
|
|
383
|
+
function angleBetweenTwoPoints(x1, y1, x2, y2) {
|
|
384
|
+
return Math.atan2(y2 - y1, x2 - x1);
|
|
385
|
+
}
|
|
386
|
+
function angleBetweenTwoLines(line, drawingLine, vertices) {
|
|
387
|
+
var points = [];
|
|
388
|
+
|
|
389
|
+
// safety guards
|
|
390
|
+
var lv = Array.isArray(line === null || line === void 0 ? void 0 : line.vertices) ? line.vertices : [];
|
|
391
|
+
var dv = Array.isArray(drawingLine === null || drawingLine === void 0 ? void 0 : drawingLine.vertices) ? drawingLine.vertices : [];
|
|
392
|
+
|
|
393
|
+
// 1) push common vertices (in order of line.vertices)
|
|
394
|
+
var _iterator = _createForOfIteratorHelper(lv),
|
|
395
|
+
_step;
|
|
396
|
+
try {
|
|
397
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
398
|
+
var vt = _step.value;
|
|
399
|
+
if (dv.includes(vt) && !points.includes(vt)) points.push(vt);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// 2) push remaining vertices from line.vertices
|
|
403
|
+
} catch (err) {
|
|
404
|
+
_iterator.e(err);
|
|
405
|
+
} finally {
|
|
406
|
+
_iterator.f();
|
|
407
|
+
}
|
|
408
|
+
var _iterator2 = _createForOfIteratorHelper(lv),
|
|
409
|
+
_step2;
|
|
410
|
+
try {
|
|
411
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
412
|
+
var _vt = _step2.value;
|
|
413
|
+
if (!points.includes(_vt)) points.push(_vt);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 3) push remaining vertices from drawingLine.vertices
|
|
417
|
+
} catch (err) {
|
|
418
|
+
_iterator2.e(err);
|
|
419
|
+
} finally {
|
|
420
|
+
_iterator2.f();
|
|
421
|
+
}
|
|
422
|
+
var _iterator3 = _createForOfIteratorHelper(dv),
|
|
423
|
+
_step3;
|
|
424
|
+
try {
|
|
425
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
426
|
+
var _vt2 = _step3.value;
|
|
427
|
+
if (!points.includes(_vt2)) points.push(_vt2);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// If no points at all, nothing to compute — return 0 (safe fallback)
|
|
431
|
+
} catch (err) {
|
|
432
|
+
_iterator3.e(err);
|
|
433
|
+
} finally {
|
|
434
|
+
_iterator3.f();
|
|
435
|
+
}
|
|
436
|
+
if (points.length === 0) return 0;
|
|
437
|
+
|
|
438
|
+
// Ensure we have at least 3 entries (same behaviour as original)
|
|
439
|
+
while (points.length < 3) points.push(points[points.length - 1]);
|
|
440
|
+
var _points$slice$map = points.slice(0, 3).map(function (idx) {
|
|
441
|
+
var v = vertices === null || vertices === void 0 ? void 0 : vertices[idx];
|
|
442
|
+
return v ? new Three.Vector2(v.x, v.y) : new Three.Vector2(0, 0);
|
|
443
|
+
}),
|
|
444
|
+
_points$slice$map2 = (0, _slicedToArray2["default"])(_points$slice$map, 3),
|
|
445
|
+
c = _points$slice$map2[0],
|
|
446
|
+
p1 = _points$slice$map2[1],
|
|
447
|
+
p2 = _points$slice$map2[2];
|
|
448
|
+
var vec1 = p1.clone().sub(c).normalize();
|
|
449
|
+
var vec2 = p2.clone().sub(c).normalize();
|
|
450
|
+
return Math.floor(vec1.angle() * 180 / Math.PI - vec2.angle() * 180 / Math.PI + 0.5);
|
|
451
|
+
}
|
|
452
|
+
var getRelatedLines = exports.getRelatedLines = function getRelatedLines(tlines, drawingLine, vertices, lines) {
|
|
453
|
+
var exceptLineId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
454
|
+
if (!(drawingLine !== null && drawingLine !== void 0 && drawingLine.vertices) || !Array.isArray(drawingLine.vertices)) return;
|
|
455
|
+
var seen = new Set();
|
|
456
|
+
var _iterator4 = _createForOfIteratorHelper(drawingLine.vertices),
|
|
457
|
+
_step4;
|
|
458
|
+
try {
|
|
459
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
460
|
+
var vIdx = _step4.value;
|
|
461
|
+
var vertex = vertices === null || vertices === void 0 ? void 0 : vertices[vIdx];
|
|
462
|
+
if (!(vertex !== null && vertex !== void 0 && vertex.lines)) continue;
|
|
463
|
+
var _iterator5 = _createForOfIteratorHelper(vertex.lines),
|
|
464
|
+
_step5;
|
|
465
|
+
try {
|
|
466
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
467
|
+
var lineId = _step5.value;
|
|
468
|
+
if (lineId !== drawingLine.id && lineId !== exceptLineId && !(0, _helper.isEmpty)(lines === null || lines === void 0 ? void 0 : lines[lineId]) && !seen.has(lineId)) {
|
|
469
|
+
seen.add(lineId);
|
|
470
|
+
tlines.push(lines[lineId]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
} catch (err) {
|
|
474
|
+
_iterator5.e(err);
|
|
475
|
+
} finally {
|
|
476
|
+
_iterator5.f();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
_iterator4.e(err);
|
|
481
|
+
} finally {
|
|
482
|
+
_iterator4.f();
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
function snapAngleByUnit(lineAngle, vertices, drawingLine, x, y, dragVertexId) {
|
|
486
|
+
var tx, ty;
|
|
487
|
+
var absAngle = Math.abs(lineAngle);
|
|
488
|
+
// angle snapping as a value of UNIT_ANGLE
|
|
489
|
+
var rest = absAngle % _constants.UNIT_ANGLE;
|
|
490
|
+
var missAngle = _constants.UNIT_ANGLE - rest;
|
|
491
|
+
var isSingleLine = !drawingLine.vertices.some(function (vetID) {
|
|
492
|
+
return vertices[vetID].lines.some(function (lineID) {
|
|
493
|
+
return lineID !== drawingLine.id;
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
// the origin point of rotation(snapping)
|
|
497
|
+
var originVerIndex = drawingLine.vertices.findIndex(function (vertice) {
|
|
498
|
+
return vertice !== dragVertexId;
|
|
499
|
+
});
|
|
500
|
+
var originVerId = originVerIndex < 0 ? drawingLine.vertices[0] : drawingLine.vertices[originVerIndex];
|
|
501
|
+
var ox = vertices[originVerId].x;
|
|
502
|
+
var oy = vertices[originVerId].y;
|
|
503
|
+
// check whether the line is snapped to before point.
|
|
504
|
+
if (rest <= _constants.UNIT_ANGLE / 2) {
|
|
505
|
+
// determine the direction of rotation.
|
|
506
|
+
rest = lineAngle > 0 ? rest : -rest;
|
|
507
|
+
rest = isSingleLine ? -rest : rest;
|
|
508
|
+
// rotate the current point to last point around the first point of drawing line.
|
|
509
|
+
tx = rotatePointAroundPoint(x, y, ox, oy, rest).x;
|
|
510
|
+
ty = rotatePointAroundPoint(x, y, ox, oy, rest).y;
|
|
511
|
+
}
|
|
512
|
+
// check whether the line is snapped to next new point.
|
|
513
|
+
else if (rest > _constants.UNIT_ANGLE / 2) {
|
|
514
|
+
// determine the direction of rotation.
|
|
515
|
+
missAngle = lineAngle > 0 ? -missAngle : missAngle;
|
|
516
|
+
missAngle = isSingleLine ? -missAngle : missAngle;
|
|
517
|
+
// rotate the current point to last point around the first point of drawing line.
|
|
518
|
+
tx = rotatePointAroundPoint(x, y, ox, oy, missAngle).x;
|
|
519
|
+
ty = rotatePointAroundPoint(x, y, ox, oy, missAngle).y;
|
|
520
|
+
}
|
|
521
|
+
var resPoint = {
|
|
522
|
+
x: tx,
|
|
523
|
+
y: ty
|
|
524
|
+
};
|
|
525
|
+
return resPoint;
|
|
526
|
+
}
|
|
527
|
+
function absAngleBetweenTwoPoints(x1, y1, x2, y2) {
|
|
528
|
+
return Math.atan2(y2 - y1, Math.abs(x2 - x1));
|
|
529
|
+
}
|
|
530
|
+
function samePoints(_ref, _ref2) {
|
|
531
|
+
var x1 = _ref.x,
|
|
532
|
+
y1 = _ref.y;
|
|
533
|
+
var x2 = _ref2.x,
|
|
534
|
+
y2 = _ref2.y;
|
|
535
|
+
return (0, _math.fAbs)(x1 - x2) <= _constants.EPSILON && (0, _math.fAbs)(y1 - y2) <= _constants.EPSILON;
|
|
536
|
+
}
|
|
537
|
+
function sameDistances(dis1, dis2) {
|
|
538
|
+
return (0, _math.fAbs)(dis1 - dis2) <= _constants.EPSILON;
|
|
539
|
+
}
|
|
540
|
+
function sameMPoints(_ref3, _ref4) {
|
|
541
|
+
var x1 = _ref3.x,
|
|
542
|
+
y1 = _ref3.y;
|
|
543
|
+
var x2 = _ref4.x,
|
|
544
|
+
y2 = _ref4.y;
|
|
545
|
+
return (0, _math.fAbs)(x1 - x2) <= _constants.MEPSILON && (0, _math.fAbs)(y1 - y2) <= _constants.MEPSILON;
|
|
546
|
+
}
|
|
547
|
+
function sameMDistances(dis1, dis2) {
|
|
548
|
+
return (0, _math.fAbs)(dis1 - dis2) <= _constants.MEPSILON;
|
|
549
|
+
}
|
|
550
|
+
function isPointInRect(rect, point) {
|
|
551
|
+
var result = true;
|
|
552
|
+
for (var i = 0; i < rect.length; i++) {
|
|
553
|
+
var pos1 = rect[i];
|
|
554
|
+
var pos2 = rect[(i + 1) % rect.length];
|
|
555
|
+
if (isPointOnLineSegment(pos1.x, pos1.y, pos2.x, pos2.y, point.x, point.y)) {
|
|
556
|
+
result = false;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return result;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** @description Extend line based on coordinates and new line length
|
|
563
|
+
* @param {number} x1 Vertex 1 x
|
|
564
|
+
* @param {number} y1 Vertex 1 y
|
|
565
|
+
* @param {number} x2 Vertex 2 x
|
|
566
|
+
* @param {number} y2 Vertex 2 y
|
|
567
|
+
* @param {number} newDistance New line length
|
|
568
|
+
* @return {object}
|
|
569
|
+
*/
|
|
570
|
+
function extendLine(x1, y1, x2, y2, newDistance) {
|
|
571
|
+
var precision = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 6;
|
|
572
|
+
var rad = angleBetweenTwoPoints(x1, y1, x2, y2);
|
|
573
|
+
return {
|
|
574
|
+
x: (0, _math.toFixedFloat)(x1 + Math.cos(rad) * newDistance, precision),
|
|
575
|
+
y: (0, _math.toFixedFloat)(y1 + Math.sin(rad) * newDistance, precision)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function roundVertex(vertex) {
|
|
579
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
|
|
580
|
+
vertex.set('x', (0, _math.toFixedFloat)(vertex.get('x'), precision));
|
|
581
|
+
vertex.set('y', (0, _math.toFixedFloat)(vertex.get('y'), precision));
|
|
582
|
+
return vertex;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
//https://github.com/MartyWallace/PolyK
|
|
586
|
+
function ContainsPoint(polygon, pointX, pointY) {
|
|
587
|
+
var n = polygon.length >> 1;
|
|
588
|
+
var ax, lup;
|
|
589
|
+
var ay = polygon[2 * n - 3] - pointY;
|
|
590
|
+
var bx = polygon[2 * n - 2] - pointX;
|
|
591
|
+
var by = polygon[2 * n - 1] - pointY;
|
|
592
|
+
if (bx === 0 && by === 0) return false; // point on edge
|
|
593
|
+
|
|
594
|
+
// let lup = by > ay;
|
|
595
|
+
for (var ii = 0; ii < n; ii++) {
|
|
596
|
+
ax = bx;
|
|
597
|
+
ay = by;
|
|
598
|
+
bx = polygon[2 * ii] - pointX;
|
|
599
|
+
by = polygon[2 * ii + 1] - pointY;
|
|
600
|
+
if (bx === 0 && by === 0) return false; // point on edge
|
|
601
|
+
if (ay === by) continue;
|
|
602
|
+
lup = by > ay;
|
|
603
|
+
}
|
|
604
|
+
var depth = 0;
|
|
605
|
+
for (var i = 0; i < n; i++) {
|
|
606
|
+
ax = bx;
|
|
607
|
+
ay = by;
|
|
608
|
+
bx = polygon[2 * i] - pointX;
|
|
609
|
+
by = polygon[2 * i + 1] - pointY;
|
|
610
|
+
if (ay < 0 && by < 0) continue; // both 'up' or both 'down'
|
|
611
|
+
if (ay > 0 && by > 0) continue; // both 'up' or both 'down'
|
|
612
|
+
if (ax < 0 && bx < 0) continue; // both points on the left
|
|
613
|
+
|
|
614
|
+
if (ay === by && Math.min(ax, bx) < 0) return true;
|
|
615
|
+
if (ay === by) continue;
|
|
616
|
+
var lx = ax + (bx - ax) * -ay / (by - ay);
|
|
617
|
+
if (lx === 0) return false; // point on edge
|
|
618
|
+
if (lx > 0) depth++;
|
|
619
|
+
if (ay === 0 && lup && by > ay) depth--; // hit vertex, both up
|
|
620
|
+
if (ay === 0 && !lup && by < ay) depth--; // hit vertex, both down
|
|
621
|
+
lup = by > ay;
|
|
622
|
+
}
|
|
623
|
+
return (depth & 1) === 1;
|
|
624
|
+
}
|
|
625
|
+
function cosWithThreshold(alpha, threshold) {
|
|
626
|
+
var cos = Math.cos(alpha);
|
|
627
|
+
return cos < threshold ? 0 : cos;
|
|
628
|
+
}
|
|
629
|
+
function sinWithThreshold(alpha, threshold) {
|
|
630
|
+
var sin = Math.sin(alpha);
|
|
631
|
+
return sin < threshold ? 0 : sin;
|
|
632
|
+
}
|
|
633
|
+
function midPoint(x1, y1, x2, y2) {
|
|
634
|
+
return {
|
|
635
|
+
x: (x1 + x2) / 2,
|
|
636
|
+
y: (y1 + y2) / 2
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function verticesMidPoint(verticesArray) {
|
|
640
|
+
var res = verticesArray.reduce(function (incr, vertex) {
|
|
641
|
+
return {
|
|
642
|
+
x: incr.x + vertex.x,
|
|
643
|
+
y: incr.y + vertex.y
|
|
644
|
+
};
|
|
645
|
+
}, {
|
|
646
|
+
x: 0,
|
|
647
|
+
y: 0
|
|
648
|
+
});
|
|
649
|
+
return {
|
|
650
|
+
x: res.x / verticesArray.length,
|
|
651
|
+
y: res.y / verticesArray.length
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function rotatePointAroundPoint(px, py, ox, oy, theta) {
|
|
655
|
+
var thetaRad = theta * Math.PI / 180;
|
|
656
|
+
var cos = Math.cos(thetaRad);
|
|
657
|
+
var sin = Math.sin(thetaRad);
|
|
658
|
+
var deltaX = px - ox;
|
|
659
|
+
var deltaY = py - oy;
|
|
660
|
+
return {
|
|
661
|
+
x: cos * deltaX - sin * deltaY + ox,
|
|
662
|
+
y: sin * deltaX + cos * deltaY + oy
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// point: x,y
|
|
667
|
+
// itemrectInfo: pos(x,y),rotRad,size,layoutpos,is_corner
|
|
668
|
+
// calcRect: rect(point[4]),pos(x,y),rotRad,size,layoutpos,is_corner
|
|
669
|
+
|
|
670
|
+
function point(x, y) {
|
|
671
|
+
return {
|
|
672
|
+
x: x,
|
|
673
|
+
y: y
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function itemrectInfo(x, y, rotRad, size, layoutpos, is_corner) {
|
|
677
|
+
return {
|
|
678
|
+
pos: {
|
|
679
|
+
x: x,
|
|
680
|
+
y: y
|
|
681
|
+
},
|
|
682
|
+
rotRad: rotRad,
|
|
683
|
+
size: size,
|
|
684
|
+
layoutpos: layoutpos,
|
|
685
|
+
is_corner: is_corner
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
function getCalcRectFromItem(item) {
|
|
689
|
+
var itemInfo;
|
|
690
|
+
if (item === undefined) itemInfo = [];else itemInfo = item.item;
|
|
691
|
+
var x = item.pos.x;
|
|
692
|
+
var y = item.pos.y;
|
|
693
|
+
var rotRad = item.rotRad;
|
|
694
|
+
var w = item.size && item.size.width / 2;
|
|
695
|
+
var h = item.size && item.size.height / 2;
|
|
696
|
+
var mx = x - w * Math.cos(rotRad);
|
|
697
|
+
var my = y - w * Math.sin(rotRad);
|
|
698
|
+
var x0 = mx + h * Math.sin(rotRad);
|
|
699
|
+
var y0 = my - h * Math.cos(rotRad);
|
|
700
|
+
var x3 = mx * 2 - x0;
|
|
701
|
+
var y3 = my * 2 - y0;
|
|
702
|
+
var x1 = x * 2 - x3;
|
|
703
|
+
var y1 = y * 2 - y3;
|
|
704
|
+
var x2 = x * 2 - x0;
|
|
705
|
+
var y2 = y * 2 - y0;
|
|
706
|
+
return {
|
|
707
|
+
rect: [point(x0, y0), point(x1, y1), point(x2, y2), point(x3, y3)],
|
|
708
|
+
pos: point(x, y),
|
|
709
|
+
rotRad: rotRad,
|
|
710
|
+
size: item.size,
|
|
711
|
+
layoutpos: item.layoutpos,
|
|
712
|
+
is_corner: item.is_corner,
|
|
713
|
+
itemInfo: itemInfo
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
function getCalcRectFromItem3D(item) {
|
|
717
|
+
var itemInfo;
|
|
718
|
+
if (item === undefined) itemInfo = [];else itemInfo = item.item;
|
|
719
|
+
var x = item.pos.x;
|
|
720
|
+
var y = item.pos.y;
|
|
721
|
+
var rotRad = item.rotRad;
|
|
722
|
+
var w = item.size.width / 2;
|
|
723
|
+
var h = item.size.depth / 2;
|
|
724
|
+
var mx = x - w * Math.cos(rotRad);
|
|
725
|
+
var my = y - w * Math.sin(rotRad);
|
|
726
|
+
var x0 = mx + h * Math.sin(rotRad);
|
|
727
|
+
var y0 = my - h * Math.cos(rotRad);
|
|
728
|
+
var x3 = mx * 2 - x0;
|
|
729
|
+
var y3 = my * 2 - y0;
|
|
730
|
+
var x1 = x * 2 - x3;
|
|
731
|
+
var y1 = y * 2 - y3;
|
|
732
|
+
var x2 = x * 2 - x0;
|
|
733
|
+
var y2 = y * 2 - y0;
|
|
734
|
+
return {
|
|
735
|
+
rect: [point(x0, y0), point(x1, y1), point(x2, y2), point(x3, y3)],
|
|
736
|
+
pos: point(x, y),
|
|
737
|
+
rotRad: rotRad,
|
|
738
|
+
size: item.size,
|
|
739
|
+
layoutpos: item.layoutpos,
|
|
740
|
+
is_corner: item.is_corner,
|
|
741
|
+
itemInfo: itemInfo
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function getAllItems(scene, catalog, allLineRects) {
|
|
745
|
+
var layerID = scene.selectedLayer;
|
|
746
|
+
var layer = scene.layers.get(layerID);
|
|
747
|
+
var curiteminfo;
|
|
748
|
+
var iteminfo = [];
|
|
749
|
+
var otherItems = [];
|
|
750
|
+
var selectedItem;
|
|
751
|
+
var currentItem;
|
|
752
|
+
if (layer.selected.items.size > 0) {
|
|
753
|
+
selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
|
|
754
|
+
var catid = selectedItem.type;
|
|
755
|
+
var cat = catalog.elements[catid];
|
|
756
|
+
if (!cat) cat = catalog.elements[(0, _utils.returnReplaceableDeepSearchType)(catid)];
|
|
757
|
+
currentItem = {
|
|
758
|
+
selectedItem: selectedItem,
|
|
759
|
+
cat: cat
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
layer.items.forEach(function (item) {
|
|
763
|
+
var val = {
|
|
764
|
+
pos: {
|
|
765
|
+
x: item.x,
|
|
766
|
+
y: item.y
|
|
767
|
+
},
|
|
768
|
+
rotRad: item.rotation / 180 * Math.PI
|
|
769
|
+
};
|
|
770
|
+
var catid = item.type;
|
|
771
|
+
var cat = catalog.elements[catid];
|
|
772
|
+
if (!cat) {
|
|
773
|
+
cat = catalog.elements[(0, _utils.returnReplaceableDeepSearchType)(catid)];
|
|
774
|
+
}
|
|
775
|
+
var sizeinfo = [];
|
|
776
|
+
var width, height, depth;
|
|
777
|
+
sizeinfo = {
|
|
778
|
+
width: item.properties.get('width').get('_length'),
|
|
779
|
+
height: item.properties.get('height').get('_length'),
|
|
780
|
+
depth: item.properties.get('depth').get('_length'),
|
|
781
|
+
widthUnit: item.properties.get('width').get('_unit'),
|
|
782
|
+
heightUnit: item.properties.get('height').get('_unit'),
|
|
783
|
+
depthUnit: item.properties.get('depth').get('_unit')
|
|
784
|
+
};
|
|
785
|
+
sizeinfo = _objectSpread(_objectSpread({}, sizeinfo), {}, {
|
|
786
|
+
layoutpos: cat && cat.info.layoutpos,
|
|
787
|
+
is_corner: cat && cat.info.is_corner
|
|
788
|
+
});
|
|
789
|
+
width = (0, _convertUnitsLite.convert)(sizeinfo.width).from(sizeinfo.widthUnit).to(scene.unit);
|
|
790
|
+
height = (0, _convertUnitsLite.convert)(sizeinfo.depth).from(sizeinfo.depthUnit).to(scene.unit);
|
|
791
|
+
depth = (0, _convertUnitsLite.convert)(sizeinfo.height).from(sizeinfo.heightUnit).to(scene.unit);
|
|
792
|
+
val.size = {
|
|
793
|
+
width: width,
|
|
794
|
+
height: height,
|
|
795
|
+
depth: depth
|
|
796
|
+
};
|
|
797
|
+
val.layoutpos = sizeinfo.layoutpos;
|
|
798
|
+
val.is_corner = sizeinfo.is_corner;
|
|
799
|
+
val.doorStyle = item.doorStyle;
|
|
800
|
+
val.item = item;
|
|
801
|
+
var otherItem = {
|
|
802
|
+
item: item,
|
|
803
|
+
cat: cat
|
|
804
|
+
};
|
|
805
|
+
if (!needSnap(currentItem, otherItem)) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (item.selected) {
|
|
809
|
+
curiteminfo = getCalcRectFromItem(val);
|
|
810
|
+
} else {
|
|
811
|
+
var calcrect = getCalcRectFromItem(val);
|
|
812
|
+
calcrect.isSnappedLine = isSnappedLine(calcrect, allLineRects);
|
|
813
|
+
iteminfo.push(calcrect);
|
|
814
|
+
otherItems.push(otherItem);
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
return {
|
|
818
|
+
cur: curiteminfo,
|
|
819
|
+
others: iteminfo,
|
|
820
|
+
currentItem: currentItem,
|
|
821
|
+
otherItems: otherItems
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
function getAllItemSpecified(scene, catalog, filter) {
|
|
825
|
+
var _scene$layers, _scene$layers$get;
|
|
826
|
+
var snappedLineRect = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
827
|
+
var layerID = scene === null || scene === void 0 ? void 0 : scene.selectedLayer;
|
|
828
|
+
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);
|
|
829
|
+
if (!layer || !layer.items) return {
|
|
830
|
+
cur: null,
|
|
831
|
+
others: []
|
|
832
|
+
};
|
|
833
|
+
var curiteminfo;
|
|
834
|
+
var iteminfo = [];
|
|
835
|
+
layer.items.forEach(function (item) {
|
|
836
|
+
var _cat$obj;
|
|
837
|
+
if (!item) return;
|
|
838
|
+
var val = {
|
|
839
|
+
pos: {
|
|
840
|
+
x: item.x,
|
|
841
|
+
y: item.y
|
|
842
|
+
},
|
|
843
|
+
rotRad: item.rotation / 180 * Math.PI
|
|
844
|
+
};
|
|
845
|
+
var cat = item.type ? findCatalogElement(catalog, item.type) : null;
|
|
846
|
+
val.layoutpos = item.layoutpos;
|
|
847
|
+
val.is_corner = item.is_corner;
|
|
848
|
+
var props = item.properties;
|
|
849
|
+
var getSize = function getSize(key) {
|
|
850
|
+
var _props$getIn, _props$getIn2, _props$getIn3;
|
|
851
|
+
var length = props === null || props === void 0 || (_props$getIn = props.getIn) === null || _props$getIn === void 0 ? void 0 : _props$getIn.call(props, [key, '_length']);
|
|
852
|
+
return length != null ? (0, _convertUnitsLite.convert)(length).from((_props$getIn2 = props === null || props === void 0 || (_props$getIn3 = props.getIn) === null || _props$getIn3 === void 0 ? void 0 : _props$getIn3.call(props, [key, '_unit'])) !== null && _props$getIn2 !== void 0 ? _props$getIn2 : 'in').to(scene.unit) : 0;
|
|
853
|
+
};
|
|
854
|
+
val.size = {
|
|
855
|
+
width: getSize('width'),
|
|
856
|
+
height: getSize('height'),
|
|
857
|
+
depth: getSize('depth')
|
|
858
|
+
};
|
|
859
|
+
val.item = item;
|
|
860
|
+
|
|
861
|
+
// Filter check
|
|
862
|
+
if (Array.isArray(filter)) {
|
|
863
|
+
if (!val.layoutpos || !filter.includes(val.layoutpos)) return;
|
|
864
|
+
} else if (val.layoutpos !== filter || (0, _helper.isEmpty)(cat) || (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)) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Current vs others
|
|
869
|
+
var rect = getCalcRectFromItem3D(val);
|
|
870
|
+
|
|
871
|
+
// check current item is snapped to the [snappedLineRect]
|
|
872
|
+
if (!(0, _helper.isEmpty)(snappedLineRect)) {
|
|
873
|
+
var isSnapped = false;
|
|
874
|
+
var overlapList = [_constants.OVERLAP_INCLUDED, _constants.OVERLAP_SAME, _constants.OVERLAP_SOME];
|
|
875
|
+
for (var i = 0; i < (rect === null || rect === void 0 || (_rect$rect = rect.rect) === null || _rect$rect === void 0 ? void 0 : _rect$rect.length); i++) {
|
|
876
|
+
var _rect$rect;
|
|
877
|
+
if (isSnapped) break;
|
|
878
|
+
var curItemPt = rect.rect[i];
|
|
879
|
+
var nextItemPt = i === rect.rect.length - 1 ? rect.rect[0] : rect.rect[i + 1];
|
|
880
|
+
var srcLine = {
|
|
881
|
+
x1: curItemPt.x,
|
|
882
|
+
y1: curItemPt.y,
|
|
883
|
+
x2: nextItemPt.x,
|
|
884
|
+
y2: nextItemPt.y
|
|
885
|
+
};
|
|
886
|
+
for (var j = 0; j < (snappedLineRect === null || snappedLineRect === void 0 ? void 0 : snappedLineRect.length); j++) {
|
|
887
|
+
var curLineRectPt = snappedLineRect[j];
|
|
888
|
+
var nextLineRectPt = j === snappedLineRect.length - 1 ? snappedLineRect[0] : snappedLineRect[j + 1];
|
|
889
|
+
var destLine = {
|
|
890
|
+
x1: curLineRectPt.x,
|
|
891
|
+
y1: curLineRectPt.y,
|
|
892
|
+
x2: nextLineRectPt.x,
|
|
893
|
+
y2: nextLineRectPt.y
|
|
894
|
+
};
|
|
895
|
+
if (overlapList.includes(relationshipOfTwoOverlappedLines(srcLine, destLine).result)) {
|
|
896
|
+
isSnapped = true;
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (!isSnapped) return;
|
|
902
|
+
}
|
|
903
|
+
if (item.selected) {
|
|
904
|
+
curiteminfo = rect;
|
|
905
|
+
} else {
|
|
906
|
+
iteminfo.push(rect);
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
return {
|
|
910
|
+
cur: curiteminfo,
|
|
911
|
+
others: iteminfo
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
function findCatalogElement(catalog, elementName) {
|
|
915
|
+
if (!elementName || !catalog) return null;
|
|
916
|
+
var variants = [elementName, elementName.toLowerCase()];
|
|
917
|
+
var deepVariants = variants.map(function (v) {
|
|
918
|
+
return (0, _utils.returnReplaceableDeepSearchType)(v);
|
|
919
|
+
}).filter(Boolean);
|
|
920
|
+
var allCandidates = [].concat(variants, (0, _toConsumableArray2["default"])(deepVariants));
|
|
921
|
+
var getElement = function getElement(catid) {
|
|
922
|
+
if (!catid) return null;
|
|
923
|
+
|
|
924
|
+
// Immutable.js Map
|
|
925
|
+
if (typeof catalog.getIn === 'function') {
|
|
926
|
+
return catalog.getIn(['elements', catid]);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// Plain JS object
|
|
930
|
+
if (catalog.elements && catalog.elements[catid]) {
|
|
931
|
+
return catalog.elements[catid];
|
|
932
|
+
}
|
|
933
|
+
return null;
|
|
934
|
+
};
|
|
935
|
+
var _iterator6 = _createForOfIteratorHelper(allCandidates),
|
|
936
|
+
_step6;
|
|
937
|
+
try {
|
|
938
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
939
|
+
var name = _step6.value;
|
|
940
|
+
var cat = getElement(name);
|
|
941
|
+
if (cat) return cat;
|
|
942
|
+
}
|
|
943
|
+
} catch (err) {
|
|
944
|
+
_iterator6.e(err);
|
|
945
|
+
} finally {
|
|
946
|
+
_iterator6.f();
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
function isSnappedLine(calcrect, allLineRects) {
|
|
951
|
+
if (allLineRects === undefined) return false;
|
|
952
|
+
var r2 = calcrect.rect[2];
|
|
953
|
+
var r3 = calcrect.rect[3];
|
|
954
|
+
var result = allLineRects.some(function (linerect) {
|
|
955
|
+
var l2 = linerect.rect[2];
|
|
956
|
+
var l3 = linerect.rect[3];
|
|
957
|
+
var delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
|
|
958
|
+
if (delta < _constants.EPSILON) {
|
|
959
|
+
return true;
|
|
960
|
+
} else {
|
|
961
|
+
l2 = linerect.rect[3];
|
|
962
|
+
l3 = linerect.rect[2];
|
|
963
|
+
delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
|
|
964
|
+
return delta < _constants.EPSILON;
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
return result;
|
|
968
|
+
}
|
|
969
|
+
function isSnappedSideLine(calcrect, allLineRects) {
|
|
970
|
+
if (allLineRects === undefined) return 0;
|
|
971
|
+
var r2 = calcrect.rect[1];
|
|
972
|
+
var r3 = calcrect.rect[2];
|
|
973
|
+
var result = allLineRects.some(function (linerect) {
|
|
974
|
+
var l2 = linerect.rect[2];
|
|
975
|
+
var l3 = linerect.rect[3];
|
|
976
|
+
var delta = verticesDistance(l2, r3) + verticesDistance(r3, r2) + verticesDistance(r2, l3) - verticesDistance(l3, l2);
|
|
977
|
+
return delta < _constants.EPSILON;
|
|
978
|
+
});
|
|
979
|
+
return result;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/** Calculate candidate positions */
|
|
983
|
+
function getAllItemSnap(allItemRects) {
|
|
984
|
+
var allItemSnap = [];
|
|
985
|
+
var cur = allItemRects.cur;
|
|
986
|
+
|
|
987
|
+
// For development
|
|
988
|
+
var otherItems = allItemRects.otherItems,
|
|
989
|
+
currentItem = allItemRects.currentItem;
|
|
990
|
+
allItemRects.others.forEach(function (rect, index) {
|
|
991
|
+
var cw = cur && cur.size.width / 2;
|
|
992
|
+
var ch = cur && cur.size.height / 2;
|
|
993
|
+
var cos = Math.cos(rect.rotRad);
|
|
994
|
+
var sin = Math.sin(rect.rotRad);
|
|
995
|
+
var ox0 = cw * cos - ch * sin; // (cw, ch) rot
|
|
996
|
+
var oy0 = cw * sin + ch * cos;
|
|
997
|
+
var ox1 = -cw * cos - ch * sin; // (-cw, ch) rot
|
|
998
|
+
var oy1 = -cw * sin + ch * cos;
|
|
999
|
+
var ox2 = ch * sin - cw * cos;
|
|
1000
|
+
var oy2 = -ch * cos - cw * sin;
|
|
1001
|
+
var ox3 = ch * sin + cw * cos;
|
|
1002
|
+
var oy3 = -ch * cos + cw * sin;
|
|
1003
|
+
var nrot = rect.rotRad + Math.PI;
|
|
1004
|
+
if (nrot >= Math.PI) nrot -= Math.PI * 2;
|
|
1005
|
+
var snap1 = itemrectInfo(rect.rect[2].x + ox3, rect.rect[2].y + oy3, rect.rotRad, cur && cur.size, rect.layoutpos, rect.is_corner);
|
|
1006
|
+
var snap2 = itemrectInfo(rect.rect[3].x + ox2, rect.rect[3].y + oy2, rect.rotRad, cur && cur.size, rect.layoutpos, rect.is_corner);
|
|
1007
|
+
var snap3 = itemrectInfo(rect.rect[2].x + ox1, rect.rect[2].y + oy1, nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
|
|
1008
|
+
var snap4 = itemrectInfo(rect.rect[3].x + ox0, rect.rect[3].y + oy0, nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
|
|
1009
|
+
var sizeinfo = otherItems[index].cat && otherItems[index].cat.info.sizeinfo;
|
|
1010
|
+
if (sizeinfo) {
|
|
1011
|
+
var leftBlindLength = sizeinfo.leftBlindLength,
|
|
1012
|
+
rightBlindLength = sizeinfo.rightBlindLength;
|
|
1013
|
+
if (leftBlindLength > 0) {
|
|
1014
|
+
var vx = leftBlindLength - ch;
|
|
1015
|
+
var vy = cw;
|
|
1016
|
+
var dx = vx * cos + vy * sin;
|
|
1017
|
+
var dy = vx * sin - vy * cos;
|
|
1018
|
+
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);
|
|
1019
|
+
allItemSnap.push(snap6);
|
|
1020
|
+
}
|
|
1021
|
+
if (rightBlindLength > 0) {
|
|
1022
|
+
var _vx = ch - rightBlindLength;
|
|
1023
|
+
var _vy = cw;
|
|
1024
|
+
var _dx = _vx * cos + _vy * sin;
|
|
1025
|
+
var _dy = _vx * sin - _vy * cos;
|
|
1026
|
+
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);
|
|
1027
|
+
allItemSnap.push(snap7);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (rect.isSnappedLine) {
|
|
1031
|
+
snap1.isSnappedLine = true;
|
|
1032
|
+
snap2.isSnappedLine = true;
|
|
1033
|
+
}
|
|
1034
|
+
if (rect.is_corner) {
|
|
1035
|
+
var _nrot = rect.rotRad + Math.PI * 3 / 2;
|
|
1036
|
+
if (_nrot >= Math.PI) _nrot -= Math.PI * 2;
|
|
1037
|
+
var snap5 = itemrectInfo(rect.rect[1].x - oy1, rect.rect[1].y + ox1, _nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
|
|
1038
|
+
allItemSnap.push(snap2);
|
|
1039
|
+
allItemSnap.push(snap5);
|
|
1040
|
+
} else {
|
|
1041
|
+
allItemSnap.push(snap1);
|
|
1042
|
+
allItemSnap.push(snap2);
|
|
1043
|
+
allItemSnap.push(snap3);
|
|
1044
|
+
allItemSnap.push(snap4);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
return allItemSnap;
|
|
1048
|
+
}
|
|
1049
|
+
function getAllArea(layer) {
|
|
1050
|
+
var allAreaLines = [];
|
|
1051
|
+
var allLines = [];
|
|
1052
|
+
var verticesArray = [];
|
|
1053
|
+
var vertexID_to_verticesArrayIndex = {};
|
|
1054
|
+
layer.vertices.forEach(function (vertex) {
|
|
1055
|
+
var verticesCount = verticesArray.push([vertex.x, vertex.y]);
|
|
1056
|
+
var latestVertexIndex = verticesCount - 1;
|
|
1057
|
+
vertexID_to_verticesArrayIndex[vertex.id] = latestVertexIndex;
|
|
1058
|
+
});
|
|
1059
|
+
layer.areas.forEach(function (area) {
|
|
1060
|
+
allAreaLines.push(area.vertices);
|
|
1061
|
+
});
|
|
1062
|
+
allAreaLines.forEach(function (area) {
|
|
1063
|
+
var pt = [];
|
|
1064
|
+
area.forEach(function (element) {
|
|
1065
|
+
pt.push({
|
|
1066
|
+
x: verticesArray[vertexID_to_verticesArrayIndex[element]][0],
|
|
1067
|
+
y: verticesArray[vertexID_to_verticesArrayIndex[element]][1]
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
1070
|
+
allLines.push(pt);
|
|
1071
|
+
});
|
|
1072
|
+
return allLines;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/** Get all lines of the scene */
|
|
1076
|
+
function getAllLines(layer) {
|
|
1077
|
+
var allArea = getAllArea(layer);
|
|
1078
|
+
var allAreaLines = [];
|
|
1079
|
+
var allVertices = layer.get('vertices').toJS();
|
|
1080
|
+
layer.lines.forEach(function (tline) {
|
|
1081
|
+
var line = tline.toJS();
|
|
1082
|
+
if (isPointInArea(allArea, allVertices[line.vertices[0]]) || isPointInArea(allArea, allVertices[line.vertices[1]])) {
|
|
1083
|
+
allAreaLines.push(line.vertices.reverse());
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
var allLines = [];
|
|
1087
|
+
//let allNonAreaLines = [];
|
|
1088
|
+
var thick = _constants.LINE_THICKNESS / 2;
|
|
1089
|
+
layer.lines.forEach(function (line) {
|
|
1090
|
+
var i = containLine(allAreaLines, line);
|
|
1091
|
+
// let thick = line.properties.getIn(['thickness', 'length']);
|
|
1092
|
+
if (i < 0) {
|
|
1093
|
+
var vertices = line.vertices.toJS();
|
|
1094
|
+
var tmp_vertices = {
|
|
1095
|
+
x1: layer.vertices.get(vertices[0]).x,
|
|
1096
|
+
y1: layer.vertices.get(vertices[0]).y,
|
|
1097
|
+
x2: layer.vertices.get(vertices[1]).x,
|
|
1098
|
+
y2: layer.vertices.get(vertices[1]).y
|
|
1099
|
+
};
|
|
1100
|
+
if (tmp_vertices.x1 == tmp_vertices.x2 && tmp_vertices.y1 == tmp_vertices.y2) return;
|
|
1101
|
+
var addIdx = allLines.length;
|
|
1102
|
+
var flag = 0;
|
|
1103
|
+
allLines.forEach(function (element, idx) {
|
|
1104
|
+
if (flag == 0) {
|
|
1105
|
+
var el = element[0];
|
|
1106
|
+
var tmp_el = {
|
|
1107
|
+
x1: layer.vertices.get(el[0]).x,
|
|
1108
|
+
y1: layer.vertices.get(el[0]).y,
|
|
1109
|
+
x2: layer.vertices.get(el[1]).x,
|
|
1110
|
+
y2: layer.vertices.get(el[1]).y
|
|
1111
|
+
};
|
|
1112
|
+
if (tmp_el.x1 == tmp_vertices.x1 && tmp_el.y1 == tmp_vertices.y1) {
|
|
1113
|
+
var tmp = vertices[0];
|
|
1114
|
+
vertices[0] = vertices[1];
|
|
1115
|
+
vertices[1] = tmp;
|
|
1116
|
+
addIdx = idx == 0 ? 0 : idx - 1;
|
|
1117
|
+
flag = 1;
|
|
1118
|
+
} else if (tmp_el.x2 == tmp_vertices.x1 && tmp_el.y2 == tmp_vertices.y1) {
|
|
1119
|
+
addIdx = idx;
|
|
1120
|
+
flag = 1;
|
|
1121
|
+
} else if (tmp_el.x1 == tmp_vertices.x2 && tmp_el.y1 == tmp_vertices.y2) {
|
|
1122
|
+
addIdx = idx == 0 ? 0 : idx - 1;
|
|
1123
|
+
flag = 1;
|
|
1124
|
+
} else if (tmp_el.x2 == tmp_vertices.x2 && tmp_el.y2 == tmp_vertices.y2) {
|
|
1125
|
+
var _tmp = vertices[0];
|
|
1126
|
+
vertices[0] = vertices[1];
|
|
1127
|
+
vertices[1] = _tmp;
|
|
1128
|
+
addIdx = idx;
|
|
1129
|
+
flag = 1;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
allLines.splice(addIdx, 0, [vertices, thick, line.id]);
|
|
1134
|
+
} else {
|
|
1135
|
+
allLines.push([allAreaLines[i], thick, line.id]);
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
return allLines;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/** Get lines that wraps the area */
|
|
1142
|
+
function getAllAreaLines(layer) {
|
|
1143
|
+
var areainfo = [];
|
|
1144
|
+
layer.areas.forEach(function (area) {
|
|
1145
|
+
var sz = area.vertices.size;
|
|
1146
|
+
for (var i = 0; i < sz; i++) {
|
|
1147
|
+
areainfo.push([area.vertices.get(i), area.vertices.get((i + 1) % sz)]);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
return areainfo;
|
|
1151
|
+
}
|
|
1152
|
+
function containLine(lines, line) {
|
|
1153
|
+
// lines: [array]
|
|
1154
|
+
var sz = lines.length;
|
|
1155
|
+
for (var i = 0; i < sz; i++) {
|
|
1156
|
+
var l = lines[i];
|
|
1157
|
+
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]) {
|
|
1158
|
+
return i;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return -1;
|
|
1162
|
+
}
|
|
1163
|
+
function buildRectFromLines(layer, lines) {
|
|
1164
|
+
var rect = [];
|
|
1165
|
+
lines.forEach(function (line) {
|
|
1166
|
+
var vxys = []; // 0: x0, 1: y0, 2: x1, 3: y1
|
|
1167
|
+
line[0].forEach(function (vertex) {
|
|
1168
|
+
var vert = layer.vertices.get(vertex);
|
|
1169
|
+
vxys.push(vert.x);
|
|
1170
|
+
vxys.push(vert.y);
|
|
1171
|
+
});
|
|
1172
|
+
var thick = line[1];
|
|
1173
|
+
var x0 = vxys[0];
|
|
1174
|
+
var y0 = vxys[1];
|
|
1175
|
+
var x1 = vxys[2];
|
|
1176
|
+
var y1 = vxys[3];
|
|
1177
|
+
var rectLine = getCalcRectFromLine(x0, y0, x1, y1, thick, layer);
|
|
1178
|
+
rectLine.lineId = line.length > 2 ? line[2] : null;
|
|
1179
|
+
rect.push(rectLine);
|
|
1180
|
+
});
|
|
1181
|
+
return rect;
|
|
1182
|
+
}
|
|
1183
|
+
function getRelatedVertices(x0, y0, x1, y1, layer) {
|
|
1184
|
+
var verticesArray = [];
|
|
1185
|
+
var mapVertIDtoIndex = {};
|
|
1186
|
+
layer.vertices.forEach(function (vertex) {
|
|
1187
|
+
var verticesCount = verticesArray.push([vertex.x, vertex.y]);
|
|
1188
|
+
var latestVertexIndex = verticesCount - 1;
|
|
1189
|
+
mapVertIDtoIndex[vertex.id] = latestVertexIndex;
|
|
1190
|
+
});
|
|
1191
|
+
var relVerts = [];
|
|
1192
|
+
layer.lines.some(function (line) {
|
|
1193
|
+
var vertID0 = line.vertices.get(0);
|
|
1194
|
+
var vertID1 = line.vertices.get(1);
|
|
1195
|
+
var pt0 = {
|
|
1196
|
+
x: verticesArray[mapVertIDtoIndex[vertID0]][0],
|
|
1197
|
+
y: verticesArray[mapVertIDtoIndex[vertID0]][1]
|
|
1198
|
+
};
|
|
1199
|
+
var pt1 = {
|
|
1200
|
+
x: verticesArray[mapVertIDtoIndex[vertID1]][0],
|
|
1201
|
+
y: verticesArray[mapVertIDtoIndex[vertID1]][1]
|
|
1202
|
+
};
|
|
1203
|
+
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) {
|
|
1204
|
+
if (line.relatedVertices.size == 2) {
|
|
1205
|
+
var relPt0 = point(x0, y0);
|
|
1206
|
+
var relPt1 = point(x1, y1);
|
|
1207
|
+
line.relatedVertices.forEach(function (relatedVertice, index) {
|
|
1208
|
+
if (relatedVertice.index == undefined) relatedVertice = relatedVertice.toJSON();
|
|
1209
|
+
if (relatedVertice.index == 0) relPt0 = point(relatedVertice.point.x, relatedVertice.point.y);else relPt1 = point(relatedVertice.point.x, relatedVertice.point.y);
|
|
1210
|
+
});
|
|
1211
|
+
relVerts.push(relPt0);
|
|
1212
|
+
relVerts.push(relPt1);
|
|
1213
|
+
}
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
return relVerts;
|
|
1218
|
+
}
|
|
1219
|
+
function getCalcRectFromLine(x0, y0, x1, y1, thick, layer) {
|
|
1220
|
+
// get line from vertex coordinate
|
|
1221
|
+
var relVerts = getRelatedVertices(x0, y0, x1, y1, layer);
|
|
1222
|
+
var dx = x1 - x0;
|
|
1223
|
+
var dy = y1 - y0;
|
|
1224
|
+
var dl = Math.sqrt(dx * dx + dy * dy);
|
|
1225
|
+
var ox = -dy / dl * thick;
|
|
1226
|
+
var oy = dx / dl * thick;
|
|
1227
|
+
var rot = Math.atan2(dy, dx);
|
|
1228
|
+
if (relVerts.length == 2) {
|
|
1229
|
+
var vN = point(ox, oy);
|
|
1230
|
+
var vR = point(relVerts[0].x - x0, relVerts[0].y - y0);
|
|
1231
|
+
if (dotprod(vN, vR) < 0) {
|
|
1232
|
+
ox = -ox;
|
|
1233
|
+
oy = -oy;
|
|
1234
|
+
} else {
|
|
1235
|
+
rot += Math.PI;
|
|
1236
|
+
}
|
|
1237
|
+
} else {
|
|
1238
|
+
ox = -ox;
|
|
1239
|
+
oy = -oy;
|
|
1240
|
+
}
|
|
1241
|
+
return {
|
|
1242
|
+
rectEnd: [point(x0 + ox / 2, y0 + oy / 2), point(x1 + ox / 2, y1 + oy / 2)],
|
|
1243
|
+
rect: [point(x0 + ox, y0 + oy), point(x1 + ox, y1 + oy), point(x1, y1), point(x0, y0)],
|
|
1244
|
+
pos: point((x0 + x1 + ox) / 2, (y0 + y1 + ox) / 2),
|
|
1245
|
+
rotRad: rot,
|
|
1246
|
+
size: {
|
|
1247
|
+
width: dl,
|
|
1248
|
+
height: thick / 2
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
function getAllLineSnap(allLineRects, curItemRect) {
|
|
1253
|
+
var allLineSnap = [];
|
|
1254
|
+
var cur = curItemRect;
|
|
1255
|
+
if (cur === undefined || cur === null) return;else allLineRects.forEach(function (rect) {
|
|
1256
|
+
var cw = cur.size.width / 2;
|
|
1257
|
+
var ch = cur.size.height / 2;
|
|
1258
|
+
var cos = Math.cos(rect.rotRad);
|
|
1259
|
+
var sin = Math.sin(rect.rotRad);
|
|
1260
|
+
var ox0 = cw * cos - ch * sin; // (cw, ch) rot
|
|
1261
|
+
var oy0 = cw * sin + ch * cos;
|
|
1262
|
+
var ox1 = -cw * cos - ch * sin; // (-cw, ch) rot
|
|
1263
|
+
var oy1 = -cw * sin + ch * cos;
|
|
1264
|
+
var nrot = rect.rotRad + Math.PI;
|
|
1265
|
+
if (nrot >= Math.PI) nrot -= Math.PI * 2;
|
|
1266
|
+
var thick = rect.size.height;
|
|
1267
|
+
var snap3 = itemInfo(rect.rect[2].x + ox1, rect.rect[2].y + oy1, nrot, cur.size);
|
|
1268
|
+
var snap4 = itemInfo(rect.rect[3].x + ox0, rect.rect[3].y + oy0, nrot, cur.size);
|
|
1269
|
+
if (!cur.is_corner) {
|
|
1270
|
+
allLineSnap.push(snap3);
|
|
1271
|
+
}
|
|
1272
|
+
allLineSnap.push(snap4);
|
|
1273
|
+
});
|
|
1274
|
+
return allLineSnap;
|
|
1275
|
+
}
|
|
1276
|
+
function validateSnaps(allSnaps, allRects) {
|
|
1277
|
+
var validSnaps = [];
|
|
1278
|
+
if (allSnaps !== undefined && allSnaps !== null && allSnaps.length > 0) allSnaps.forEach(function (snap) {
|
|
1279
|
+
if (validSnap(snap, allRects)) {
|
|
1280
|
+
validSnaps.push(snap);
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
return validSnaps;
|
|
1284
|
+
}
|
|
1285
|
+
function validateLineSnaps(allSnaps, allItemSnap, allLineSnap, allItemRects, allLineRects, allRects) {
|
|
1286
|
+
var validSnaps = [];
|
|
1287
|
+
var addFlag = true;
|
|
1288
|
+
allSnaps.forEach(function (snap) {
|
|
1289
|
+
if (validSnap(snap, allRects)) {
|
|
1290
|
+
validSnaps.push(snap);
|
|
1291
|
+
} else if (addFlag) {
|
|
1292
|
+
allItemSnap.forEach(function (snap) {
|
|
1293
|
+
validSnaps.push(snap);
|
|
1294
|
+
});
|
|
1295
|
+
allLineSnap.forEach(function (snap) {
|
|
1296
|
+
validSnaps.push(snap);
|
|
1297
|
+
});
|
|
1298
|
+
addFlag = false;
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
return validSnaps;
|
|
1302
|
+
}
|
|
1303
|
+
function validSnap(snap, rects) {
|
|
1304
|
+
var snaprect = getCalcRectFromItem(snap);
|
|
1305
|
+
return rects.every(function (rect) {
|
|
1306
|
+
return !intersectRect(rect.rect, snaprect.rect);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
function itemInfo(x, y, rotRad, size) {
|
|
1310
|
+
return {
|
|
1311
|
+
pos: {
|
|
1312
|
+
x: x,
|
|
1313
|
+
y: y
|
|
1314
|
+
},
|
|
1315
|
+
rotRad: rotRad,
|
|
1316
|
+
size: size
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
function intersectRect(rect1, rect2) {
|
|
1320
|
+
var ret = false;
|
|
1321
|
+
rect1 = shrinkRect(rect1);
|
|
1322
|
+
rect2 = shrinkRect(rect2);
|
|
1323
|
+
ret = ret || getInterSect(rect1, rect2);
|
|
1324
|
+
ret = ret || rect1.some(function (pt) {
|
|
1325
|
+
return containPointInRect(pt, rect2);
|
|
1326
|
+
});
|
|
1327
|
+
ret = ret || rect2.some(function (pt) {
|
|
1328
|
+
return containPointInRect(pt, rect1);
|
|
1329
|
+
});
|
|
1330
|
+
return ret;
|
|
1331
|
+
}
|
|
1332
|
+
function containPointInRect(point, rect) {
|
|
1333
|
+
// true: contain, false: not contain
|
|
1334
|
+
for (var i = 0; i < rect.length; i++) {
|
|
1335
|
+
var ni = (i + 1) % rect.length;
|
|
1336
|
+
if (crossprod(diff(point, rect[i]), diff(rect[i], rect[ni])) < 0) {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
function diff(v0, v1) {
|
|
1343
|
+
return {
|
|
1344
|
+
x: v0.x - v1.x,
|
|
1345
|
+
y: v0.y - v1.y
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function crossprod(v0, v1) {
|
|
1349
|
+
return v0.x * v1.y - v0.y * v1.x;
|
|
1350
|
+
}
|
|
1351
|
+
function shrinkRect(rect) {
|
|
1352
|
+
var v02x = rect[2].x - rect[0].x;
|
|
1353
|
+
var v02y = rect[2].y - rect[0].y;
|
|
1354
|
+
var d02 = Math.sqrt(v02x * v02x + v02y * v02y);
|
|
1355
|
+
var o02x = v02x / d02 * 0.1;
|
|
1356
|
+
var o02y = v02y / d02 * 0.1;
|
|
1357
|
+
var v13x = rect[3].x - rect[1].x;
|
|
1358
|
+
var v13y = rect[3].y - rect[1].y;
|
|
1359
|
+
var d13 = Math.sqrt(v02x * v02x + v02y * v02y);
|
|
1360
|
+
var o13x = v13x / d13 * 0.1;
|
|
1361
|
+
var o13y = v13y / d13 * 0.1;
|
|
1362
|
+
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)];
|
|
1363
|
+
}
|
|
1364
|
+
function getInterSect(shape1, shape2) {
|
|
1365
|
+
// return result of intersect of two shape
|
|
1366
|
+
var count = 0;
|
|
1367
|
+
for (var i = 0; i < shape1.length; i++) {
|
|
1368
|
+
var sl1 = {
|
|
1369
|
+
x: shape1[i].x,
|
|
1370
|
+
y: shape1[i].y
|
|
1371
|
+
};
|
|
1372
|
+
var sl2 = {
|
|
1373
|
+
x: shape1[(i + 1) % shape1.length].x,
|
|
1374
|
+
y: shape1[(i + 1) % shape1.length].y
|
|
1375
|
+
};
|
|
1376
|
+
for (var j = 0; j < shape2.length; j++) {
|
|
1377
|
+
var el1 = {
|
|
1378
|
+
x: shape2[j].x,
|
|
1379
|
+
y: shape2[j].y
|
|
1380
|
+
};
|
|
1381
|
+
var el2 = {
|
|
1382
|
+
x: shape2[(j + 1) % shape2.length].x,
|
|
1383
|
+
y: shape2[(j + 1) % shape2.length].y
|
|
1384
|
+
};
|
|
1385
|
+
var flag = getLineInterSect(sl1.x, sl1.y, sl2.x, sl2.y, el1.x, el1.y, el2.x, el2.y);
|
|
1386
|
+
if (flag) {
|
|
1387
|
+
count++;
|
|
1388
|
+
if (count > 1) return true;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
function getLineInterSect(s1x, s1y, e1x, e1y, s2x, s2y, e2x, e2y) {
|
|
1395
|
+
var ax = s1x;
|
|
1396
|
+
var ay = s1y;
|
|
1397
|
+
var bx = e1x - s1x;
|
|
1398
|
+
var by = e1y - s1y;
|
|
1399
|
+
var cx = s2x;
|
|
1400
|
+
var cy = s2y;
|
|
1401
|
+
var dx = e2x - s2x;
|
|
1402
|
+
var dy = e2y - s2y;
|
|
1403
|
+
if (Math.abs(bx * dy - by * dx) < 0.00000001) {
|
|
1404
|
+
if (Math.abs((cx - ax) * by - (cy - ay) * bx) < 0.00000001) {
|
|
1405
|
+
var maxX = ax;
|
|
1406
|
+
var minX = ax;
|
|
1407
|
+
var maxY = ay;
|
|
1408
|
+
var minY = ay;
|
|
1409
|
+
if (maxX < e1x) maxX = e1x;
|
|
1410
|
+
if (maxX < cx) maxX = cx;
|
|
1411
|
+
if (maxX < e2x) maxX = e2x;
|
|
1412
|
+
if (minX > e1x) minX = e1x;
|
|
1413
|
+
if (minX > cx) minX = cx;
|
|
1414
|
+
if (minX > e2x) minX = e2x;
|
|
1415
|
+
if (maxY < e1y) maxY = e1y;
|
|
1416
|
+
if (maxY < cy) maxY = cy;
|
|
1417
|
+
if (maxY < e2y) maxY = e2y;
|
|
1418
|
+
if (minY > e1y) minY = e1y;
|
|
1419
|
+
if (minY > cy) minY = cy;
|
|
1420
|
+
if (minY > e2y) minX = e2y;
|
|
1421
|
+
var len = Math.sqrt((maxX - minX) * (maxX - minX) + (maxY - minY) * (maxY - minY));
|
|
1422
|
+
var len1 = Math.sqrt(bx * bx + by * by);
|
|
1423
|
+
var len2 = Math.sqrt(dx * dx + dy * dy);
|
|
1424
|
+
if (len < len1 + len2) {
|
|
1425
|
+
return true;
|
|
1426
|
+
} else {
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
} else {
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
} else {
|
|
1433
|
+
var t = (dx * (ay - cy) + dy * (cx - ax)) / (bx * dy - by * dx);
|
|
1434
|
+
var u = (bx * (cy - ay) + by * (ax - cx)) / (dx * by - dy * bx);
|
|
1435
|
+
var ret = u < 1 && u > 0 && t > 0 && t < 1;
|
|
1436
|
+
return ret;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
function isPointInArea(allArea, pt) {
|
|
1440
|
+
var x = pt.x;
|
|
1441
|
+
var y = pt.y;
|
|
1442
|
+
var result = false;
|
|
1443
|
+
result = allArea.some(function (area) {
|
|
1444
|
+
var sum = 0,
|
|
1445
|
+
alpha = 0;
|
|
1446
|
+
for (var i = 0; i < area.length; i++) {
|
|
1447
|
+
var x0 = area[i].x;
|
|
1448
|
+
var y0 = area[i].y;
|
|
1449
|
+
var x1 = area[(i + 1) % area.length].x;
|
|
1450
|
+
var y1 = area[(i + 1) % area.length].y;
|
|
1451
|
+
var v0 = {
|
|
1452
|
+
x: x0 - x,
|
|
1453
|
+
y: y0 - y
|
|
1454
|
+
};
|
|
1455
|
+
var v1 = {
|
|
1456
|
+
x: x1 - x,
|
|
1457
|
+
y: y1 - y
|
|
1458
|
+
};
|
|
1459
|
+
if (Math.abs(v0.x) < _constants.EPSILON && Math.abs(v0.y) < _constants.EPSILON)
|
|
1460
|
+
// check if pt is area point
|
|
1461
|
+
return true;
|
|
1462
|
+
|
|
1463
|
+
// check if pt is in area line
|
|
1464
|
+
var lineLen = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
|
1465
|
+
var v0Len = Math.sqrt(v0.x * v0.x + v0.y * v0.y);
|
|
1466
|
+
var vPt = {
|
|
1467
|
+
x: -v0.x / v0Len,
|
|
1468
|
+
y: -v0.y / v0Len
|
|
1469
|
+
};
|
|
1470
|
+
var xE = x0 + vPt.x * lineLen;
|
|
1471
|
+
var yE = y0 + vPt.y * lineLen;
|
|
1472
|
+
if (v0Len <= lineLen && Math.abs(xE - x1) < _constants.EPSILON && Math.abs(yE - y1) < _constants.EPSILON) return true;
|
|
1473
|
+
alpha = Math.atan2(v0.x * v1.y - v1.x * v0.y, v0.x * v1.x + v0.y * v1.y);
|
|
1474
|
+
sum += alpha;
|
|
1475
|
+
}
|
|
1476
|
+
if (Math.abs(Math.abs(sum) - Math.PI * 2) < _constants.EPSILON) return true;
|
|
1477
|
+
});
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
function calcSnap(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allAreaLines) {
|
|
1481
|
+
return calcSnap2(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allAreaLines);
|
|
1482
|
+
}
|
|
1483
|
+
function calcCreateSnap(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, polygonPoint) {
|
|
1484
|
+
// Validate required input and guard against missing `.cur`
|
|
1485
|
+
if (!allItemRect || !allItemRect.cur) return;
|
|
1486
|
+
var cur = allItemRect.cur; // safe alias
|
|
1487
|
+
var cx = x;
|
|
1488
|
+
var cy = y;
|
|
1489
|
+
var ndist = 5000;
|
|
1490
|
+
var rotRad = cur.rotRad;
|
|
1491
|
+
|
|
1492
|
+
// Get candidate snaps and validate them as before
|
|
1493
|
+
var allCurSnap = getAllCurSnap(allLineRects, x, y, cur);
|
|
1494
|
+
allCurSnap = validateLineSnaps(allCurSnap, allItemSnap, allLineSnap, allItemRect, allLineRects, allRect);
|
|
1495
|
+
var getSnap = false;
|
|
1496
|
+
var snapdist = [];
|
|
1497
|
+
|
|
1498
|
+
// Build distances for snaps that lie inside polygonPoint (if any)
|
|
1499
|
+
if (Array.isArray(allCurSnap)) {
|
|
1500
|
+
allCurSnap.forEach(function (snap) {
|
|
1501
|
+
if (!snap || !snap.pos) return;
|
|
1502
|
+
var inside = ContainsPoint(polygonPoint, snap.pos.x, snap.pos.y);
|
|
1503
|
+
if (inside) {
|
|
1504
|
+
var dx = snap.pos.x - x;
|
|
1505
|
+
var dy = snap.pos.y - y;
|
|
1506
|
+
snapdist.push(dx * dx + dy * dy);
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// Find minimum distance (Infinity if none)
|
|
1512
|
+
var edist = snapdist.length ? Math.min.apply(Math, snapdist) : Infinity;
|
|
1513
|
+
|
|
1514
|
+
// Choose the snap with distance === edist
|
|
1515
|
+
if (Array.isArray(allCurSnap)) {
|
|
1516
|
+
allCurSnap.forEach(function (snap) {
|
|
1517
|
+
if (!snap || !snap.pos) return;
|
|
1518
|
+
var dx = snap.pos.x - x;
|
|
1519
|
+
var dy = snap.pos.y - y;
|
|
1520
|
+
var dist = dx * dx + dy * dy;
|
|
1521
|
+
if (dist === edist) {
|
|
1522
|
+
var _snap$rotRad;
|
|
1523
|
+
ndist = dist;
|
|
1524
|
+
cx = snap.pos.x;
|
|
1525
|
+
cy = snap.pos.y;
|
|
1526
|
+
rotRad = (_snap$rotRad = snap.rotRad) !== null && _snap$rotRad !== void 0 ? _snap$rotRad : rotRad; // nullish coalescing
|
|
1527
|
+
getSnap = true;
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
var crot = rotRad / Math.PI * 180;
|
|
1532
|
+
return {
|
|
1533
|
+
cx: cx,
|
|
1534
|
+
cy: cy,
|
|
1535
|
+
crot: crot,
|
|
1536
|
+
rotRad: rotRad
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
////////////
|
|
1541
|
+
function calcSnap1(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y) {
|
|
1542
|
+
var cx = allItemRect.cur.pos.x;
|
|
1543
|
+
var cy = allItemRect.cur.pos.y;
|
|
1544
|
+
var nx = x;
|
|
1545
|
+
var ny = y;
|
|
1546
|
+
var cursize = allItemRect.cur.size;
|
|
1547
|
+
var ndist = cursize.width * cursize.width + cursize.height * cursize.height;
|
|
1548
|
+
ndist = ndist / 4;
|
|
1549
|
+
var rotRad = allItemRect.cur.rotRad;
|
|
1550
|
+
var allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
|
|
1551
|
+
allCurSnap = validateSnaps(allCurSnap, allRect);
|
|
1552
|
+
var getSnap = false;
|
|
1553
|
+
allCurSnap.forEach(function (snap) {
|
|
1554
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1555
|
+
if (dist < ndist) {
|
|
1556
|
+
ndist = dist;
|
|
1557
|
+
nx = snap.pos.x;
|
|
1558
|
+
ny = snap.pos.y;
|
|
1559
|
+
rotRad = snap.rotRad;
|
|
1560
|
+
getSnap = true;
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
if (!getSnap) {
|
|
1564
|
+
allLineSnap.concat(allItemSnap).forEach(function (snap) {
|
|
1565
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1566
|
+
if (dist < ndist) {
|
|
1567
|
+
ndist = dist;
|
|
1568
|
+
nx = snap.pos.x;
|
|
1569
|
+
ny = snap.pos.y;
|
|
1570
|
+
rotRad = snap.rotRad;
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
var rot = rotRad / Math.PI * 180;
|
|
1575
|
+
var ret = {
|
|
1576
|
+
nx: nx,
|
|
1577
|
+
ny: ny,
|
|
1578
|
+
rot: rot,
|
|
1579
|
+
rotRad: rotRad
|
|
1580
|
+
};
|
|
1581
|
+
return ret;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
////////////
|
|
1585
|
+
function calcSnap2(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y, allArea) {
|
|
1586
|
+
var nx = x;
|
|
1587
|
+
var ny = y;
|
|
1588
|
+
var ndist = 20;
|
|
1589
|
+
var rotRad = allItemRect.cur && allItemRect.cur.rotRad;
|
|
1590
|
+
var val = {
|
|
1591
|
+
pos: {
|
|
1592
|
+
x: x,
|
|
1593
|
+
y: y
|
|
1594
|
+
},
|
|
1595
|
+
rotRad: rotRad
|
|
1596
|
+
};
|
|
1597
|
+
val.size = allItemRect.cur && allItemRect.cur.size;
|
|
1598
|
+
val.layoutpos = allItemRect.cur && allItemRect.cur.layoutpos;
|
|
1599
|
+
val.is_corner = allItemRect.cur && allItemRect.cur.is_corner;
|
|
1600
|
+
var curitem = getCalcRectFromItem(val);
|
|
1601
|
+
var allCurSnap = [];
|
|
1602
|
+
allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
|
|
1603
|
+
allCurSnap = validateSnaps(allCurSnap, allRect);
|
|
1604
|
+
var getSnap = false;
|
|
1605
|
+
var snapdist = [];
|
|
1606
|
+
//console.log("allItemSnap", allItemSnap.filter(e => e.isSnappedLine))
|
|
1607
|
+
//console.log("~~~~start~~~~");
|
|
1608
|
+
allItemSnap.filter(function (e) {
|
|
1609
|
+
return e.isSnappedLine;
|
|
1610
|
+
}).forEach(function (snap) {
|
|
1611
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1612
|
+
snapdist.push(dist);
|
|
1613
|
+
//console.log("dist", snap)
|
|
1614
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < 100) {
|
|
1615
|
+
ndist = dist;
|
|
1616
|
+
nx = snap.pos.x;
|
|
1617
|
+
ny = snap.pos.y;
|
|
1618
|
+
rotRad = snap.rotRad;
|
|
1619
|
+
getSnap = true;
|
|
1620
|
+
|
|
1621
|
+
//console.log("SUCCESS!!!!");
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
//console.log("====end====");
|
|
1625
|
+
if (getSnap == false) {
|
|
1626
|
+
allCurSnap.forEach(function (snap) {
|
|
1627
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1628
|
+
snapdist.push(dist);
|
|
1629
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < ndist) {
|
|
1630
|
+
ndist = dist;
|
|
1631
|
+
nx = snap.pos.x;
|
|
1632
|
+
ny = snap.pos.y;
|
|
1633
|
+
rotRad = snap.rotRad;
|
|
1634
|
+
getSnap = true;
|
|
1635
|
+
//console.log("SUCCE!!!!");
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
if (!getSnap && allLineRects.some(function (others) {
|
|
1639
|
+
return intersectRect(others.rect, curitem.rect);
|
|
1640
|
+
})) {
|
|
1641
|
+
var edist = Math.min.apply(null, snapdist);
|
|
1642
|
+
allCurSnap.forEach(function (snap) {
|
|
1643
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1644
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist === edist) {
|
|
1645
|
+
ndist = dist;
|
|
1646
|
+
nx = snap.pos.x;
|
|
1647
|
+
ny = snap.pos.y;
|
|
1648
|
+
rotRad = snap.rotRad;
|
|
1649
|
+
getSnap = true;
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
if (getSnap === false) {
|
|
1654
|
+
var nearRect = null;
|
|
1655
|
+
var minDist = Infinity;
|
|
1656
|
+
allLineRects.forEach(function (rect) {
|
|
1657
|
+
var e = rect.rectEnd[0];
|
|
1658
|
+
e = clone_point(e);
|
|
1659
|
+
e.x -= curitem.pos.x;
|
|
1660
|
+
e.y -= curitem.pos.y;
|
|
1661
|
+
var nRot = rect.rotRad + Math.PI / 2;
|
|
1662
|
+
var dist = Math.abs(e.x * Math.cos(nRot) + e.y * Math.sin(nRot));
|
|
1663
|
+
if (minDist > dist) {
|
|
1664
|
+
minDist = dist;
|
|
1665
|
+
nearRect = rect;
|
|
1666
|
+
}
|
|
1667
|
+
});
|
|
1668
|
+
var containrect = nearRect && intersectRect(nearRect.rect, curitem.rect);
|
|
1669
|
+
if (containrect) {
|
|
1670
|
+
var filter_func = function filter_func(snap) {
|
|
1671
|
+
var diff = Math.abs(snap.rotRad - nearRect.rotRad - Math.PI);
|
|
1672
|
+
return diff == 0 || diff == 2 * Math.PI;
|
|
1673
|
+
};
|
|
1674
|
+
var tempSnap = allLineSnap.filter(filter_func);
|
|
1675
|
+
tempSnap = tempSnap.concat(allLineSnap.filter(function (snap) {
|
|
1676
|
+
return !filter_func(snap);
|
|
1677
|
+
}));
|
|
1678
|
+
tempSnap.some(function (snap) {
|
|
1679
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1680
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < 5000) {
|
|
1681
|
+
nx = snap.pos.x;
|
|
1682
|
+
ny = snap.pos.y;
|
|
1683
|
+
rotRad = snap.rotRad;
|
|
1684
|
+
getSnap = true;
|
|
1685
|
+
return true;
|
|
1686
|
+
}
|
|
1687
|
+
return false;
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
if (allItemRect.others.some(function (others) {
|
|
1692
|
+
return intersectRect(others.rect, curitem.rect);
|
|
1693
|
+
})) {
|
|
1694
|
+
getSnap = false;
|
|
1695
|
+
}
|
|
1696
|
+
if (!getSnap) {
|
|
1697
|
+
var _snapdist = [];
|
|
1698
|
+
allItemSnap.forEach(function (snap) {
|
|
1699
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1700
|
+
_snapdist.push(dist);
|
|
1701
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist < ndist) {
|
|
1702
|
+
ndist = dist;
|
|
1703
|
+
nx = snap.pos.x;
|
|
1704
|
+
ny = snap.pos.y;
|
|
1705
|
+
rotRad = snap.rotRad;
|
|
1706
|
+
getSnap = true;
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
if (!getSnap && allItemRect.others.some(function (others) {
|
|
1710
|
+
return intersectRect(others.rect, curitem.rect);
|
|
1711
|
+
})) {
|
|
1712
|
+
var _edist = Math.min.apply(null, _snapdist);
|
|
1713
|
+
allItemSnap.forEach(function (snap) {
|
|
1714
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1715
|
+
if (isPointInArea(allArea, snap.pos) || !allArea.length) if (dist === _edist) {
|
|
1716
|
+
ndist = dist;
|
|
1717
|
+
nx = snap.pos.x;
|
|
1718
|
+
ny = snap.pos.y;
|
|
1719
|
+
rotRad = snap.rotRad;
|
|
1720
|
+
}
|
|
1721
|
+
});
|
|
1722
|
+
if (allItemRect.cur.itemInfo.name.includes('Cook Top')) {
|
|
1723
|
+
var intersects = allItemRect.others.filter(function (others) {
|
|
1724
|
+
return intersectRect(others.rect, curitem.rect);
|
|
1725
|
+
});
|
|
1726
|
+
intersects.forEach(function (rect) {
|
|
1727
|
+
if (isPointInArea(allArea, rect.itemInfo) || !allArea.length) if (rect.itemInfo.layoutpos.includes(_constants.BASE_CABINET_LAYOUTPOS)) {
|
|
1728
|
+
nx = rect.itemInfo.x;
|
|
1729
|
+
ny = rect.itemInfo.y;
|
|
1730
|
+
rotRad = rect.itemInfo.rotation * Math.PI / 180;
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
if (allItemRect.cur.itemInfo.name.includes('Hood') || allItemRect.cur.itemInfo.name.includes('Range') || allItemRect.cur.itemInfo.name.includes('Cook Top')) {
|
|
1735
|
+
var _intersects = allItemRect.others.filter(function (others) {
|
|
1736
|
+
return intersectRect(others.rect, curitem.rect);
|
|
1737
|
+
});
|
|
1738
|
+
_intersects.forEach(function (rect) {
|
|
1739
|
+
if (isPointInArea(allArea, rect.itemInfo) || !allArea.length) if (rect.itemInfo.name.includes('Hood') || rect.itemInfo.name.includes('Range') || rect.itemInfo.name.includes('Cook Top')) {
|
|
1740
|
+
nx = rect.itemInfo.x;
|
|
1741
|
+
ny = rect.itemInfo.y;
|
|
1742
|
+
rotRad = rect.itemInfo.rotation * Math.PI / 180;
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
var rot = rotRad / Math.PI * 180;
|
|
1750
|
+
|
|
1751
|
+
//Check case.
|
|
1752
|
+
//If item is 'blind base cabinet', it must be pulled from other 3".
|
|
1753
|
+
if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.startsWith('BBC')) {
|
|
1754
|
+
var offset3inch = (0, _convertUnitsLite.convert)(3).from('in').to('cm');
|
|
1755
|
+
var tx = nx,
|
|
1756
|
+
ty = ny;
|
|
1757
|
+
if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.endsWith('-L')) {
|
|
1758
|
+
if (rot == 0 || rot == -180) {
|
|
1759
|
+
tx -= offset3inch * Math.cos(rotRad);
|
|
1760
|
+
}
|
|
1761
|
+
if (rot == 90 || rot == -90) {
|
|
1762
|
+
ty -= offset3inch * Math.sin(rotRad);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
if (allItemRect.cur && allItemRect.cur.itemInfo.sku_number.endsWith('-R')) {
|
|
1766
|
+
if (rot == 0 || rot == -180) {
|
|
1767
|
+
tx += offset3inch * Math.cos(rotRad);
|
|
1768
|
+
}
|
|
1769
|
+
if (rot == 90 || rot == -90) {
|
|
1770
|
+
ty += offset3inch * Math.sin(rotRad);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
var t_val = {
|
|
1774
|
+
pos: {
|
|
1775
|
+
x: tx,
|
|
1776
|
+
y: ty
|
|
1777
|
+
},
|
|
1778
|
+
rotRad: rotRad,
|
|
1779
|
+
size: allItemRect.cur.size,
|
|
1780
|
+
layoutpos: allItemRect.cur.layoutpos,
|
|
1781
|
+
is_corner: allItemRect.cur.is_corner
|
|
1782
|
+
};
|
|
1783
|
+
var isItemRectSect = validInterSect(allItemRect.others, t_val);
|
|
1784
|
+
var isWallRectSect = validInterSect(allLineRects, t_val);
|
|
1785
|
+
if (isItemRectSect && isWallRectSect) {
|
|
1786
|
+
nx = tx;
|
|
1787
|
+
ny = ty;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
return {
|
|
1791
|
+
nx: nx,
|
|
1792
|
+
ny: ny,
|
|
1793
|
+
rot: rot,
|
|
1794
|
+
rotRad: rotRad
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
////////////
|
|
1799
|
+
function calcSnap3(allItemRect, allItemSnap, allLineRects, allLineSnap, allRect, x, y) {
|
|
1800
|
+
// let layer = scene.layers.get(layerID);
|
|
1801
|
+
// let cx = allItemRect.cur.pos.x;
|
|
1802
|
+
// let cy = allItemRect.cur.pos.y;
|
|
1803
|
+
var nx = x;
|
|
1804
|
+
var ny = y;
|
|
1805
|
+
var ndist = 20;
|
|
1806
|
+
var rotRad = allItemRect.cur.rotRad;
|
|
1807
|
+
var val = {
|
|
1808
|
+
pos: {
|
|
1809
|
+
x: x,
|
|
1810
|
+
y: y
|
|
1811
|
+
},
|
|
1812
|
+
rotRad: rotRad
|
|
1813
|
+
};
|
|
1814
|
+
val.size = allItemRect.cur.size;
|
|
1815
|
+
val.layoutpos = allItemRect.cur.layoutpos;
|
|
1816
|
+
val.is_corner = allItemRect.cur.is_corner;
|
|
1817
|
+
var curitem = getCalcRectFromItem3D(val);
|
|
1818
|
+
var allCurSnap = getAllCurSnap(allLineRects, x, y, allItemRect.cur);
|
|
1819
|
+
allCurSnap = validateSnaps(allCurSnap, allRect);
|
|
1820
|
+
var getSnap = false;
|
|
1821
|
+
var snapdist = [];
|
|
1822
|
+
allCurSnap.forEach(function (snap) {
|
|
1823
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1824
|
+
snapdist.push(dist);
|
|
1825
|
+
if (dist < ndist) {
|
|
1826
|
+
ndist = dist;
|
|
1827
|
+
nx = snap.pos.x;
|
|
1828
|
+
ny = snap.pos.y;
|
|
1829
|
+
rotRad = snap.rotRad;
|
|
1830
|
+
getSnap = true;
|
|
1831
|
+
} else {
|
|
1832
|
+
var i = 0;
|
|
1833
|
+
allLineRects.forEach(function (others) {
|
|
1834
|
+
var containrect = intersectRect(others.rect, curitem.rect);
|
|
1835
|
+
if (containrect) {
|
|
1836
|
+
var edist = Math.min.apply(null, snapdist);
|
|
1837
|
+
allCurSnap.forEach(function (snap) {
|
|
1838
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1839
|
+
if (dist === edist) {
|
|
1840
|
+
ndist = dist;
|
|
1841
|
+
nx = snap.pos.x;
|
|
1842
|
+
ny = snap.pos.y;
|
|
1843
|
+
rotRad = snap.rotRad;
|
|
1844
|
+
getSnap = true;
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
});
|
|
1851
|
+
if (getSnap === false) {
|
|
1852
|
+
allLineRects.forEach(function (others) {
|
|
1853
|
+
var containrect = intersectRect(others.rect, curitem.rect);
|
|
1854
|
+
if (containrect) {
|
|
1855
|
+
allLineSnap.forEach(function (snap) {
|
|
1856
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1857
|
+
if (dist < 5000) {
|
|
1858
|
+
nx = snap.pos.x;
|
|
1859
|
+
ny = snap.pos.y;
|
|
1860
|
+
rotRad = snap.rotRad;
|
|
1861
|
+
getSnap = true;
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
allItemRect.others.forEach(function (others) {
|
|
1868
|
+
if (!(others.layoutpos === 'base' && allItemRect.cur.layoutpos === 'wall') || !(others.layoutpos === 'wall' && allItemRect.cur.layoutpos === 'base')) {
|
|
1869
|
+
var containrect = intersectRect(others.rect, curitem.rect);
|
|
1870
|
+
if (containrect) {
|
|
1871
|
+
getSnap = false;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
if (!getSnap) {
|
|
1876
|
+
var _snapdist2 = [];
|
|
1877
|
+
allItemSnap.forEach(function (snap) {
|
|
1878
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1879
|
+
_snapdist2.push(dist);
|
|
1880
|
+
if (dist < ndist) {
|
|
1881
|
+
ndist = dist;
|
|
1882
|
+
nx = snap.pos.x;
|
|
1883
|
+
ny = snap.pos.y;
|
|
1884
|
+
rotRad = snap.rotRad;
|
|
1885
|
+
} else {
|
|
1886
|
+
allItemRect.others.forEach(function (others) {
|
|
1887
|
+
if (!(others.layoutpos === 'base' && allItemRect.cur.layoutpos === 'wall') || !(others.layoutpos === 'wall' && allItemRect.cur.layoutpos === 'base')) {
|
|
1888
|
+
var containrect = intersectRect(others.rect, curitem.rect);
|
|
1889
|
+
if (containrect) {
|
|
1890
|
+
var edist = Math.min.apply(null, _snapdist2);
|
|
1891
|
+
allItemSnap.forEach(function (snap) {
|
|
1892
|
+
var dist = (snap.pos.x - x) * (snap.pos.x - x) + (snap.pos.y - y) * (snap.pos.y - y);
|
|
1893
|
+
if (dist === edist) {
|
|
1894
|
+
ndist = dist;
|
|
1895
|
+
nx = snap.pos.x;
|
|
1896
|
+
ny = snap.pos.y;
|
|
1897
|
+
rotRad = snap.rotRad;
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
var rot = rotRad / Math.PI * 180;
|
|
1907
|
+
return {
|
|
1908
|
+
nx: nx,
|
|
1909
|
+
ny: ny,
|
|
1910
|
+
rot: rot,
|
|
1911
|
+
rotRad: rotRad
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
function getAllCurSnap(allLineRects, x, y, curItemRect) {
|
|
1915
|
+
if (!curItemRect) return;
|
|
1916
|
+
var allCurSnap = [];
|
|
1917
|
+
var thick = _constants.LINE_THICKNESS / 2;
|
|
1918
|
+
allLineRects.forEach(function (linerect) {
|
|
1919
|
+
//allLineRects:left, right, top, bottom line
|
|
1920
|
+
var p0 = clone_point(linerect.rect[2]); //point 2(x, y) inside of line
|
|
1921
|
+
var p1 = clone_point(linerect.rect[3]); //point 3(x, y) inside of line
|
|
1922
|
+
var q = point(x, y); // point of item
|
|
1923
|
+
var cos = Math.cos(linerect.rotRad);
|
|
1924
|
+
var sin = Math.sin(linerect.rotRad);
|
|
1925
|
+
p0.x -= cos * curItemRect.size.width / 2;
|
|
1926
|
+
p0.y -= sin * curItemRect.size.width / 2;
|
|
1927
|
+
p1.x += cos * curItemRect.size.width / 2;
|
|
1928
|
+
p1.y += sin * curItemRect.size.width / 2;
|
|
1929
|
+
var n = point(-sin, cos);
|
|
1930
|
+
var v3to0 = {
|
|
1931
|
+
x: linerect.rect[0].x - p1.x,
|
|
1932
|
+
y: linerect.rect[0].y - p1.y
|
|
1933
|
+
};
|
|
1934
|
+
var fDot = dotprod(n, v3to0);
|
|
1935
|
+
if (fDot > 0) {
|
|
1936
|
+
// normal vector is crossing the wall
|
|
1937
|
+
n.x = -n.x;
|
|
1938
|
+
n.y = -n.y;
|
|
1939
|
+
}
|
|
1940
|
+
var dist = dotprod(diff(p1, q), n);
|
|
1941
|
+
var h = point(q.x + dist * n.x, q.y + dist * n.y);
|
|
1942
|
+
var nrot = linerect.rotRad + Math.PI;
|
|
1943
|
+
if (nrot >= Math.PI) nrot -= Math.PI * 2;
|
|
1944
|
+
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);
|
|
1945
|
+
allCurSnap.push(o);
|
|
1946
|
+
nrot = nrot + Math.PI;
|
|
1947
|
+
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);
|
|
1948
|
+
allCurSnap.push(o);
|
|
1949
|
+
});
|
|
1950
|
+
return allCurSnap;
|
|
1951
|
+
}
|
|
1952
|
+
function clone_point(pt) {
|
|
1953
|
+
return point(pt.x, pt.y);
|
|
1954
|
+
}
|
|
1955
|
+
function dotprod(v0, v1) {
|
|
1956
|
+
return v0.x * v1.x + v0.y * v1.y;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
//////////
|
|
1960
|
+
function validInterSect(rect, val) {
|
|
1961
|
+
var curitem = getCalcRectFromItem(val);
|
|
1962
|
+
var datas = [];
|
|
1963
|
+
rect.forEach(function (line) {
|
|
1964
|
+
datas.push(line);
|
|
1965
|
+
});
|
|
1966
|
+
for (var i = 0; i < datas.length; i++) {
|
|
1967
|
+
var data = datas[i];
|
|
1968
|
+
var containrect = intersectRect(data.rect, curitem.rect);
|
|
1969
|
+
if (containrect) {
|
|
1970
|
+
return false;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
return true;
|
|
1974
|
+
}
|
|
1975
|
+
var lineRect = function lineRect(layer) {
|
|
1976
|
+
var areainfo = [];
|
|
1977
|
+
layer.areas.forEach(function (area) {
|
|
1978
|
+
var sz = area.vertices.size;
|
|
1979
|
+
for (var i = 0; i < sz; i++) {
|
|
1980
|
+
areainfo.push(area.vertices.get(i));
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
var rect = [];
|
|
1984
|
+
areainfo.forEach(function (area) {
|
|
1985
|
+
var vert = layer.vertices.get(area);
|
|
1986
|
+
rect.push(vert.x, vert.y);
|
|
1987
|
+
});
|
|
1988
|
+
return rect;
|
|
1989
|
+
};
|
|
1990
|
+
function getAllHoleRect(scene, val) {
|
|
1991
|
+
var layerID = scene.selectedLayer;
|
|
1992
|
+
var layer = scene.layers.get(layerID);
|
|
1993
|
+
var selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
|
|
1994
|
+
if (selectedItem !== undefined) {
|
|
1995
|
+
if (selectedItem.category != 'cabinet') {
|
|
1996
|
+
// If selected Item type is not `cabinet` then do not snap at windows
|
|
1997
|
+
return {
|
|
1998
|
+
isSect: true,
|
|
1999
|
+
snap: null
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
} else {
|
|
2003
|
+
return {
|
|
2004
|
+
isSect: false,
|
|
2005
|
+
snap: null
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
var holes = [];
|
|
2009
|
+
var itemRect = getCalcRectFromItem(val);
|
|
2010
|
+
layer.lines.forEach(function (line) {
|
|
2011
|
+
line.holes.forEach(function (holeID) {
|
|
2012
|
+
var hole = layer.holes.get(holeID);
|
|
2013
|
+
if (hole) holes.push(hole);
|
|
2014
|
+
});
|
|
2015
|
+
});
|
|
2016
|
+
var i = 0;
|
|
2017
|
+
for (; i < holes.length; i++) {
|
|
2018
|
+
var twidth = holes[i].properties.getIn(['width', 'length']);
|
|
2019
|
+
var theight = holes[i].properties.getIn(['thickness', 'length']) + 1;
|
|
2020
|
+
var tdepth = holes[i].properties.getIn(['altitude', 'length']);
|
|
2021
|
+
//let trot = holes[i].rotation;
|
|
2022
|
+
var verticeIDs = scene.getIn(['layers', layerID, 'lines', holes[i].line, 'vertices'])._tail.array;
|
|
2023
|
+
var vertice0 = scene.getIn(['layers', layerID, 'vertices', verticeIDs[0]]);
|
|
2024
|
+
var vertice1 = scene.getIn(['layers', layerID, 'vertices', verticeIDs[1]]);
|
|
2025
|
+
var point0 = {
|
|
2026
|
+
x: vertice0.x,
|
|
2027
|
+
y: vertice0.y
|
|
2028
|
+
};
|
|
2029
|
+
var point1 = {
|
|
2030
|
+
x: vertice1.x,
|
|
2031
|
+
y: vertice1.y
|
|
2032
|
+
};
|
|
2033
|
+
var rotation = Math.atan2(point1.y - point0.y, point1.x - point0.x);
|
|
2034
|
+
var rectInfo = getCalcRectFromLine(point1.x, point1.y, point0.x, point0.y, _constants.LINE_THICKNESS, layer);
|
|
2035
|
+
var vN = point(rectInfo.rect[0].x - rectInfo.rect[3].x, rectInfo.rect[0].y - rectInfo.rect[3].y);
|
|
2036
|
+
var lenN = Math.sqrt(vN.x * vN.x + vN.y * vN.y);
|
|
2037
|
+
vN.x /= lenN;
|
|
2038
|
+
vN.y /= lenN;
|
|
2039
|
+
var hx = holes[i].x;
|
|
2040
|
+
var hy = holes[i].y;
|
|
2041
|
+
hx += theight / 2 * vN.x;
|
|
2042
|
+
hy += theight / 2 * vN.y;
|
|
2043
|
+
var tval = {
|
|
2044
|
+
pos: {
|
|
2045
|
+
x: hx,
|
|
2046
|
+
y: hy
|
|
2047
|
+
},
|
|
2048
|
+
rotRad: rotation
|
|
2049
|
+
};
|
|
2050
|
+
tval.size = {
|
|
2051
|
+
width: twidth,
|
|
2052
|
+
height: theight
|
|
2053
|
+
};
|
|
2054
|
+
var hole_rect = getCalcRectFromItem(tval);
|
|
2055
|
+
if (intersectRect(itemRect.rect, hole_rect.rect)) {
|
|
2056
|
+
if (tdepth > itemRect.size.depth && itemRect.layoutpos !== _constants.WALL_CABINET_LAYOUTPOS) {
|
|
2057
|
+
var dist = itemRect.size.height / 2 + theight / 2;
|
|
2058
|
+
var snap = [];
|
|
2059
|
+
var p0 = {
|
|
2060
|
+
x: hx + dist * Math.cos(rotation + Math.PI / 2),
|
|
2061
|
+
y: hy + dist * Math.sin(rotation + Math.PI / 2)
|
|
2062
|
+
};
|
|
2063
|
+
var p1 = {
|
|
2064
|
+
x: hx - dist * Math.cos(rotation + Math.PI / 2),
|
|
2065
|
+
y: hy - dist * Math.sin(rotation + Math.PI / 2)
|
|
2066
|
+
};
|
|
2067
|
+
var allArea = getAllArea(layer);
|
|
2068
|
+
if (isPointInArea(allArea, p0)) {
|
|
2069
|
+
snap.push(p0);
|
|
2070
|
+
}
|
|
2071
|
+
if (isPointInArea(allArea, p1)) {
|
|
2072
|
+
snap.push(p1);
|
|
2073
|
+
}
|
|
2074
|
+
return {
|
|
2075
|
+
isSect: true,
|
|
2076
|
+
snap: snap
|
|
2077
|
+
};
|
|
2078
|
+
} else return {
|
|
2079
|
+
isSect: false,
|
|
2080
|
+
snap: null
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
return {
|
|
2085
|
+
isSect: true,
|
|
2086
|
+
snap: null
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
function getHoleItems(layer) {
|
|
2090
|
+
var holeItems = [];
|
|
2091
|
+
layer.holes.map(function (hole) {
|
|
2092
|
+
var width = hole.properties.getIn(['width', 'length']);
|
|
2093
|
+
var altitude = hole.properties.getIn(['altitude', 'length']);
|
|
2094
|
+
holeItems.push({
|
|
2095
|
+
x: hole.x,
|
|
2096
|
+
y: hole.y,
|
|
2097
|
+
width: width,
|
|
2098
|
+
altitude: altitude
|
|
2099
|
+
});
|
|
2100
|
+
});
|
|
2101
|
+
return holeItems;
|
|
2102
|
+
}
|
|
2103
|
+
function needSnap(curItem, othItem) {
|
|
2104
|
+
var blSnap = false;
|
|
2105
|
+
if (curItem == undefined || curItem == null) return false;
|
|
2106
|
+
var altitude = curItem.selectedItem.properties.get('altitude');
|
|
2107
|
+
var heightFromFloor = (0, _convertUnitsLite.convert)(altitude.get('_length')).from(altitude.get('_unit')).to('in');
|
|
2108
|
+
var height = curItem.cat.info.sizeinfo.height;
|
|
2109
|
+
var currentItem = {
|
|
2110
|
+
heightFromFloor: heightFromFloor,
|
|
2111
|
+
height: height
|
|
2112
|
+
};
|
|
2113
|
+
altitude = othItem.item.properties.get('altitude');
|
|
2114
|
+
heightFromFloor = (0, _convertUnitsLite.convert)(altitude.get('_length')).from(altitude.get('_unit')).to('in');
|
|
2115
|
+
height = othItem.cat && othItem.cat.info.sizeinfo.height;
|
|
2116
|
+
var otherItem = {
|
|
2117
|
+
heightFromFloor: heightFromFloor,
|
|
2118
|
+
height: height
|
|
2119
|
+
};
|
|
2120
|
+
var curFloor = currentItem.heightFromFloor;
|
|
2121
|
+
var otherFloor = otherItem.heightFromFloor;
|
|
2122
|
+
var delta;
|
|
2123
|
+
curFloor > otherFloor ? delta = otherItem.height : delta = currentItem.height;
|
|
2124
|
+
if (Math.abs(curFloor - otherFloor) < delta) blSnap = true;
|
|
2125
|
+
if (curItem.cat.hasOwnProperty('long_name') || othItem.cat && othItem.cat.hasOwnProperty('long_name')) {
|
|
2126
|
+
if (curItem.cat.long_name.includes('Hood') || othItem.cat && othItem.cat.long_name.includes('Hood')) blSnap = true;
|
|
2127
|
+
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;
|
|
2128
|
+
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;
|
|
2129
|
+
}
|
|
2130
|
+
return blSnap;
|
|
2131
|
+
}
|
|
2132
|
+
function isFrontWall(v0, v1) {
|
|
2133
|
+
var x1 = v0.x,
|
|
2134
|
+
y1 = v0.y;
|
|
2135
|
+
var x2 = v1.x,
|
|
2136
|
+
y2 = v1.y;
|
|
2137
|
+
var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
|
|
2138
|
+
return almostEqual(y1, y2) && x1 < x2 || -Math.PI / 2 < alpha && alpha < Math.PI / 2;
|
|
2139
|
+
}
|
|
2140
|
+
function isBackWall(v0, v1) {
|
|
2141
|
+
var x1 = v0.x,
|
|
2142
|
+
y1 = v0.y;
|
|
2143
|
+
var x2 = v1.x,
|
|
2144
|
+
y2 = v1.y;
|
|
2145
|
+
var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
|
|
2146
|
+
return almostEqual(y1, y2) && x1 > x2 || -Math.PI / 2 > alpha || alpha > Math.PI / 2;
|
|
2147
|
+
}
|
|
2148
|
+
function isLeftWall(v0, v1) {
|
|
2149
|
+
var x1 = v0.x,
|
|
2150
|
+
y1 = v0.y;
|
|
2151
|
+
var x2 = v1.x,
|
|
2152
|
+
y2 = v1.y;
|
|
2153
|
+
var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
|
|
2154
|
+
return almostEqual(x1, x2) && y1 < y2 || Math.PI > alpha && alpha > 0;
|
|
2155
|
+
}
|
|
2156
|
+
function isRightWall(v0, v1) {
|
|
2157
|
+
var x1 = v0.x,
|
|
2158
|
+
y1 = v0.y;
|
|
2159
|
+
var x2 = v1.x,
|
|
2160
|
+
y2 = v1.y;
|
|
2161
|
+
var alpha = angleBetweenTwoPoints(x1, y1, x2, y2);
|
|
2162
|
+
return almostEqual(x1, x2) && y1 > y2 || -Math.PI < alpha && alpha < 0;
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
/**
|
|
2166
|
+
* Calculate the overlapping relationship of two lines
|
|
2167
|
+
* @param {*} srcLine // source line
|
|
2168
|
+
* @param {*} destLine // destination line
|
|
2169
|
+
* @returns overlapping status (OVERLAP_NONE | OVERLAP_SAME | OVERLAP_LINK | OVERLAP_INCLUDED | OVERLAP_SOME) and line segments of srcLine which broken with destLine
|
|
2170
|
+
* OVERLAP_NONE: two lines are not overlapped
|
|
2171
|
+
* OVERLAP_SAME: the start point and endpoint of two lines are same
|
|
2172
|
+
* OVERLAP_LINK: two lines are linked at the common point, so they can be merged to one line
|
|
2173
|
+
* OVERLAP_INCLUDED: destLine includes srcLine
|
|
2174
|
+
* OVERLAP_SOME: two lines are overlapped with some common range, then returns the trimmed segments of srcLine
|
|
2175
|
+
*
|
|
2176
|
+
* //////// test - start /////////////
|
|
2177
|
+
const p1 = { x1: 1413.1313131313132, y1: 1044.949494949495 };
|
|
2178
|
+
const p2 = { x1: 1476.2626262626263, y1: 1108.0808080808079 };
|
|
2179
|
+
const p3 = { x1: 1596.969696969697, y1: 1228.7878787878785 };
|
|
2180
|
+
const p4 = { x1: 1664.1414141414139, y1: 1295.9595959595958 };
|
|
2181
|
+
const tempRet = GeometryUtils.relationshipOfTwoOverlappedLines(
|
|
2182
|
+
{ x1: p3.x1, y1: p3.y1, x2: p1.x1, y2: p1.y1 },
|
|
2183
|
+
{ x1: p1.x1, y1: p1.y1, x2: p3.x1, y2: p3.y1 }
|
|
2184
|
+
);
|
|
2185
|
+
console.log(tempRet);
|
|
2186
|
+
//////// test - end /////////////
|
|
2187
|
+
|
|
2188
|
+
*/
|
|
2189
|
+
function relationshipOfTwoOverlappedLines(srcLine, destLine) {
|
|
2190
|
+
// let res1 = relationshipOfTwoOverlappedLines1(srcLine, destLine);
|
|
2191
|
+
var res2 = relationshipOfTwoOverlappedLines2(srcLine, destLine);
|
|
2192
|
+
// if (res1.result !== 0 || res2.result !== 0) {
|
|
2193
|
+
// console.group(res1.result);
|
|
2194
|
+
// console.log(res1);
|
|
2195
|
+
// console.log(res2);
|
|
2196
|
+
// console.log(srcLine, destLine);
|
|
2197
|
+
// console.groupEnd();
|
|
2198
|
+
// }
|
|
2199
|
+
return res2;
|
|
2200
|
+
}
|
|
2201
|
+
function relationshipOfTwoOverlappedLines2(srcLine, destLine) {
|
|
2202
|
+
var p1 = {
|
|
2203
|
+
x: Math.round(srcLine.x1 * 100) / 100,
|
|
2204
|
+
y: Math.round(srcLine.y1 * 100) / 100
|
|
2205
|
+
};
|
|
2206
|
+
var p2 = {
|
|
2207
|
+
x: Math.round(srcLine.x2 * 100) / 100,
|
|
2208
|
+
y: Math.round(srcLine.y2 * 100) / 100
|
|
2209
|
+
};
|
|
2210
|
+
var p3 = {
|
|
2211
|
+
x: Math.round(destLine.x1 * 100) / 100,
|
|
2212
|
+
y: Math.round(destLine.y1 * 100) / 100
|
|
2213
|
+
};
|
|
2214
|
+
var p4 = {
|
|
2215
|
+
x: Math.round(destLine.x2 * 100) / 100,
|
|
2216
|
+
y: Math.round(destLine.y2 * 100) / 100
|
|
2217
|
+
};
|
|
2218
|
+
var x1 = p1.x,
|
|
2219
|
+
y1 = p1.y;
|
|
2220
|
+
var x2 = p2.x,
|
|
2221
|
+
y2 = p2.y;
|
|
2222
|
+
var x3 = p3.x,
|
|
2223
|
+
y3 = p3.y;
|
|
2224
|
+
var x4 = p4.x,
|
|
2225
|
+
y4 = p4.y;
|
|
2226
|
+
var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
2227
|
+
var numA = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
|
|
2228
|
+
var numB = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
|
2229
|
+
if ((0, _math.fAbs)(denom) <= _constants.EPSILON) {
|
|
2230
|
+
if ((0, _math.fAbs)(numA) <= _constants.EPSILON && (0, _math.fAbs)(numB) <= _constants.EPSILON) {
|
|
2231
|
+
var comparator = function comparator(pa, pb) {
|
|
2232
|
+
return (0, _math.fAbs)(pa.x - pb.x) <= _constants.EPSILON ? pa.y - pb.y : pa.x - pb.x;
|
|
2233
|
+
};
|
|
2234
|
+
var line0 = [p1, p2].sort(comparator);
|
|
2235
|
+
var line1 = [p3, p4].sort(comparator);
|
|
2236
|
+
var _sort3 = [line0, line1].sort(function (lineA, lineB) {
|
|
2237
|
+
return comparator(lineA[0], lineB[0]);
|
|
2238
|
+
}),
|
|
2239
|
+
_sort4 = (0, _slicedToArray2["default"])(_sort3, 2),
|
|
2240
|
+
lineSX = _sort4[0],
|
|
2241
|
+
lineDX = _sort4[1];
|
|
2242
|
+
var isReversedSrcLineIdx = false;
|
|
2243
|
+
if (lineSX[0].x === line0[0].x && lineSX[0].y === line0[0].y) isReversedSrcLineIdx = false; // SX=srcLine, DX=destLine
|
|
2244
|
+
else if (lineSX[0].x === line1[0].x && lineSX[0].y === line1[0].y) isReversedSrcLineIdx = true; // DX=srcLine, SX=destLine
|
|
2245
|
+
|
|
2246
|
+
var compare0 = comparator(lineSX[0], lineDX[0]); // always <= 0
|
|
2247
|
+
var compare1 = comparator(lineSX[1], lineDX[0]);
|
|
2248
|
+
var compare2 = comparator(lineSX[1], lineDX[1]);
|
|
2249
|
+
var sp = null,
|
|
2250
|
+
ep = null;
|
|
2251
|
+
if (_export.MathUtils.fAbs(compare1) < _constants.EPSILON) {
|
|
2252
|
+
// SX
|
|
2253
|
+
// |----------|
|
|
2254
|
+
// DX
|
|
2255
|
+
// |------------|
|
|
2256
|
+
// link : lineSX[0] - lineDX[1]
|
|
2257
|
+
if (lineSX[0].x === p1.x && lineSX[0].y === p1.y || lineDX[1].x === p2.x && lineDX[1].y === p2.y) {
|
|
2258
|
+
sp = {
|
|
2259
|
+
x: lineSX[0].x,
|
|
2260
|
+
y: lineSX[0].y
|
|
2261
|
+
};
|
|
2262
|
+
ep = {
|
|
2263
|
+
x: lineDX[1].x,
|
|
2264
|
+
y: lineDX[1].y
|
|
2265
|
+
};
|
|
2266
|
+
} else {
|
|
2267
|
+
// srcLine Direction is reversed
|
|
2268
|
+
sp = {
|
|
2269
|
+
x: lineDX[1].x,
|
|
2270
|
+
y: lineDX[1].y
|
|
2271
|
+
};
|
|
2272
|
+
ep = {
|
|
2273
|
+
x: lineSX[0].x,
|
|
2274
|
+
y: lineSX[0].y
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
return {
|
|
2278
|
+
result: _constants.OVERLAP_LINK,
|
|
2279
|
+
linkedLine: {
|
|
2280
|
+
x1: sp.x,
|
|
2281
|
+
y1: sp.y,
|
|
2282
|
+
x2: ep.x,
|
|
2283
|
+
y2: ep.y
|
|
2284
|
+
}
|
|
2285
|
+
};
|
|
2286
|
+
} else if (compare1 < 0) {
|
|
2287
|
+
// SX
|
|
2288
|
+
// |----------|
|
|
2289
|
+
// DX
|
|
2290
|
+
// |----------|
|
|
2291
|
+
// none
|
|
2292
|
+
return {
|
|
2293
|
+
result: _constants.OVERLAP_NONE
|
|
2294
|
+
};
|
|
2295
|
+
} else if (_export.MathUtils.fAbs(compare0) < _constants.EPSILON && _export.MathUtils.fAbs(compare2) < _constants.EPSILON) {
|
|
2296
|
+
// SX
|
|
2297
|
+
// |----------|
|
|
2298
|
+
// DX
|
|
2299
|
+
// |----------|
|
|
2300
|
+
return {
|
|
2301
|
+
result: _constants.OVERLAP_SAME
|
|
2302
|
+
};
|
|
2303
|
+
} else if (_export.MathUtils.fAbs(compare0) < _constants.EPSILON) {
|
|
2304
|
+
if (compare2 < 0 && isReversedSrcLineIdx) {
|
|
2305
|
+
// SX
|
|
2306
|
+
// |---------------|
|
|
2307
|
+
// DX
|
|
2308
|
+
// |-----------------------|
|
|
2309
|
+
// DX includes SX, DX=srcLine, SX=destLine : sx1 - dx1
|
|
2310
|
+
if (lineDX[1].x === p2.x && lineDX[1].y === p2.y) {
|
|
2311
|
+
sp = {
|
|
2312
|
+
x: lineSX[1].x,
|
|
2313
|
+
y: lineSX[1].y
|
|
2314
|
+
};
|
|
2315
|
+
ep = {
|
|
2316
|
+
x: lineDX[1].x,
|
|
2317
|
+
y: lineDX[1].y
|
|
2318
|
+
};
|
|
2319
|
+
} else {
|
|
2320
|
+
// srcLine Direction is reversed
|
|
2321
|
+
sp = {
|
|
2322
|
+
x: lineDX[1].x,
|
|
2323
|
+
y: lineDX[1].y
|
|
2324
|
+
};
|
|
2325
|
+
ep = {
|
|
2326
|
+
x: lineSX[1].x,
|
|
2327
|
+
y: lineSX[1].y
|
|
2328
|
+
};
|
|
2329
|
+
}
|
|
2330
|
+
return {
|
|
2331
|
+
result: _constants.OVERLAP_SOME,
|
|
2332
|
+
trimmedSegs: [{
|
|
2333
|
+
x1: sp.x,
|
|
2334
|
+
y1: sp.y,
|
|
2335
|
+
x2: ep.x,
|
|
2336
|
+
y2: ep.y
|
|
2337
|
+
}]
|
|
2338
|
+
};
|
|
2339
|
+
} else if (compare2 > 0 && !isReversedSrcLineIdx) {
|
|
2340
|
+
// SX
|
|
2341
|
+
// |-----------------------|
|
|
2342
|
+
// DX
|
|
2343
|
+
// |---------------|
|
|
2344
|
+
// SX includes DX, SX=srcLine, DX=destLine : dx1 - sx1
|
|
2345
|
+
if (lineSX[1].x === p2.x && lineSX[1].y === p2.y) {
|
|
2346
|
+
sp = {
|
|
2347
|
+
x: lineDX[1].x,
|
|
2348
|
+
y: lineDX[1].y
|
|
2349
|
+
};
|
|
2350
|
+
ep = {
|
|
2351
|
+
x: lineSX[1].x,
|
|
2352
|
+
y: lineSX[1].y
|
|
2353
|
+
};
|
|
2354
|
+
} else {
|
|
2355
|
+
// srcLine Direction is reversed
|
|
2356
|
+
sp = {
|
|
2357
|
+
x: lineSX[1].x,
|
|
2358
|
+
y: lineSX[1].y
|
|
2359
|
+
};
|
|
2360
|
+
ep = {
|
|
2361
|
+
x: lineDX[1].x,
|
|
2362
|
+
y: lineDX[1].y
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
return {
|
|
2366
|
+
result: _constants.OVERLAP_SOME,
|
|
2367
|
+
trimmedSegs: [{
|
|
2368
|
+
x1: sp.x,
|
|
2369
|
+
y1: sp.y,
|
|
2370
|
+
x2: ep.x,
|
|
2371
|
+
y2: ep.y
|
|
2372
|
+
}]
|
|
2373
|
+
};
|
|
2374
|
+
} else {
|
|
2375
|
+
// srcLine
|
|
2376
|
+
// |---------------|
|
|
2377
|
+
// destLine
|
|
2378
|
+
// |-----------------------|
|
|
2379
|
+
// destLine includes srcLine
|
|
2380
|
+
return {
|
|
2381
|
+
result: _constants.OVERLAP_INCLUDED
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
} else if (_export.MathUtils.fAbs(compare2) < _constants.EPSILON) {
|
|
2385
|
+
// SX
|
|
2386
|
+
// |-----------------------|
|
|
2387
|
+
// DX
|
|
2388
|
+
// |------------------|
|
|
2389
|
+
if (isReversedSrcLineIdx) {
|
|
2390
|
+
// SX includes DX, DX=srcLine, SX=destLine
|
|
2391
|
+
// destLine includes srcLine
|
|
2392
|
+
return {
|
|
2393
|
+
result: _constants.OVERLAP_INCLUDED
|
|
2394
|
+
};
|
|
2395
|
+
} else {
|
|
2396
|
+
// SX includes DX, SX=srcLine, DX=destLine
|
|
2397
|
+
// srcLine incluedes destLine : sx0 - dx0
|
|
2398
|
+
if (lineSX[1].x === p2.x && lineSX[1].y === p2.y) {
|
|
2399
|
+
sp = {
|
|
2400
|
+
x: lineSX[0].x,
|
|
2401
|
+
y: lineSX[0].y
|
|
2402
|
+
};
|
|
2403
|
+
ep = {
|
|
2404
|
+
x: lineDX[0].x,
|
|
2405
|
+
y: lineDX[0].y
|
|
2406
|
+
};
|
|
2407
|
+
} else {
|
|
2408
|
+
// srcLine direction is reversed
|
|
2409
|
+
sp = {
|
|
2410
|
+
x: lineDX[0].x,
|
|
2411
|
+
y: lineDX[0].y
|
|
2412
|
+
};
|
|
2413
|
+
ep = {
|
|
2414
|
+
x: lineSX[0].x,
|
|
2415
|
+
y: lineSX[0].y
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
return {
|
|
2419
|
+
result: _constants.OVERLAP_SOME,
|
|
2420
|
+
trimmedSegs: [{
|
|
2421
|
+
x1: sp.x,
|
|
2422
|
+
y1: sp.y,
|
|
2423
|
+
x2: ep.x,
|
|
2424
|
+
y2: ep.y
|
|
2425
|
+
}]
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2428
|
+
} else if (compare0 < 0 && compare2 > 0) {
|
|
2429
|
+
// SX
|
|
2430
|
+
// |-----------------------|
|
|
2431
|
+
// DX
|
|
2432
|
+
// |----------------|
|
|
2433
|
+
if (isReversedSrcLineIdx) {
|
|
2434
|
+
// SX includes DX, DX=srcLine, SX=destLine
|
|
2435
|
+
// destLine includes srcLine
|
|
2436
|
+
return {
|
|
2437
|
+
result: _constants.OVERLAP_INCLUDED
|
|
2438
|
+
};
|
|
2439
|
+
} else {
|
|
2440
|
+
// SX includes DX, SX=srcLine, DX=destLine
|
|
2441
|
+
// srcLine incluedes destLine : sx0 - dx0, dx1 - sx1
|
|
2442
|
+
if (lineSX[1].x === p2.x && lineSX[1].y === p2.y) {
|
|
2443
|
+
return {
|
|
2444
|
+
result: _constants.OVERLAP_SOME,
|
|
2445
|
+
trimmedSegs: [{
|
|
2446
|
+
x1: lineSX[0].x,
|
|
2447
|
+
y1: lineSX[0].y,
|
|
2448
|
+
x2: lineDX[0].x,
|
|
2449
|
+
y2: lineDX[0].y
|
|
2450
|
+
}, {
|
|
2451
|
+
x1: lineDX[1].x,
|
|
2452
|
+
y1: lineDX[1].y,
|
|
2453
|
+
x2: lineSX[1].x,
|
|
2454
|
+
y2: lineSX[1].y
|
|
2455
|
+
}]
|
|
2456
|
+
};
|
|
2457
|
+
} else {
|
|
2458
|
+
// srcLine direction is reversed
|
|
2459
|
+
return {
|
|
2460
|
+
result: _constants.OVERLAP_SOME,
|
|
2461
|
+
trimmedSegs: [{
|
|
2462
|
+
x1: lineDX[0].x,
|
|
2463
|
+
y1: lineDX[0].y,
|
|
2464
|
+
x2: lineSX[0].x,
|
|
2465
|
+
y2: lineSX[0].y
|
|
2466
|
+
}, {
|
|
2467
|
+
x1: lineSX[1].x,
|
|
2468
|
+
y1: lineSX[1].y,
|
|
2469
|
+
x2: lineDX[1].x,
|
|
2470
|
+
y2: lineDX[1].y
|
|
2471
|
+
}]
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
} else if (compare2 < 0) {
|
|
2476
|
+
// SX
|
|
2477
|
+
// |-----------------------|
|
|
2478
|
+
// DX
|
|
2479
|
+
// |----------------------------|
|
|
2480
|
+
// overlap some
|
|
2481
|
+
if (isReversedSrcLineIdx) {
|
|
2482
|
+
// DX=srcLine, SX=destLine
|
|
2483
|
+
if (lineDX[1].x === p2.x && lineDX[1].y === p2.y) {
|
|
2484
|
+
sp = {
|
|
2485
|
+
x: lineSX[1].x,
|
|
2486
|
+
y: lineSX[1].y
|
|
2487
|
+
};
|
|
2488
|
+
ep = {
|
|
2489
|
+
x: lineDX[1].x,
|
|
2490
|
+
y: lineDX[1].y
|
|
2491
|
+
};
|
|
2492
|
+
} else {
|
|
2493
|
+
// srcLine direction is reversed
|
|
2494
|
+
sp = {
|
|
2495
|
+
x: lineDX[1].x,
|
|
2496
|
+
y: lineDX[1].y
|
|
2497
|
+
};
|
|
2498
|
+
ep = {
|
|
2499
|
+
x: lineSX[1].x,
|
|
2500
|
+
y: lineSX[1].y
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
return {
|
|
2504
|
+
result: _constants.OVERLAP_SOME,
|
|
2505
|
+
trimmedSegs: [{
|
|
2506
|
+
x1: sp.x,
|
|
2507
|
+
y1: sp.y,
|
|
2508
|
+
x2: ep.x,
|
|
2509
|
+
y2: ep.y
|
|
2510
|
+
}]
|
|
2511
|
+
};
|
|
2512
|
+
} else {
|
|
2513
|
+
// SX=srcLine, DX=destLine
|
|
2514
|
+
if (lineSX[1].x === p2.x && lineSX[1].y === p2.y) {
|
|
2515
|
+
sp = {
|
|
2516
|
+
x: lineSX[0].x,
|
|
2517
|
+
y: lineSX[0].y
|
|
2518
|
+
};
|
|
2519
|
+
ep = {
|
|
2520
|
+
x: lineDX[0].x,
|
|
2521
|
+
y: lineDX[0].y
|
|
2522
|
+
};
|
|
2523
|
+
} else {
|
|
2524
|
+
// srcLine direction is reversed
|
|
2525
|
+
sp = {
|
|
2526
|
+
x: lineDX[0].x,
|
|
2527
|
+
y: lineDX[0].y
|
|
2528
|
+
};
|
|
2529
|
+
ep = {
|
|
2530
|
+
x: lineSX[0].x,
|
|
2531
|
+
y: lineSX[0].y
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
return {
|
|
2535
|
+
result: _constants.OVERLAP_SOME,
|
|
2536
|
+
trimmedSegs: [{
|
|
2537
|
+
x1: sp.x,
|
|
2538
|
+
y1: sp.y,
|
|
2539
|
+
x2: ep.x,
|
|
2540
|
+
y2: ep.y
|
|
2541
|
+
}]
|
|
2542
|
+
};
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
return {
|
|
2548
|
+
result: _constants.OVERLAP_NONE
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
function relationshipOfTwoOverlappedLines1(srcLine, destLine) {
|
|
2552
|
+
var INFINITY = 1000000;
|
|
2553
|
+
var ZERO_DELTA = 0.01;
|
|
2554
|
+
// geometric equation of srcLine
|
|
2555
|
+
var dx1 = srcLine.x2 - srcLine.x1;
|
|
2556
|
+
dx1 = _export.MathUtils.fAbs(dx1) < ZERO_DELTA ? 0 : dx1;
|
|
2557
|
+
var dy1 = srcLine.y2 - srcLine.y1;
|
|
2558
|
+
dy1 = _export.MathUtils.fAbs(dy1) < ZERO_DELTA ? 0 : dy1;
|
|
2559
|
+
var a1 = dx1 === 0 ? INFINITY : dy1 / dx1;
|
|
2560
|
+
var b1 = a1 === INFINITY ? srcLine.x1 : srcLine.y1 - a1 * srcLine.x1;
|
|
2561
|
+
// geometric equation of destLine
|
|
2562
|
+
var dx2 = destLine.x2 - destLine.x1;
|
|
2563
|
+
dx2 = _export.MathUtils.fAbs(dx2) < ZERO_DELTA ? 0 : dx2;
|
|
2564
|
+
var dy2 = destLine.y2 - destLine.y1;
|
|
2565
|
+
dy2 = _export.MathUtils.fAbs(dy2) < ZERO_DELTA ? 0 : dy2;
|
|
2566
|
+
var a2 = dx2 === 0 ? INFINITY : dy2 / dx2;
|
|
2567
|
+
var b2 = a2 === INFINITY ? destLine.x1 : destLine.y1 - a2 * destLine.x1;
|
|
2568
|
+
if (_export.MathUtils.fAbs(_export.MathUtils.fAbs(a1) - _export.MathUtils.fAbs(a2)) > ZERO_DELTA)
|
|
2569
|
+
// two lines are not parallel
|
|
2570
|
+
return {
|
|
2571
|
+
result: _constants.OVERLAP_NONE
|
|
2572
|
+
};
|
|
2573
|
+
if (_export.MathUtils.fAbs(_export.MathUtils.fAbs(b1) - _export.MathUtils.fAbs(b2)) > ZERO_DELTA)
|
|
2574
|
+
// two lines are parallel but not overlap
|
|
2575
|
+
return {
|
|
2576
|
+
result: _constants.OVERLAP_NONE
|
|
2577
|
+
};
|
|
2578
|
+
|
|
2579
|
+
// parametric equation of destLine
|
|
2580
|
+
var sk1 = dx1 === 0 ? INFINITY : _export.MathUtils.toFixedFloat((destLine.x1 - srcLine.x1) / dx1, 3);
|
|
2581
|
+
var sk2 = dy1 === 0 ? INFINITY : _export.MathUtils.toFixedFloat((destLine.y1 - srcLine.y1) / dy1, 3);
|
|
2582
|
+
var ek1 = dx1 === 0 ? INFINITY : _export.MathUtils.toFixedFloat((destLine.x2 - srcLine.x1) / dx1, 3);
|
|
2583
|
+
var ek2 = dy1 === 0 ? INFINITY : _export.MathUtils.toFixedFloat((destLine.y2 - srcLine.y1) / dy1, 3);
|
|
2584
|
+
if (sk1 !== INFINITY && sk2 !== INFINITY && ek1 !== INFINITY && ek2 !== INFINITY && (sk1 !== sk2 || ek1 !== ek2))
|
|
2585
|
+
// destLine does not overlap with srcLine
|
|
2586
|
+
return {
|
|
2587
|
+
result: _constants.OVERLAP_NONE
|
|
2588
|
+
};
|
|
2589
|
+
|
|
2590
|
+
// parameter of destLine on the start and end points
|
|
2591
|
+
var sk = Math.min(sk1, sk2);
|
|
2592
|
+
if (Math.abs(sk) < 0.05) sk = 0;else if (Math.abs(Math.abs(sk) - 1) < 0.05) sk = 1;
|
|
2593
|
+
var ek = Math.abs(Math.min(ek1, ek2)) > 0.05 ? Math.min(ek1, ek2) : 0;
|
|
2594
|
+
if (Math.abs(ek) < 0.05) ek = 0;else if (Math.abs(Math.abs(ek) - 1) < 0.05) ek = 1;
|
|
2595
|
+
// let ek = Math.min(ek1, ek2);
|
|
2596
|
+
|
|
2597
|
+
// check the relationship between srcLine and destLine
|
|
2598
|
+
if (sk < 0 && ek < 0 || sk > 1 && ek > 1)
|
|
2599
|
+
// not overlap
|
|
2600
|
+
return {
|
|
2601
|
+
result: _constants.OVERLAP_NONE
|
|
2602
|
+
};
|
|
2603
|
+
if (sk === 0 && ek === 1 || sk === 1 && ek === 0)
|
|
2604
|
+
// same lines
|
|
2605
|
+
return {
|
|
2606
|
+
result: _constants.OVERLAP_SAME
|
|
2607
|
+
};
|
|
2608
|
+
if (sk <= 0 && ek >= 1 || sk >= 1 && ek <= 0)
|
|
2609
|
+
// destLine includes srcLine
|
|
2610
|
+
return {
|
|
2611
|
+
result: _constants.OVERLAP_INCLUDED
|
|
2612
|
+
};
|
|
2613
|
+
if (sk === 0 && ek < 0 || sk === 1 && ek > 1 || ek === 0 && sk < 0 || ek === 1 && sk > 1) {
|
|
2614
|
+
// linked with one common point
|
|
2615
|
+
var linkedLine;
|
|
2616
|
+
if (sk === 0 && ek < 0) {
|
|
2617
|
+
// destE destS srcS srcE
|
|
2618
|
+
// |----------|------------|
|
|
2619
|
+
linkedLine = {
|
|
2620
|
+
x1: destLine.x2,
|
|
2621
|
+
y1: destLine.y2,
|
|
2622
|
+
x2: srcLine.x2,
|
|
2623
|
+
y2: srcLine.y2
|
|
2624
|
+
};
|
|
2625
|
+
} else if (sk === 1 && ek > 1) {
|
|
2626
|
+
// srcS srcE destS destE
|
|
2627
|
+
// |----------|------------|
|
|
2628
|
+
linkedLine = {
|
|
2629
|
+
x1: srcLine.x1,
|
|
2630
|
+
y1: srcLine.y1,
|
|
2631
|
+
x2: destLine.x2,
|
|
2632
|
+
y2: destLine.y2
|
|
2633
|
+
};
|
|
2634
|
+
} else if (ek === 0 && sk < 0) {
|
|
2635
|
+
// destS destE srcS srcE
|
|
2636
|
+
// |----------|------------|
|
|
2637
|
+
linkedLine = {
|
|
2638
|
+
x1: destLine.x1,
|
|
2639
|
+
y1: destLine.y1,
|
|
2640
|
+
x2: srcLine.x2,
|
|
2641
|
+
y2: srcLine.y2
|
|
2642
|
+
};
|
|
2643
|
+
} else if (ek === 1 && sk > 1) {
|
|
2644
|
+
// srcS srcE destE destS
|
|
2645
|
+
// |----------|------------|
|
|
2646
|
+
linkedLine = {
|
|
2647
|
+
x1: srcLine.x1,
|
|
2648
|
+
y1: srcLine.y1,
|
|
2649
|
+
x2: destLine.x1,
|
|
2650
|
+
y2: destLine.y1
|
|
2651
|
+
};
|
|
2652
|
+
}
|
|
2653
|
+
return {
|
|
2654
|
+
result: _constants.OVERLAP_LINK,
|
|
2655
|
+
linkedLine: linkedLine
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
var trimmedSegment1 = null;
|
|
2659
|
+
var trimmedSegment2 = null;
|
|
2660
|
+
var ret = {
|
|
2661
|
+
result: _constants.OVERLAP_SOME,
|
|
2662
|
+
trimmedSegs: []
|
|
2663
|
+
};
|
|
2664
|
+
if (0 <= sk && sk <= 1 && 0 <= ek && ek <= 1) {
|
|
2665
|
+
// srcLine includes destLine
|
|
2666
|
+
if (sk < ek) {
|
|
2667
|
+
// srcS destS destE srcE
|
|
2668
|
+
// |------|---------|-------|
|
|
2669
|
+
if (sk > 0) trimmedSegment1 = {
|
|
2670
|
+
x1: srcLine.x1,
|
|
2671
|
+
y1: srcLine.y1,
|
|
2672
|
+
x2: destLine.x1,
|
|
2673
|
+
y2: destLine.y1
|
|
2674
|
+
};
|
|
2675
|
+
if (ek < 1) trimmedSegment2 = {
|
|
2676
|
+
x1: destLine.x2,
|
|
2677
|
+
y1: destLine.y2,
|
|
2678
|
+
x2: srcLine.x2,
|
|
2679
|
+
y2: srcLine.y2
|
|
2680
|
+
};
|
|
2681
|
+
} else {
|
|
2682
|
+
// srcS destE destS srcE
|
|
2683
|
+
// |------|---------|-------|
|
|
2684
|
+
if (ek > 0) trimmedSegment1 = {
|
|
2685
|
+
x1: srcLine.x1,
|
|
2686
|
+
y1: srcLine.y1,
|
|
2687
|
+
x2: destLine.x2,
|
|
2688
|
+
y2: destLine.y2
|
|
2689
|
+
};
|
|
2690
|
+
if (sk < 1) trimmedSegment2 = {
|
|
2691
|
+
x1: destLine.x1,
|
|
2692
|
+
y1: destLine.y1,
|
|
2693
|
+
x2: srcLine.x2,
|
|
2694
|
+
y2: srcLine.y2
|
|
2695
|
+
};
|
|
2696
|
+
}
|
|
2697
|
+
} else {
|
|
2698
|
+
// srcLine and destLine are overlapped with some range
|
|
2699
|
+
if (sk < 0) {
|
|
2700
|
+
// destS srcS destE srcE
|
|
2701
|
+
// |------|---------|-------|
|
|
2702
|
+
trimmedSegment1 = {
|
|
2703
|
+
x1: destLine.x2,
|
|
2704
|
+
y1: destLine.y2,
|
|
2705
|
+
x2: srcLine.x2,
|
|
2706
|
+
y2: srcLine.y2
|
|
2707
|
+
};
|
|
2708
|
+
} else if (ek < 0) {
|
|
2709
|
+
// destE srcS destS srcE
|
|
2710
|
+
// |------|---------|-------|
|
|
2711
|
+
trimmedSegment1 = {
|
|
2712
|
+
x1: destLine.x1,
|
|
2713
|
+
y1: destLine.y1,
|
|
2714
|
+
x2: srcLine.x2,
|
|
2715
|
+
y2: srcLine.y2
|
|
2716
|
+
};
|
|
2717
|
+
} else if (sk > 1) {
|
|
2718
|
+
// srcS destE srcE destS
|
|
2719
|
+
// |------|---------|-------|
|
|
2720
|
+
trimmedSegment1 = {
|
|
2721
|
+
x1: srcLine.x1,
|
|
2722
|
+
y1: srcLine.y1,
|
|
2723
|
+
x2: destLine.x2,
|
|
2724
|
+
y2: destLine.y2
|
|
2725
|
+
};
|
|
2726
|
+
} else if (ek > 1) {
|
|
2727
|
+
// srcS destS srcE destE
|
|
2728
|
+
// |------|---------|-------|
|
|
2729
|
+
trimmedSegment1 = {
|
|
2730
|
+
x1: srcLine.x1,
|
|
2731
|
+
y1: srcLine.y1,
|
|
2732
|
+
x2: destLine.x1,
|
|
2733
|
+
y2: destLine.y1
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
if (trimmedSegment1 !== null) ret.trimmedSegs.push(trimmedSegment1);
|
|
2738
|
+
if (trimmedSegment2 !== null) ret.trimmedSegs.push(trimmedSegment2);
|
|
2739
|
+
return ret;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
/**
|
|
2743
|
+
*
|
|
2744
|
+
* @param {Array} points points of polygon [[x0, y0], [x1, y1], ...]
|
|
2745
|
+
* @returns {Array} { x, y } position of centroid
|
|
2746
|
+
*/
|
|
2747
|
+
function getCentroidOfPolygon(points) {
|
|
2748
|
+
var centroid = points.reduce(function (x, y) {
|
|
2749
|
+
return [x[0] + y[0] / points.length, x[1] + y[1] / points.length];
|
|
2750
|
+
}, [0, 0]);
|
|
2751
|
+
return {
|
|
2752
|
+
x: centroid[0],
|
|
2753
|
+
y: centroid[1]
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
/**
|
|
2758
|
+
* Return the polygon points of room
|
|
2759
|
+
* @param {Object} layer
|
|
2760
|
+
* @returns {Array} polygon points [x0, y0, x1, y1, ... ]
|
|
2761
|
+
*/
|
|
2762
|
+
function getPoylgonPoints(layer) {
|
|
2763
|
+
var _layer$areas;
|
|
2764
|
+
var areainfo = [];
|
|
2765
|
+
(_layer$areas = layer.areas) === null || _layer$areas === void 0 || _layer$areas.forEach(function (area) {
|
|
2766
|
+
var _area$vertices;
|
|
2767
|
+
var sz = (_area$vertices = area.vertices) === null || _area$vertices === void 0 ? void 0 : _area$vertices.size;
|
|
2768
|
+
for (var i = 0; i < sz; i++) {
|
|
2769
|
+
areainfo.push(area.vertices.get(i));
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
var rect = [];
|
|
2773
|
+
areainfo.forEach(function (area) {
|
|
2774
|
+
var _layer$vertices;
|
|
2775
|
+
var vert = (_layer$vertices = layer.vertices) === null || _layer$vertices === void 0 ? void 0 : _layer$vertices.get(area);
|
|
2776
|
+
rect.push(vert === null || vert === void 0 ? void 0 : vert.x, vert === null || vert === void 0 ? void 0 : vert.y);
|
|
2777
|
+
});
|
|
2778
|
+
return rect;
|
|
2779
|
+
}
|
|
2780
|
+
function validRect(itemRect, rects) {
|
|
2781
|
+
var updatedItemRect = getCalcRectFromItem(itemRect);
|
|
2782
|
+
return rects.every(function (rect) {
|
|
2783
|
+
return !intersectRect(rect.rect, updatedItemRect.rect);
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
function getCalcRectFromItem2(itemInfo) {
|
|
2787
|
+
var x = itemInfo.pos.x;
|
|
2788
|
+
var y = itemInfo.pos.y;
|
|
2789
|
+
var w = itemInfo.size.width / 2;
|
|
2790
|
+
var h = itemInfo.size.height / 2;
|
|
2791
|
+
var rotRad = itemInfo.rotRad;
|
|
2792
|
+
var mx = x - w * Math.cos(rotRad);
|
|
2793
|
+
var my = y - w * Math.sin(rotRad);
|
|
2794
|
+
var m2x = x + w * Math.cos(rotRad);
|
|
2795
|
+
var m2y = y + w * Math.sin(rotRad);
|
|
2796
|
+
var m3x = x - h * Math.sin(rotRad);
|
|
2797
|
+
var m3y = y + h * Math.cos(rotRad);
|
|
2798
|
+
var m1x = x + h * Math.sin(rotRad);
|
|
2799
|
+
var m1y = y - h * Math.cos(rotRad);
|
|
2800
|
+
return {
|
|
2801
|
+
rectCenterPoint: [[point(mx, my), 180], [point(m1x, m1y), -90], [point(m2x, m2y), 0], [point(m3x, m3y), 90]]
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
function getAllItems2(curItem, layer) {
|
|
2805
|
+
var rectarray = [];
|
|
2806
|
+
layer.items.forEach(function (item) {
|
|
2807
|
+
var val = {
|
|
2808
|
+
pos: {
|
|
2809
|
+
x: item.x,
|
|
2810
|
+
y: item.y
|
|
2811
|
+
},
|
|
2812
|
+
rotRad: item.rotation / 180 * Math.PI
|
|
2813
|
+
};
|
|
2814
|
+
var width = (0, _convertUnitsLite.convert)(item.properties.getIn(['width', '_length'])).from(curItem.get('properties').get('width').get('_unit')).to('cm');
|
|
2815
|
+
var height = (0, _convertUnitsLite.convert)(item.properties.getIn(['depth', '_length'])).from(curItem.get('properties').get('depth').get('_unit')).to('cm');
|
|
2816
|
+
val.size = {
|
|
2817
|
+
width: width,
|
|
2818
|
+
height: height
|
|
2819
|
+
};
|
|
2820
|
+
var curItemTall = (0, _convertUnitsLite.convert)(curItem.get('properties').get('height').get('_length')).from(curItem.get('properties').get('height').get('_unit')).to('cm');
|
|
2821
|
+
var zMinCurItem = (0, _convertUnitsLite.convert)(curItem.get('properties').get('altitude').get('_length')).from(curItem.get('properties').get('altitude').get('_unit')).to('cm');
|
|
2822
|
+
var zMaxCurItem = zMinCurItem + curItemTall;
|
|
2823
|
+
if (curItem.get('id') !== item.id) {
|
|
2824
|
+
var detectObjectsAtSameAltitudeFlag = false;
|
|
2825
|
+
var itemTall = (0, _convertUnitsLite.convert)(item.properties.getIn(['height', '_length'])).from(item.get('properties').get('height').get('_unit')).to('cm');
|
|
2826
|
+
var zMinItem = (0, _convertUnitsLite.convert)(item.properties.getIn(['altitude', '_length'])).from(item.get('properties').get('altitude').get('_unit')).to('cm');
|
|
2827
|
+
var zMaxItem = zMinItem + itemTall;
|
|
2828
|
+
if (zMinItem - zMinCurItem >= 0 && zMaxCurItem - zMinItem > _constants.EPSILON || zMinCurItem - zMinItem >= 0 && zMaxItem - zMinCurItem > _constants.EPSILON) detectObjectsAtSameAltitudeFlag = true;
|
|
2829
|
+
if (detectObjectsAtSameAltitudeFlag) {
|
|
2830
|
+
var x = val.pos.x;
|
|
2831
|
+
var y = val.pos.y;
|
|
2832
|
+
var rotRad = val.rotRad;
|
|
2833
|
+
var w = val.size.width / 2;
|
|
2834
|
+
var h = val.size.height / 2;
|
|
2835
|
+
var mx = x - w * Math.cos(rotRad);
|
|
2836
|
+
var my = y - w * Math.sin(rotRad);
|
|
2837
|
+
var x0 = mx + h * Math.sin(rotRad);
|
|
2838
|
+
var y0 = my - h * Math.cos(rotRad);
|
|
2839
|
+
var x3 = mx * 2 - x0;
|
|
2840
|
+
var y3 = my * 2 - y0;
|
|
2841
|
+
var x1 = x * 2 - x3;
|
|
2842
|
+
var y1 = y * 2 - y3;
|
|
2843
|
+
var x2 = x * 2 - x0;
|
|
2844
|
+
var y2 = y * 2 - y0;
|
|
2845
|
+
rectarray.push({
|
|
2846
|
+
rect: [point(x0, y0), point(x1, y1), point(x0, y0), point(x1, y1)]
|
|
2847
|
+
});
|
|
2848
|
+
rectarray.push({
|
|
2849
|
+
rect: [point(x1, y1), point(x2, y2), point(x1, y1), point(x2, y2)]
|
|
2850
|
+
});
|
|
2851
|
+
rectarray.push({
|
|
2852
|
+
rect: [point(x2, y2), point(x3, y3), point(x2, y2), point(x3, y3)]
|
|
2853
|
+
});
|
|
2854
|
+
rectarray.push({
|
|
2855
|
+
rect: [point(x3, y3), point(x0, y0), point(x3, y3), point(x0, y0)]
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
});
|
|
2860
|
+
return {
|
|
2861
|
+
others: rectarray
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
2864
|
+
function calcDistancesFromItemToWalls(curItem, layer) {
|
|
2865
|
+
if ((0, _helper.isEmpty)(curItem)) return [];
|
|
2866
|
+
var x = curItem.get('x');
|
|
2867
|
+
var y = curItem.get('y');
|
|
2868
|
+
var rotRad = curItem.get('rotation') / 180 * Math.PI;
|
|
2869
|
+
var width, height;
|
|
2870
|
+
if (curItem.get('properties').get('width') || curItem.get('properties').get('depth')) {
|
|
2871
|
+
width = (0, _convertUnitsLite.convert)(curItem.get('properties').get('width').get('_length')).from(curItem.get('properties').get('width').get('_unit')).to('cm');
|
|
2872
|
+
height = (0, _convertUnitsLite.convert)(curItem.get('properties').get('depth').get('_length')).from(curItem.get('properties').get('depth').get('_unit')).to('cm');
|
|
2873
|
+
} else {
|
|
2874
|
+
width = (0, _convertUnitsLite.convert)(curItem.info.sizeinfo.width).from('in').to('cm');
|
|
2875
|
+
height = (0, _convertUnitsLite.convert)(curItem.info.sizeinfo.depth).from('in').to('cm');
|
|
2876
|
+
}
|
|
2877
|
+
var center_x = x; // middle of front line of cabinet rect
|
|
2878
|
+
var center_y = y;
|
|
2879
|
+
var PointArray = [];
|
|
2880
|
+
var itemInfo = {
|
|
2881
|
+
pos: {
|
|
2882
|
+
x: x,
|
|
2883
|
+
y: y
|
|
2884
|
+
},
|
|
2885
|
+
rotRad: rotRad
|
|
2886
|
+
};
|
|
2887
|
+
itemInfo.size = {
|
|
2888
|
+
width: width,
|
|
2889
|
+
height: height
|
|
2890
|
+
};
|
|
2891
|
+
var curiteminfo = getCalcRectFromItem2(itemInfo);
|
|
2892
|
+
var allItemRect = getAllItems2(curItem, layer); // get all item edge rects
|
|
2893
|
+
var allLines = getAllLines(layer); // get all wall lines
|
|
2894
|
+
var allLineRects = buildRectFromLines(layer, allLines); // make line rects from wall lines
|
|
2895
|
+
var allRect = allLineRects.concat(allItemRect.others); // item edges + wall lines
|
|
2896
|
+
var _loop = function _loop(i) {
|
|
2897
|
+
// [rectCenterPoint] has four middle points of cabinet rect edges
|
|
2898
|
+
var centerpoint = curiteminfo.rectCenterPoint[i];
|
|
2899
|
+
var comparelength = []; // distance array from rectCenterPoint[i] to other lines(walls, other cabinet rect edges)
|
|
2900
|
+
var a;
|
|
2901
|
+
var RectLineFuction = linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x, center_y); // normal line of cabinet rect edge
|
|
2902
|
+
|
|
2903
|
+
allRect.forEach(function (linerect) {
|
|
2904
|
+
// calc distance to all other lines
|
|
2905
|
+
var p0 = clone_point(linerect.rect[2]);
|
|
2906
|
+
var p1 = clone_point(linerect.rect[3]);
|
|
2907
|
+
var lineFunction = {}; // other line function
|
|
2908
|
+
if (p0.x !== p1.x || p0.y !== p1.y) lineFunction = linePassingThroughTwoPoints(p0.x, p0.y, p1.x, p1.y);
|
|
2909
|
+
// intersection between normal line and other line
|
|
2910
|
+
var coordinatePoint = twoLinesIntersection(lineFunction.a, lineFunction.b, lineFunction.c, RectLineFuction.a, RectLineFuction.b, RectLineFuction.c);
|
|
2911
|
+
if (coordinatePoint !== undefined) {
|
|
2912
|
+
if (
|
|
2913
|
+
// intersection point is on the other line
|
|
2914
|
+
pointsDistance(p0.x, p0.y, p1.x, p1.y) > pointsDistance(p0.x, p0.y, coordinatePoint.x, coordinatePoint.y) && pointsDistance(p0.x, p0.y, p1.x, p1.y) > pointsDistance(p1.x, p1.y, coordinatePoint.x, coordinatePoint.y)) {
|
|
2915
|
+
// check the intersection point is outside direction of edge
|
|
2916
|
+
var isOutside = true;
|
|
2917
|
+
for (var j = 0; j < curiteminfo.rectCenterPoint.length; j++) {
|
|
2918
|
+
if (j === i) continue;
|
|
2919
|
+
var otherCenterPoint = curiteminfo.rectCenterPoint[j];
|
|
2920
|
+
if (isPointOnLineSegment(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y, otherCenterPoint[0].x, otherCenterPoint[0].y)) isOutside = false;
|
|
2921
|
+
}
|
|
2922
|
+
if (isOutside && pointsDistance(coordinatePoint.x, coordinatePoint.y, center_x, center_y) > pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y)) {
|
|
2923
|
+
comparelength.push(pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y));
|
|
2924
|
+
a = Math.min.apply(null, comparelength);
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
});
|
|
2929
|
+
PointArray.push([a, centerpoint[1]]);
|
|
2930
|
+
};
|
|
2931
|
+
for (var i = 0; i < curiteminfo.rectCenterPoint.length; i++) {
|
|
2932
|
+
_loop(i);
|
|
2933
|
+
}
|
|
2934
|
+
PointArray.forEach(function (pointElement, index) {
|
|
2935
|
+
if (pointElement[0] == undefined) PointArray[index][0] = 0;
|
|
2936
|
+
});
|
|
2937
|
+
var cnt = 0;
|
|
2938
|
+
PointArray.forEach(function (pointElement) {
|
|
2939
|
+
if (pointElement[0] == 0) cnt++;
|
|
2940
|
+
});
|
|
2941
|
+
if (cnt == 4 || cnt == 3) {
|
|
2942
|
+
PointArray[0][0] = 100;
|
|
2943
|
+
PointArray[1][0] = 100;
|
|
2944
|
+
}
|
|
2945
|
+
return {
|
|
2946
|
+
PointArray: PointArray
|
|
2947
|
+
};
|
|
2948
|
+
}
|
|
2949
|
+
function calcDistancesFromHoleToNearestOneOrWall(curHole, layer) {
|
|
2950
|
+
var _layer$lines, _layer$vertices2, _line$vertices, _layer$vertices3, _line$vertices2, _curHole$properties$g, _curHole$properties, _line$get;
|
|
2951
|
+
var distArray = {
|
|
2952
|
+
distLeft: 0,
|
|
2953
|
+
distRight: 0
|
|
2954
|
+
};
|
|
2955
|
+
if ((0, _helper.isEmpty)(curHole)) return distArray;
|
|
2956
|
+
/***** calculate Left & Right distance from nearest hole ******/
|
|
2957
|
+
// parent line of curHole
|
|
2958
|
+
var line = (_layer$lines = layer.lines) === null || _layer$lines === void 0 ? void 0 : _layer$lines.get(curHole.line);
|
|
2959
|
+
var v0 = (_layer$vertices2 = layer.vertices) === null || _layer$vertices2 === void 0 ? void 0 : _layer$vertices2.get(line === null || line === void 0 || (_line$vertices = line.vertices) === null || _line$vertices === void 0 ? void 0 : _line$vertices.get(0));
|
|
2960
|
+
var v1 = (_layer$vertices3 = layer.vertices) === null || _layer$vertices3 === void 0 ? void 0 : _layer$vertices3.get(line === null || line === void 0 || (_line$vertices2 = line.vertices) === null || _line$vertices2 === void 0 ? void 0 : _line$vertices2.get(1));
|
|
2961
|
+
var lineLength = pointsDistance(v0.x, v0.y, v1.x, v1.y);
|
|
2962
|
+
if ((0, _helper.isEmpty)(line) || (0, _helper.isEmpty)(v0) || (0, _helper.isEmpty)(v1)) return distArray;
|
|
2963
|
+
var angle = angleBetweenTwoPoints(v0.x, v0.y, v1.x, v1.y);
|
|
2964
|
+
|
|
2965
|
+
// start point and end point of current hole
|
|
2966
|
+
var chw = (_curHole$properties$g = (_curHole$properties = curHole.properties) === null || _curHole$properties === void 0 || (_curHole$properties = _curHole$properties.get('width')) === null || _curHole$properties === void 0 ? void 0 : _curHole$properties.get('length')) !== null && _curHole$properties$g !== void 0 ? _curHole$properties$g : 0;
|
|
2967
|
+
var chPt = {
|
|
2968
|
+
x: v0.x + lineLength * curHole.offset * Math.cos(angle),
|
|
2969
|
+
y: v0.y + lineLength * curHole.offset * Math.sin(angle)
|
|
2970
|
+
};
|
|
2971
|
+
var chsp = {
|
|
2972
|
+
x: chPt.x - chw / 2 * Math.cos(angle),
|
|
2973
|
+
y: chPt.y - chw / 2 * Math.sin(angle)
|
|
2974
|
+
};
|
|
2975
|
+
var chep = {
|
|
2976
|
+
x: chPt.x + chw / 2 * Math.cos(angle),
|
|
2977
|
+
y: chPt.y + chw / 2 * Math.sin(angle)
|
|
2978
|
+
};
|
|
2979
|
+
distArray.distLeft = pointsDistance(v0.x, v0.y, chsp.x, chsp.y);
|
|
2980
|
+
distArray.distRight = pointsDistance(v1.x, v1.y, chep.x, chep.y);
|
|
2981
|
+
(_line$get = line.get('holes')) === null || _line$get === void 0 || _line$get.forEach(function (hId) {
|
|
2982
|
+
if (hId !== curHole.id) {
|
|
2983
|
+
var _layer$holes, _hole$properties$get$, _hole$properties;
|
|
2984
|
+
var hole = (_layer$holes = layer.holes) === null || _layer$holes === void 0 ? void 0 : _layer$holes.get(hId);
|
|
2985
|
+
// start point and end point of other hole
|
|
2986
|
+
var hw = (_hole$properties$get$ = (_hole$properties = hole.properties) === null || _hole$properties === void 0 || (_hole$properties = _hole$properties.get('width')) === null || _hole$properties === void 0 ? void 0 : _hole$properties.get('length')) !== null && _hole$properties$get$ !== void 0 ? _hole$properties$get$ : 0;
|
|
2987
|
+
var hPt = {
|
|
2988
|
+
x: v0.x + lineLength * hole.offset * Math.cos(angle),
|
|
2989
|
+
y: v0.y + lineLength * hole.offset * Math.sin(angle)
|
|
2990
|
+
};
|
|
2991
|
+
var hsp = {
|
|
2992
|
+
x: hPt.x - hw / 2 * Math.cos(angle),
|
|
2993
|
+
y: hPt.y - hw / 2 * Math.sin(angle)
|
|
2994
|
+
};
|
|
2995
|
+
var hep = {
|
|
2996
|
+
x: hPt.x + hw / 2 * Math.cos(angle),
|
|
2997
|
+
y: hPt.y + hw / 2 * Math.sin(angle)
|
|
2998
|
+
};
|
|
2999
|
+
var relation = relationshipOfTwoOverlappedLines({
|
|
3000
|
+
x1: chsp.x,
|
|
3001
|
+
y1: chsp.y,
|
|
3002
|
+
x2: chep.x,
|
|
3003
|
+
y2: chep.y
|
|
3004
|
+
}, {
|
|
3005
|
+
x1: hsp.x,
|
|
3006
|
+
y1: hsp.y,
|
|
3007
|
+
x2: hep.x,
|
|
3008
|
+
y2: hep.y
|
|
3009
|
+
});
|
|
3010
|
+
// two holes(current hole and other hole) are not overlaped, then get distance
|
|
3011
|
+
if (relation.result === _constants.OVERLAP_NONE || relation.result === _constants.OVERLAP_LINK) {
|
|
3012
|
+
if (hole.offset < curHole.offset)
|
|
3013
|
+
// other hole is on the left side
|
|
3014
|
+
distArray.distLeft = Math.min(distArray.distLeft, pointsDistance(chsp.x, chsp.y, hep.x, hep.y));
|
|
3015
|
+
// other hole is on the right side
|
|
3016
|
+
else distArray.distRight = Math.min(distArray.distRight, pointsDistance(chep.x, chep.y, hsp.x, hsp.y));
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
});
|
|
3020
|
+
return distArray;
|
|
3021
|
+
}
|
|
3022
|
+
function getSnappedWallLines(item, layer, catalog) {
|
|
3023
|
+
var _element;
|
|
3024
|
+
var snappedWallLines = [];
|
|
3025
|
+
if ((0, _helper.isEmpty)(item)) return snappedWallLines;
|
|
3026
|
+
var vertexLines = getAllLines(layer);
|
|
3027
|
+
var rectLines = buildRectFromLines(layer, vertexLines);
|
|
3028
|
+
var outline = null;
|
|
3029
|
+
var element = catalog.elements[item.get('type')];
|
|
3030
|
+
if (!element) element = catalog.elements[(0, _utils.returnReplaceableDeepSearchType)(item.get('type'))];
|
|
3031
|
+
var newWidth = item.properties.get('width').get('_length');
|
|
3032
|
+
var wUnit = item.properties.get('width').get('_unit') || 'cm';
|
|
3033
|
+
newWidth = (0, _convertUnitsLite.convert)(newWidth).from(wUnit).to('cm');
|
|
3034
|
+
var newDepth = item.properties.get('depth').get('_length');
|
|
3035
|
+
var hUnit = item.properties.get('depth').get('_unit') || 'cm';
|
|
3036
|
+
newDepth = (0, _convertUnitsLite.convert)(newDepth).from(hUnit).to('cm');
|
|
3037
|
+
var overlapList = [_constants.OVERLAP_INCLUDED, _constants.OVERLAP_SAME, _constants.OVERLAP_SOME];
|
|
3038
|
+
|
|
3039
|
+
// Get Outline Data of Selected Item
|
|
3040
|
+
outline = (_element = element) === null || _element === void 0 || (_element = _element.info) === null || _element === void 0 ? void 0 : _element.outline;
|
|
3041
|
+
if (outline) {
|
|
3042
|
+
// Extract Points from `outline`
|
|
3043
|
+
var outlinePaths = outline.paths;
|
|
3044
|
+
var outlineWidth = outline.svgWidth;
|
|
3045
|
+
var outlineHeight = outline.svgHeight;
|
|
3046
|
+
var outlinePoints = []; // Hold Points Of SVG
|
|
3047
|
+
var _iterator7 = _createForOfIteratorHelper(outlinePaths),
|
|
3048
|
+
_step7;
|
|
3049
|
+
try {
|
|
3050
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
3051
|
+
var path = _step7.value;
|
|
3052
|
+
var _iterator8 = _createForOfIteratorHelper(path.subPaths),
|
|
3053
|
+
_step8;
|
|
3054
|
+
try {
|
|
3055
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
3056
|
+
var subPath = _step8.value;
|
|
3057
|
+
outlinePoints = outlinePoints.concat(subPath.getPoints());
|
|
3058
|
+
}
|
|
3059
|
+
} catch (err) {
|
|
3060
|
+
_iterator8.e(err);
|
|
3061
|
+
} finally {
|
|
3062
|
+
_iterator8.f();
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
} catch (err) {
|
|
3066
|
+
_iterator7.e(err);
|
|
3067
|
+
} finally {
|
|
3068
|
+
_iterator7.f();
|
|
3069
|
+
}
|
|
3070
|
+
outline.reverse && outlinePoints.reverse();
|
|
3071
|
+
for (var i = 0; i < outlinePoints.length - 1; i++) {
|
|
3072
|
+
var v0 = rotatePointAroundPoint((outlinePoints[i].x / outlineWidth - 0.5) * newWidth + item.x, (outlinePoints[i].y / outlineHeight - 0.5) * newDepth + item.y, item.x, item.y, item.rotation + 90);
|
|
3073
|
+
var v1 = rotatePointAroundPoint((outlinePoints[i + 1].x / outlineWidth - 0.5) * newWidth + item.x, (outlinePoints[i + 1].y / outlineHeight - 0.5) * newDepth + item.y, item.x, item.y, item.rotation + 90);
|
|
3074
|
+
var srcLine = {
|
|
3075
|
+
x1: v0.x,
|
|
3076
|
+
y1: v0.y,
|
|
3077
|
+
x2: v1.x,
|
|
3078
|
+
y2: v1.y
|
|
3079
|
+
};
|
|
3080
|
+
var _loop2 = function _loop2(j) {
|
|
3081
|
+
var destLine1 = {
|
|
3082
|
+
x1: rectLines[j].rect[2].x,
|
|
3083
|
+
y1: rectLines[j].rect[2].y,
|
|
3084
|
+
x2: rectLines[j].rect[3].x,
|
|
3085
|
+
y2: rectLines[j].rect[3].y
|
|
3086
|
+
};
|
|
3087
|
+
var destLine2 = {
|
|
3088
|
+
x1: rectLines[j].rect[0].x,
|
|
3089
|
+
y1: rectLines[j].rect[0].y,
|
|
3090
|
+
x2: rectLines[j].rect[1].x,
|
|
3091
|
+
y2: rectLines[j].rect[1].y
|
|
3092
|
+
};
|
|
3093
|
+
if (overlapList.includes(relationshipOfTwoOverlappedLines(srcLine, destLine1).result) || overlapList.includes(relationshipOfTwoOverlappedLines(srcLine, destLine2).result)) {
|
|
3094
|
+
var idx = snappedWallLines.findIndex(function (v) {
|
|
3095
|
+
return v.id === rectLines[j].lineId;
|
|
3096
|
+
});
|
|
3097
|
+
var snapSide = 'unknown';
|
|
3098
|
+
if (idx < 0) snappedWallLines.push({
|
|
3099
|
+
id: rectLines[j].lineId,
|
|
3100
|
+
lineRect: rectLines[j].rect,
|
|
3101
|
+
snapSide: snapSide
|
|
3102
|
+
});else snappedWallLines[idx].snapSide = snapSide;
|
|
3103
|
+
}
|
|
3104
|
+
};
|
|
3105
|
+
for (var j = 0; j < (rectLines === null || rectLines === void 0 ? void 0 : rectLines.length); j++) {
|
|
3106
|
+
_loop2(j);
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
} else {
|
|
3110
|
+
var pos = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
|
|
3111
|
+
for (var _i = 0; _i < 4; _i++) {
|
|
3112
|
+
var _v = rotatePointAroundPoint(pos[_i][0] * newWidth / 2 + item.x, pos[_i][1] * newDepth / 2 + item.y, item.x, item.y, item.rotation);
|
|
3113
|
+
var _v2 = rotatePointAroundPoint(pos[(_i + 1) % 4][0] * newWidth / 2 + item.x, pos[(_i + 1) % 4][1] * newDepth / 2 + item.y, item.x, item.y, item.rotation);
|
|
3114
|
+
var _srcLine = {
|
|
3115
|
+
x1: _v.x,
|
|
3116
|
+
y1: _v.y,
|
|
3117
|
+
x2: _v2.x,
|
|
3118
|
+
y2: _v2.y
|
|
3119
|
+
};
|
|
3120
|
+
var _loop3 = function _loop3(_j) {
|
|
3121
|
+
var destLine1 = {
|
|
3122
|
+
x1: rectLines[_j].rect[2].x,
|
|
3123
|
+
y1: rectLines[_j].rect[2].y,
|
|
3124
|
+
x2: rectLines[_j].rect[3].x,
|
|
3125
|
+
y2: rectLines[_j].rect[3].y
|
|
3126
|
+
};
|
|
3127
|
+
var destLine2 = {
|
|
3128
|
+
x1: rectLines[_j].rect[0].x,
|
|
3129
|
+
y1: rectLines[_j].rect[0].y,
|
|
3130
|
+
x2: rectLines[_j].rect[1].x,
|
|
3131
|
+
y2: rectLines[_j].rect[1].y
|
|
3132
|
+
};
|
|
3133
|
+
if (overlapList.includes(relationshipOfTwoOverlappedLines(_srcLine, destLine1).result) || overlapList.includes(relationshipOfTwoOverlappedLines(_srcLine, destLine2).result)) {
|
|
3134
|
+
var idx = snappedWallLines.findIndex(function (v) {
|
|
3135
|
+
return v.id === rectLines[_j].lineId;
|
|
3136
|
+
});
|
|
3137
|
+
var snapSide = _i === 0 || _i === 2 ? 'front' : 'side';
|
|
3138
|
+
if (idx < 0) snappedWallLines.push({
|
|
3139
|
+
id: rectLines[_j].lineId,
|
|
3140
|
+
lineRect: rectLines[_j].rect,
|
|
3141
|
+
snapSide: snapSide
|
|
3142
|
+
});else snappedWallLines[idx].snapSide = snapSide;
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
for (var _j = 0; _j < (rectLines === null || rectLines === void 0 ? void 0 : rectLines.length); _j++) {
|
|
3146
|
+
_loop3(_j);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
return snappedWallLines;
|
|
3151
|
+
}
|
|
3152
|
+
function getLineSnapPointsOfItem(layer, curLine, item) {
|
|
3153
|
+
var _layer$lines2, _layer$vertices4, _line$vertices3, _layer$vertices5, _line$vertices4;
|
|
3154
|
+
// V0
|
|
3155
|
+
// /|
|
|
3156
|
+
// D0 /|-----------|
|
|
3157
|
+
// /| |
|
|
3158
|
+
// /| Item | ====> get D0, D1
|
|
3159
|
+
// /| |
|
|
3160
|
+
// D1 /|-----------|
|
|
3161
|
+
// /|
|
|
3162
|
+
// get v0, v1 of line
|
|
3163
|
+
var line = (_layer$lines2 = layer.lines) === null || _layer$lines2 === void 0 ? void 0 : _layer$lines2.get(curLine === null || curLine === void 0 ? void 0 : curLine.id);
|
|
3164
|
+
var v0 = (_layer$vertices4 = layer.vertices) === null || _layer$vertices4 === void 0 ? void 0 : _layer$vertices4.get(line === null || line === void 0 || (_line$vertices3 = line.vertices) === null || _line$vertices3 === void 0 ? void 0 : _line$vertices3.get(0));
|
|
3165
|
+
var v1 = (_layer$vertices5 = layer.vertices) === null || _layer$vertices5 === void 0 ? void 0 : _layer$vertices5.get(line === null || line === void 0 || (_line$vertices4 = line.vertices) === null || _line$vertices4 === void 0 ? void 0 : _line$vertices4.get(1));
|
|
3166
|
+
var pointGroup = [];
|
|
3167
|
+
if ((0, _helper.isEmpty)(v0) || (0, _helper.isEmpty)(v1)) return pointGroup;
|
|
3168
|
+
var itemRect = item === null || item === void 0 ? void 0 : item.rect;
|
|
3169
|
+
if (!(0, _helper.isEmpty)(itemRect)) {
|
|
3170
|
+
for (var i = 0; i < itemRect.length; i++) {
|
|
3171
|
+
if (distancePointFromLineSegment(v0, v1, itemRect[i].x, itemRect[i].y) < _constants.EPSILON) {
|
|
3172
|
+
pointGroup.push(itemRect[i]);
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
return pointGroup;
|
|
3177
|
+
}
|
|
3178
|
+
function isOverlappedTwoItemsOnOneLine(layer, curLine, srcItem, desItem) {
|
|
3179
|
+
var _layer$lines3, _layer$vertices6, _line$vertices5, _layer$vertices7, _line$vertices6, _S, _S2, _S3, _S4;
|
|
3180
|
+
if ((0, _helper.isEmpty)(layer) || (0, _helper.isEmpty)(curLine) || (0, _helper.isEmpty)(srcItem) || (0, _helper.isEmpty)(desItem) || (0, _helper.isEmpty)(desItem.D0) || (0, _helper.isEmpty)(desItem.D1)) return false;
|
|
3181
|
+
// get v0, v1 of line
|
|
3182
|
+
var line = (_layer$lines3 = layer.lines) === null || _layer$lines3 === void 0 ? void 0 : _layer$lines3.get(curLine === null || curLine === void 0 ? void 0 : curLine.id);
|
|
3183
|
+
var v0 = (_layer$vertices6 = layer.vertices) === null || _layer$vertices6 === void 0 ? void 0 : _layer$vertices6.get(line === null || line === void 0 || (_line$vertices5 = line.vertices) === null || _line$vertices5 === void 0 ? void 0 : _line$vertices5.get(0));
|
|
3184
|
+
var v1 = (_layer$vertices7 = layer.vertices) === null || _layer$vertices7 === void 0 ? void 0 : _layer$vertices7.get(line === null || line === void 0 || (_line$vertices6 = line.vertices) === null || _line$vertices6 === void 0 ? void 0 : _line$vertices6.get(1));
|
|
3185
|
+
var S0,
|
|
3186
|
+
S1,
|
|
3187
|
+
D0 = desItem === null || desItem === void 0 ? void 0 : desItem.D0,
|
|
3188
|
+
D1 = desItem === null || desItem === void 0 ? void 0 : desItem.D1;
|
|
3189
|
+
if ((0, _helper.isEmpty)(v0) || (0, _helper.isEmpty)(v1)) return false;
|
|
3190
|
+
// get distance from v0 to srcItem's S0, S1 and desItem(item or hole)'s D0, D1 are placed on line
|
|
3191
|
+
var srcPoints = getLineSnapPointsOfItem(layer, curLine, srcItem);
|
|
3192
|
+
if (srcPoints.length > 1) {
|
|
3193
|
+
S0 = srcPoints[0];
|
|
3194
|
+
S1 = srcPoints[1];
|
|
3195
|
+
}
|
|
3196
|
+
var disV0S0 = pointsDistance(v0.x, v0.y, (_S = S0) === null || _S === void 0 ? void 0 : _S.x, (_S2 = S0) === null || _S2 === void 0 ? void 0 : _S2.y);
|
|
3197
|
+
var disV0S1 = pointsDistance(v0.x, v0.y, (_S3 = S1) === null || _S3 === void 0 ? void 0 : _S3.x, (_S4 = S1) === null || _S4 === void 0 ? void 0 : _S4.y);
|
|
3198
|
+
var disV0D0 = pointsDistance(v0.x, v0.y, D0.x, D0.y);
|
|
3199
|
+
var disV0D1 = pointsDistance(v0.x, v0.y, D1.x, D1.y);
|
|
3200
|
+
// detect two items are overlapped
|
|
3201
|
+
var maxDisV0S = Math.max(disV0S0, disV0S1);
|
|
3202
|
+
var minDisV0S = Math.min(disV0S0, disV0S1);
|
|
3203
|
+
var maxDisV0D = Math.max(disV0D0, disV0D1);
|
|
3204
|
+
var minDisV0D = Math.min(disV0D0, disV0D1);
|
|
3205
|
+
if (maxDisV0S > maxDisV0D && maxDisV0D - minDisV0S > _constants.EPSILON) {
|
|
3206
|
+
// d0 s0 d1 s1 ===> maxDisV0S: v0s1, minDisV0S: v0s0, maxDisV0D: v0d1, minDisV0D: v0d0
|
|
3207
|
+
// v0 __________________________ v1
|
|
3208
|
+
// | | | |
|
|
3209
|
+
// | | | |
|
|
3210
|
+
// |__DI__|__| |
|
|
3211
|
+
// |__SI__|
|
|
3212
|
+
/////////////////////////////////////////
|
|
3213
|
+
// s0 d0 d1 s1 ===> maxDisV0S: v0s1, minDisV0S: v0s0, maxDisV0D: v0d1, minDisV0D: v0d0
|
|
3214
|
+
// v0 __________________________ v1
|
|
3215
|
+
// | | | |
|
|
3216
|
+
// | |__DI__| |
|
|
3217
|
+
// |_________SI_______|
|
|
3218
|
+
return true;
|
|
3219
|
+
} else if (minDisV0S < minDisV0D && maxDisV0S - minDisV0D > _constants.EPSILON) {
|
|
3220
|
+
// s0 d0 s1 d1 ===> maxDisV0S: v0s1, minDisV0S: v0s0, maxDisV0D: v0d1, minDisV0D: v0d0
|
|
3221
|
+
// v0 __________________________ v1
|
|
3222
|
+
// | | | |
|
|
3223
|
+
// | |__DI__|
|
|
3224
|
+
// |__SI_____|
|
|
3225
|
+
//
|
|
3226
|
+
return true;
|
|
3227
|
+
} else {
|
|
3228
|
+
return false;
|
|
3229
|
+
}
|
|
3230
|
+
}
|