@ahrowe/ui 0.33.0 → 0.35.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/README.md +101 -40
- package/dist/esm/common/accordion/accordion.mjs +1 -1
- package/dist/esm/common/accordion/accordion.mjs.map +1 -1
- package/dist/esm/common/accordion/accordion.module.mjs +1 -1
- package/dist/esm/common/accordion/accordion.module.mjs.map +1 -1
- package/dist/esm/common/accordion/accordion.plain.module.mjs +1 -1
- package/dist/esm/common/accordion/accordion.plain.module.mjs.map +1 -1
- package/dist/esm/common/accordion/accordion.primary.module.mjs +1 -1
- package/dist/esm/common/accordion/accordion.primary.module.mjs.map +1 -1
- package/dist/esm/common/accordion/accordion.types.mjs +1 -1
- package/dist/esm/common/accordion/accordion.types.mjs.map +1 -1
- package/dist/esm/common/actionButtons/actionButtons.mjs +1 -1
- package/dist/esm/common/actionButtons/actionButtons.mjs.map +1 -1
- package/dist/esm/common/actionButtons/actionButtons.module.mjs +1 -1
- package/dist/esm/common/actionIcon/actionIcon.mjs +1 -1
- package/dist/esm/common/actionIcon/actionIcon.mjs.map +1 -1
- package/dist/esm/common/actionIcon/actionIcon.module.mjs +1 -1
- package/dist/esm/common/actionIcon/actionIcon.module.mjs.map +1 -1
- package/dist/esm/common/alert/alert.mjs +1 -1
- package/dist/esm/common/alert/alert.mjs.map +1 -1
- package/dist/esm/common/alert/alert.module.mjs +1 -1
- package/dist/esm/common/alert/alert.types.mjs +1 -1
- package/dist/esm/common/alert/alert.types.mjs.map +1 -1
- package/dist/esm/common/animatedIcon/animatedIcon.mjs +1 -1
- package/dist/esm/common/animatedIcon/animatedIcon.mjs.map +1 -1
- package/dist/esm/common/animatedIcon/animatedIcon.module.mjs +1 -1
- package/dist/esm/common/animatedLogo/animatedLogo.mjs +1 -1
- package/dist/esm/common/animatedLogo/animatedLogo.mjs.map +1 -1
- package/dist/esm/common/animatedLogo/animatedLogo.module.mjs +1 -1
- package/dist/esm/common/animatedText/animatedText.mjs +1 -1
- package/dist/esm/common/animatedText/animatedText.mjs.map +1 -1
- package/dist/esm/common/animatedText/animatedText.module.mjs +1 -1
- package/dist/esm/common/animatedText/animatedText.types.mjs +1 -1
- package/dist/esm/common/animatedText/animatedText.types.mjs.map +1 -1
- package/dist/esm/common/avatar/avatar.mjs +1 -1
- package/dist/esm/common/avatar/avatar.mjs.map +1 -1
- package/dist/esm/common/avatar/avatar.module.mjs +1 -1
- package/dist/esm/common/avatar/avatarGroup.mjs +1 -1
- package/dist/esm/common/avatar/avatarGroup.mjs.map +1 -1
- package/dist/esm/common/badge/badge.mjs +1 -1
- package/dist/esm/common/badge/badge.mjs.map +1 -1
- package/dist/esm/common/badge/badge.module.mjs +1 -1
- package/dist/esm/common/badge/badge.types.mjs +1 -1
- package/dist/esm/common/badge/badge.types.mjs.map +1 -1
- package/dist/esm/common/bodyEnd/bodyEnd.mjs +1 -1
- package/dist/esm/common/bodyEnd/bodyEnd.mjs.map +1 -1
- package/dist/esm/common/breadcrumb/breadcrumb.mjs +1 -1
- package/dist/esm/common/breadcrumb/breadcrumb.mjs.map +1 -1
- package/dist/esm/common/breadcrumb/breadcrumb.module.mjs +1 -1
- package/dist/esm/common/breadcrumb/breadcrumb.module.mjs.map +1 -1
- package/dist/esm/common/button/button.mjs +1 -1
- package/dist/esm/common/button/button.mjs.map +1 -1
- package/dist/esm/common/button/button.module.mjs +1 -1
- package/dist/esm/common/button/button.types.mjs +1 -1
- package/dist/esm/common/button/button.types.mjs.map +1 -1
- package/dist/esm/common/buttonGroup/buttonGroup.mjs +1 -1
- package/dist/esm/common/buttonGroup/buttonGroup.mjs.map +1 -1
- package/dist/esm/common/buttonGroup/buttonGroup.module.mjs +1 -1
- package/dist/esm/common/buttonGroup/buttonGroup.types.mjs +1 -1
- package/dist/esm/common/buttonGroup/buttonGroup.types.mjs.map +1 -1
- package/dist/esm/common/card/Card.mjs +1 -1
- package/dist/esm/common/card/Card.mjs.map +1 -1
- package/dist/esm/common/card/CardActions.mjs +1 -1
- package/dist/esm/common/card/CardActions.mjs.map +1 -1
- package/dist/esm/common/card/CardContent.mjs +1 -1
- package/dist/esm/common/card/CardContent.mjs.map +1 -1
- package/dist/esm/common/card/CardHeader.mjs +1 -1
- package/dist/esm/common/card/CardHeader.mjs.map +1 -1
- package/dist/esm/common/card/CardMedia.mjs +1 -1
- package/dist/esm/common/card/CardMedia.mjs.map +1 -1
- package/dist/esm/common/card/card.module.mjs +1 -1
- package/dist/esm/common/card/card.module.mjs.map +1 -1
- package/dist/esm/common/card/card.types.mjs +1 -1
- package/dist/esm/common/card/card.types.mjs.map +1 -1
- package/dist/esm/common/carousel/carousel.mjs +1 -1
- package/dist/esm/common/carousel/carousel.mjs.map +1 -1
- package/dist/esm/common/carousel/carousel.module.mjs +1 -1
- package/dist/esm/common/checkbox/checkbox.mjs +1 -1
- package/dist/esm/common/checkbox/checkbox.mjs.map +1 -1
- package/dist/esm/common/checkbox/checkbox.module.mjs +1 -1
- package/dist/esm/common/checkbox/checkbox.module.mjs.map +1 -1
- package/dist/esm/common/chip/chip.mjs +1 -1
- package/dist/esm/common/chip/chip.mjs.map +1 -1
- package/dist/esm/common/chip/chip.module.mjs +1 -1
- package/dist/esm/common/chip/chip.types.mjs +1 -1
- package/dist/esm/common/chip/chip.types.mjs.map +1 -1
- package/dist/esm/common/chip/chipContainer.mjs +1 -1
- package/dist/esm/common/chip/chipContainer.mjs.map +1 -1
- package/dist/esm/common/colorPicker/colorPicker.mjs +1 -1
- package/dist/esm/common/colorPicker/colorPicker.mjs.map +1 -1
- package/dist/esm/common/colorPicker/colorPicker.module.mjs +1 -1
- package/dist/esm/common/colorPicker/colorPicker.module.mjs.map +1 -1
- package/dist/esm/common/colorPicker/toHex.mjs +1 -1
- package/dist/esm/common/colorPicker/toHex.mjs.map +1 -1
- package/dist/esm/common/configProvider/configProvider.mjs +1 -1
- package/dist/esm/common/configProvider/configProvider.mjs.map +1 -1
- package/dist/esm/common/configProvider/presentation.types.mjs +2 -0
- package/dist/esm/common/configProvider/presentation.types.mjs.map +1 -0
- package/dist/esm/common/configProvider/useComponentDefaults.mjs +1 -1
- package/dist/esm/common/configProvider/useComponentDefaults.mjs.map +1 -1
- package/dist/esm/common/configProvider/useLabels.mjs +1 -1
- package/dist/esm/common/configProvider/useLabels.mjs.map +1 -1
- package/dist/esm/common/configProvider/usePresentationDefault.mjs +1 -1
- package/dist/esm/common/configProvider/usePresentationDefault.mjs.map +1 -1
- package/dist/esm/common/confirmModal/confirmModal.mjs +1 -1
- package/dist/esm/common/confirmModal/confirmModal.mjs.map +1 -1
- package/dist/esm/common/datePicker/components/datePickerMonth/datePickerMonth.mjs +1 -1
- package/dist/esm/common/datePicker/components/datePickerMonth/datePickerMonth.mjs.map +1 -1
- package/dist/esm/common/datePicker/components/datePickerMonth/datePickerMonth.module.mjs +1 -1
- package/dist/esm/common/datePicker/components/datePickerMonth/datePickerMonth.module.mjs.map +1 -1
- package/dist/esm/common/datePicker/dateFunctions.mjs +1 -1
- package/dist/esm/common/datePicker/dateFunctions.mjs.map +1 -1
- package/dist/esm/common/datePicker/datePicker.mjs +1 -1
- package/dist/esm/common/datePicker/datePicker.mjs.map +1 -1
- package/dist/esm/common/datePicker/datePicker.module.mjs +1 -1
- package/dist/esm/common/divider/divider.mjs +1 -1
- package/dist/esm/common/divider/divider.mjs.map +1 -1
- package/dist/esm/common/divider/divider.module.mjs +1 -1
- package/dist/esm/common/divider/divider.types.mjs +1 -1
- package/dist/esm/common/divider/divider.types.mjs.map +1 -1
- package/dist/esm/common/drawer/drawer.mjs +1 -1
- package/dist/esm/common/drawer/drawer.mjs.map +1 -1
- package/dist/esm/common/drawer/drawer.module.mjs +1 -1
- package/dist/esm/common/dropZone/dropZone.mjs +1 -1
- package/dist/esm/common/dropZone/dropZone.mjs.map +1 -1
- package/dist/esm/common/dropZone/dropZone.module.mjs +1 -1
- package/dist/esm/common/dropZone/dropZone.types.mjs +1 -1
- package/dist/esm/common/dropZone/dropZone.types.mjs.map +1 -1
- package/dist/esm/common/dropdown/dropdown.mjs +1 -1
- package/dist/esm/common/dropdown/dropdown.mjs.map +1 -1
- package/dist/esm/common/dropdown/dropdown.module.mjs +1 -1
- package/dist/esm/common/dropdown/dropdown.module.mjs.map +1 -1
- package/dist/esm/common/emptyState/emptyState.mjs +1 -1
- package/dist/esm/common/emptyState/emptyState.mjs.map +1 -1
- package/dist/esm/common/emptyState/emptyState.module.mjs +1 -1
- package/dist/esm/common/errorBoundary/errorBoundary.mjs +1 -1
- package/dist/esm/common/errorBoundary/errorBoundary.mjs.map +1 -1
- package/dist/esm/common/errorBoundary/errorBoundary.module.mjs +1 -1
- package/dist/esm/common/fab/components/fabBase/fabBase.mjs +1 -1
- package/dist/esm/common/fab/components/fabBase/fabBase.mjs.map +1 -1
- package/dist/esm/common/fab/components/fabBase/fabBase.module.mjs +1 -1
- package/dist/esm/common/fab/fab.mjs +1 -1
- package/dist/esm/common/fab/fab.mjs.map +1 -1
- package/dist/esm/common/fab/fab.module.mjs +1 -1
- package/dist/esm/common/fab/fab.module.mjs.map +1 -1
- package/dist/esm/common/flip/flip.mjs +1 -1
- package/dist/esm/common/flip/flip.mjs.map +1 -1
- package/dist/esm/common/flip/flip.module.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.faces.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.faces.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.geometry.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.geometry.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.graph.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.graph.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.hit.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.hit.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.json.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.json.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.mesh.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.mesh.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.path.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.path.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.plan.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.plan.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.rooms.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.rooms.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.snap.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.snap.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.triangulate.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.triangulate.mjs.map +1 -1
- package/dist/esm/common/floorPlan/floorPlan.types.mjs +1 -1
- package/dist/esm/common/floorPlan/floorPlan.types.mjs.map +1 -1
- package/dist/esm/common/floorPlan/legacySvg.mjs +1 -1
- package/dist/esm/common/floorPlan/legacySvg.mjs.map +1 -1
- package/dist/esm/common/hooks/useAnchorTracking.mjs +1 -1
- package/dist/esm/common/hooks/useAnchorTracking.mjs.map +1 -1
- package/dist/esm/common/hooks/useCoarsePointer.mjs +1 -1
- package/dist/esm/common/hooks/useCoarsePointer.mjs.map +1 -1
- package/dist/esm/common/hooks/useFocusBoundary.mjs +1 -1
- package/dist/esm/common/hooks/useFocusBoundary.mjs.map +1 -1
- package/dist/esm/common/hooks/useMediaQuery.mjs +1 -1
- package/dist/esm/common/hooks/useMediaQuery.mjs.map +1 -1
- package/dist/esm/common/hooks/useOverlay.mjs +1 -1
- package/dist/esm/common/hooks/useOverlay.mjs.map +1 -1
- package/dist/esm/common/hooks/useSheet.mjs +1 -1
- package/dist/esm/common/hooks/useSheet.mjs.map +1 -1
- package/dist/esm/common/hooks/useSwipeDismiss.mjs +1 -1
- package/dist/esm/common/hooks/useSwipeDismiss.mjs.map +1 -1
- package/dist/esm/common/hooks/useVisualViewportSize.mjs +1 -1
- package/dist/esm/common/hooks/useVisualViewportSize.mjs.map +1 -1
- package/dist/esm/common/iconPicker/iconPicker.mjs +1 -1
- package/dist/esm/common/iconPicker/iconPicker.mjs.map +1 -1
- package/dist/esm/common/iconPicker/iconPicker.module.mjs +1 -1
- package/dist/esm/common/idleManager/idleManager.mjs +1 -1
- package/dist/esm/common/idleManager/idleManager.mjs.map +1 -1
- package/dist/esm/common/infiniteBlock/infiniteBlock.mjs +1 -1
- package/dist/esm/common/infiniteBlock/infiniteBlock.mjs.map +1 -1
- package/dist/esm/common/infiniteBlock/infiniteBlock.module.mjs +1 -1
- package/dist/esm/common/input/input.mjs +1 -1
- package/dist/esm/common/input/input.mjs.map +1 -1
- package/dist/esm/common/input/input.module.mjs +1 -1
- package/dist/esm/common/input/input.module.mjs.map +1 -1
- package/dist/esm/common/input/input.types.mjs +1 -1
- package/dist/esm/common/input/input.types.mjs.map +1 -1
- package/dist/esm/common/inputDropdown/inputDropdown.mjs +1 -1
- package/dist/esm/common/inputDropdown/inputDropdown.mjs.map +1 -1
- package/dist/esm/common/inputDropdown/inputDropdown.module.mjs +1 -1
- package/dist/esm/common/inputDropdown/inputDropdown.module.mjs.map +1 -1
- package/dist/esm/common/interactableDiv/index.mjs +1 -1
- package/dist/esm/common/interactableDiv/index.mjs.map +1 -1
- package/dist/esm/common/interactableDiv/interactableDiv.mjs +1 -1
- package/dist/esm/common/interactableDiv/interactableDiv.mjs.map +1 -1
- package/dist/esm/common/interactableDiv/interactableDiv.module.mjs +1 -1
- package/dist/esm/common/kanbanBoard/KanbanBoard.mjs +1 -1
- package/dist/esm/common/kanbanBoard/KanbanBoard.mjs.map +1 -1
- package/dist/esm/common/kanbanBoard/KanbanColumn.mjs +1 -1
- package/dist/esm/common/kanbanBoard/KanbanColumn.mjs.map +1 -1
- package/dist/esm/common/kanbanBoard/KanbanItem.mjs +1 -1
- package/dist/esm/common/kanbanBoard/KanbanItem.mjs.map +1 -1
- package/dist/esm/common/kanbanBoard/kanbanBoard.module.mjs +1 -1
- package/dist/esm/common/kanbanBoard/kanbanBoard.utils.mjs +1 -1
- package/dist/esm/common/kanbanBoard/kanbanBoard.utils.mjs.map +1 -1
- package/dist/esm/common/klipyPicker/components/gifPreview/gifPreview.mjs +1 -1
- package/dist/esm/common/klipyPicker/components/gifPreview/gifPreview.mjs.map +1 -1
- package/dist/esm/common/klipyPicker/components/gifPreview/gifPreview.module.mjs +1 -1
- package/dist/esm/common/klipyPicker/components/gifView/gifView.mjs +1 -1
- package/dist/esm/common/klipyPicker/components/gifView/gifView.mjs.map +1 -1
- package/dist/esm/common/klipyPicker/components/gifView/gifView.module.mjs +1 -1
- package/dist/esm/common/klipyPicker/klipyPicker.mjs +1 -1
- package/dist/esm/common/klipyPicker/klipyPicker.mjs.map +1 -1
- package/dist/esm/common/klipyPicker/klipyPicker.module.mjs +1 -1
- package/dist/esm/common/loading/iconLoading/iconLoading.mjs +1 -1
- package/dist/esm/common/loading/iconLoading/iconLoading.mjs.map +1 -1
- package/dist/esm/common/loading/iconLoading/iconLoading.module.mjs +1 -1
- package/dist/esm/common/loading/iconLoading/index.mjs +1 -1
- package/dist/esm/common/loading/iconLoading/index.mjs.map +1 -1
- package/dist/esm/common/loading/spinnerLoading/index.mjs +1 -1
- package/dist/esm/common/loading/spinnerLoading/index.mjs.map +1 -1
- package/dist/esm/common/loading/spinnerLoading/spinnerLoading.mjs +1 -1
- package/dist/esm/common/loading/spinnerLoading/spinnerLoading.mjs.map +1 -1
- package/dist/esm/common/loading/spinnerLoading/spinnerLoading.module.mjs +1 -1
- package/dist/esm/common/menu/menu.mjs +2 -0
- package/dist/esm/common/menu/menu.mjs.map +1 -0
- package/dist/esm/common/menu/menu.module.mjs +2 -0
- package/dist/esm/common/menu/menu.module.mjs.map +1 -0
- package/dist/esm/common/menu/menu.types.mjs +2 -0
- package/dist/esm/common/menu/menu.types.mjs.map +1 -0
- package/dist/esm/common/modal/modal.mjs +1 -1
- package/dist/esm/common/modal/modal.mjs.map +1 -1
- package/dist/esm/common/modal/modal.module.mjs +1 -1
- package/dist/esm/common/modal/modal.module.mjs.map +1 -1
- package/dist/esm/common/multiSelect/multiSelect.mjs +1 -1
- package/dist/esm/common/multiSelect/multiSelect.mjs.map +1 -1
- package/dist/esm/common/multiSelect/multiSelect.module.mjs +1 -1
- package/dist/esm/common/multiSelect/multiSelect.module.mjs.map +1 -1
- package/dist/esm/common/numberInput/index.mjs +1 -1
- package/dist/esm/common/numberInput/index.mjs.map +1 -1
- package/dist/esm/common/numberInput/numberInput.mjs +1 -1
- package/dist/esm/common/numberInput/numberInput.mjs.map +1 -1
- package/dist/esm/common/numberInput/numberInput.module.mjs +1 -1
- package/dist/esm/common/numberInput/useStepRepeat.mjs +1 -1
- package/dist/esm/common/numberInput/useStepRepeat.mjs.map +1 -1
- package/dist/esm/common/optionPicker/optionPicker.mjs +1 -1
- package/dist/esm/common/optionPicker/optionPicker.mjs.map +1 -1
- package/dist/esm/common/optionPicker/optionPicker.module.mjs +1 -1
- package/dist/esm/common/otpInput/otpInput.mjs +1 -1
- package/dist/esm/common/otpInput/otpInput.mjs.map +1 -1
- package/dist/esm/common/otpInput/otpInput.module.mjs +1 -1
- package/dist/esm/common/otpInput/otpInput.types.mjs +1 -1
- package/dist/esm/common/otpInput/otpInput.types.mjs.map +1 -1
- package/dist/esm/common/overscroll/overscroll.mjs +1 -1
- package/dist/esm/common/overscroll/overscroll.mjs.map +1 -1
- package/dist/esm/common/overscroll/overscroll.module.mjs +1 -1
- package/dist/esm/common/pagination/pagination.mjs +1 -1
- package/dist/esm/common/pagination/pagination.mjs.map +1 -1
- package/dist/esm/common/pagination/pagination.module.mjs +1 -1
- package/dist/esm/common/planCanvas/planCanvas.mjs +1 -1
- package/dist/esm/common/planCanvas/planCanvas.mjs.map +1 -1
- package/dist/esm/common/planCanvas/planCanvas.module.mjs +1 -1
- package/dist/esm/common/popover/popover.mjs +1 -1
- package/dist/esm/common/popover/popover.mjs.map +1 -1
- package/dist/esm/common/popover/popover.module.mjs +1 -1
- package/dist/esm/common/popover/popover.module.mjs.map +1 -1
- package/dist/esm/common/popover/popover.types.mjs +1 -1
- package/dist/esm/common/popover/popover.types.mjs.map +1 -1
- package/dist/esm/common/popover/usePopoverPosition.mjs +1 -1
- package/dist/esm/common/popover/usePopoverPosition.mjs.map +1 -1
- package/dist/esm/common/progressBar/progressBar.mjs +1 -1
- package/dist/esm/common/progressBar/progressBar.mjs.map +1 -1
- package/dist/esm/common/progressBar/progressBar.module.mjs +1 -1
- package/dist/esm/common/progressBar/progressBar.module.mjs.map +1 -1
- package/dist/esm/common/radioGroup/radioGroup.mjs +1 -1
- package/dist/esm/common/radioGroup/radioGroup.mjs.map +1 -1
- package/dist/esm/common/radioGroup/radioGroup.module.mjs +1 -1
- package/dist/esm/common/radioGroup/radioGroup.module.mjs.map +1 -1
- package/dist/esm/common/radioGroup/radioGroup.types.mjs +1 -1
- package/dist/esm/common/radioGroup/radioGroup.types.mjs.map +1 -1
- package/dist/esm/common/rating/rating.mjs +1 -1
- package/dist/esm/common/rating/rating.mjs.map +1 -1
- package/dist/esm/common/rating/rating.module.mjs +1 -1
- package/dist/esm/common/revealLens/revealLens.mjs +1 -1
- package/dist/esm/common/revealLens/revealLens.mjs.map +1 -1
- package/dist/esm/common/revealLens/revealLens.module.mjs +1 -1
- package/dist/esm/common/ripple/ripple.mjs +1 -1
- package/dist/esm/common/ripple/ripple.mjs.map +1 -1
- package/dist/esm/common/ripple/ripple.module.mjs +1 -1
- package/dist/esm/common/ripple/ripple.module.mjs.map +1 -1
- package/dist/esm/common/roomDrawer/roomDrawer.mjs +1 -1
- package/dist/esm/common/roomDrawer/roomDrawer.mjs.map +1 -1
- package/dist/esm/common/roomDrawer/roomDrawer.module.mjs +1 -1
- package/dist/esm/common/roomDrawer/usePlanHistory.mjs +1 -1
- package/dist/esm/common/roomDrawer/usePlanHistory.mjs.map +1 -1
- package/dist/esm/common/roomViewer/roomViewer.mjs +1 -1
- package/dist/esm/common/roomViewer/roomViewer.mjs.map +1 -1
- package/dist/esm/common/roomViewer/roomViewer.module.mjs +1 -1
- package/dist/esm/common/scrollbarProvider/index.mjs +1 -1
- package/dist/esm/common/scrollbarProvider/index.mjs.map +1 -1
- package/dist/esm/common/scrollbarProvider/scrollbarProvider.mjs +1 -1
- package/dist/esm/common/scrollbarProvider/scrollbarProvider.mjs.map +1 -1
- package/dist/esm/common/scrollbarProvider/scrollbarProvider.module.mjs +1 -1
- package/dist/esm/common/searchInput/searchInput.mjs +1 -1
- package/dist/esm/common/searchInput/searchInput.mjs.map +1 -1
- package/dist/esm/common/searchInput/searchInput.module.mjs +1 -1
- package/dist/esm/common/sectionHeader/sectionHeader.mjs +1 -1
- package/dist/esm/common/sectionHeader/sectionHeader.mjs.map +1 -1
- package/dist/esm/common/sectionHeader/sectionHeader.module.mjs +1 -1
- package/dist/esm/common/sectionHeader/sectionHeader.types.mjs +1 -1
- package/dist/esm/common/sectionHeader/sectionHeader.types.mjs.map +1 -1
- package/dist/esm/common/sheetBackdrop/sheetBackdrop.mjs +1 -1
- package/dist/esm/common/sheetBackdrop/sheetBackdrop.mjs.map +1 -1
- package/dist/esm/common/skeleton/skeleton.mjs +1 -1
- package/dist/esm/common/skeleton/skeleton.mjs.map +1 -1
- package/dist/esm/common/skeleton/skeleton.module.mjs +1 -1
- package/dist/esm/common/skeleton/skeleton.types.mjs +1 -1
- package/dist/esm/common/skeleton/skeleton.types.mjs.map +1 -1
- package/dist/esm/common/slider/slider.mjs +1 -1
- package/dist/esm/common/slider/slider.mjs.map +1 -1
- package/dist/esm/common/slider/slider.module.mjs +1 -1
- package/dist/esm/common/splitButton/splitButton.mjs +1 -1
- package/dist/esm/common/splitButton/splitButton.mjs.map +1 -1
- package/dist/esm/common/splitButton/splitButton.module.mjs +1 -1
- package/dist/esm/common/splitButton/splitButton.module.mjs.map +1 -1
- package/dist/esm/common/stepper/stepper.mjs +1 -1
- package/dist/esm/common/stepper/stepper.mjs.map +1 -1
- package/dist/esm/common/stepper/stepper.module.mjs +1 -1
- package/dist/esm/common/stepper/stepper.types.mjs +1 -1
- package/dist/esm/common/stepper/stepper.types.mjs.map +1 -1
- package/dist/esm/common/sticky/sticky.mjs +1 -1
- package/dist/esm/common/sticky/sticky.mjs.map +1 -1
- package/dist/esm/common/sticky/sticky.module.mjs +1 -1
- package/dist/esm/common/sticky/stickyStack.mjs +1 -1
- package/dist/esm/common/sticky/stickyStack.mjs.map +1 -1
- package/dist/esm/common/styles/sheet.module.mjs +1 -1
- package/dist/esm/common/styles/sheet.module.mjs.map +1 -1
- package/dist/esm/common/switch/switch.mjs +1 -1
- package/dist/esm/common/switch/switch.mjs.map +1 -1
- package/dist/esm/common/switch/switch.module.mjs +1 -1
- package/dist/esm/common/switch/switch.module.mjs.map +1 -1
- package/dist/esm/common/tabHeader/tabHeader.mjs +1 -1
- package/dist/esm/common/tabHeader/tabHeader.mjs.map +1 -1
- package/dist/esm/common/tabHeader/tabHeader.module.mjs +1 -1
- package/dist/esm/common/textarea/textarea.mjs +1 -1
- package/dist/esm/common/textarea/textarea.mjs.map +1 -1
- package/dist/esm/common/themeProvider/defaultTheme.mjs +1 -1
- package/dist/esm/common/themeProvider/defaultTheme.mjs.map +1 -1
- package/dist/esm/common/themeProvider/lightTheme.mjs +2 -0
- package/dist/esm/common/themeProvider/lightTheme.mjs.map +1 -0
- package/dist/esm/common/themeProvider/theme.module.mjs +1 -1
- package/dist/esm/common/themeProvider/themeProvider.mjs +1 -1
- package/dist/esm/common/themeProvider/themeProvider.mjs.map +1 -1
- package/dist/esm/common/themeProvider/themeVariablesContext.mjs +1 -1
- package/dist/esm/common/themeProvider/themeVariablesContext.mjs.map +1 -1
- package/dist/esm/common/themeProvider/useTheme.mjs +1 -1
- package/dist/esm/common/themeProvider/useTheme.mjs.map +1 -1
- package/dist/esm/common/tilt/tilt.mjs +1 -1
- package/dist/esm/common/tilt/tilt.mjs.map +1 -1
- package/dist/esm/common/tilt/tilt.module.mjs +1 -1
- package/dist/esm/common/tilt/tiltMath.mjs +1 -1
- package/dist/esm/common/tilt/tiltMath.mjs.map +1 -1
- package/dist/esm/common/tiltGroup/tiltGroup.mjs +1 -1
- package/dist/esm/common/tiltGroup/tiltGroup.mjs.map +1 -1
- package/dist/esm/common/timeInput/components/clockDial/clockDial.mjs +1 -1
- package/dist/esm/common/timeInput/components/clockDial/clockDial.mjs.map +1 -1
- package/dist/esm/common/timeInput/components/clockDial/clockDial.module.mjs +1 -1
- package/dist/esm/common/timeInput/timeFunctions.mjs +1 -1
- package/dist/esm/common/timeInput/timeFunctions.mjs.map +1 -1
- package/dist/esm/common/timeInput/timeInput.mjs +1 -1
- package/dist/esm/common/timeInput/timeInput.mjs.map +1 -1
- package/dist/esm/common/timeInput/timeInput.module.mjs +1 -1
- package/dist/esm/common/timeline/timeline.mjs +1 -1
- package/dist/esm/common/timeline/timeline.mjs.map +1 -1
- package/dist/esm/common/timeline/timeline.module.mjs +1 -1
- package/dist/esm/common/timeline/timeline.types.mjs +1 -1
- package/dist/esm/common/timeline/timeline.types.mjs.map +1 -1
- package/dist/esm/common/timer/timer.chime.mjs +1 -1
- package/dist/esm/common/timer/timer.chime.mjs.map +1 -1
- package/dist/esm/common/timer/timer.mjs +1 -1
- package/dist/esm/common/timer/timer.mjs.map +1 -1
- package/dist/esm/common/timer/timer.module.mjs +1 -1
- package/dist/esm/common/toast/toast.mjs +1 -1
- package/dist/esm/common/toast/toast.mjs.map +1 -1
- package/dist/esm/common/toast/toast.module.mjs +1 -1
- package/dist/esm/common/toast/toast.module.mjs.map +1 -1
- package/dist/esm/common/toast/toastProvider.mjs +1 -1
- package/dist/esm/common/toast/toastProvider.mjs.map +1 -1
- package/dist/esm/common/toast/toastService.mjs +1 -1
- package/dist/esm/common/toast/toastService.mjs.map +1 -1
- package/dist/esm/common/tooltip/tooltip.mjs +1 -1
- package/dist/esm/common/tooltip/tooltip.mjs.map +1 -1
- package/dist/esm/common/tooltip/tooltip.module.mjs +1 -1
- package/dist/esm/common/tooltip/tooltip.module.mjs.map +1 -1
- package/dist/esm/common/tree/flattenTree.mjs +1 -1
- package/dist/esm/common/tree/flattenTree.mjs.map +1 -1
- package/dist/esm/common/tree/tree.mjs +1 -1
- package/dist/esm/common/tree/tree.mjs.map +1 -1
- package/dist/esm/common/tree/tree.module.mjs +1 -1
- package/dist/esm/common/tree/tree.module.mjs.map +1 -1
- package/dist/esm/common/utils/activationKey.mjs +1 -1
- package/dist/esm/common/utils/activationKey.mjs.map +1 -1
- package/dist/esm/common/utils/mergeRefs.mjs +2 -0
- package/dist/esm/common/utils/mergeRefs.mjs.map +1 -0
- package/dist/esm/common/utils/renderIcon.mjs +1 -1
- package/dist/esm/common/utils/renderIcon.mjs.map +1 -1
- package/dist/esm/common/utils/scrollAncestors.mjs +1 -1
- package/dist/esm/common/utils/scrollAncestors.mjs.map +1 -1
- package/dist/esm/common/utils/visualViewport.mjs +1 -1
- package/dist/esm/common/utils/visualViewport.mjs.map +1 -1
- package/dist/esm/common/virtualList/useColumnResize.mjs +1 -1
- package/dist/esm/common/virtualList/useColumnResize.mjs.map +1 -1
- package/dist/esm/common/virtualList/useColumns.mjs +1 -1
- package/dist/esm/common/virtualList/useColumns.mjs.map +1 -1
- package/dist/esm/common/virtualList/useHeaderNavigation.mjs +1 -1
- package/dist/esm/common/virtualList/useHeaderNavigation.mjs.map +1 -1
- package/dist/esm/common/virtualList/useRowDrag.mjs +1 -1
- package/dist/esm/common/virtualList/useRowDrag.mjs.map +1 -1
- package/dist/esm/common/virtualList/useRowNavigation.mjs +1 -1
- package/dist/esm/common/virtualList/useRowNavigation.mjs.map +1 -1
- package/dist/esm/common/virtualList/useSelection.mjs +1 -1
- package/dist/esm/common/virtualList/useSelection.mjs.map +1 -1
- package/dist/esm/common/virtualList/useSorting.mjs +1 -1
- package/dist/esm/common/virtualList/useSorting.mjs.map +1 -1
- package/dist/esm/common/virtualList/useVirtualWindow.mjs +1 -1
- package/dist/esm/common/virtualList/useVirtualWindow.mjs.map +1 -1
- package/dist/esm/common/virtualList/virtualList.mjs +1 -1
- package/dist/esm/common/virtualList/virtualList.mjs.map +1 -1
- package/dist/esm/common/virtualList/virtualList.module.mjs +1 -1
- package/dist/esm/common/virtualList/virtualList.module.mjs.map +1 -1
- package/dist/esm/common/virtualList/virtualList.utils.mjs +1 -1
- package/dist/esm/common/virtualList/virtualList.utils.mjs.map +1 -1
- package/dist/esm/common/virtualList/virtualListHeader.mjs +1 -1
- package/dist/esm/common/virtualList/virtualListHeader.mjs.map +1 -1
- package/dist/esm/common/virtualList/virtualRow.mjs +1 -1
- package/dist/esm/common/virtualList/virtualRow.mjs.map +1 -1
- package/dist/esm/common/wizard/wizard.mjs +1 -1
- package/dist/esm/common/wizard/wizard.mjs.map +1 -1
- package/dist/esm/common/wizard/wizard.module.mjs +1 -1
- package/dist/esm/hooks/useWindowSize.mjs +1 -1
- package/dist/esm/hooks/useWindowSize.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/services/formValidation/FormValidatorGroupWithForm.mjs +1 -1
- package/dist/esm/services/formValidation/FormValidatorGroupWithForm.mjs.map +1 -1
- package/dist/esm/services/formValidation/index.mjs +1 -1
- package/dist/esm/services/formValidation/useFormValidatorGroup.mjs +1 -1
- package/dist/esm/services/formValidation/useFormValidatorGroup.mjs.map +1 -1
- package/dist/esm/services/formValidation/validatableComponent.mjs +1 -1
- package/dist/esm/services/formValidation/validatableComponent.mjs.map +1 -1
- package/dist/esm/services/klipy.mjs +1 -1
- package/dist/esm/services/klipy.mjs.map +1 -1
- package/dist/esm/services/localization.mjs +1 -1
- package/dist/esm/services/localization.mjs.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/mcp.js +21096 -5
- package/dist/style.css +1 -1
- package/dist/types/common/actionIcon/actionIcon.types.d.ts +3 -1
- package/dist/types/common/card/card.types.d.ts +3 -1
- package/dist/types/common/checkbox/checkbox.types.d.ts +3 -1
- package/dist/types/common/colorPicker/colorPicker.types.d.ts +4 -0
- package/dist/types/common/configProvider/configProvider.d.ts +1 -1
- package/dist/types/common/configProvider/configProvider.types.d.ts +6 -3
- package/dist/types/common/configProvider/index.d.ts +1 -0
- package/dist/types/common/configProvider/presentation.types.d.ts +14 -0
- package/dist/types/common/configProvider/usePresentationDefault.d.ts +1 -1
- package/dist/types/common/dropdown/dropdown.types.d.ts +1 -1
- package/dist/types/common/flip/flip.d.ts +2 -2
- package/dist/types/common/flip/flip.types.d.ts +3 -1
- package/dist/types/common/hooks/useAnchorTracking.d.ts +1 -1
- package/dist/types/common/hooks/useFocusBoundary.d.ts +3 -3
- package/dist/types/common/hooks/useSheet.d.ts +1 -1
- package/dist/types/common/input/input.types.d.ts +5 -0
- package/dist/types/common/interactableDiv/interactableDiv.d.ts +3 -2
- package/dist/types/common/loading/spinnerLoading/spinnerLoading.d.ts +0 -5
- package/dist/types/common/menu/index.d.ts +2 -0
- package/dist/types/common/menu/menu.d.ts +14 -0
- package/dist/types/common/menu/menu.types.d.ts +55 -0
- package/dist/types/common/modal/modal.types.d.ts +1 -1
- package/dist/types/common/multiSelect/multiSelect.types.d.ts +1 -1
- package/dist/types/common/numberInput/numberInput.types.d.ts +2 -0
- package/dist/types/common/otpInput/otpInput.types.d.ts +2 -0
- package/dist/types/common/planCanvas/planCanvas.d.ts +1 -1
- package/dist/types/common/planCanvas/planCanvas.types.d.ts +3 -1
- package/dist/types/common/popover/popover.types.d.ts +34 -3
- package/dist/types/common/popover/usePopoverPosition.d.ts +20 -1
- package/dist/types/common/ripple/ripple.d.ts +1 -1
- package/dist/types/common/ripple/ripple.types.d.ts +1 -0
- package/dist/types/common/roomDrawer/roomDrawer.d.ts +2 -2
- package/dist/types/common/roomDrawer/roomDrawer.types.d.ts +3 -1
- package/dist/types/common/roomViewer/roomViewer.d.ts +2 -2
- package/dist/types/common/roomViewer/roomViewer.types.d.ts +3 -1
- package/dist/types/common/searchInput/searchInput.d.ts +1 -1
- package/dist/types/common/searchInput/searchInput.types.d.ts +3 -0
- package/dist/types/common/splitButton/splitButton.types.d.ts +3 -3
- package/dist/types/common/switch/switch.types.d.ts +3 -1
- package/dist/types/common/themeProvider/index.d.ts +1 -0
- package/dist/types/common/themeProvider/lightTheme.d.ts +13 -0
- package/dist/types/common/tilt/tilt.d.ts +2 -2
- package/dist/types/common/tilt/tilt.types.d.ts +3 -1
- package/dist/types/common/timer/timer.d.ts +2 -2
- package/dist/types/common/timer/timer.types.d.ts +3 -1
- package/dist/types/common/tooltip/tooltip.d.ts +1 -1
- package/dist/types/common/tooltip/tooltip.types.d.ts +7 -0
- package/dist/types/common/types/baseProps.types.d.ts +6 -0
- package/dist/types/common/utils/mergeRefs.d.ts +12 -0
- package/dist/types/common/virtualList/virtualList.d.ts +2 -4
- package/dist/types/common/virtualList/virtualList.types.d.ts +3 -1
- package/dist/types/index.d.ts +2 -2
- package/docs/Accordion.md +9 -0
- package/docs/ActionIcon.md +1 -0
- package/docs/Breadcrumb.md +2 -2
- package/docs/ButtonGroup.md +1 -1
- package/docs/CLAUDE.md +38 -1
- package/docs/Card.md +2 -1
- package/docs/Checkbox.md +1 -0
- package/docs/ColorPicker.md +13 -1
- package/docs/ConfigProvider.md +2 -2
- package/docs/Dropdown.md +1 -1
- package/docs/Input.md +1 -0
- package/docs/InputDropdown.md +1 -1
- package/docs/InteractableDiv.md +2 -0
- package/docs/KlipyPicker.md +1 -1
- package/docs/Menu.md +107 -0
- package/docs/Modal.md +1 -1
- package/docs/NumberInput.md +1 -0
- package/docs/OtpInput.md +1 -0
- package/docs/Popover.md +11 -5
- package/docs/SearchInput.md +1 -0
- package/docs/SplitButton.md +8 -4
- package/docs/Switch.md +1 -0
- package/docs/Textarea.md +1 -0
- package/docs/ThemeProvider.md +31 -2
- package/docs/Tooltip.md +23 -1
- package/docs/VirtualList.md +2 -2
- package/package.json +8 -7
- package/dist/esm/common/floatingMenu/floatingMenu.mjs +0 -2
- package/dist/esm/common/floatingMenu/floatingMenu.mjs.map +0 -1
- package/dist/esm/common/floatingMenu/floatingMenu.module.mjs +0 -2
- package/dist/esm/common/floatingMenu/floatingMenu.module.mjs.map +0 -1
- package/dist/esm/common/floatingMenu/floatingMenu.types.mjs +0 -2
- package/dist/esm/common/floatingMenu/floatingMenu.types.mjs.map +0 -1
- package/dist/esm/common/floatingMenu/useFloatingPosition.mjs +0 -2
- package/dist/esm/common/floatingMenu/useFloatingPosition.mjs.map +0 -1
- package/dist/types/common/floatingMenu/floatingMenu.d.ts +0 -3
- package/dist/types/common/floatingMenu/floatingMenu.types.d.ts +0 -32
- package/dist/types/common/floatingMenu/index.d.ts +0 -2
- package/dist/types/common/floatingMenu/useFloatingPosition.d.ts +0 -27
- package/docs/FloatingMenu.md +0 -90
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floorPlan.mesh.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.mesh.ts"],"sourcesContent":["/**\n * Turns a floor into triangles: wall solids with their openings cut out, and a floor\n * slab under them.\n *\n * Plain arrays, no renderer and no dependency. `positions`/`normals`/`indices` is the\n * shape every engine takes, so the result feeds three.js, Babylon, a glTF writer or a\n * software rasteriser without this package having an opinion about which.\n *\n * AXES: plan x becomes world x, plan y becomes world z, and world y is up. A plan is\n * drawn in SVG's y-down space, so that mapping is a handedness flip, which is why\n * winding is fixed per face here rather than inherited from the 2D rings.\n *\n * Openings are cut by SPLITTING the wall, not by subtracting solids. Every opening is an\n * axis-aligned rectangle in its wall's own plane, so the wall falls into at most three\n * prisms — under the sill, over the head, and the full-height stretches between openings.\n * That is exact, and it needs no CSG.\n */\n\nimport { dist } from './floorPlan.geometry';\nimport { derivePlan } from './floorPlan.rooms';\nimport { wallCentrelineSpans } from './floorPlan.path';\nimport { triangulate } from './floorPlan.triangulate';\nimport type { PlanFloor, PlanOpening, PlanPoint, PlanWall } from './floorPlan.types';\n\nconst EPS = 1e-6;\n\n/**\n * Millimetres the walls drop past the slab, so the two solids never share a face.\n *\n * A wall overlaps the slab it stands over, because the slab reaches the wall centrelines\n * and the wall straddles them. Land their undersides on the same plane and the two\n * downward faces fight for the same pixels, which speckles the whole underside of the\n * building. One millimetre on a slab of a couple of hundred puts the wall's face clear\n * below and the slab's inside the wall, so each height has exactly one surface at it.\n */\nconst Z_BIAS = 1;\n\nexport type PlanMeshPart = 'wall' | 'floor';\n\nexport interface PlanMeshGroup {\n part: PlanMeshPart;\n /** Offset into `indices`, and how many of them. Draw ranges, or assign materials. */\n start: number;\n count: number;\n}\n\nexport interface PlanMesh {\n /** World-space xyz triples, in millimetres. */\n positions: Float32Array;\n /** Unit face normals, one per vertex. */\n normals: Float32Array;\n indices: Uint32Array;\n groups: PlanMeshGroup[];\n}\n\nexport interface BuildPlanMeshOptions {\n /** Storey height for walls that do not carry their own. Defaults to the floor's. */\n wallHeight?: number;\n /** Lay a slab under each room. Default true. */\n includeFloorSlab?: boolean;\n /** Millimetres. The slab hangs below the floor level. Default 200. */\n slabThickness?: number;\n /**\n * Lift everything by the floor's own elevation, so several storeys stack into one\n * scene. Default true.\n */\n applyElevation?: boolean;\n}\n\n/** Accumulates triangles as flat arrays, with a face normal per triangle. */\nclass MeshBuilder {\n readonly positions: number[] = [];\n readonly normals: number[] = [];\n readonly indices: number[] = [];\n\n /**\n * One triangle, with its vertices duplicated rather than shared.\n *\n * Walls are flat-shaded: sharing a vertex between two faces would average their\n * normals and round off a corner that is physically square.\n */\n triangle(a: number[], b: number[], c: number[]): void {\n const ux = b[0] - a[0];\n const uy = b[1] - a[1];\n const uz = b[2] - a[2];\n const vx = c[0] - a[0];\n const vy = c[1] - a[1];\n const vz = c[2] - a[2];\n let nx = uy * vz - uz * vy;\n let ny = uz * vx - ux * vz;\n let nz = ux * vy - uy * vx;\n const len = Math.hypot(nx, ny, nz);\n if (len < EPS) return; // degenerate: contributes nothing and has no normal\n nx /= len;\n ny /= len;\n nz /= len;\n\n const base = this.positions.length / 3;\n for (const p of [a, b, c]) this.positions.push(p[0], p[1], p[2]);\n for (let i = 0; i < 3; i++) this.normals.push(nx, ny, nz);\n this.indices.push(base, base + 1, base + 2);\n }\n\n /** A planar quad as two triangles, wound so its normal follows a -> b -> c. */\n quad(a: number[], b: number[], c: number[], d: number[]): void {\n this.triangle(a, b, c);\n this.triangle(a, c, d);\n }\n}\n\n/**\n * A wall as a box: its footprint corners in plan, and the heights it spans.\n *\n * The footprint is the centreline offset by half the thickness each way. Walls that meet\n * at a corner overlap slightly inside the joint rather than mitring into each other; for\n * an opaque solid that is invisible from any angle, and it keeps each wall a closed box\n * instead of a shape that depends on its neighbours.\n */\n/** The walls meeting at each node, for mitring a corner. */\nfunction wallsByNode(floor: PlanFloor): Map<string, PlanWall[]> {\n const at = new Map<string, PlanWall[]>();\n for (const wall of Object.values(floor.walls)) {\n for (const id of [wall.a, wall.b]) {\n const list = at.get(id);\n if (list) list.push(wall);\n else at.set(id, [wall]);\n }\n }\n return at;\n}\n\n/** How far a mitre may run before the corner is left square, as multiples of half a wall. */\nconst MITRE_LIMIT = 4;\n\n/**\n * How far the footprint's two edges reach past a node, as a vector to be scaled by half\n * the thickness and added on the wall's left, subtracted on its right.\n *\n * Two walls meeting at a corner both STOP at the shared node, so between them they leave\n * a square of half a thickness uncovered on the outside of the turn — the same notch the\n * 2D renderer fills with a mitre join, cut here through the full height of the wall.\n * Extending both walls to where their edges actually cross closes it.\n *\n * `null` leaves the end square: at a junction there is no single corner to mitre to, at a\n * change of thickness the two edges are offset by different amounts, and past the mitre\n * limit an acute corner would run away into a spike.\n */\nfunction mitreVector(floor: PlanFloor, wall: PlanWall, nodeId: string, at: Map<string, PlanWall[]>): PlanPoint | null {\n const here = at.get(nodeId);\n if (!here || here.length !== 2) return null;\n const other = here[0].id === wall.id ? here[1] : here[0];\n if (other.thickness !== wall.thickness) return null;\n\n const node = floor.nodes[nodeId];\n const far = floor.nodes[wall.a === nodeId ? wall.b : wall.a];\n const onward = floor.nodes[other.a === nodeId ? other.b : other.a];\n if (!node || !far || !onward) return null;\n\n // Into the corner along this wall, then out along its neighbour.\n const u = unit(far, node);\n const v = unit(node, onward);\n if (!u || !v) return null;\n\n const along = u.x * v.x + u.y * v.y;\n if (along < -1 + EPS) return null; // doubles back on itself: no corner to speak of\n const nu = { x: -u.y, y: u.x };\n const nv = { x: -v.y, y: v.x };\n const scale = 1 + along;\n const mitre = { x: (nu.x + nv.x) / scale, y: (nu.y + nv.y) / scale };\n if (Math.hypot(mitre.x, mitre.y) > MITRE_LIMIT) return null;\n\n // Returned on the wall's own left, which is `u`'s left at this end.\n return wall.b === nodeId ? mitre : { x: -mitre.x, y: -mitre.y };\n}\n\nfunction unit(from: PlanPoint, to: PlanPoint): PlanPoint | null {\n const len = dist(from, to);\n if (len < EPS) return null;\n return { x: (to.x - from.x) / len, y: (to.y - from.y) / len };\n}\n\n/**\n * The stretch of a wall between two offsets along it, as a footprint quad.\n *\n * Ends that are the wall's true ends are mitred into their neighbour; ends created by an\n * opening are left square, because a jamb is a square face.\n */\nfunction footprintBetween(\n floor: PlanFloor,\n wall: PlanWall,\n from: number,\n to: number,\n at: Map<string, PlanWall[]>,\n): [PlanPoint, PlanPoint, PlanPoint, PlanPoint] | null {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return null;\n const len = dist(a, b);\n if (len < EPS || to - from < EPS) return null;\n\n const d = unit(a, b)!;\n const half = wall.thickness / 2;\n const n = { x: -d.y * half, y: d.x * half };\n\n const start = { x: a.x + d.x * from, y: a.y + d.y * from };\n const end = { x: a.x + d.x * to, y: a.y + d.y * to };\n\n const mitreA = from < EPS ? mitreVector(floor, wall, wall.a, at) : null;\n const mitreB = to > len - EPS ? mitreVector(floor, wall, wall.b, at) : null;\n\n const offset = (p: PlanPoint, m: PlanPoint | null, sign: 1 | -1) =>\n m ? { x: p.x + m.x * half * sign, y: p.y + m.y * half * sign } : { x: p.x + n.x * sign, y: p.y + n.y * sign };\n\n return [offset(start, mitreA, 1), offset(end, mitreB, 1), offset(end, mitreB, -1), offset(start, mitreA, -1)];\n}\n\n/** A closed box over a footprint, between two heights. */\nfunction box(mesh: MeshBuilder, foot: readonly PlanPoint[], bottom: number, top: number): void {\n if (top - bottom < EPS) return;\n const lo = foot.map((p) => [p.x, bottom, p.y]);\n const hi = foot.map((p) => [p.x, top, p.y]);\n\n /*\n * Which way round the footprint runs decides which way the faces look. Plan y becomes\n * world z with y up, which is a handedness flip, so a footprint that reads\n * counter-clockwise in plan comes out clockwise seen from above and its faces would\n * point inwards. Hence the inversion rather than taking the plan winding at its word.\n */\n let twice = 0;\n for (let i = 0; i < foot.length; i++) {\n const p = foot[i];\n const q = foot[(i + 1) % foot.length];\n twice += p.x * q.y - q.x * p.y;\n }\n const ccw = twice < 0;\n\n for (let i = 0; i < foot.length; i++) {\n const j = (i + 1) % foot.length;\n if (ccw) mesh.quad(lo[i], lo[j], hi[j], hi[i]);\n else mesh.quad(lo[j], lo[i], hi[i], hi[j]);\n }\n\n // Caps. A footprint is always convex here — it is a rectangle — so a fan is enough.\n for (let i = 1; i + 1 < foot.length; i++) {\n if (ccw) {\n mesh.triangle(hi[0], hi[i], hi[i + 1]);\n mesh.triangle(lo[0], lo[i + 1], lo[i]);\n } else {\n mesh.triangle(hi[0], hi[i + 1], hi[i]);\n mesh.triangle(lo[0], lo[i], lo[i + 1]);\n }\n }\n}\n\n/** The openings on one wall, clamped to it and sorted along it. */\nfunction openingsOn(floor: PlanFloor, wall: PlanWall, length: number): PlanOpening[] {\n return Object.values(floor.openings)\n .filter((o) => o.wallId === wall.id)\n .filter((o) => o.offset + o.width / 2 > EPS && o.offset - o.width / 2 < length - EPS)\n .sort((a, b) => a.offset - b.offset);\n}\n\n/**\n * Triangles for one floor: every wall, with its openings cut out, and a slab per room.\n *\n * Call it per storey and concatenate to build a whole building; each floor already knows\n * its own elevation.\n */\nexport function buildPlanMesh(floor: PlanFloor, options: BuildPlanMeshOptions = {}): PlanMesh {\n const { wallHeight, includeFloorSlab = true, slabThickness = 200, applyElevation = true } = options;\n\n const mesh = new MeshBuilder();\n const groups: PlanMeshGroup[] = [];\n const base = applyElevation ? floor.elevation : 0;\n\n /*\n * `elevation` is the FINISHED FLOOR LEVEL, so a storey's slab hangs below it. Walls\n * start at the slab's underside rather than at the level itself, which is to say they\n * clothe the floor plate the way a facade does instead of stopping short of it.\n *\n * That keeps a wall exactly `floor.height` tall, and makes each storey's walls meet the\n * ones below face to face: this storey starts at `elevation - slab`, and the storey\n * below ends there too. No band of exposed slab between them, and nothing overlapping\n * along the facade.\n */\n const slabDrop = includeFloorSlab ? slabThickness + Z_BIAS : 0;\n\n // ── Walls ──────────────────────────────────────────────────────────────────────\n const atNode = wallsByNode(floor);\n const wallStart = mesh.indices.length;\n for (const wall of Object.values(floor.walls)) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) continue;\n const length = dist(a, b);\n if (length < EPS) continue;\n\n const bottom = base + (wall.baseHeight ?? 0) - slabDrop;\n const top = bottom + (wall.height ?? wallHeight ?? floor.height);\n if (top - bottom < EPS) continue;\n\n const openings = openingsOn(floor, wall, length);\n if (openings.length === 0) {\n const foot = footprintBetween(floor, wall, 0, length, atNode);\n if (foot) box(mesh, foot, bottom, top);\n continue;\n }\n\n // Full-height stretches between the openings, from `wallCentrelineSpans` so the\n // solid is cut exactly where the drawing is.\n for (const [from, to] of wallCentrelineSpans(floor, wall)) {\n const foot = footprintBetween(floor, wall, from, to, atNode);\n if (foot) box(mesh, foot, bottom, top);\n }\n\n // Then the lintel over each opening and the upstand under it.\n for (const opening of openings) {\n const from = Math.max(0, opening.offset - opening.width / 2);\n const to = Math.min(length, opening.offset + opening.width / 2);\n const foot = footprintBetween(floor, wall, from, to, atNode);\n if (!foot) continue;\n const sill = bottom + Math.max(0, opening.sill);\n const head = bottom + Math.max(0, opening.head);\n if (sill > bottom + EPS) box(mesh, foot, bottom, Math.min(sill, top));\n if (head < top - EPS) box(mesh, foot, Math.max(head, bottom), top);\n }\n }\n if (mesh.indices.length > wallStart) {\n groups.push({ part: 'wall', start: wallStart, count: mesh.indices.length - wallStart });\n }\n\n // ── Floor slabs ────────────────────────────────────────────────────────────────\n if (includeFloorSlab) {\n const slabStart = mesh.indices.length;\n for (const room of derivePlan(floor).rooms) {\n const { vertices, indices } = triangulate(room.outer, room.holes);\n if (indices.length === 0) continue;\n const top = base;\n const bottom = base - slabThickness;\n\n for (let i = 0; i < indices.length; i += 3) {\n const t = [vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]];\n const up = t.map((q) => [q.x, top, q.y]);\n const down = t.map((q) => [q.x, bottom, q.y]);\n // `triangulate` returns counter-clockwise triangles in plan space; the y-down to\n // y-up flip reverses that, so the top face is wound the other way here.\n mesh.triangle(up[0], up[2], up[1]);\n mesh.triangle(down[0], down[1], down[2]);\n }\n\n // The slab's edge, so it is a solid rather than two sheets.\n for (const ring of [room.outer, ...room.holes]) {\n for (let i = 0; i < ring.length; i++) {\n const q = ring[i];\n const r = ring[(i + 1) % ring.length];\n // Wound so the face looks away from the solid. Holes come back wound opposite\n // to the outer ring, so walking each ring as it is gives both the right way out.\n mesh.quad([q.x, bottom, q.y], [q.x, top, q.y], [r.x, top, r.y], [r.x, bottom, r.y]);\n }\n }\n }\n if (mesh.indices.length > slabStart) {\n groups.push({ part: 'floor', start: slabStart, count: mesh.indices.length - slabStart });\n }\n }\n\n return {\n positions: new Float32Array(mesh.positions),\n normals: new Float32Array(mesh.normals),\n indices: new Uint32Array(mesh.indices),\n groups,\n };\n}\n"],"mappings":"wNAwBA,IAAM,EAAM,KAWN,EAAS,EAmCT,EAAN,KAAkB,eACe,KAAA,UAAA,CAAC,EACH,KAAA,QAAA,CAAC,EACD,KAAA,QAAA,CAAC,EAQ9B,SAAS,EAAa,EAAa,EAAmB,CACpD,IAAM,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAA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AO,EACrC,QACF,CACF"}
|
|
1
|
+
{"version":3,"file":"floorPlan.mesh.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.mesh.ts"],"sourcesContent":["/**\n * Turns a floor into triangles: wall solids with their openings cut out, and a floor\n * slab under them.\n *\n * Plain arrays, no renderer and no dependency. `positions`/`normals`/`indices` is the\n * shape every engine takes, so the result feeds three.js, Babylon, a glTF writer or a\n * software rasteriser without this package having an opinion about which.\n *\n * AXES: plan x becomes world x, plan y becomes world z, and world y is up. A plan is\n * drawn in SVG's y-down space, so that mapping is a handedness flip, which is why\n * winding is fixed per face here rather than inherited from the 2D rings.\n *\n * Openings are cut by SPLITTING the wall, not by subtracting solids. Every opening is an\n * axis-aligned rectangle in its wall's own plane, so the wall falls into at most three\n * prisms — under the sill, over the head, and the full-height stretches between openings.\n * That is exact, and it needs no CSG.\n */\n\nimport { dist } from './floorPlan.geometry';\nimport { derivePlan } from './floorPlan.rooms';\nimport { wallCentrelineSpans } from './floorPlan.path';\nimport { triangulate } from './floorPlan.triangulate';\nimport type { PlanFloor, PlanOpening, PlanPoint, PlanWall } from './floorPlan.types';\n\nconst EPS = 1e-6;\n\n/**\n * Millimetres the walls drop past the slab, so the two solids never share a face.\n *\n * A wall overlaps the slab it stands over, because the slab reaches the wall centrelines\n * and the wall straddles them. Land their undersides on the same plane and the two\n * downward faces fight for the same pixels, which speckles the whole underside of the\n * building. One millimetre on a slab of a couple of hundred puts the wall's face clear\n * below and the slab's inside the wall, so each height has exactly one surface at it.\n */\nconst Z_BIAS = 1;\n\nexport type PlanMeshPart = 'wall' | 'floor';\n\nexport interface PlanMeshGroup {\n part: PlanMeshPart;\n /** Offset into `indices`, and how many of them. Draw ranges, or assign materials. */\n start: number;\n count: number;\n}\n\nexport interface PlanMesh {\n /** World-space xyz triples, in millimetres. */\n positions: Float32Array;\n /** Unit face normals, one per vertex. */\n normals: Float32Array;\n indices: Uint32Array;\n groups: PlanMeshGroup[];\n}\n\nexport interface BuildPlanMeshOptions {\n /** Storey height for walls that do not carry their own. Defaults to the floor's. */\n wallHeight?: number;\n /** Lay a slab under each room. Default true. */\n includeFloorSlab?: boolean;\n /** Millimetres. The slab hangs below the floor level. Default 200. */\n slabThickness?: number;\n /**\n * Lift everything by the floor's own elevation, so several storeys stack into one\n * scene. Default true.\n */\n applyElevation?: boolean;\n}\n\n/** Accumulates triangles as flat arrays, with a face normal per triangle. */\nclass MeshBuilder {\n readonly positions: number[] = [];\n readonly normals: number[] = [];\n readonly indices: number[] = [];\n\n /**\n * One triangle, with its vertices duplicated rather than shared.\n *\n * Walls are flat-shaded: sharing a vertex between two faces would average their\n * normals and round off a corner that is physically square.\n */\n triangle(a: number[], b: number[], c: number[]): void {\n const ux = b[0] - a[0];\n const uy = b[1] - a[1];\n const uz = b[2] - a[2];\n const vx = c[0] - a[0];\n const vy = c[1] - a[1];\n const vz = c[2] - a[2];\n let nx = uy * vz - uz * vy;\n let ny = uz * vx - ux * vz;\n let nz = ux * vy - uy * vx;\n const len = Math.hypot(nx, ny, nz);\n if (len < EPS) return; // degenerate: contributes nothing and has no normal\n nx /= len;\n ny /= len;\n nz /= len;\n\n const base = this.positions.length / 3;\n for (const p of [a, b, c]) this.positions.push(p[0], p[1], p[2]);\n for (let i = 0; i < 3; i++) this.normals.push(nx, ny, nz);\n this.indices.push(base, base + 1, base + 2);\n }\n\n /** A planar quad as two triangles, wound so its normal follows a -> b -> c. */\n quad(a: number[], b: number[], c: number[], d: number[]): void {\n this.triangle(a, b, c);\n this.triangle(a, c, d);\n }\n}\n\n/**\n * A wall as a box: its footprint corners in plan, and the heights it spans.\n *\n * The footprint is the centreline offset by half the thickness each way. Walls that meet\n * at a corner overlap slightly inside the joint rather than mitring into each other; for\n * an opaque solid that is invisible from any angle, and it keeps each wall a closed box\n * instead of a shape that depends on its neighbours.\n */\n/** The walls meeting at each node, for mitring a corner. */\nfunction wallsByNode(floor: PlanFloor): Map<string, PlanWall[]> {\n const at = new Map<string, PlanWall[]>();\n for (const wall of Object.values(floor.walls)) {\n for (const id of [wall.a, wall.b]) {\n const list = at.get(id);\n if (list) list.push(wall);\n else at.set(id, [wall]);\n }\n }\n return at;\n}\n\n/** How far a mitre may run before the corner is left square, as multiples of half a wall. */\nconst MITRE_LIMIT = 4;\n\n/**\n * How far the footprint's two edges reach past a node, as a vector to be scaled by half\n * the thickness and added on the wall's left, subtracted on its right.\n *\n * Two walls meeting at a corner both STOP at the shared node, so between them they leave\n * a square of half a thickness uncovered on the outside of the turn — the same notch the\n * 2D renderer fills with a mitre join, cut here through the full height of the wall.\n * Extending both walls to where their edges actually cross closes it.\n *\n * `null` leaves the end square: at a junction there is no single corner to mitre to, at a\n * change of thickness the two edges are offset by different amounts, and past the mitre\n * limit an acute corner would run away into a spike.\n */\nfunction mitreVector(floor: PlanFloor, wall: PlanWall, nodeId: string, at: Map<string, PlanWall[]>): PlanPoint | null {\n const here = at.get(nodeId);\n if (!here || here.length !== 2) return null;\n const other = here[0].id === wall.id ? here[1] : here[0];\n if (other.thickness !== wall.thickness) return null;\n\n const node = floor.nodes[nodeId];\n const far = floor.nodes[wall.a === nodeId ? wall.b : wall.a];\n const onward = floor.nodes[other.a === nodeId ? other.b : other.a];\n if (!node || !far || !onward) return null;\n\n // Into the corner along this wall, then out along its neighbour.\n const u = unit(far, node);\n const v = unit(node, onward);\n if (!u || !v) return null;\n\n const along = u.x * v.x + u.y * v.y;\n if (along < -1 + EPS) return null; // doubles back on itself: no corner to speak of\n const nu = { x: -u.y, y: u.x };\n const nv = { x: -v.y, y: v.x };\n const scale = 1 + along;\n const mitre = { x: (nu.x + nv.x) / scale, y: (nu.y + nv.y) / scale };\n if (Math.hypot(mitre.x, mitre.y) > MITRE_LIMIT) return null;\n\n // Returned on the wall's own left, which is `u`'s left at this end.\n return wall.b === nodeId ? mitre : { x: -mitre.x, y: -mitre.y };\n}\n\nfunction unit(from: PlanPoint, to: PlanPoint): PlanPoint | null {\n const len = dist(from, to);\n if (len < EPS) return null;\n return { x: (to.x - from.x) / len, y: (to.y - from.y) / len };\n}\n\n/**\n * The stretch of a wall between two offsets along it, as a footprint quad.\n *\n * Ends that are the wall's true ends are mitred into their neighbour; ends created by an\n * opening are left square, because a jamb is a square face.\n */\nfunction footprintBetween(\n floor: PlanFloor,\n wall: PlanWall,\n from: number,\n to: number,\n at: Map<string, PlanWall[]>,\n): [PlanPoint, PlanPoint, PlanPoint, PlanPoint] | null {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return null;\n const len = dist(a, b);\n if (len < EPS || to - from < EPS) return null;\n\n const d = unit(a, b)!;\n const half = wall.thickness / 2;\n const n = { x: -d.y * half, y: d.x * half };\n\n const start = { x: a.x + d.x * from, y: a.y + d.y * from };\n const end = { x: a.x + d.x * to, y: a.y + d.y * to };\n\n const mitreA = from < EPS ? mitreVector(floor, wall, wall.a, at) : null;\n const mitreB = to > len - EPS ? mitreVector(floor, wall, wall.b, at) : null;\n\n const offset = (p: PlanPoint, m: PlanPoint | null, sign: 1 | -1) =>\n m ? { x: p.x + m.x * half * sign, y: p.y + m.y * half * sign } : { x: p.x + n.x * sign, y: p.y + n.y * sign };\n\n return [offset(start, mitreA, 1), offset(end, mitreB, 1), offset(end, mitreB, -1), offset(start, mitreA, -1)];\n}\n\n/** A closed box over a footprint, between two heights. */\nfunction box(mesh: MeshBuilder, foot: readonly PlanPoint[], bottom: number, top: number): void {\n if (top - bottom < EPS) return;\n const lo = foot.map((p) => [p.x, bottom, p.y]);\n const hi = foot.map((p) => [p.x, top, p.y]);\n\n /*\n * Which way round the footprint runs decides which way the faces look. Plan y becomes\n * world z with y up, which is a handedness flip, so a footprint that reads\n * counter-clockwise in plan comes out clockwise seen from above and its faces would\n * point inwards. Hence the inversion rather than taking the plan winding at its word.\n */\n let twice = 0;\n for (let i = 0; i < foot.length; i++) {\n const p = foot[i];\n const q = foot[(i + 1) % foot.length];\n twice += p.x * q.y - q.x * p.y;\n }\n const ccw = twice < 0;\n\n for (let i = 0; i < foot.length; i++) {\n const j = (i + 1) % foot.length;\n if (ccw) mesh.quad(lo[i], lo[j], hi[j], hi[i]);\n else mesh.quad(lo[j], lo[i], hi[i], hi[j]);\n }\n\n // Caps. A footprint is always convex here — it is a rectangle — so a fan is enough.\n for (let i = 1; i + 1 < foot.length; i++) {\n if (ccw) {\n mesh.triangle(hi[0], hi[i], hi[i + 1]);\n mesh.triangle(lo[0], lo[i + 1], lo[i]);\n } else {\n mesh.triangle(hi[0], hi[i + 1], hi[i]);\n mesh.triangle(lo[0], lo[i], lo[i + 1]);\n }\n }\n}\n\n/** The openings on one wall, clamped to it and sorted along it. */\nfunction openingsOn(floor: PlanFloor, wall: PlanWall, length: number): PlanOpening[] {\n return Object.values(floor.openings)\n .filter((o) => o.wallId === wall.id)\n .filter((o) => o.offset + o.width / 2 > EPS && o.offset - o.width / 2 < length - EPS)\n .sort((a, b) => a.offset - b.offset);\n}\n\n/**\n * Triangles for one floor: every wall, with its openings cut out, and a slab per room.\n *\n * Call it per storey and concatenate to build a whole building; each floor already knows\n * its own elevation.\n */\nexport function buildPlanMesh(floor: PlanFloor, options: BuildPlanMeshOptions = {}): PlanMesh {\n const { wallHeight, includeFloorSlab = true, slabThickness = 200, applyElevation = true } = options;\n\n const mesh = new MeshBuilder();\n const groups: PlanMeshGroup[] = [];\n const base = applyElevation ? floor.elevation : 0;\n\n /*\n * `elevation` is the FINISHED FLOOR LEVEL, so a storey's slab hangs below it. Walls\n * start at the slab's underside rather than at the level itself, which is to say they\n * clothe the floor plate the way a facade does instead of stopping short of it.\n *\n * That keeps a wall exactly `floor.height` tall, and makes each storey's walls meet the\n * ones below face to face: this storey starts at `elevation - slab`, and the storey\n * below ends there too. No band of exposed slab between them, and nothing overlapping\n * along the facade.\n */\n const slabDrop = includeFloorSlab ? slabThickness + Z_BIAS : 0;\n\n // ── Walls ──────────────────────────────────────────────────────────────────────\n const atNode = wallsByNode(floor);\n const wallStart = mesh.indices.length;\n for (const wall of Object.values(floor.walls)) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) continue;\n const length = dist(a, b);\n if (length < EPS) continue;\n\n const bottom = base + (wall.baseHeight ?? 0) - slabDrop;\n const top = bottom + (wall.height ?? wallHeight ?? floor.height);\n if (top - bottom < EPS) continue;\n\n const openings = openingsOn(floor, wall, length);\n if (openings.length === 0) {\n const foot = footprintBetween(floor, wall, 0, length, atNode);\n if (foot) box(mesh, foot, bottom, top);\n continue;\n }\n\n // Full-height stretches between the openings, from `wallCentrelineSpans` so the\n // solid is cut exactly where the drawing is.\n for (const [from, to] of wallCentrelineSpans(floor, wall)) {\n const foot = footprintBetween(floor, wall, from, to, atNode);\n if (foot) box(mesh, foot, bottom, top);\n }\n\n // Then the lintel over each opening and the upstand under it.\n for (const opening of openings) {\n const from = Math.max(0, opening.offset - opening.width / 2);\n const to = Math.min(length, opening.offset + opening.width / 2);\n const foot = footprintBetween(floor, wall, from, to, atNode);\n if (!foot) continue;\n const sill = bottom + Math.max(0, opening.sill);\n const head = bottom + Math.max(0, opening.head);\n if (sill > bottom + EPS) box(mesh, foot, bottom, Math.min(sill, top));\n if (head < top - EPS) box(mesh, foot, Math.max(head, bottom), top);\n }\n }\n if (mesh.indices.length > wallStart) {\n groups.push({ part: 'wall', start: wallStart, count: mesh.indices.length - wallStart });\n }\n\n // ── Floor slabs ────────────────────────────────────────────────────────────────\n if (includeFloorSlab) {\n const slabStart = mesh.indices.length;\n for (const room of derivePlan(floor).rooms) {\n const { vertices, indices } = triangulate(room.outer, room.holes);\n if (indices.length === 0) continue;\n const top = base;\n const bottom = base - slabThickness;\n\n for (let i = 0; i < indices.length; i += 3) {\n const t = [vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]];\n const up = t.map((q) => [q.x, top, q.y]);\n const down = t.map((q) => [q.x, bottom, q.y]);\n // `triangulate` returns counter-clockwise triangles in plan space; the y-down to\n // y-up flip reverses that, so the top face is wound the other way here.\n mesh.triangle(up[0], up[2], up[1]);\n mesh.triangle(down[0], down[1], down[2]);\n }\n\n // The slab's edge, so it is a solid rather than two sheets.\n for (const ring of [room.outer, ...room.holes]) {\n for (let i = 0; i < ring.length; i++) {\n const q = ring[i];\n const r = ring[(i + 1) % ring.length];\n // Wound so the face looks away from the solid. Holes come back wound opposite\n // to the outer ring, so walking each ring as it is gives both the right way out.\n mesh.quad([q.x, bottom, q.y], [q.x, top, q.y], [r.x, top, r.y], [r.x, bottom, r.y]);\n }\n }\n }\n if (mesh.indices.length > slabStart) {\n groups.push({ part: 'floor', start: slabStart, count: mesh.indices.length - slabStart });\n }\n }\n\n return {\n positions: new Float32Array(mesh.positions),\n normals: new Float32Array(mesh.normals),\n indices: new Uint32Array(mesh.indices),\n groups,\n };\n}\n"],"mappings":"qOAwBA,IAAM,EAAM,KAWN,EAAS,EAmCT,EAAN,KAAkB,eACe,KAAA,UAAA,CAAC,EACH,KAAA,QAAA,CAAC,EACD,KAAA,QAAA,CAAC,EAQ9B,SAAS,EAAa,EAAa,EAAmB,CACpD,IAAM,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GACd,EAAK,EAAE,GAAK,EAAE,GAChB,EAAK,EAAK,EAAK,EAAK,EACpB,EAAK,EAAK,EAAK,EAAK,EACpB,EAAK,EAAK,EAAK,EAAK,EAClB,EAAM,KAAK,MAAM,EAAI,EAAI,CAAE,EACjC,GAAI,EAAM,EAAK,OACf,GAAM,EACN,GAAM,EACN,GAAM,EAEN,IAAM,EAAO,KAAK,UAAU,OAAS,EACrC,IAAK,IAAM,IAAK,CAAC,EAAG,EAAG,CAAC,EAAG,KAAK,UAAU,KAAK,EAAE,GAAI,EAAE,GAAI,EAAE,EAAE,EAC/D,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,KAAK,QAAQ,KAAK,EAAI,EAAI,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AAE,CAAC,CAAC,EAG5C,EAAK,SAAS,EAAG,GAAI,EAAG,GAAI,EAAG,EAAE,EACjC,EAAK,SAAS,EAAK,GAAI,EAAK,GAAI,EAAK,EAAE,CACzC,CAGA,IAAK,IAAM,IAAQ,CAAC,EAAK,MAAO,GAAG,EAAK,KAAK,EAC3C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,CACpC,IAAM,EAAI,EAAK,GACT,EAAI,GAAM,EAAI,GAAK,EAAK,QAG9B,EAAK,KAAK,CAAC,EAAE,EAAG,EAAQ,EAAE,CAAC,EAAG,CAAC,EAAE,EAAG,EAAK,EAAE,CAAC,EAAG,CAAC,EAAE,EAAG,EAAK,EAAE,CAAC,EAAG,CAAC,EAAE,EAAG,EAAQ,EAAE,CAAC,CAAC,CACpF,CAEJ,CACI,EAAK,QAAQ,OAAS,GACxB,EAAO,KAAK,CAAE,KAAM,QAAS,MAAO,EAAW,MAAO,EAAK,QAAQ,OAAS,CAAU,CAAC,CAE3F,CAEA,MAAO,CACL,UAAW,IAAI,aAAa,EAAK,SAAS,EAC1C,QAAS,IAAI,aAAa,EAAK,OAAO,EACtC,QAAS,IAAI,YAAY,EAAK,OAAO,EACrC,QACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{dist as e}from"./floorPlan.geometry.mjs";import{nodeDegrees as t}from"./floorPlan.faces.mjs";var n=1e-6;function r(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function i(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,``)}function a(e,t){return Math.abs(e.x-t.x)<.001&&Math.abs(e.y-t.y)<.001}function o(t,r){let i=t.nodes[r.a],a=t.nodes[r.b];if(!i||!a)return[];let o=e(i,a);if(o<n)return[];let s=[];for(let e of Object.values(t.openings)){if(e.wallId!==r.id)continue;let t=e.width/2,n=Math.max(0,e.offset-t),i=Math.min(o,e.offset+t);i>n&&s.push([n,i])}if(s.length===0)return[[0,o]];s.sort((e,t)=>e[0]-t[0]);let c=[s[0]];for(let e=1;e<s.length;e++){let t=c[c.length-1];s[e][0]<=t[1]?t[1]=Math.max(t[1],s[e][1]):c.push(s[e])}let l=[],u=0;for(let[e,t]of c)e-u>n&&l.push([u,e]),u=t;return o-u>n&&l.push([u,o]),l}function s(t,r){let i=t.walls[r.wallId];if(!i)return null;let a=t.nodes[i.a],o=t.nodes[i.b];if(!a||!o)return null;let s=e(a,o);if(s<n)return null;let c={x:(o.x-a.x)/s,y:(o.y-a.y)/s},l={x:-c.y,y:c.x},u=Math.min(r.width/2,s/2),d=Math.min(Math.max(r.offset,u),s-u),f={x:a.x+c.x*d,y:a.y+c.y*d};return{centre:f,dir:c,normal:l,p1:{x:f.x-c.x*u,y:f.y-c.y*u},p2:{x:f.x+c.x*u,y:f.y+c.y*u}}}function c(e,t,n){let r=new Map(t.map(e=>[e.id,e])),i=new Map;for(let e of t)for(let t of[e.a,e.b]){let n=i.get(t);n?n.push(e):i.set(t,[e])}let a=e=>{if((n.get(e)??0)!==2)return null;let t=i.get(e);return!t||t.length!==2?null:t},o=new Set,s=[],c=(e,t)=>e.a===t?e.b:e.a;for(let e of t){if(o.has(e.id))continue;let t=e,n=e.a,i=new Set([e.id]);for(;;){let e=a(n);if(!e)break;let r=e[0].id===t.id?e[1]:e[0];if(i.has(r.id))break;i.add(r.id),t=r,n=c(r,n)}let l=[],u=t,d=n;for(;!o.has(u.id);){o.add(u.id);let e=c(u,d);l.push({wall:u,from:d,to:e});let t=a(e);if(!t)break;let n=t[0].id===u.id?t[1]:t[0];if(o.has(n.id)||(u=n,d=e,!r.has(u.id)))break}l.length>0&&s.push(l)}return s}function l(t,r,a){let s=new Map,c=(e,t)=>{let n=s.get(e);n?n.push(t):s.set(e,[t])};for(let i of r){let r=t.nodes[i.a],a=t.nodes[i.b],s=e(r,a);if(s<n)continue;let l=o(t,i);if(l.length===0)continue;let u={x:(a.x-r.x)/s,y:(a.y-r.y)/s},d=l[0],f=l[l.length-1];c(i.a,{wall:i,dir:u,angle:Math.atan2(u.y,u.x),reach:d[0]<n?d[1]:0}),c(i.b,{wall:i,dir:{x:-u.x,y:-u.y},angle:Math.atan2(-u.y,-u.x),reach:f[1]>s-n?s-f[0]:0})}let l=[],u=Math.PI*2;for(let[e,r]of s){if(r.length<2||(a.get(e)??0)===2&&r.length===2&&r[0].wall.thickness===r[1].wall.thickness)continue;r.sort((e,t)=>e.angle-t.angle);let o=0,s=-1;for(let e=0;e<r.length;e++){let t=r[(e+1)%r.length],n=e===r.length-1?t.angle+u-r[e].angle:t.angle-r[e].angle;n>s&&(s=n,o=e)}if(s<=Math.PI+n)continue;let c=r[o],d=r[(o+1)%r.length],f=Math.min(c.wall.thickness,d.wall.thickness),p=Math.min(f/2,c.reach),m=Math.min(f/2,d.reach);if(p<n||m<n)continue;let h=t.nodes[e];l.push({thickness:f,d:`M ${i(h.x+c.dir.x*p)},${i(h.y+c.dir.y*p)} L ${i(h.x)},${i(h.y)} L ${i(h.x+d.dir.x*m)},${i(h.y+d.dir.y*m)}`})}return l}function u(s,u={}){let{wallIds:d,capFreeEnds:f=!0,capThicknessSteps:p=!0}=u,m=Object.values(s.walls).filter(t=>{if(d&&!d.has(t.id))return!1;let r=s.nodes[t.a],i=s.nodes[t.b];return r&&i&&e(r,i)>n&&t.a!==t.b});if(m.length===0)return{groups:[],caps:[]};let h=t(s),g=[],_=new Map;for(let e of m){let t=_.get(e.thickness);t?t.push(e):_.set(e.thickness,[e])}let v=new Map,y=(e,t)=>{let n=v.get(e);n?n.push(t):v.set(e,[t])};for(let[t,l]of _)for(let u of c(s,l,h)){let c=[],l=()=>{c.length>=2&&y(t,c.map((e,t)=>`${t===0?`M`:`L`} ${i(e.x)},${i(e.y)}`).join(` `)),c=[]};for(let t of u){let i=s.nodes[t.from],u=s.nodes[t.to],d=e(i,u);if(d<n)continue;let f=o(s,t.wall);t.from!==t.wall.a&&(f=f.map(([e,t])=>[d-t,d-e]).reverse());for(let[e,t]of f){let n=r(i,u,e/d),o=r(i,u,t/d);c.length>0&&a(c[c.length-1],n)?c.push(o):(l(),c=[n,o])}(f.length===0||f[f.length-1][1]<d-n)&&l()}let d=u[0],f=u[u.length-1];d.from===f.to&&c.length>=3&&a(c[0],c[c.length-1])?(y(t,`${c.slice(0,-1).map((e,t)=>`${t===0?`M`:`L`} ${i(e.x)},${i(e.y)}`).join(` `)} Z`),c=[]):l()}for(let e of l(s,m,h))y(e.thickness,e.d);let b=(t,r,i)=>{let a=s.nodes[t.a],o=s.nodes[t.b],c=e(a,o);if(c<n)return;let l={x:(o.x-a.x)/c,y:(o.y-a.y)/c},u={x:-l.y,y:l.x},d={x:a.x+l.x*r,y:a.y+l.y*r},f=t.thickness/2;g.push({a:{x:d.x-u.x*f,y:d.y-u.y*f},b:{x:d.x+u.x*f,y:d.y+u.y*f},reason:i,wallId:t.id})};for(let t of m){let r=s.nodes[t.a],i=s.nodes[t.b],a=e(r,i);for(let[e,r]of o(s,t))e>n?b(t,e,`jamb`):f&&(h.get(t.a)??0)===1&&b(t,0,`freeEnd`),r<a-n?b(t,r,`jamb`):f&&(h.get(t.b)??0)===1&&b(t,a,`freeEnd`)}if(p){let t=new Map;for(let e of m)for(let n of[e.a,e.b]){let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let[n,r]of t){if(r.length!==2)continue;let[t,i]=r;if(t.thickness===i.thickness)continue;let a=t.thickness>=i.thickness?t:i;b(a,a.a===n?0:e(s.nodes[a.a],s.nodes[a.b]),`thicknessStep`)}}return{groups:[...v.entries()].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({thickness:e,d:t.join(` `)})),caps:g}}export{u as buildWallPaths,s as openingGeometry,o as wallCentrelineSpans};
|
|
1
|
+
"use client";import{dist as e}from"./floorPlan.geometry.mjs";import{nodeDegrees as t}from"./floorPlan.faces.mjs";var n=1e-6;function r(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function i(e){return Number.isInteger(e)?String(e):e.toFixed(3).replace(/\.?0+$/,``)}function a(e,t){return Math.abs(e.x-t.x)<.001&&Math.abs(e.y-t.y)<.001}function o(t,r){let i=t.nodes[r.a],a=t.nodes[r.b];if(!i||!a)return[];let o=e(i,a);if(o<n)return[];let s=[];for(let e of Object.values(t.openings)){if(e.wallId!==r.id)continue;let t=e.width/2,n=Math.max(0,e.offset-t),i=Math.min(o,e.offset+t);i>n&&s.push([n,i])}if(s.length===0)return[[0,o]];s.sort((e,t)=>e[0]-t[0]);let c=[s[0]];for(let e=1;e<s.length;e++){let t=c[c.length-1];s[e][0]<=t[1]?t[1]=Math.max(t[1],s[e][1]):c.push(s[e])}let l=[],u=0;for(let[e,t]of c)e-u>n&&l.push([u,e]),u=t;return o-u>n&&l.push([u,o]),l}function s(t,r){let i=t.walls[r.wallId];if(!i)return null;let a=t.nodes[i.a],o=t.nodes[i.b];if(!a||!o)return null;let s=e(a,o);if(s<n)return null;let c={x:(o.x-a.x)/s,y:(o.y-a.y)/s},l={x:-c.y,y:c.x},u=Math.min(r.width/2,s/2),d=Math.min(Math.max(r.offset,u),s-u),f={x:a.x+c.x*d,y:a.y+c.y*d};return{centre:f,dir:c,normal:l,p1:{x:f.x-c.x*u,y:f.y-c.y*u},p2:{x:f.x+c.x*u,y:f.y+c.y*u}}}function c(e,t,n){let r=new Map(t.map(e=>[e.id,e])),i=new Map;for(let e of t)for(let t of[e.a,e.b]){let n=i.get(t);n?n.push(e):i.set(t,[e])}let a=e=>{if((n.get(e)??0)!==2)return null;let t=i.get(e);return!t||t.length!==2?null:t},o=new Set,s=[],c=(e,t)=>e.a===t?e.b:e.a;for(let e of t){if(o.has(e.id))continue;let t=e,n=e.a,i=new Set([e.id]);for(;;){let e=a(n);if(!e)break;let r=e[0].id===t.id?e[1]:e[0];if(i.has(r.id))break;i.add(r.id),t=r,n=c(r,n)}let l=[],u=t,d=n;for(;!o.has(u.id);){o.add(u.id);let e=c(u,d);l.push({wall:u,from:d,to:e});let t=a(e);if(!t)break;let n=t[0].id===u.id?t[1]:t[0];if(o.has(n.id)||(u=n,d=e,!r.has(u.id)))break}l.length>0&&s.push(l)}return s}function l(t,r,a){let s=new Map,c=(e,t)=>{let n=s.get(e);n?n.push(t):s.set(e,[t])};for(let i of r){let r=t.nodes[i.a],a=t.nodes[i.b],s=e(r,a);if(s<n)continue;let l=o(t,i);if(l.length===0)continue;let u={x:(a.x-r.x)/s,y:(a.y-r.y)/s},d=l[0],f=l[l.length-1];c(i.a,{wall:i,dir:u,angle:Math.atan2(u.y,u.x),reach:d[0]<n?d[1]:0}),c(i.b,{wall:i,dir:{x:-u.x,y:-u.y},angle:Math.atan2(-u.y,-u.x),reach:f[1]>s-n?s-f[0]:0})}let l=[],u=Math.PI*2;for(let[e,r]of s){if(r.length<2||(a.get(e)??0)===2&&r.length===2&&r[0].wall.thickness===r[1].wall.thickness)continue;r.sort((e,t)=>e.angle-t.angle);let o=0,s=-1;for(let e=0;e<r.length;e++){let t=r[(e+1)%r.length],n=e===r.length-1?t.angle+u-r[e].angle:t.angle-r[e].angle;n>s&&(s=n,o=e)}if(s<=Math.PI+n)continue;let c=r[o],d=r[(o+1)%r.length],f=Math.min(c.wall.thickness,d.wall.thickness),p=Math.min(f/2,c.reach),m=Math.min(f/2,d.reach);if(p<n||m<n)continue;let h=t.nodes[e];l.push({thickness:f,d:`M ${i(h.x+c.dir.x*p)},${i(h.y+c.dir.y*p)} L ${i(h.x)},${i(h.y)} L ${i(h.x+d.dir.x*m)},${i(h.y+d.dir.y*m)}`})}return l}function u(s,u={}){let{wallIds:d,capFreeEnds:f=!0,capThicknessSteps:p=!0}=u,m=Object.values(s.walls).filter(t=>{if(d&&!d.has(t.id))return!1;let r=s.nodes[t.a],i=s.nodes[t.b];return r&&i&&e(r,i)>n&&t.a!==t.b});if(m.length===0)return{groups:[],caps:[]};let h=t(s),g=[],_=new Map;for(let e of m){let t=_.get(e.thickness);t?t.push(e):_.set(e.thickness,[e])}let v=new Map,y=(e,t)=>{let n=v.get(e);n?n.push(t):v.set(e,[t])};for(let[t,l]of _)for(let u of c(s,l,h)){let c=[],l=()=>{c.length>=2&&y(t,c.map((e,t)=>`${t===0?`M`:`L`} ${i(e.x)},${i(e.y)}`).join(` `)),c=[]};for(let t of u){let i=s.nodes[t.from],u=s.nodes[t.to],d=e(i,u);if(d<n)continue;let f=o(s,t.wall);t.from!==t.wall.a&&(f=f.map(([e,t])=>[d-t,d-e]).reverse());for(let[e,t]of f){let n=r(i,u,e/d),o=r(i,u,t/d);c.length>0&&a(c[c.length-1],n)?c.push(o):(l(),c=[n,o])}(f.length===0||f[f.length-1][1]<d-n)&&l()}let d=u[0],f=u[u.length-1];d.from===f.to&&c.length>=3&&a(c[0],c[c.length-1])?(y(t,`${c.slice(0,-1).map((e,t)=>`${t===0?`M`:`L`} ${i(e.x)},${i(e.y)}`).join(` `)} Z`),c=[]):l()}for(let e of l(s,m,h))y(e.thickness,e.d);let b=(t,r,i)=>{let a=s.nodes[t.a],o=s.nodes[t.b],c=e(a,o);if(c<n)return;let l={x:(o.x-a.x)/c,y:(o.y-a.y)/c},u={x:-l.y,y:l.x},d={x:a.x+l.x*r,y:a.y+l.y*r},f=t.thickness/2;g.push({a:{x:d.x-u.x*f,y:d.y-u.y*f},b:{x:d.x+u.x*f,y:d.y+u.y*f},reason:i,wallId:t.id})};for(let t of m){let r=s.nodes[t.a],i=s.nodes[t.b],a=e(r,i);for(let[e,r]of o(s,t))e>n?b(t,e,`jamb`):f&&(h.get(t.a)??0)===1&&b(t,0,`freeEnd`),r<a-n?b(t,r,`jamb`):f&&(h.get(t.b)??0)===1&&b(t,a,`freeEnd`)}if(p){let t=new Map;for(let e of m)for(let n of[e.a,e.b]){let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let[n,r]of t){if(r.length!==2)continue;let[t,i]=r;if(t.thickness===i.thickness)continue;let a=t.thickness>=i.thickness?t:i;b(a,a.a===n?0:e(s.nodes[a.a],s.nodes[a.b]),`thicknessStep`)}}return{groups:[...v.entries()].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({thickness:e,d:t.join(` `)})),caps:g}}export{u as buildWallPaths,s as openingGeometry,o as wallCentrelineSpans};
|
|
2
2
|
//# sourceMappingURL=floorPlan.path.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floorPlan.path.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.path.ts"],"sourcesContent":["/**\n * Turns walls into SVG path data for the two-pass thick-wall rendering.\n *\n * The trick: both passes stroke the SAME path data, the outline pass at `thickness` and\n * the fill pass at `thickness - 2 * outlineWidth`. The visible outline is not drawn at\n * all, it is what is left of the outline pass after the fill pass covers its middle.\n * That is why the two must never diverge, and why every outline path has to be drawn\n * before every fill path (one `<g>` each, never interleaved pairs).\n *\n * Three things do not fall out of that trick and are handled explicitly:\n *\n * 1. Nothing is ever drawn across a butt end, because there both passes terminate at\n * the same coordinate. Openings and free ends therefore need explicit cap lines.\n * 2. Two butt-capped walls meeting at an angle leave an uncovered notch at the outer\n * corner. Walls are emitted as CHAINS through degree-2 nodes so `stroke-linejoin`\n * miters the corner, and where a chain has to stop, `reflexCornerStubs` mitres the\n * one corner a junction cannot close by itself.\n * 3. Where two walls of different thickness meet end to end, the drawing steps from\n * thick fill straight to background with no edge, so that joint needs a cap too.\n */\n\nimport { nodeDegrees } from './floorPlan.faces';\nimport { dist } from './floorPlan.geometry';\nimport type { PlanFloor, PlanOpening, PlanPoint, PlanWall } from './floorPlan.types';\n\nexport interface WallPathGroup {\n /** Millimetres. The stroke width for the outline pass. */\n thickness: number;\n /**\n * Path data, to be handed VERBATIM to both passes. The outline pass strokes it at\n * `thickness`, the fill pass at `thickness - 2 * outlineWidth`.\n */\n d: string;\n}\n\nexport type WallCapReason = 'jamb' | 'freeEnd' | 'thicknessStep';\n\nexport interface WallCapLine {\n a: PlanPoint;\n b: PlanPoint;\n reason: WallCapReason;\n wallId: string;\n}\n\nexport interface WallPathResult {\n /** Render every group's outline first, then every group's fill. */\n groups: WallPathGroup[];\n /** Drawn last, in the outline colour, at the outline width. */\n caps: WallCapLine[];\n}\n\nexport interface BuildWallPathsOptions {\n /**\n * Build paths for only these walls, as if the rest were not drawn.\n *\n * Node degrees still come from the WHOLE floor, so chains break and corners are filled\n * exactly where they are for the real walls. That is what lets a subset be painted over\n * the top of the full drawing and land on it precisely: a highlight of a room's\n * boundary is the same geometry as the walls themselves, openings and all.\n */\n wallIds?: ReadonlySet<string>;\n /** Cap the free end of a wall that stops in mid-air. Default true. */\n capFreeEnds?: boolean;\n /** Cap the joint where two walls of different thickness meet. Default true. */\n capThicknessSteps?: boolean;\n}\n\nconst EPS = 1e-6;\n\nfunction lerpPoint(a: PlanPoint, b: PlanPoint, t: number): PlanPoint {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\n\nfunction fmt(n: number): string {\n return Number.isInteger(n) ? String(n) : n.toFixed(3).replace(/\\.?0+$/, '');\n}\n\nfunction samePoint(a: PlanPoint, b: PlanPoint): boolean {\n return Math.abs(a.x - b.x) < 0.001 && Math.abs(a.y - b.y) < 0.001;\n}\n\n/**\n * The parts of a wall's centreline that are actually wall, as `[start, end]` offsets in\n * millimetres from node `a`.\n *\n * Overlapping openings merge into one gap; an opening reaching an end removes that span\n * entirely. An empty result means the opening spans the whole wall.\n */\nexport function wallCentrelineSpans(floor: PlanFloor, wall: PlanWall): Array<[number, number]> {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return [];\n const len = dist(a, b);\n if (len < EPS) return [];\n\n const gaps: Array<[number, number]> = [];\n for (const opening of Object.values(floor.openings)) {\n if (opening.wallId !== wall.id) continue;\n const half = opening.width / 2;\n const start = Math.max(0, opening.offset - half);\n const end = Math.min(len, opening.offset + half);\n if (end > start) gaps.push([start, end]);\n }\n if (gaps.length === 0) return [[0, len]];\n\n gaps.sort((x, y) => x[0] - y[0]);\n const merged: Array<[number, number]> = [gaps[0]];\n for (let i = 1; i < gaps.length; i++) {\n const last = merged[merged.length - 1];\n if (gaps[i][0] <= last[1]) last[1] = Math.max(last[1], gaps[i][1]);\n else merged.push(gaps[i]);\n }\n\n const spans: Array<[number, number]> = [];\n let cursor = 0;\n for (const [start, end] of merged) {\n if (start - cursor > EPS) spans.push([cursor, start]);\n cursor = end;\n }\n if (len - cursor > EPS) spans.push([cursor, len]);\n return spans;\n}\n\n/** Everything a renderer needs to draw a door leaf, swing arc or window symbol. */\nexport function openingGeometry(\n floor: PlanFloor,\n opening: PlanOpening,\n): { centre: PlanPoint; dir: PlanPoint; normal: PlanPoint; p1: PlanPoint; p2: PlanPoint } | null {\n const wall = floor.walls[opening.wallId];\n if (!wall) return null;\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return null;\n const len = dist(a, b);\n if (len < EPS) return null;\n\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const normal = { x: -dir.y, y: dir.x };\n const half = Math.min(opening.width / 2, len / 2);\n const offset = Math.min(Math.max(opening.offset, half), len - half);\n const centre = { x: a.x + dir.x * offset, y: a.y + dir.y * offset };\n\n return {\n centre,\n dir,\n normal,\n p1: { x: centre.x - dir.x * half, y: centre.y - dir.y * half },\n p2: { x: centre.x + dir.x * half, y: centre.y + dir.y * half },\n };\n}\n\n/** One directed step along a chain. */\ninterface Step {\n wall: PlanWall;\n from: string;\n to: string;\n}\n\n/**\n * Maximal runs of same-thickness walls joined through degree-2 nodes.\n *\n * A chain may only continue through a node whose TOTAL degree is 2 and whose two walls\n * share a thickness: a different stroke width means a different path, and a degree-3+\n * node is a junction rather than a corner.\n */\nfunction buildChains(floor: PlanFloor, walls: PlanWall[], degrees: Map<string, number>): Step[][] {\n const byId = new Map(walls.map((w) => [w.id, w]));\n const atNode = new Map<string, PlanWall[]>();\n for (const wall of walls) {\n for (const nodeId of [wall.a, wall.b]) {\n const list = atNode.get(nodeId);\n if (list) list.push(wall);\n else atNode.set(nodeId, [wall]);\n }\n }\n\n const continuesThrough = (nodeId: string): PlanWall[] | null => {\n if ((degrees.get(nodeId) ?? 0) !== 2) return null;\n const here = atNode.get(nodeId);\n // Both walls must be in this thickness group, or the chain has to break here.\n if (!here || here.length !== 2) return null;\n return here;\n };\n\n const used = new Set<string>();\n const chains: Step[][] = [];\n\n const other = (wall: PlanWall, nodeId: string): string => (wall.a === nodeId ? wall.b : wall.a);\n\n for (const wall of walls) {\n if (used.has(wall.id)) continue;\n\n // Walk backwards to the start of the run, unless it closes on itself.\n let startWall = wall;\n let startNode = wall.a;\n const seenBack = new Set<string>([wall.id]);\n for (;;) {\n const pair = continuesThrough(startNode);\n if (!pair) break;\n const prev = pair[0].id === startWall.id ? pair[1] : pair[0];\n if (seenBack.has(prev.id)) break; // closed loop\n seenBack.add(prev.id);\n startWall = prev;\n startNode = other(prev, startNode);\n }\n\n // Walk forwards, collecting directed steps.\n const steps: Step[] = [];\n let current = startWall;\n let from = startNode;\n for (;;) {\n if (used.has(current.id)) break;\n used.add(current.id);\n const to = other(current, from);\n steps.push({ wall: current, from, to });\n const pair = continuesThrough(to);\n if (!pair) break;\n const next = pair[0].id === current.id ? pair[1] : pair[0];\n if (used.has(next.id)) break;\n current = next;\n from = to;\n if (!byId.has(current.id)) break;\n }\n\n if (steps.length > 0) chains.push(steps);\n }\n\n return chains;\n}\n\n/**\n * The outer corner of the one REFLEX gap at a node, as a two-legged stub.\n *\n * A chain's `stroke-linejoin` mitres the corner wherever a wall bends, but a chain has\n * to stop at a junction, and at a thickness change, so something else has to close the\n * corner there. Most junction corners need nothing: where the angular gap between two\n * neighbouring walls is at most 180 degrees, the two bands reach across it and already\n * meet at the mitre point, because both start AT the node rather than short of it.\n *\n * A gap WIDER than 180 degrees is the exception, and it is the only one. There the two\n * faces bounding the gap diverge instead of crossing, so nothing spans the gap and what\n * is left between the two butt ends is an open wedge biting into the node. It shows up\n * whenever every wall at a node points into the same half-plane: a wall running east, a\n * wall running north, and a third splitting the two leaves a quarter-circle bitten out\n * of the south-west side. Because the gaps around a node sum to 360 degrees, at most\n * one can be reflex, so a node never needs more than one of these.\n *\n * The stub is two legs laid back along the two walls bounding that gap. Stroked at the\n * wall thickness it stays within their own bands, adding nothing anywhere else, and its\n * mitre join fills the wedge and bevels under the same `stroke-miterlimit` as every\n * other corner. Filling every gap this way instead of only the reflex one is what used\n * to fire spikes out of narrow junctions: those gaps had nothing to fill, so the join\n * ran outside the walls, the further the tighter the angle.\n */\nfunction reflexCornerStubs(\n floor: PlanFloor,\n walls: PlanWall[],\n degrees: Map<string, number>,\n): Array<{ thickness: number; d: string }> {\n interface Arm {\n wall: PlanWall;\n dir: PlanPoint;\n angle: number;\n /** Millimetres of wall between the node and the first opening, if any. */\n reach: number;\n }\n\n const armsAt = new Map<string, Arm[]>();\n const addArm = (nodeId: string, arm: Arm) => {\n const list = armsAt.get(nodeId);\n if (list) list.push(arm);\n else armsAt.set(nodeId, [arm]);\n };\n\n for (const wall of walls) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n if (len < EPS) continue;\n const spans = wallCentrelineSpans(floor, wall);\n if (spans.length === 0) continue;\n\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const first = spans[0];\n const last = spans[spans.length - 1];\n addArm(wall.a, {\n wall,\n dir,\n angle: Math.atan2(dir.y, dir.x),\n reach: first[0] < EPS ? first[1] : 0,\n });\n addArm(wall.b, {\n wall,\n dir: { x: -dir.x, y: -dir.y },\n angle: Math.atan2(-dir.y, -dir.x),\n reach: last[1] > len - EPS ? len - last[0] : 0,\n });\n }\n\n const stubs: Array<{ thickness: number; d: string }> = [];\n const TAU = Math.PI * 2;\n\n for (const [nodeId, arms] of armsAt) {\n if (arms.length < 2) continue;\n /*\n * A chain runs straight through a plain corner, and its own join closes it. The test\n * has to be the one `buildChains` uses, which reads the degree of the node in the\n * WHOLE floor: drawing a subset of the walls, two arms at a T junction look like a\n * corner but the chain still breaks there, and skipping the fill left a notch bitten\n * out of the join.\n */\n const chainRunsThrough =\n (degrees.get(nodeId) ?? 0) === 2 && arms.length === 2 && arms[0].wall.thickness === arms[1].wall.thickness;\n if (chainRunsThrough) continue;\n\n arms.sort((p, q) => p.angle - q.angle);\n\n let widest = 0;\n let widestGap = -1;\n for (let i = 0; i < arms.length; i++) {\n const next = arms[(i + 1) % arms.length];\n const gap = i === arms.length - 1 ? next.angle + TAU - arms[i].angle : next.angle - arms[i].angle;\n if (gap > widestGap) {\n widestGap = gap;\n widest = i;\n }\n }\n if (widestGap <= Math.PI + EPS) continue;\n\n const from = arms[widest];\n const to = arms[(widest + 1) % arms.length];\n // The thinner of the two, so the stub can never bulge out past the thinner wall.\n const thickness = Math.min(from.wall.thickness, to.wall.thickness);\n // Half a thickness of leg is enough to carry the join, and an opening close to the\n // node shortens it so the stub cannot paint across the jamb.\n const legFrom = Math.min(thickness / 2, from.reach);\n const legTo = Math.min(thickness / 2, to.reach);\n if (legFrom < EPS || legTo < EPS) continue;\n\n const node = floor.nodes[nodeId];\n stubs.push({\n thickness,\n d:\n `M ${fmt(node.x + from.dir.x * legFrom)},${fmt(node.y + from.dir.y * legFrom)}` +\n ` L ${fmt(node.x)},${fmt(node.y)}` +\n ` L ${fmt(node.x + to.dir.x * legTo)},${fmt(node.y + to.dir.y * legTo)}`,\n });\n }\n\n return stubs;\n}\n\n/**\n * Builds the stroke path data for every wall, grouped by thickness, plus the cap lines\n * the two-pass trick cannot produce on its own.\n */\nexport function buildWallPaths(floor: PlanFloor, options: BuildWallPathsOptions = {}): WallPathResult {\n const { wallIds, capFreeEnds = true, capThicknessSteps = true } = options;\n\n const walls = Object.values(floor.walls).filter((w) => {\n if (wallIds && !wallIds.has(w.id)) return false;\n const a = floor.nodes[w.a];\n const b = floor.nodes[w.b];\n return a && b && dist(a, b) > EPS && w.a !== w.b;\n });\n if (walls.length === 0) return { groups: [], caps: [] };\n\n const degrees = nodeDegrees(floor);\n const caps: WallCapLine[] = [];\n\n // ── Group by thickness: one stroke width per path. ────────────────────────────\n const byThickness = new Map<number, PlanWall[]>();\n for (const wall of walls) {\n const list = byThickness.get(wall.thickness);\n if (list) list.push(wall);\n else byThickness.set(wall.thickness, [wall]);\n }\n\n const subpathsByThickness = new Map<number, string[]>();\n const pushSubpath = (thickness: number, d: string) => {\n const list = subpathsByThickness.get(thickness);\n if (list) list.push(d);\n else subpathsByThickness.set(thickness, [d]);\n };\n\n for (const [thickness, groupWalls] of byThickness) {\n for (const chain of buildChains(floor, groupWalls, degrees)) {\n let current: PlanPoint[] = [];\n const flush = () => {\n if (current.length >= 2) {\n pushSubpath(thickness, current.map((p, i) => `${i === 0 ? 'M' : 'L'} ${fmt(p.x)},${fmt(p.y)}`).join(' '));\n }\n current = [];\n };\n\n for (const step of chain) {\n const a = floor.nodes[step.from];\n const b = floor.nodes[step.to];\n const len = dist(a, b);\n if (len < EPS) continue;\n\n // Spans come back in the wall's own a->b direction; flip them when the chain\n // traverses the wall the other way.\n let spans = wallCentrelineSpans(floor, step.wall);\n if (step.from !== step.wall.a) {\n spans = spans.map(([s, e]) => [len - e, len - s] as [number, number]).reverse();\n }\n\n for (const [s, e] of spans) {\n const p1 = lerpPoint(a, b, s / len);\n const p2 = lerpPoint(a, b, e / len);\n if (current.length > 0 && samePoint(current[current.length - 1], p1)) {\n current.push(p2);\n } else {\n flush();\n current = [p1, p2];\n }\n }\n // An opening reaching the far end leaves nothing to continue from.\n if (spans.length === 0 || spans[spans.length - 1][1] < len - EPS) flush();\n }\n\n // A chain that returns to where it started closes properly, so the final corner\n // gets a miter join like every other corner rather than two butt caps.\n const first = chain[0];\n const last = chain[chain.length - 1];\n const closed = first.from === last.to;\n if (closed && current.length >= 3 && samePoint(current[0], current[current.length - 1])) {\n const ring = current.slice(0, -1);\n pushSubpath(thickness, `${ring.map((p, i) => `${i === 0 ? 'M' : 'L'} ${fmt(p.x)},${fmt(p.y)}`).join(' ')} Z`);\n current = [];\n } else {\n flush();\n }\n }\n }\n\n for (const stub of reflexCornerStubs(floor, walls, degrees)) pushSubpath(stub.thickness, stub.d);\n\n // ── Caps. ─────────────────────────────────────────────────────────────────────\n const capAt = (wall: PlanWall, offset: number, reason: WallCapReason) => {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n if (len < EPS) return;\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const normal = { x: -dir.y, y: dir.x };\n const centre = { x: a.x + dir.x * offset, y: a.y + dir.y * offset };\n const half = wall.thickness / 2;\n caps.push({\n a: { x: centre.x - normal.x * half, y: centre.y - normal.y * half },\n b: { x: centre.x + normal.x * half, y: centre.y + normal.y * half },\n reason,\n wallId: wall.id,\n });\n };\n\n for (const wall of walls) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n for (const [s, e] of wallCentrelineSpans(floor, wall)) {\n if (s > EPS) capAt(wall, s, 'jamb');\n else if (capFreeEnds && (degrees.get(wall.a) ?? 0) === 1) capAt(wall, 0, 'freeEnd');\n\n if (e < len - EPS) capAt(wall, e, 'jamb');\n else if (capFreeEnds && (degrees.get(wall.b) ?? 0) === 1) capAt(wall, len, 'freeEnd');\n }\n }\n\n if (capThicknessSteps) {\n const atNode = new Map<string, PlanWall[]>();\n for (const wall of walls) {\n for (const nodeId of [wall.a, wall.b]) {\n const list = atNode.get(nodeId);\n if (list) list.push(wall);\n else atNode.set(nodeId, [wall]);\n }\n }\n for (const [nodeId, incident] of atNode) {\n if (incident.length !== 2) continue;\n const [w1, w2] = incident;\n if (w1.thickness === w2.thickness) continue;\n // Draw the thicker wall's full cross-section. It overdraws a line across the\n // thinner wall's interior, which is the usual CAD convention for a joint between\n // two wall constructions, and far better than leaving no edge at all.\n const thicker = w1.thickness >= w2.thickness ? w1 : w2;\n const offset = thicker.a === nodeId ? 0 : dist(floor.nodes[thicker.a], floor.nodes[thicker.b]);\n capAt(thicker, offset, 'thicknessStep');\n }\n }\n\n const groups: WallPathGroup[]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IAAM,KAAQ,EACjB,IAAK,IAAM,IAAU,CAAC,EAAK,EAAG,EAAK,CAAC,EAAG,CACrC,IAAM,EAAO,EAAO,IAAI,CAAM,EAC1B,EAAM,EAAK,KAAK,CAAI,EACnB,EAAO,IAAI,EAAQ,CAAC,CAAI,CAAC,CAChC,CAEF,IAAK,GAAM,CAAC,EAAQ,KAAa,EAAQ,CACvC,GAAI,EAAS,SAAW,EAAG,SAC3B,GAAM,CAAC,EAAI,GAAM,EACjB,GAAI,EAAG,YAAc,EAAG,UAAW,SAInC,IAAM,EAAU,EAAG,WAAa,EAAG,UAAY,EAAK,EAEpD,EAAM,EADS,EAAQ,IAAM,EAAS,EAAI,EAAK,EAAM,MAAM,EAAQ,GAAI,EAAM,MAAM,EAAQ,EAAE,EACtE,eAAe,CACxC,CACF,CAMA,MAAO,CAAE,OAJuB,CAAC,GAAG,EAAoB,QAAQ,CAAC,CAAC,CAC/D,MAAM,EAAG,IAAM,EAAE,GAAK,EAAE,EAAE,CAAC,CAC3B,KAAK,CAAC,EAAW,MAAe,CAAE,YAAW,EAAG,EAAS,KAAK,GAAG,CAAE,EAE7D,EAAQ,MAAK,CACxB"}
|
|
1
|
+
{"version":3,"file":"floorPlan.path.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.path.ts"],"sourcesContent":["/**\n * Turns walls into SVG path data for the two-pass thick-wall rendering.\n *\n * The trick: both passes stroke the SAME path data, the outline pass at `thickness` and\n * the fill pass at `thickness - 2 * outlineWidth`. The visible outline is not drawn at\n * all, it is what is left of the outline pass after the fill pass covers its middle.\n * That is why the two must never diverge, and why every outline path has to be drawn\n * before every fill path (one `<g>` each, never interleaved pairs).\n *\n * Three things do not fall out of that trick and are handled explicitly:\n *\n * 1. Nothing is ever drawn across a butt end, because there both passes terminate at\n * the same coordinate. Openings and free ends therefore need explicit cap lines.\n * 2. Two butt-capped walls meeting at an angle leave an uncovered notch at the outer\n * corner. Walls are emitted as CHAINS through degree-2 nodes so `stroke-linejoin`\n * miters the corner, and where a chain has to stop, `reflexCornerStubs` mitres the\n * one corner a junction cannot close by itself.\n * 3. Where two walls of different thickness meet end to end, the drawing steps from\n * thick fill straight to background with no edge, so that joint needs a cap too.\n */\n\nimport { nodeDegrees } from './floorPlan.faces';\nimport { dist } from './floorPlan.geometry';\nimport type { PlanFloor, PlanOpening, PlanPoint, PlanWall } from './floorPlan.types';\n\nexport interface WallPathGroup {\n /** Millimetres. The stroke width for the outline pass. */\n thickness: number;\n /**\n * Path data, to be handed VERBATIM to both passes. The outline pass strokes it at\n * `thickness`, the fill pass at `thickness - 2 * outlineWidth`.\n */\n d: string;\n}\n\nexport type WallCapReason = 'jamb' | 'freeEnd' | 'thicknessStep';\n\nexport interface WallCapLine {\n a: PlanPoint;\n b: PlanPoint;\n reason: WallCapReason;\n wallId: string;\n}\n\nexport interface WallPathResult {\n /** Render every group's outline first, then every group's fill. */\n groups: WallPathGroup[];\n /** Drawn last, in the outline colour, at the outline width. */\n caps: WallCapLine[];\n}\n\nexport interface BuildWallPathsOptions {\n /**\n * Build paths for only these walls, as if the rest were not drawn.\n *\n * Node degrees still come from the WHOLE floor, so chains break and corners are filled\n * exactly where they are for the real walls. That is what lets a subset be painted over\n * the top of the full drawing and land on it precisely: a highlight of a room's\n * boundary is the same geometry as the walls themselves, openings and all.\n */\n wallIds?: ReadonlySet<string>;\n /** Cap the free end of a wall that stops in mid-air. Default true. */\n capFreeEnds?: boolean;\n /** Cap the joint where two walls of different thickness meet. Default true. */\n capThicknessSteps?: boolean;\n}\n\nconst EPS = 1e-6;\n\nfunction lerpPoint(a: PlanPoint, b: PlanPoint, t: number): PlanPoint {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\n\nfunction fmt(n: number): string {\n return Number.isInteger(n) ? String(n) : n.toFixed(3).replace(/\\.?0+$/, '');\n}\n\nfunction samePoint(a: PlanPoint, b: PlanPoint): boolean {\n return Math.abs(a.x - b.x) < 0.001 && Math.abs(a.y - b.y) < 0.001;\n}\n\n/**\n * The parts of a wall's centreline that are actually wall, as `[start, end]` offsets in\n * millimetres from node `a`.\n *\n * Overlapping openings merge into one gap; an opening reaching an end removes that span\n * entirely. An empty result means the opening spans the whole wall.\n */\nexport function wallCentrelineSpans(floor: PlanFloor, wall: PlanWall): Array<[number, number]> {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return [];\n const len = dist(a, b);\n if (len < EPS) return [];\n\n const gaps: Array<[number, number]> = [];\n for (const opening of Object.values(floor.openings)) {\n if (opening.wallId !== wall.id) continue;\n const half = opening.width / 2;\n const start = Math.max(0, opening.offset - half);\n const end = Math.min(len, opening.offset + half);\n if (end > start) gaps.push([start, end]);\n }\n if (gaps.length === 0) return [[0, len]];\n\n gaps.sort((x, y) => x[0] - y[0]);\n const merged: Array<[number, number]> = [gaps[0]];\n for (let i = 1; i < gaps.length; i++) {\n const last = merged[merged.length - 1];\n if (gaps[i][0] <= last[1]) last[1] = Math.max(last[1], gaps[i][1]);\n else merged.push(gaps[i]);\n }\n\n const spans: Array<[number, number]> = [];\n let cursor = 0;\n for (const [start, end] of merged) {\n if (start - cursor > EPS) spans.push([cursor, start]);\n cursor = end;\n }\n if (len - cursor > EPS) spans.push([cursor, len]);\n return spans;\n}\n\n/** Everything a renderer needs to draw a door leaf, swing arc or window symbol. */\nexport function openingGeometry(\n floor: PlanFloor,\n opening: PlanOpening,\n): { centre: PlanPoint; dir: PlanPoint; normal: PlanPoint; p1: PlanPoint; p2: PlanPoint } | null {\n const wall = floor.walls[opening.wallId];\n if (!wall) return null;\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n if (!a || !b) return null;\n const len = dist(a, b);\n if (len < EPS) return null;\n\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const normal = { x: -dir.y, y: dir.x };\n const half = Math.min(opening.width / 2, len / 2);\n const offset = Math.min(Math.max(opening.offset, half), len - half);\n const centre = { x: a.x + dir.x * offset, y: a.y + dir.y * offset };\n\n return {\n centre,\n dir,\n normal,\n p1: { x: centre.x - dir.x * half, y: centre.y - dir.y * half },\n p2: { x: centre.x + dir.x * half, y: centre.y + dir.y * half },\n };\n}\n\n/** One directed step along a chain. */\ninterface Step {\n wall: PlanWall;\n from: string;\n to: string;\n}\n\n/**\n * Maximal runs of same-thickness walls joined through degree-2 nodes.\n *\n * A chain may only continue through a node whose TOTAL degree is 2 and whose two walls\n * share a thickness: a different stroke width means a different path, and a degree-3+\n * node is a junction rather than a corner.\n */\nfunction buildChains(floor: PlanFloor, walls: PlanWall[], degrees: Map<string, number>): Step[][] {\n const byId = new Map(walls.map((w) => [w.id, w]));\n const atNode = new Map<string, PlanWall[]>();\n for (const wall of walls) {\n for (const nodeId of [wall.a, wall.b]) {\n const list = atNode.get(nodeId);\n if (list) list.push(wall);\n else atNode.set(nodeId, [wall]);\n }\n }\n\n const continuesThrough = (nodeId: string): PlanWall[] | null => {\n if ((degrees.get(nodeId) ?? 0) !== 2) return null;\n const here = atNode.get(nodeId);\n // Both walls must be in this thickness group, or the chain has to break here.\n if (!here || here.length !== 2) return null;\n return here;\n };\n\n const used = new Set<string>();\n const chains: Step[][] = [];\n\n const other = (wall: PlanWall, nodeId: string): string => (wall.a === nodeId ? wall.b : wall.a);\n\n for (const wall of walls) {\n if (used.has(wall.id)) continue;\n\n // Walk backwards to the start of the run, unless it closes on itself.\n let startWall = wall;\n let startNode = wall.a;\n const seenBack = new Set<string>([wall.id]);\n for (;;) {\n const pair = continuesThrough(startNode);\n if (!pair) break;\n const prev = pair[0].id === startWall.id ? pair[1] : pair[0];\n if (seenBack.has(prev.id)) break; // closed loop\n seenBack.add(prev.id);\n startWall = prev;\n startNode = other(prev, startNode);\n }\n\n // Walk forwards, collecting directed steps.\n const steps: Step[] = [];\n let current = startWall;\n let from = startNode;\n for (;;) {\n if (used.has(current.id)) break;\n used.add(current.id);\n const to = other(current, from);\n steps.push({ wall: current, from, to });\n const pair = continuesThrough(to);\n if (!pair) break;\n const next = pair[0].id === current.id ? pair[1] : pair[0];\n if (used.has(next.id)) break;\n current = next;\n from = to;\n if (!byId.has(current.id)) break;\n }\n\n if (steps.length > 0) chains.push(steps);\n }\n\n return chains;\n}\n\n/**\n * The outer corner of the one REFLEX gap at a node, as a two-legged stub.\n *\n * A chain's `stroke-linejoin` mitres the corner wherever a wall bends, but a chain has\n * to stop at a junction, and at a thickness change, so something else has to close the\n * corner there. Most junction corners need nothing: where the angular gap between two\n * neighbouring walls is at most 180 degrees, the two bands reach across it and already\n * meet at the mitre point, because both start AT the node rather than short of it.\n *\n * A gap WIDER than 180 degrees is the exception, and it is the only one. There the two\n * faces bounding the gap diverge instead of crossing, so nothing spans the gap and what\n * is left between the two butt ends is an open wedge biting into the node. It shows up\n * whenever every wall at a node points into the same half-plane: a wall running east, a\n * wall running north, and a third splitting the two leaves a quarter-circle bitten out\n * of the south-west side. Because the gaps around a node sum to 360 degrees, at most\n * one can be reflex, so a node never needs more than one of these.\n *\n * The stub is two legs laid back along the two walls bounding that gap. Stroked at the\n * wall thickness it stays within their own bands, adding nothing anywhere else, and its\n * mitre join fills the wedge and bevels under the same `stroke-miterlimit` as every\n * other corner. Filling every gap this way instead of only the reflex one is what used\n * to fire spikes out of narrow junctions: those gaps had nothing to fill, so the join\n * ran outside the walls, the further the tighter the angle.\n */\nfunction reflexCornerStubs(\n floor: PlanFloor,\n walls: PlanWall[],\n degrees: Map<string, number>,\n): Array<{ thickness: number; d: string }> {\n interface Arm {\n wall: PlanWall;\n dir: PlanPoint;\n angle: number;\n /** Millimetres of wall between the node and the first opening, if any. */\n reach: number;\n }\n\n const armsAt = new Map<string, Arm[]>();\n const addArm = (nodeId: string, arm: Arm) => {\n const list = armsAt.get(nodeId);\n if (list) list.push(arm);\n else armsAt.set(nodeId, [arm]);\n };\n\n for (const wall of walls) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n if (len < EPS) continue;\n const spans = wallCentrelineSpans(floor, wall);\n if (spans.length === 0) continue;\n\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const first = spans[0];\n const last = spans[spans.length - 1];\n addArm(wall.a, {\n wall,\n dir,\n angle: Math.atan2(dir.y, dir.x),\n reach: first[0] < EPS ? first[1] : 0,\n });\n addArm(wall.b, {\n wall,\n dir: { x: -dir.x, y: -dir.y },\n angle: Math.atan2(-dir.y, -dir.x),\n reach: last[1] > len - EPS ? len - last[0] : 0,\n });\n }\n\n const stubs: Array<{ thickness: number; d: string }> = [];\n const TAU = Math.PI * 2;\n\n for (const [nodeId, arms] of armsAt) {\n if (arms.length < 2) continue;\n /*\n * A chain runs straight through a plain corner, and its own join closes it. The test\n * has to be the one `buildChains` uses, which reads the degree of the node in the\n * WHOLE floor: drawing a subset of the walls, two arms at a T junction look like a\n * corner but the chain still breaks there, and skipping the fill left a notch bitten\n * out of the join.\n */\n const chainRunsThrough =\n (degrees.get(nodeId) ?? 0) === 2 && arms.length === 2 && arms[0].wall.thickness === arms[1].wall.thickness;\n if (chainRunsThrough) continue;\n\n arms.sort((p, q) => p.angle - q.angle);\n\n let widest = 0;\n let widestGap = -1;\n for (let i = 0; i < arms.length; i++) {\n const next = arms[(i + 1) % arms.length];\n const gap = i === arms.length - 1 ? next.angle + TAU - arms[i].angle : next.angle - arms[i].angle;\n if (gap > widestGap) {\n widestGap = gap;\n widest = i;\n }\n }\n if (widestGap <= Math.PI + EPS) continue;\n\n const from = arms[widest];\n const to = arms[(widest + 1) % arms.length];\n // The thinner of the two, so the stub can never bulge out past the thinner wall.\n const thickness = Math.min(from.wall.thickness, to.wall.thickness);\n // Half a thickness of leg is enough to carry the join, and an opening close to the\n // node shortens it so the stub cannot paint across the jamb.\n const legFrom = Math.min(thickness / 2, from.reach);\n const legTo = Math.min(thickness / 2, to.reach);\n if (legFrom < EPS || legTo < EPS) continue;\n\n const node = floor.nodes[nodeId];\n stubs.push({\n thickness,\n d:\n `M ${fmt(node.x + from.dir.x * legFrom)},${fmt(node.y + from.dir.y * legFrom)}` +\n ` L ${fmt(node.x)},${fmt(node.y)}` +\n ` L ${fmt(node.x + to.dir.x * legTo)},${fmt(node.y + to.dir.y * legTo)}`,\n });\n }\n\n return stubs;\n}\n\n/**\n * Builds the stroke path data for every wall, grouped by thickness, plus the cap lines\n * the two-pass trick cannot produce on its own.\n */\nexport function buildWallPaths(floor: PlanFloor, options: BuildWallPathsOptions = {}): WallPathResult {\n const { wallIds, capFreeEnds = true, capThicknessSteps = true } = options;\n\n const walls = Object.values(floor.walls).filter((w) => {\n if (wallIds && !wallIds.has(w.id)) return false;\n const a = floor.nodes[w.a];\n const b = floor.nodes[w.b];\n return a && b && dist(a, b) > EPS && w.a !== w.b;\n });\n if (walls.length === 0) return { groups: [], caps: [] };\n\n const degrees = nodeDegrees(floor);\n const caps: WallCapLine[] = [];\n\n // ── Group by thickness: one stroke width per path. ────────────────────────────\n const byThickness = new Map<number, PlanWall[]>();\n for (const wall of walls) {\n const list = byThickness.get(wall.thickness);\n if (list) list.push(wall);\n else byThickness.set(wall.thickness, [wall]);\n }\n\n const subpathsByThickness = new Map<number, string[]>();\n const pushSubpath = (thickness: number, d: string) => {\n const list = subpathsByThickness.get(thickness);\n if (list) list.push(d);\n else subpathsByThickness.set(thickness, [d]);\n };\n\n for (const [thickness, groupWalls] of byThickness) {\n for (const chain of buildChains(floor, groupWalls, degrees)) {\n let current: PlanPoint[] = [];\n const flush = () => {\n if (current.length >= 2) {\n pushSubpath(thickness, current.map((p, i) => `${i === 0 ? 'M' : 'L'} ${fmt(p.x)},${fmt(p.y)}`).join(' '));\n }\n current = [];\n };\n\n for (const step of chain) {\n const a = floor.nodes[step.from];\n const b = floor.nodes[step.to];\n const len = dist(a, b);\n if (len < EPS) continue;\n\n // Spans come back in the wall's own a->b direction; flip them when the chain\n // traverses the wall the other way.\n let spans = wallCentrelineSpans(floor, step.wall);\n if (step.from !== step.wall.a) {\n spans = spans.map(([s, e]) => [len - e, len - s] as [number, number]).reverse();\n }\n\n for (const [s, e] of spans) {\n const p1 = lerpPoint(a, b, s / len);\n const p2 = lerpPoint(a, b, e / len);\n if (current.length > 0 && samePoint(current[current.length - 1], p1)) {\n current.push(p2);\n } else {\n flush();\n current = [p1, p2];\n }\n }\n // An opening reaching the far end leaves nothing to continue from.\n if (spans.length === 0 || spans[spans.length - 1][1] < len - EPS) flush();\n }\n\n // A chain that returns to where it started closes properly, so the final corner\n // gets a miter join like every other corner rather than two butt caps.\n const first = chain[0];\n const last = chain[chain.length - 1];\n const closed = first.from === last.to;\n if (closed && current.length >= 3 && samePoint(current[0], current[current.length - 1])) {\n const ring = current.slice(0, -1);\n pushSubpath(thickness, `${ring.map((p, i) => `${i === 0 ? 'M' : 'L'} ${fmt(p.x)},${fmt(p.y)}`).join(' ')} Z`);\n current = [];\n } else {\n flush();\n }\n }\n }\n\n for (const stub of reflexCornerStubs(floor, walls, degrees)) pushSubpath(stub.thickness, stub.d);\n\n // ── Caps. ─────────────────────────────────────────────────────────────────────\n const capAt = (wall: PlanWall, offset: number, reason: WallCapReason) => {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n if (len < EPS) return;\n const dir = { x: (b.x - a.x) / len, y: (b.y - a.y) / len };\n const normal = { x: -dir.y, y: dir.x };\n const centre = { x: a.x + dir.x * offset, y: a.y + dir.y * offset };\n const half = wall.thickness / 2;\n caps.push({\n a: { x: centre.x - normal.x * half, y: centre.y - normal.y * half },\n b: { x: centre.x + normal.x * half, y: centre.y + normal.y * half },\n reason,\n wallId: wall.id,\n });\n };\n\n for (const wall of walls) {\n const a = floor.nodes[wall.a];\n const b = floor.nodes[wall.b];\n const len = dist(a, b);\n for (const [s, e] of wallCentrelineSpans(floor, wall)) {\n if (s > EPS) capAt(wall, s, 'jamb');\n else if (capFreeEnds && (degrees.get(wall.a) ?? 0) === 1) capAt(wall, 0, 'freeEnd');\n\n if (e < len - EPS) capAt(wall, e, 'jamb');\n else if (capFreeEnds && (degrees.get(wall.b) ?? 0) === 1) capAt(wall, len, 'freeEnd');\n }\n }\n\n if (capThicknessSteps) {\n const atNode = new Map<string, PlanWall[]>();\n for (const wall of walls) {\n for (const nodeId of [wall.a, wall.b]) {\n const list = atNode.get(nodeId);\n if (list) list.push(wall);\n else atNode.set(nodeId, [wall]);\n }\n }\n for (const [nodeId, incident] of atNode) {\n if (incident.length !== 2) continue;\n const [w1, w2] = incident;\n if (w1.thickness === w2.thickness) continue;\n // Draw the thicker wall's full cross-section. It overdraws a line across the\n // thinner wall's interior, which is the usual CAD convention for a joint between\n // two wall constructions, and far better than leaving no edge at all.\n const thicker = w1.thickness >= w2.thickness ? w1 : w2;\n const offset = thicker.a === nodeId ? 0 : dist(floor.nodes[thicker.a], floor.nodes[thicker.b]);\n capAt(thicker, offset, 'thicknessStep');\n }\n }\n\n const groups: WallPathGroup[] = [...subpathsByThickness.entries()]\n .sort((x, y) => x[0] - y[0])\n .map(([thickness, subpaths]) => ({ thickness, d: subpaths.join(' ') }));\n\n return { groups, caps };\n}\n"],"mappings":"iHAmEA,IAAM,EAAM,KAEZ,SAAS,EAAU,EAAc,EAAc,EAAsB,CACnE,MAAO,CAAE,EAAG,EAAE,GAAK,EAAE,EAAI,EAAE,GAAK,EAAG,EAAG,EAAE,GAAK,EAAE,EAAI,EAAE,GAAK,CAAE,CAC9D,CAEA,SAAS,EAAI,EAAmB,CAC9B,OAAO,OAAO,UAAU,CAAC,EAAI,OAAO,CAAC,EAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,SAAU,EAAE,CAC5E,CAEA,SAAS,EAAU,EAAc,EAAuB,CACtD,OAAO,KAAK,IAAI,EAAE,EAAI,EAAE,CAAC,EAAI,MAAS,KAAK,IAAI,EAAE,EAAI,EAAE,CAAC,EAAI,IAC9D,CASA,SAAgB,EAAoB,EAAkB,EAAyC,CAC7F,IAAM,EAAI,EAAM,MAAM,EAAK,GACrB,EAAI,EAAM,MAAM,EAAK,GAC3B,GAAI,C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,EAE7D,EAAQ,MAAK,CACxB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{PlanUnitSystem as e}from"./floorPlan.types.mjs";import{boundsOf as t}from"./floorPlan.geometry.mjs";import{newId as n}from"./floorPlan.graph.mjs";function r(e={}){return{id:e.floorId??n(`f`),label:e.floorLabel??`Ground floor`,elevation:0,height:e.height??2500,nodes:{},walls:{},openings:{},rooms:{}}}function i(t={}){return{id:t.id??n(`plan`),name:t.name,version:1,unitSystem:t.unitSystem??e.Metric,floors:[r(t)],revision:0}}function a(e,t){return t?e.floors.find(e=>e.id===t)??null:e.floors[0]??null}function o(e,t,n){let i=a(e,t);if(!i)return{plan:e,floor:r(),result:void 0,issues:[]};let o=n(i);return o.floor===i?{...o,plan:e}:{...o,plan:{...e,floors:e.floors.map(e=>e.id===i.id?o.floor:e),revision:e.revision+1}}}function s(e,t){let n=e.floors.some(e=>e.id===t.id);return{...e,floors:n?e.floors.map(e=>e.id===t.id?t:e):[...e.floors,t],revision:e.revision+1}}function c(e,t){return e.floors.findIndex(e=>e.id===t)}function l(e,t){let n=c(e,t);return n>0?e.floors[n-1]:null}function u(e,t={}){let i=e.floors[0]?.elevation??0,a=Math.max(0,Math.min(t.index??e.floors.length,e.floors.length)),o=e.floors[a-1],s={...r({height:t.height??o?.height??2500}),id:t.id??n(`f`),label:t.label??v(e),elevation:o?o.elevation+o.height:0},c=[...e.floors.slice(0,a),s,...e.floors.slice(a)];return{plan:{...e,floors:_(c,i),revision:e.revision+1},floor:s}}function d(e,t){if(e.floors.length<=1)return e;let n=e.floors[0].elevation,r=e.floors.filter(e=>e.id!==t);return r.length===e.floors.length?e:{...e,floors:_(r,n),revision:e.revision+1}}function f(e,t,r={}){let i=a(e,t);if(!i)return{plan:e,floor:null};let o=new Map(Object.keys(i.nodes).map(e=>[e,n(`n`)])),s=new Map(Object.keys(i.walls).map(e=>[e,n(`w`)])),l={...i,id:n(`f`),label:r.label??`${i.label} copy`,nodes:{},walls:{},openings:{},rooms:{}};for(let e of Object.values(i.nodes)){let t=o.get(e.id);l.nodes[t]={...e,id:t}}for(let e of Object.values(i.walls)){let t=s.get(e.id);l.walls[t]={...e,id:t,a:o.get(e.a),b:o.get(e.b)}}for(let e of Object.values(i.openings)){let t=s.get(e.wallId);if(!t)continue;let r=n(`o`);l.openings[r]={...e,id:r,wallId:t}}for(let e of Object.values(i.rooms)){let t=n(`r`);l.rooms[t]={...e,id:t,anchor:{...e.anchor},wallIds:e.wallIds.map(e=>s.get(e)).filter(e=>!!e)}}let u=e.floors[0].elevation,d=c(e,t)+1,f=[...e.floors.slice(0,d),l,...e.floors.slice(d)];return{plan:{...e,floors:_(f,u),revision:e.revision+1},floor:l}}var p=500;function m(e,t,n){let r=a(e,t),i=Math.max(500,Math.round(n));if(!r||r.height===i)return e;let o=e.floors[0].elevation,s=e.floors.map(e=>e.id===r.id?{...e,height:i}:e);return{...e,floors:_(s,o),revision:e.revision+1}}function h(e,t,n){let r=a(e,t);return!r||r.label===n?e:s(e,{...r,label:n})}function g(e,t,n){let r=c(e,t),i=Math.max(0,Math.min(n,e.floors.length-1));if(r<0||r===i)return e;let a=e.floors[0].elevation,o=[...e.floors],[s]=o.splice(r,1);return o.splice(i,0,s),{...e,floors:_(o,a),revision:e.revision+1}}function _(e,t){let n=t;return e.map(e=>{let t=e.elevation===n?e:{...e,elevation:n};return n+=e.height,t})}function v(e){let t=new Set(e.floors.map(e=>e.label));for(let n=e.floors.length+1;;n++){let e=`Floor ${n}`;if(!t.has(e))return e}}function y(e){let n=Object.values(e.nodes).map(e=>({x:e.x,y:e.y})),r=t(n);if(!r)return null;let i=0;for(let t of Object.values(e.walls))t.thickness>i&&(i=t.thickness);let a=i/2,o=r.minX-a,s=r.minY-a,c=r.maxX+a,l=r.maxY+a;return{minX:o,minY:s,maxX:c,maxY:l,width:c-o,height:l-s}}export{p as MIN_FLOOR_HEIGHT,u as addFloor,f as duplicateFloor,r as emptyFloor,i as emptyFloorPlan,l as floorBelow,y as floorBounds,c as floorIndex,a as getFloor,g as moveFloor,d as removeFloor,h as renameFloor,s as setFloor,m as setFloorHeight,o as updateFloor};
|
|
1
|
+
"use client";import{PlanUnitSystem as e}from"./floorPlan.types.mjs";import{boundsOf as t}from"./floorPlan.geometry.mjs";import{newId as n}from"./floorPlan.graph.mjs";function r(e={}){return{id:e.floorId??n(`f`),label:e.floorLabel??`Ground floor`,elevation:0,height:e.height??2500,nodes:{},walls:{},openings:{},rooms:{}}}function i(t={}){return{id:t.id??n(`plan`),name:t.name,version:1,unitSystem:t.unitSystem??e.Metric,floors:[r(t)],revision:0}}function a(e,t){return t?e.floors.find(e=>e.id===t)??null:e.floors[0]??null}function o(e,t,n){let i=a(e,t);if(!i)return{plan:e,floor:r(),result:void 0,issues:[]};let o=n(i);return o.floor===i?{...o,plan:e}:{...o,plan:{...e,floors:e.floors.map(e=>e.id===i.id?o.floor:e),revision:e.revision+1}}}function s(e,t){let n=e.floors.some(e=>e.id===t.id);return{...e,floors:n?e.floors.map(e=>e.id===t.id?t:e):[...e.floors,t],revision:e.revision+1}}function c(e,t){return e.floors.findIndex(e=>e.id===t)}function l(e,t){let n=c(e,t);return n>0?e.floors[n-1]:null}function u(e,t={}){let i=e.floors[0]?.elevation??0,a=Math.max(0,Math.min(t.index??e.floors.length,e.floors.length)),o=e.floors[a-1],s={...r({height:t.height??o?.height??2500}),id:t.id??n(`f`),label:t.label??v(e),elevation:o?o.elevation+o.height:0},c=[...e.floors.slice(0,a),s,...e.floors.slice(a)];return{plan:{...e,floors:_(c,i),revision:e.revision+1},floor:s}}function d(e,t){if(e.floors.length<=1)return e;let n=e.floors[0].elevation,r=e.floors.filter(e=>e.id!==t);return r.length===e.floors.length?e:{...e,floors:_(r,n),revision:e.revision+1}}function f(e,t,r={}){let i=a(e,t);if(!i)return{plan:e,floor:null};let o=new Map(Object.keys(i.nodes).map(e=>[e,n(`n`)])),s=new Map(Object.keys(i.walls).map(e=>[e,n(`w`)])),l={...i,id:n(`f`),label:r.label??`${i.label} copy`,nodes:{},walls:{},openings:{},rooms:{}};for(let e of Object.values(i.nodes)){let t=o.get(e.id);l.nodes[t]={...e,id:t}}for(let e of Object.values(i.walls)){let t=s.get(e.id);l.walls[t]={...e,id:t,a:o.get(e.a),b:o.get(e.b)}}for(let e of Object.values(i.openings)){let t=s.get(e.wallId);if(!t)continue;let r=n(`o`);l.openings[r]={...e,id:r,wallId:t}}for(let e of Object.values(i.rooms)){let t=n(`r`);l.rooms[t]={...e,id:t,anchor:{...e.anchor},wallIds:e.wallIds.map(e=>s.get(e)).filter(e=>!!e)}}let u=e.floors[0].elevation,d=c(e,t)+1,f=[...e.floors.slice(0,d),l,...e.floors.slice(d)];return{plan:{...e,floors:_(f,u),revision:e.revision+1},floor:l}}var p=500;function m(e,t,n){let r=a(e,t),i=Math.max(500,Math.round(n));if(!r||r.height===i)return e;let o=e.floors[0].elevation,s=e.floors.map(e=>e.id===r.id?{...e,height:i}:e);return{...e,floors:_(s,o),revision:e.revision+1}}function h(e,t,n){let r=a(e,t);return!r||r.label===n?e:s(e,{...r,label:n})}function g(e,t,n){let r=c(e,t),i=Math.max(0,Math.min(n,e.floors.length-1));if(r<0||r===i)return e;let a=e.floors[0].elevation,o=[...e.floors],[s]=o.splice(r,1);return o.splice(i,0,s),{...e,floors:_(o,a),revision:e.revision+1}}function _(e,t){let n=t;return e.map(e=>{let t=e.elevation===n?e:{...e,elevation:n};return n+=e.height,t})}function v(e){let t=new Set(e.floors.map(e=>e.label));for(let n=e.floors.length+1;;n++){let e=`Floor ${n}`;if(!t.has(e))return e}}function y(e){let n=Object.values(e.nodes).map(e=>({x:e.x,y:e.y})),r=t(n);if(!r)return null;let i=0;for(let t of Object.values(e.walls))t.thickness>i&&(i=t.thickness);let a=i/2,o=r.minX-a,s=r.minY-a,c=r.maxX+a,l=r.maxY+a;return{minX:o,minY:s,maxX:c,maxY:l,width:c-o,height:l-s}}export{p as MIN_FLOOR_HEIGHT,u as addFloor,f as duplicateFloor,r as emptyFloor,i as emptyFloorPlan,l as floorBelow,y as floorBounds,c as floorIndex,a as getFloor,g as moveFloor,d as removeFloor,h as renameFloor,s as setFloor,m as setFloorHeight,o as updateFloor};
|
|
2
2
|
//# sourceMappingURL=floorPlan.plan.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floorPlan.plan.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.plan.ts"],"sourcesContent":["/**\n * Document-level helpers: creating a plan, addressing a floor within it, and the\n * revision counter that memoisation keys off.\n */\n\nimport { boundsOf } from './floorPlan.geometry';\nimport { newId } from './floorPlan.graph';\nimport { PlanUnitSystem } from './floorPlan.types';\nimport type { FloorPlan, PlanEdit, PlanFloor, PlanPoint } from './floorPlan.types';\n\nexport interface EmptyFloorPlanOptions {\n id?: string;\n name?: string;\n floorId?: string;\n floorLabel?: string;\n unitSystem?: PlanUnitSystem;\n /** Default storey height in millimetres. */\n height?: number;\n}\n\nexport function emptyFloor(options: Omit<EmptyFloorPlanOptions, 'id' | 'name'> = {}): PlanFloor {\n return {\n id: options.floorId ?? newId('f'),\n label: options.floorLabel ?? 'Ground floor',\n elevation: 0,\n height: options.height ?? 2500,\n nodes: {},\n walls: {},\n openings: {},\n rooms: {},\n };\n}\n\nexport function emptyFloorPlan(options: EmptyFloorPlanOptions = {}): FloorPlan {\n return {\n id: options.id ?? newId('plan'),\n name: options.name,\n version: 1,\n unitSystem: options.unitSystem ?? PlanUnitSystem.Metric,\n floors: [emptyFloor(options)],\n revision: 0,\n };\n}\n\nexport function getFloor(plan: FloorPlan, floorId?: string): PlanFloor | null {\n if (!floorId) return plan.floors[0] ?? null;\n return plan.floors.find((f) => f.id === floorId) ?? null;\n}\n\n/**\n * Applies a floor-level edit to one floor of a plan, bumping `revision` so memoised\n * derivations know to recompute.\n *\n * The revision only moves when the edit actually returned a different floor, so a\n * gesture that changed nothing does not invalidate anything.\n */\nexport function updateFloor<T>(\n plan: FloorPlan,\n floorId: string | undefined,\n edit: (floor: PlanFloor) => PlanEdit<T>,\n): PlanEdit<T> & { plan: FloorPlan } {\n const floor = getFloor(plan, floorId);\n if (!floor) {\n return { plan, floor: emptyFloor(), result: undefined as T, issues: [] };\n }\n\n const applied = edit(floor);\n if (applied.floor === floor) {\n return { ...applied, plan };\n }\n\n return {\n ...applied,\n plan: {\n ...plan,\n floors: plan.floors.map((f) => (f.id === floor.id ? applied.floor : f)),\n revision: plan.revision + 1,\n },\n };\n}\n\n/** Replaces one floor outright, bumping the revision. */\nexport function setFloor(plan: FloorPlan, floor: PlanFloor): FloorPlan {\n const exists = plan.floors.some((f) => f.id === floor.id);\n return {\n ...plan,\n floors: exists ? plan.floors.map((f) => (f.id === floor.id ? floor : f)) : [...plan.floors, floor],\n revision: plan.revision + 1,\n };\n}\n\n// ─── Floors ────────────────────────────────────────────────────────────────────\n\n/**\n * Floors run bottom to top: index 0 is the lowest storey, and `elevation` rises with\n * the index. Nothing enforces that beyond these helpers, but `floorBelow` and the\n * drawer's underlay both read it, so an out-of-order `floors` array shows the wrong\n * storey underneath.\n */\nexport function floorIndex(plan: FloorPlan, floorId: string): number {\n return plan.floors.findIndex((f) => f.id === floorId);\n}\n\n/** The storey directly under this one, which is what an underlay traces. */\nexport function floorBelow(plan: FloorPlan, floorId: string): PlanFloor | null {\n const i = floorIndex(plan, floorId);\n return i > 0 ? plan.floors[i - 1] : null;\n}\n\nexport interface AddFloorOptions {\n label?: string;\n /** Millimetres. Defaults to the storey height of the floor it is added above. */\n height?: number;\n /** Where to put it. Defaults to directly above `aboveFloorId`, else on top. */\n index?: number;\n id?: string;\n}\n\n/**\n * Adds an empty storey and returns the plan with it, plus the floor itself.\n *\n * Its elevation is the top of the storey below, so a plan stays physically coherent\n * without the caller doing arithmetic. Everything above is pushed up by the new storey's\n * height, since inserting a floor into a building raises the ones over it.\n */\nexport function addFloor(plan: FloorPlan, options: AddFloorOptions = {}): { plan: FloorPlan; floor: PlanFloor } {\n const base = plan.floors[0]?.elevation ?? 0;\n const at = Math.max(0, Math.min(options.index ?? plan.floors.length, plan.floors.length));\n const below = plan.floors[at - 1];\n const height = options.height ?? below?.height ?? 2500;\n\n const floor: PlanFloor = {\n ...emptyFloor({ height }),\n id: options.id ?? newId('f'),\n label: options.label ?? nextFloorLabel(plan),\n elevation: below ? below.elevation + below.height : 0,\n };\n\n const floors = [...plan.floors.slice(0, at), floor, ...plan.floors.slice(at)];\n return { plan: { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 }, floor };\n}\n\n/**\n * Removes a storey, unless it is the last one: a plan with no floors has nowhere to\n * draw, and every consumer would need a special case for it.\n */\nexport function removeFloor(plan: FloorPlan, floorId: string): FloorPlan {\n if (plan.floors.length <= 1) return plan;\n const base = plan.floors[0].elevation;\n const floors = plan.floors.filter((f) => f.id !== floorId);\n if (floors.length === plan.floors.length) return plan;\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/**\n * Copies a storey, including its geometry, directly above itself.\n *\n * Every id is regenerated and every reference rewired to the copy, so the two storeys\n * share nothing: an edit to one must not reach through into the other. This is the usual\n * way to start an upper floor, since the walls below are mostly where the walls above go.\n */\nexport function duplicateFloor(\n plan: FloorPlan,\n floorId: string,\n options: { label?: string } = {},\n): { plan: FloorPlan; floor: PlanFloor | null } {\n const source = getFloor(plan, floorId);\n if (!source) return { plan, floor: null };\n\n const nodeIds = new Map(Object.keys(source.nodes).map((id) => [id, newId('n')]));\n const wallIds = new Map(Object.keys(source.walls).map((id) => [id, newId('w')]));\n\n const copy: PlanFloor = {\n ...source,\n id: newId('f'),\n label: options.label ?? `${source.label} copy`,\n nodes: {},\n walls: {},\n openings: {},\n rooms: {},\n };\n\n for (const node of Object.values(source.nodes)) {\n const id = nodeIds.get(node.id)!;\n copy.nodes[id] = { ...node, id };\n }\n for (const wall of Object.values(source.walls)) {\n const id = wallIds.get(wall.id)!;\n copy.walls[id] = { ...wall, id, a: nodeIds.get(wall.a)!, b: nodeIds.get(wall.b)! };\n }\n for (const opening of Object.values(source.openings)) {\n const wallId = wallIds.get(opening.wallId);\n if (!wallId) continue;\n const id = newId('o');\n copy.openings[id] = { ...opening, id, wallId };\n }\n for (const room of Object.values(source.rooms)) {\n const id = newId('r');\n copy.rooms[id] = {\n ...room,\n id,\n anchor: { ...room.anchor },\n // Room identity is matched on these, so they have to point at the copy's own walls\n // or the first derive would strand every room in it.\n wallIds: room.wallIds.map((w) => wallIds.get(w)).filter((w): w is string => !!w),\n };\n }\n\n const base = plan.floors[0].elevation;\n const at = floorIndex(plan, floorId) + 1;\n const floors = [...plan.floors.slice(0, at), copy, ...plan.floors.slice(at)];\n return { plan: { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 }, floor: copy };\n}\n\n/** Millimetres. Low enough for a crawl space, high enough to stop a zero-height storey. */\nexport const MIN_FLOOR_HEIGHT = 500;\n\n/**\n * Sets a storey's height, and drops or lifts everything above it to suit.\n *\n * This is why it is not a plain `setFloor`: a storey's height is what the next one sits\n * on, so changing it without re-stacking leaves the floors above either buried in it or\n * floating over it, which nothing in 2D would ever show.\n */\nexport function setFloorHeight(plan: FloorPlan, floorId: string, height: number): FloorPlan {\n const floor = getFloor(plan, floorId);\n const next = Math.max(MIN_FLOOR_HEIGHT, Math.round(height));\n if (!floor || floor.height === next) return plan;\n\n const base = plan.floors[0].elevation;\n const floors = plan.floors.map((f) => (f.id === floor.id ? { ...f, height: next } : f));\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/** Renames a storey. Its own field, since nothing else about a floor is text. */\nexport function renameFloor(plan: FloorPlan, floorId: string, label: string): FloorPlan {\n const floor = getFloor(plan, floorId);\n if (!floor || floor.label === label) return plan;\n return setFloor(plan, { ...floor, label });\n}\n\n/** Moves a storey up or down the stack, re-stacking the elevations behind it. */\nexport function moveFloor(plan: FloorPlan, floorId: string, toIndex: number): FloorPlan {\n const from = floorIndex(plan, floorId);\n const to = Math.max(0, Math.min(toIndex, plan.floors.length - 1));\n if (from < 0 || from === to) return plan;\n const base = plan.floors[0].elevation;\n const floors = [...plan.floors];\n const [moved] = floors.splice(from, 1);\n floors.splice(to, 0, moved);\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/**\n * Re-stacks elevations so each storey sits on the one below. Without this, adding or\n * removing a floor leaves a gap or an overlap in the building that only shows up in 3D.\n *\n * `base` is the building's own ground level and must come from the plan BEFORE the\n * edit: reading it off whichever floor ends up lowest moves the whole building whenever\n * two storeys of different heights are reordered.\n */\nfunction reElevate(floors: PlanFloor[], base: number): PlanFloor[] {\n let elevation = base;\n return floors.map((floor) => {\n const next = floor.elevation === elevation ? floor : { ...floor, elevation };\n elevation += floor.height;\n return next;\n });\n}\n\n/** `Floor 2`, `Floor 3`, … skipping any number already used. */\nfunction nextFloorLabel(plan: FloorPlan): string {\n const used = new Set(plan.floors.map((f) => f.label));\n for (let n = plan.floors.length + 1; ; n++) {\n const label = `Floor ${n}`;\n if (!used.has(label)) return label;\n }\n}\n\nexport interface PlanBounds {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n width: number;\n height: number;\n}\n\n/**\n * Bounding box of a floor's geometry, padded by half the thickest wall so the outer\n * face of every wall is inside it rather than its centreline.\n */\nexport function floorBounds(floor: PlanFloor): PlanBounds | null {\n const points: PlanPoint[] = Object.values(floor.nodes).map((n) => ({ x: n.x, y: n.y }));\n const raw = boundsOf(points);\n if (!raw) return null;\n\n let maxThickness = 0;\n for (const wall of Object.values(floor.walls)) {\n if (wall.thickness > maxThickness) maxThickness = wall.thickness;\n }\n const pad = maxThickness / 2;\n\n const minX = raw.minX - pad;\n const minY = raw.minY - pad;\n const maxX = raw.maxX + pad;\n const maxY = raw.maxY + pad;\n return { minX, minY, maxX, maxY, width: maxX - minX, height: maxY - minY };\n}\n"],"mappings":"yJAoBA,SAAgB,EAAW,EAAsD,CAAC,EAAc,CAC9F,MAAO,CACL,GAAI,EAAQ,SAAW,EAAM,GAAG,EAChC,MAAO,EA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sourcesContent":["/**\n * Document-level helpers: creating a plan, addressing a floor within it, and the\n * revision counter that memoisation keys off.\n */\n\nimport { boundsOf } from './floorPlan.geometry';\nimport { newId } from './floorPlan.graph';\nimport { PlanUnitSystem } from './floorPlan.types';\nimport type { FloorPlan, PlanEdit, PlanFloor, PlanPoint } from './floorPlan.types';\n\nexport interface EmptyFloorPlanOptions {\n id?: string;\n name?: string;\n floorId?: string;\n floorLabel?: string;\n unitSystem?: PlanUnitSystem;\n /** Default storey height in millimetres. */\n height?: number;\n}\n\nexport function emptyFloor(options: Omit<EmptyFloorPlanOptions, 'id' | 'name'> = {}): PlanFloor {\n return {\n id: options.floorId ?? newId('f'),\n label: options.floorLabel ?? 'Ground floor',\n elevation: 0,\n height: options.height ?? 2500,\n nodes: {},\n walls: {},\n openings: {},\n rooms: {},\n };\n}\n\nexport function emptyFloorPlan(options: EmptyFloorPlanOptions = {}): FloorPlan {\n return {\n id: options.id ?? newId('plan'),\n name: options.name,\n version: 1,\n unitSystem: options.unitSystem ?? PlanUnitSystem.Metric,\n floors: [emptyFloor(options)],\n revision: 0,\n };\n}\n\nexport function getFloor(plan: FloorPlan, floorId?: string): PlanFloor | null {\n if (!floorId) return plan.floors[0] ?? null;\n return plan.floors.find((f) => f.id === floorId) ?? null;\n}\n\n/**\n * Applies a floor-level edit to one floor of a plan, bumping `revision` so memoised\n * derivations know to recompute.\n *\n * The revision only moves when the edit actually returned a different floor, so a\n * gesture that changed nothing does not invalidate anything.\n */\nexport function updateFloor<T>(\n plan: FloorPlan,\n floorId: string | undefined,\n edit: (floor: PlanFloor) => PlanEdit<T>,\n): PlanEdit<T> & { plan: FloorPlan } {\n const floor = getFloor(plan, floorId);\n if (!floor) {\n return { plan, floor: emptyFloor(), result: undefined as T, issues: [] };\n }\n\n const applied = edit(floor);\n if (applied.floor === floor) {\n return { ...applied, plan };\n }\n\n return {\n ...applied,\n plan: {\n ...plan,\n floors: plan.floors.map((f) => (f.id === floor.id ? applied.floor : f)),\n revision: plan.revision + 1,\n },\n };\n}\n\n/** Replaces one floor outright, bumping the revision. */\nexport function setFloor(plan: FloorPlan, floor: PlanFloor): FloorPlan {\n const exists = plan.floors.some((f) => f.id === floor.id);\n return {\n ...plan,\n floors: exists ? plan.floors.map((f) => (f.id === floor.id ? floor : f)) : [...plan.floors, floor],\n revision: plan.revision + 1,\n };\n}\n\n// ─── Floors ────────────────────────────────────────────────────────────────────\n\n/**\n * Floors run bottom to top: index 0 is the lowest storey, and `elevation` rises with\n * the index. Nothing enforces that beyond these helpers, but `floorBelow` and the\n * drawer's underlay both read it, so an out-of-order `floors` array shows the wrong\n * storey underneath.\n */\nexport function floorIndex(plan: FloorPlan, floorId: string): number {\n return plan.floors.findIndex((f) => f.id === floorId);\n}\n\n/** The storey directly under this one, which is what an underlay traces. */\nexport function floorBelow(plan: FloorPlan, floorId: string): PlanFloor | null {\n const i = floorIndex(plan, floorId);\n return i > 0 ? plan.floors[i - 1] : null;\n}\n\nexport interface AddFloorOptions {\n label?: string;\n /** Millimetres. Defaults to the storey height of the floor it is added above. */\n height?: number;\n /** Where to put it. Defaults to directly above `aboveFloorId`, else on top. */\n index?: number;\n id?: string;\n}\n\n/**\n * Adds an empty storey and returns the plan with it, plus the floor itself.\n *\n * Its elevation is the top of the storey below, so a plan stays physically coherent\n * without the caller doing arithmetic. Everything above is pushed up by the new storey's\n * height, since inserting a floor into a building raises the ones over it.\n */\nexport function addFloor(plan: FloorPlan, options: AddFloorOptions = {}): { plan: FloorPlan; floor: PlanFloor } {\n const base = plan.floors[0]?.elevation ?? 0;\n const at = Math.max(0, Math.min(options.index ?? plan.floors.length, plan.floors.length));\n const below = plan.floors[at - 1];\n const height = options.height ?? below?.height ?? 2500;\n\n const floor: PlanFloor = {\n ...emptyFloor({ height }),\n id: options.id ?? newId('f'),\n label: options.label ?? nextFloorLabel(plan),\n elevation: below ? below.elevation + below.height : 0,\n };\n\n const floors = [...plan.floors.slice(0, at), floor, ...plan.floors.slice(at)];\n return { plan: { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 }, floor };\n}\n\n/**\n * Removes a storey, unless it is the last one: a plan with no floors has nowhere to\n * draw, and every consumer would need a special case for it.\n */\nexport function removeFloor(plan: FloorPlan, floorId: string): FloorPlan {\n if (plan.floors.length <= 1) return plan;\n const base = plan.floors[0].elevation;\n const floors = plan.floors.filter((f) => f.id !== floorId);\n if (floors.length === plan.floors.length) return plan;\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/**\n * Copies a storey, including its geometry, directly above itself.\n *\n * Every id is regenerated and every reference rewired to the copy, so the two storeys\n * share nothing: an edit to one must not reach through into the other. This is the usual\n * way to start an upper floor, since the walls below are mostly where the walls above go.\n */\nexport function duplicateFloor(\n plan: FloorPlan,\n floorId: string,\n options: { label?: string } = {},\n): { plan: FloorPlan; floor: PlanFloor | null } {\n const source = getFloor(plan, floorId);\n if (!source) return { plan, floor: null };\n\n const nodeIds = new Map(Object.keys(source.nodes).map((id) => [id, newId('n')]));\n const wallIds = new Map(Object.keys(source.walls).map((id) => [id, newId('w')]));\n\n const copy: PlanFloor = {\n ...source,\n id: newId('f'),\n label: options.label ?? `${source.label} copy`,\n nodes: {},\n walls: {},\n openings: {},\n rooms: {},\n };\n\n for (const node of Object.values(source.nodes)) {\n const id = nodeIds.get(node.id)!;\n copy.nodes[id] = { ...node, id };\n }\n for (const wall of Object.values(source.walls)) {\n const id = wallIds.get(wall.id)!;\n copy.walls[id] = { ...wall, id, a: nodeIds.get(wall.a)!, b: nodeIds.get(wall.b)! };\n }\n for (const opening of Object.values(source.openings)) {\n const wallId = wallIds.get(opening.wallId);\n if (!wallId) continue;\n const id = newId('o');\n copy.openings[id] = { ...opening, id, wallId };\n }\n for (const room of Object.values(source.rooms)) {\n const id = newId('r');\n copy.rooms[id] = {\n ...room,\n id,\n anchor: { ...room.anchor },\n // Room identity is matched on these, so they have to point at the copy's own walls\n // or the first derive would strand every room in it.\n wallIds: room.wallIds.map((w) => wallIds.get(w)).filter((w): w is string => !!w),\n };\n }\n\n const base = plan.floors[0].elevation;\n const at = floorIndex(plan, floorId) + 1;\n const floors = [...plan.floors.slice(0, at), copy, ...plan.floors.slice(at)];\n return { plan: { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 }, floor: copy };\n}\n\n/** Millimetres. Low enough for a crawl space, high enough to stop a zero-height storey. */\nexport const MIN_FLOOR_HEIGHT = 500;\n\n/**\n * Sets a storey's height, and drops or lifts everything above it to suit.\n *\n * This is why it is not a plain `setFloor`: a storey's height is what the next one sits\n * on, so changing it without re-stacking leaves the floors above either buried in it or\n * floating over it, which nothing in 2D would ever show.\n */\nexport function setFloorHeight(plan: FloorPlan, floorId: string, height: number): FloorPlan {\n const floor = getFloor(plan, floorId);\n const next = Math.max(MIN_FLOOR_HEIGHT, Math.round(height));\n if (!floor || floor.height === next) return plan;\n\n const base = plan.floors[0].elevation;\n const floors = plan.floors.map((f) => (f.id === floor.id ? { ...f, height: next } : f));\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/** Renames a storey. Its own field, since nothing else about a floor is text. */\nexport function renameFloor(plan: FloorPlan, floorId: string, label: string): FloorPlan {\n const floor = getFloor(plan, floorId);\n if (!floor || floor.label === label) return plan;\n return setFloor(plan, { ...floor, label });\n}\n\n/** Moves a storey up or down the stack, re-stacking the elevations behind it. */\nexport function moveFloor(plan: FloorPlan, floorId: string, toIndex: number): FloorPlan {\n const from = floorIndex(plan, floorId);\n const to = Math.max(0, Math.min(toIndex, plan.floors.length - 1));\n if (from < 0 || from === to) return plan;\n const base = plan.floors[0].elevation;\n const floors = [...plan.floors];\n const [moved] = floors.splice(from, 1);\n floors.splice(to, 0, moved);\n return { ...plan, floors: reElevate(floors, base), revision: plan.revision + 1 };\n}\n\n/**\n * Re-stacks elevations so each storey sits on the one below. Without this, adding or\n * removing a floor leaves a gap or an overlap in the building that only shows up in 3D.\n *\n * `base` is the building's own ground level and must come from the plan BEFORE the\n * edit: reading it off whichever floor ends up lowest moves the whole building whenever\n * two storeys of different heights are reordered.\n */\nfunction reElevate(floors: PlanFloor[], base: number): PlanFloor[] {\n let elevation = base;\n return floors.map((floor) => {\n const next = floor.elevation === elevation ? floor : { ...floor, elevation };\n elevation += floor.height;\n return next;\n });\n}\n\n/** `Floor 2`, `Floor 3`, … skipping any number already used. */\nfunction nextFloorLabel(plan: FloorPlan): string {\n const used = new Set(plan.floors.map((f) => f.label));\n for (let n = plan.floors.length + 1; ; n++) {\n const label = `Floor ${n}`;\n if (!used.has(label)) return label;\n }\n}\n\nexport interface PlanBounds {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n width: number;\n height: number;\n}\n\n/**\n * Bounding box of a floor's geometry, padded by half the thickest wall so the outer\n * face of every wall is inside it rather than its centreline.\n */\nexport function floorBounds(floor: PlanFloor): PlanBounds | null {\n const points: PlanPoint[] = Object.values(floor.nodes).map((n) => ({ x: n.x, y: n.y }));\n const raw = boundsOf(points);\n if (!raw) return null;\n\n let maxThickness = 0;\n for (const wall of Object.values(floor.walls)) {\n if (wall.thickness > maxThickness) maxThickness = wall.thickness;\n }\n const pad = maxThickness / 2;\n\n const minX = raw.minX - pad;\n const minY = raw.minY - pad;\n const maxX = raw.maxX + pad;\n const maxY = raw.maxY + pad;\n return { minX, minY, maxX, maxY, width: maxX - minX, height: maxY - minY };\n}\n"],"mappings":"sKAoBA,SAAgB,EAAW,EAAsD,CAAC,EAAc,CAC9F,MAAO,CACL,GAAI,EAAQ,SAAW,EAAM,GAAG,EAChC,MAAO,EAAQ,YAAc,eAC7B,UAAW,EACX,OAAQ,EAAQ,QAAU,KAC1B,MAAO,CAAC,EACR,MAAO,CAAC,EACR,SAAU,CAAC,EACX,MAAO,CAAC,CACV,CACF,CAEA,SAAgB,EAAe,EAAiC,CAAC,EAAc,CAC7E,MAAO,CACL,GAAI,EAAQ,IAAM,EAAM,MAAM,EAC9B,KAAM,EAAQ,KACd,QAAS,EACT,WAAY,EAAQ,YAAc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AK,GAAU,CAC3B,IAAM,EAAO,EAAM,YAAc,EAAY,EAAQ,CAAE,GAAG,EAAO,WAAU,EAE3E,MADA,IAAa,EAAM,OACZ,CACT,CAAC,CACH,CAGA,SAAS,EAAe,EAAyB,CAC/C,IAAM,EAAO,IAAI,IAAI,EAAK,OAAO,IAAK,GAAM,EAAE,KAAK,CAAC,EACpD,IAAK,IAAI,EAAI,EAAK,OAAO,OAAS,GAAK,IAAK,CAC1C,IAAM,EAAQ,SAAS,IACvB,GAAI,CAAC,EAAK,IAAI,CAAK,EAAG,OAAO,CAC/B,CACF,CAeA,SAAgB,EAAY,EAAqC,CAC/D,IAAM,EAAsB,OAAO,OAAO,EAAM,KAAK,CAAC,CAAC,IAAK,IAAO,CAAE,EAAG,EAAE,EAAG,EAAG,EAAE,CAAE,EAAE,EAChF,EAAM,EAAS,CAAM,EAC3B,GAAI,CAAC,EAAK,OAAO,KAEjB,IAAI,EAAe,EACnB,IAAK,IAAM,KAAQ,OAAO,OAAO,EAAM,KAAK,EACtC,EAAK,UAAY,IAAc,EAAe,EAAK,WAEzD,IAAM,EAAM,EAAe,EAErB,EAAO,EAAI,KAAO,EAClB,EAAO,EAAI,KAAO,EAClB,EAAO,EAAI,KAAO,EAClB,EAAO,EAAI,KAAO,EACxB,MAAO,CAAE,OAAM,OAAM,OAAM,OAAM,MAAO,EAAO,EAAM,OAAQ,EAAO,CAAK,CAC3E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{PlanIssueKind as e}from"./floorPlan.types.mjs";import{pointInRings as t,representativePoint as n}from"./floorPlan.geometry.mjs";import{newId as r}from"./floorPlan.graph.mjs";import{deriveFaces as i}from"./floorPlan.faces.mjs";var a={boundary:2,anchor:1,area:.25},o=.15;function s(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let r of e)t.has(r)&&(n+=1);let r=e.size+t.size-n;return r===0?0:n/r}function c(e,n,r){let i=s(new Set(e.wallIds),r),o=+!!t(e.anchor,n.outer,n.holes),c=e.area>0&&n.area>0?Math.min(e.area,n.area)/Math.max(e.area,n.area):0;return a.boundary*i+a.anchor*o+a.area*c}function l(t){let r=i(t),a=[],o=Object.values(t.rooms),s=r.map(e=>new Set(e.wallIds)),l=[];for(let e=0;e<o.length;e++)for(let t=0;t<r.length;t++){let n=c(o[e],r[t],s[t]);n>.15&&l.push({roomIndex:e,faceIndex:t,score:n})}l.sort((e,t)=>{if(t.score!==e.score)return t.score-e.score;let n=o[e.roomIndex].seq-o[t.roomIndex].seq;return n===0?r[e.faceIndex].id<r[t.faceIndex].id?-1:1:n});let u=Array(o.length).fill(!1),d=Array(r.length).fill(-1);for(let e of l)u[e.roomIndex]||d[e.faceIndex]===-1&&(u[e.roomIndex]=!0,d[e.faceIndex]=e.roomIndex);let f={...t.rooms},p=r.map((e,t)=>{let r=n(e.outer,e.holes),i=d[t];if(i===-1)return{...e,roomId:null,meta:null,anchor:r};let a=o[i],s=a.anchorPinned?a.anchor:r,c={...a,anchor:s,wallIds:[...new Set(e.wallIds)],area:e.area};return f[a.id]=c,{...e,roomId:a.id,meta:c,anchor:s}});for(let t=0;t<o.length;t++)u[t]||a.push({kind:e.UnmatchedRoom,message:`"${o[t].name}" is not currently enclosed by any walls.`,roomIds:[o[t].id]});return{floor:{...t,rooms:f},rooms:p,issues:a}}var u=0;function d(e,t={}){let{rooms:n,floor:i}=l(e),a={...i.rooms},o=[],s=0,c=new Set(Object.values(a).map(e=>e.name));for(let e of n){if(e.roomId)continue;s+=1,u+=1;let n=t.nameFor?.(s,e);if(!n){let e=Object.keys(a).length+1;for(n=`Room ${e}`;c.has(n);)e+=1,n=`Room ${e}`}c.add(n);let i={id:r(`r`),name:n,anchor:e.anchor,anchorPinned:!1,seq:u,wallIds:[...new Set(e.wallIds)],area:e.area};a[i.id]=i,o.push(i)}return{floor:{...i,rooms:a},created:o}}function f(e){let{rooms:t}=l(e),n=new Set(t.map(e=>e.roomId).filter(Boolean)),r={},i=[];for(let t of Object.values(e.rooms))n.has(t.id)?r[t.id]=t:i.push(t.id);return{floor:{...e,rooms:r},removed:i}}function p(e,n){let r=null;for(let i of e)t(n,i.outer,i.holes)&&(!r||i.area<r.area)&&(r=i);return r}export{o as MATCH_THRESHOLD,a as MATCH_WEIGHTS,d as commitDerivation,l as derivePlan,f as pruneUnmatchedRooms,p as roomAtPoint};
|
|
1
|
+
"use client";import{PlanIssueKind as e}from"./floorPlan.types.mjs";import{pointInRings as t,representativePoint as n}from"./floorPlan.geometry.mjs";import{newId as r}from"./floorPlan.graph.mjs";import{deriveFaces as i}from"./floorPlan.faces.mjs";var a={boundary:2,anchor:1,area:.25},o=.15;function s(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let r of e)t.has(r)&&(n+=1);let r=e.size+t.size-n;return r===0?0:n/r}function c(e,n,r){let i=s(new Set(e.wallIds),r),o=+!!t(e.anchor,n.outer,n.holes),c=e.area>0&&n.area>0?Math.min(e.area,n.area)/Math.max(e.area,n.area):0;return a.boundary*i+a.anchor*o+a.area*c}function l(t){let r=i(t),a=[],o=Object.values(t.rooms),s=r.map(e=>new Set(e.wallIds)),l=[];for(let e=0;e<o.length;e++)for(let t=0;t<r.length;t++){let n=c(o[e],r[t],s[t]);n>.15&&l.push({roomIndex:e,faceIndex:t,score:n})}l.sort((e,t)=>{if(t.score!==e.score)return t.score-e.score;let n=o[e.roomIndex].seq-o[t.roomIndex].seq;return n===0?r[e.faceIndex].id<r[t.faceIndex].id?-1:1:n});let u=Array(o.length).fill(!1),d=Array(r.length).fill(-1);for(let e of l)u[e.roomIndex]||d[e.faceIndex]===-1&&(u[e.roomIndex]=!0,d[e.faceIndex]=e.roomIndex);let f={...t.rooms},p=r.map((e,t)=>{let r=n(e.outer,e.holes),i=d[t];if(i===-1)return{...e,roomId:null,meta:null,anchor:r};let a=o[i],s=a.anchorPinned?a.anchor:r,c={...a,anchor:s,wallIds:[...new Set(e.wallIds)],area:e.area};return f[a.id]=c,{...e,roomId:a.id,meta:c,anchor:s}});for(let t=0;t<o.length;t++)u[t]||a.push({kind:e.UnmatchedRoom,message:`"${o[t].name}" is not currently enclosed by any walls.`,roomIds:[o[t].id]});return{floor:{...t,rooms:f},rooms:p,issues:a}}var u=0;function d(e,t={}){let{rooms:n,floor:i}=l(e),a={...i.rooms},o=[],s=0,c=new Set(Object.values(a).map(e=>e.name));for(let e of n){if(e.roomId)continue;s+=1,u+=1;let n=t.nameFor?.(s,e);if(!n){let e=Object.keys(a).length+1;for(n=`Room ${e}`;c.has(n);)e+=1,n=`Room ${e}`}c.add(n);let i={id:r(`r`),name:n,anchor:e.anchor,anchorPinned:!1,seq:u,wallIds:[...new Set(e.wallIds)],area:e.area};a[i.id]=i,o.push(i)}return{floor:{...i,rooms:a},created:o}}function f(e){let{rooms:t}=l(e),n=new Set(t.map(e=>e.roomId).filter(Boolean)),r={},i=[];for(let t of Object.values(e.rooms))n.has(t.id)?r[t.id]=t:i.push(t.id);return{floor:{...e,rooms:r},removed:i}}function p(e,n){let r=null;for(let i of e)t(n,i.outer,i.holes)&&(!r||i.area<r.area)&&(r=i);return r}export{o as MATCH_THRESHOLD,a as MATCH_WEIGHTS,d as commitDerivation,l as derivePlan,f as pruneUnmatchedRooms,p as roomAtPoint};
|
|
2
2
|
//# sourceMappingURL=floorPlan.rooms.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floorPlan.rooms.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.rooms.ts"],"sourcesContent":["/**\n * Room identity: attaching stored metadata (name, colour) to derived faces.\n *\n * Identity is primarily the SET OF BOUNDARY WALL IDS, with the anchor point as a\n * secondary signal. That ordering is the important design decision here. Anchors alone\n * look sufficient but fail in three ways: a whole-plan drag leaves every absolute\n * anchor behind, a merge gives two anchors one face with no tie-break, and dragging a\n * node can move a boundary past its own anchor. Wall ids survive every operation that\n * only moves geometry, so reshaping and translating match perfectly without anyone\n * having to remember to transform anchors.\n */\n\nimport { deriveFaces } from './floorPlan.faces';\nimport { pointInRings, representativePoint } from './floorPlan.geometry';\nimport { newId } from './floorPlan.graph';\nimport { PlanIssueKind } from './floorPlan.types';\nimport type { DerivedRoom, PlanDerivation, PlanFace, PlanFloor, PlanIssue, PlanRoom } from './floorPlan.types';\n\n/** Relative weights of the three identity signals. */\nexport const MATCH_WEIGHTS = {\n /** Wall ids survive every geometry-only edit, so they carry the most weight. */\n boundary: 2,\n /** Decides a split, where both children share half the old boundary. */\n anchor: 1,\n /** Breaks a merge towards the larger of the two rooms. */\n area: 0.25,\n} as const;\n\n/** Below this, a pair is not the same room at all. */\nexport const MATCH_THRESHOLD = 0.15;\n\nfunction jaccard(a: ReadonlySet<string>, b: ReadonlySet<string>): number {\n if (a.size === 0 && b.size === 0) return 0;\n let intersection = 0;\n for (const id of a) if (b.has(id)) intersection += 1;\n const union = a.size + b.size - intersection;\n return union === 0 ? 0 : intersection / union;\n}\n\nfunction scorePair(room: PlanRoom, face: PlanFace, faceWalls: ReadonlySet<string>): number {\n const boundary = jaccard(new Set(room.wallIds), faceWalls);\n const inside = pointInRings(room.anchor, face.outer, face.holes) ? 1 : 0;\n const areaRatio =\n room.area > 0 && face.area > 0 ? Math.min(room.area, face.area) / Math.max(room.area, face.area) : 0;\n return MATCH_WEIGHTS.boundary * boundary + MATCH_WEIGHTS.anchor * inside + MATCH_WEIGHTS.area * areaRatio;\n}\n\n/**\n * Extracts faces and attaches stored room metadata to them.\n *\n * Pure: returns a new floor whose room match caches and anchors have been refreshed.\n * It never creates or deletes a `PlanRoom`, so it is safe to call on every render.\n * Minting rooms for newly enclosed faces is `commitDerivation`'s job, called once per\n * committed edit.\n */\nexport function derivePlan(floor: PlanFloor): PlanDerivation {\n const faces = deriveFaces(floor);\n const issues: PlanIssue[] = [];\n const rooms = Object.values(floor.rooms);\n\n const faceWallSets = faces.map((f) => new Set(f.wallIds));\n\n interface Pair {\n roomIndex: number;\n faceIndex: number;\n score: number;\n }\n\n const pairs: Pair[] = [];\n for (let r = 0; r < rooms.length; r++) {\n for (let f = 0; f < faces.length; f++) {\n const score = scorePair(rooms[r], faces[f], faceWallSets[f]);\n if (score > MATCH_THRESHOLD) pairs.push({ roomIndex: r, faceIndex: f, score });\n }\n }\n\n // Greedy one-to-one. The seq/id tie-breaks keep the result deterministic, which\n // matters because a merge is decided here: two rooms both score around 0.5 against\n // the merged face, and exactly one of them must win.\n pairs.sort((x, y) => {\n if (y.score !== x.score) return y.score - x.score;\n const seqDiff = rooms[x.roomIndex].seq - rooms[y.roomIndex].seq;\n if (seqDiff !== 0) return seqDiff;\n return faces[x.faceIndex].id < faces[y.faceIndex].id ? -1 : 1;\n });\n\n const roomTaken = new Array<boolean>(rooms.length).fill(false);\n const faceToRoom = new Array<number>(faces.length).fill(-1);\n for (const pair of pairs) {\n if (roomTaken[pair.roomIndex]) continue;\n if (faceToRoom[pair.faceIndex] !== -1) continue;\n roomTaken[pair.roomIndex] = true;\n faceToRoom[pair.faceIndex] = pair.roomIndex;\n }\n\n const nextRooms: Record<string, PlanRoom> = { ...floor.rooms };\n const derived: DerivedRoom[] = faces.map((face, f) => {\n const anchorFallback = representativePoint(face.outer, face.holes);\n const roomIndex = faceToRoom[f];\n if (roomIndex === -1) {\n return { ...face, roomId: null, meta: null, anchor: anchorFallback };\n }\n\n const room = rooms[roomIndex];\n const anchor = room.anchorPinned ? room.anchor : anchorFallback;\n const updated: PlanRoom = {\n ...room,\n anchor,\n // Refreshing the cache is what lets the next edit match against where the room is\n // now rather than where it was when it was created.\n wallIds: [...new Set(face.wallIds)],\n area: face.area,\n };\n nextRooms[room.id] = updated;\n return { ...face, roomId: room.id, meta: updated, anchor };\n });\n\n for (let r = 0; r < rooms.length; r++) {\n if (roomTaken[r]) continue;\n // Kept, never deleted. Re-adding a deleted wall re-splits the face and this room\n // matches its child again by anchor, so the name comes back by itself. Dropping\n // orphans is the one way this model loses data irrecoverably.\n issues.push({\n kind: PlanIssueKind.UnmatchedRoom,\n message: `\"${rooms[r].name}\" is not currently enclosed by any walls.`,\n roomIds: [rooms[r].id],\n });\n }\n\n return { floor: { ...floor, rooms: nextRooms }, rooms: derived, issues };\n}\n\nlet roomSeq = 0;\n\n/** Test-only: makes the room sequence counter reproducible. */\nexport function __resetRoomSeq(): void {\n roomSeq = 0;\n}\n\nexport interface CommitDerivationOptions {\n /** Names new rooms. Receives the 1-based index among rooms created in this call. */\n nameFor?: (index: number, face: DerivedRoom) => string;\n}\n\n/**\n * Mints a `PlanRoom` for every face that matched nothing.\n *\n * Separate from `derivePlan` so that derivation stays free of id minting and can run on\n * every render without inflating the document. Call it once per committed edit.\n */\nexport function commitDerivation(\n floor: PlanFloor,\n options: CommitDerivationOptions = {},\n): { floor: PlanFloor; created: PlanRoom[] } {\n const { rooms: derived, floor: refreshed } = derivePlan(floor);\n const nextRooms = { ...refreshed.rooms };\n const created: PlanRoom[] = [];\n\n let index = 0;\n const existingNames = new Set(Object.values(nextRooms).map((r) => r.name));\n\n for (const face of derived) {\n if (face.roomId) continue;\n index += 1;\n roomSeq += 1;\n\n let name = options.nameFor?.(index, face);\n if (!name) {\n let n = Object.keys(nextRooms).length + 1;\n name = `Room ${n}`;\n while (existingNames.has(name)) {\n n += 1;\n name = `Room ${n}`;\n }\n }\n existingNames.add(name);\n\n const room: PlanRoom = {\n id: newId('r'),\n name,\n anchor: face.anchor,\n anchorPinned: false,\n seq: roomSeq,\n wallIds: [...new Set(face.wallIds)],\n area: face.area,\n };\n nextRooms[room.id] = room;\n created.push(room);\n }\n\n return { floor: { ...refreshed, rooms: nextRooms }, created };\n}\n\n/** Removes room metadata that matched no face. Never called automatically. */\nexport function pruneUnmatchedRooms(floor: PlanFloor): { floor: PlanFloor; removed: string[] } {\n const { rooms: derived } = derivePlan(floor);\n const matched = new Set(derived.map((d) => d.roomId).filter(Boolean) as string[]);\n const nextRooms: Record<string, PlanRoom> = {};\n const removed: string[] = [];\n for (const room of Object.values(floor.rooms)) {\n if (matched.has(room.id)) nextRooms[room.id] = room;\n else removed.push(room.id);\n }\n return { floor: { ...floor, rooms: nextRooms }, removed };\n}\n\n/** Convenience: the derived room whose polygon contains `point`, if any. */\nexport function roomAtPoint(derived: DerivedRoom[], point: { x: number; y: number }): DerivedRoom | null {\n let best: DerivedRoom | null = null;\n for (const room of derived) {\n if (!pointInRings(point, room.outer, room.holes)) continue;\n // Smallest wins, so a room nested inside another is selectable.\n if (!best || room.area < best.area) best = room;\n }\n return best;\n}\n"],"mappings":"yOAmBA,IAAa,EAAgB,CAE3B,SAAU,EAEV,OAAQ,EAER,KAAM,GACR,EAGa,EAAkB,IAE/B,SAAS,EAAQ,EAAwB,EAAgC,CACvE,GAAI,EAAE,OAAS,GAAK,EAAE,OAAS,EAAG,MAAO,GACzC,IAAI,EAAe,EACnB,IAAK,IAAM,KAAM,EAAO,EAAE,IAAI,CAAE,IAAG,GAAgB,GACnD,IAAM,EAAQ,EAAE,KAAO,EAAE,KAAO,EAChC,OAAO,IAAU,EAAI,EAAI,EAAe,CAC1C,CAEA,SAAS,EAAU,EAAgB,EAAgB,EAAwC,CACzF,IAAM,EAAW,EAAQ,IAAI,IAAI,EAAK,OAAO,EAAG,CAAS,EACnD,EAAS,KAAa,EAAK,OAAQ,EAAK,MAAO,EAAK,KAAK,EACzD,EACJ,EAAK,KAAO,GAAK,EAAK,KAAO,EAAI,KAAK,IAAI,EAAK,KAAM,EAAK,IAAI,EAAI,KAAK,IAAI,EAAK,KAAM,EAAK,IAAI,EAAI,EACrG,OAAO,EAAc,SAAW,EAAW,EAAc,OAAS,EAAS,EAAc,KAAO,CAClG,CAUA,SAAgB,EAAW,EAAkC,CAC3D,IAAM,EAAQ,EAAY,CAAK,EACzB,EAAsB,CAAC,EACvB,EAAQ,OAAO,OAAO,EAAM,KAAK,EAEjC,EAAe,EAAM,IAAK,GAAM,IAAI,IAAI,EAAE,OAAO,CAAC,EAQlD,EAAgB,CAAC,EACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,IAAK,IAAI,EAAI,EAAG,E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CAAC,CAAC,OAAO,OAAO,CAAa,EAC1E,EAAsC,CAAC,EACvC,EAAoB,CAAC,EAC3B,IAAK,IAAM,KAAQ,OAAO,OAAO,EAAM,KAAK,EACtC,EAAQ,IAAI,EAAK,EAAE,EAAG,EAAU,EAAK,IAAM,EAC1C,EAAQ,KAAK,EAAK,EAAE,EAE3B,MAAO,CAAE,MAAO,CAAE,GAAG,EAAO,MAAO,CAAU,EAAG,SAAQ,CAC1D,CAGA,SAAgB,EAAY,EAAwB,EAAqD,CACvG,IAAI,EAA2B,KAC/B,IAAK,IAAM,KAAQ,EACZ,EAAa,EAAO,EAAK,MAAO,EAAK,KAAK,IAE3C,CAAC,GAAQ,EAAK,KAAO,EAAK,QAAM,EAAO,GAE7C,OAAO,CACT"}
|
|
1
|
+
{"version":3,"file":"floorPlan.rooms.mjs","names":[],"sources":["../../../../package/common/floorPlan/floorPlan.rooms.ts"],"sourcesContent":["/**\n * Room identity: attaching stored metadata (name, colour) to derived faces.\n *\n * Identity is primarily the SET OF BOUNDARY WALL IDS, with the anchor point as a\n * secondary signal. That ordering is the important design decision here. Anchors alone\n * look sufficient but fail in three ways: a whole-plan drag leaves every absolute\n * anchor behind, a merge gives two anchors one face with no tie-break, and dragging a\n * node can move a boundary past its own anchor. Wall ids survive every operation that\n * only moves geometry, so reshaping and translating match perfectly without anyone\n * having to remember to transform anchors.\n */\n\nimport { deriveFaces } from './floorPlan.faces';\nimport { pointInRings, representativePoint } from './floorPlan.geometry';\nimport { newId } from './floorPlan.graph';\nimport { PlanIssueKind } from './floorPlan.types';\nimport type { DerivedRoom, PlanDerivation, PlanFace, PlanFloor, PlanIssue, PlanRoom } from './floorPlan.types';\n\n/** Relative weights of the three identity signals. */\nexport const MATCH_WEIGHTS = {\n /** Wall ids survive every geometry-only edit, so they carry the most weight. */\n boundary: 2,\n /** Decides a split, where both children share half the old boundary. */\n anchor: 1,\n /** Breaks a merge towards the larger of the two rooms. */\n area: 0.25,\n} as const;\n\n/** Below this, a pair is not the same room at all. */\nexport const MATCH_THRESHOLD = 0.15;\n\nfunction jaccard(a: ReadonlySet<string>, b: ReadonlySet<string>): number {\n if (a.size === 0 && b.size === 0) return 0;\n let intersection = 0;\n for (const id of a) if (b.has(id)) intersection += 1;\n const union = a.size + b.size - intersection;\n return union === 0 ? 0 : intersection / union;\n}\n\nfunction scorePair(room: PlanRoom, face: PlanFace, faceWalls: ReadonlySet<string>): number {\n const boundary = jaccard(new Set(room.wallIds), faceWalls);\n const inside = pointInRings(room.anchor, face.outer, face.holes) ? 1 : 0;\n const areaRatio =\n room.area > 0 && face.area > 0 ? Math.min(room.area, face.area) / Math.max(room.area, face.area) : 0;\n return MATCH_WEIGHTS.boundary * boundary + MATCH_WEIGHTS.anchor * inside + MATCH_WEIGHTS.area * areaRatio;\n}\n\n/**\n * Extracts faces and attaches stored room metadata to them.\n *\n * Pure: returns a new floor whose room match caches and anchors have been refreshed.\n * It never creates or deletes a `PlanRoom`, so it is safe to call on every render.\n * Minting rooms for newly enclosed faces is `commitDerivation`'s job, called once per\n * committed edit.\n */\nexport function derivePlan(floor: PlanFloor): PlanDerivation {\n const faces = deriveFaces(floor);\n const issues: PlanIssue[] = [];\n const rooms = Object.values(floor.rooms);\n\n const faceWallSets = faces.map((f) => new Set(f.wallIds));\n\n interface Pair {\n roomIndex: number;\n faceIndex: number;\n score: number;\n }\n\n const pairs: Pair[] = [];\n for (let r = 0; r < rooms.length; r++) {\n for (let f = 0; f < faces.length; f++) {\n const score = scorePair(rooms[r], faces[f], faceWallSets[f]);\n if (score > MATCH_THRESHOLD) pairs.push({ roomIndex: r, faceIndex: f, score });\n }\n }\n\n // Greedy one-to-one. The seq/id tie-breaks keep the result deterministic, which\n // matters because a merge is decided here: two rooms both score around 0.5 against\n // the merged face, and exactly one of them must win.\n pairs.sort((x, y) => {\n if (y.score !== x.score) return y.score - x.score;\n const seqDiff = rooms[x.roomIndex].seq - rooms[y.roomIndex].seq;\n if (seqDiff !== 0) return seqDiff;\n return faces[x.faceIndex].id < faces[y.faceIndex].id ? -1 : 1;\n });\n\n const roomTaken = new Array<boolean>(rooms.length).fill(false);\n const faceToRoom = new Array<number>(faces.length).fill(-1);\n for (const pair of pairs) {\n if (roomTaken[pair.roomIndex]) continue;\n if (faceToRoom[pair.faceIndex] !== -1) continue;\n roomTaken[pair.roomIndex] = true;\n faceToRoom[pair.faceIndex] = pair.roomIndex;\n }\n\n const nextRooms: Record<string, PlanRoom> = { ...floor.rooms };\n const derived: DerivedRoom[] = faces.map((face, f) => {\n const anchorFallback = representativePoint(face.outer, face.holes);\n const roomIndex = faceToRoom[f];\n if (roomIndex === -1) {\n return { ...face, roomId: null, meta: null, anchor: anchorFallback };\n }\n\n const room = rooms[roomIndex];\n const anchor = room.anchorPinned ? room.anchor : anchorFallback;\n const updated: PlanRoom = {\n ...room,\n anchor,\n // Refreshing the cache is what lets the next edit match against where the room is\n // now rather than where it was when it was created.\n wallIds: [...new Set(face.wallIds)],\n area: face.area,\n };\n nextRooms[room.id] = updated;\n return { ...face, roomId: room.id, meta: updated, anchor };\n });\n\n for (let r = 0; r < rooms.length; r++) {\n if (roomTaken[r]) continue;\n // Kept, never deleted. Re-adding a deleted wall re-splits the face and this room\n // matches its child again by anchor, so the name comes back by itself. Dropping\n // orphans is the one way this model loses data irrecoverably.\n issues.push({\n kind: PlanIssueKind.UnmatchedRoom,\n message: `\"${rooms[r].name}\" is not currently enclosed by any walls.`,\n roomIds: [rooms[r].id],\n });\n }\n\n return { floor: { ...floor, rooms: nextRooms }, rooms: derived, issues };\n}\n\nlet roomSeq = 0;\n\n/** Test-only: makes the room sequence counter reproducible. */\nexport function __resetRoomSeq(): void {\n roomSeq = 0;\n}\n\nexport interface CommitDerivationOptions {\n /** Names new rooms. Receives the 1-based index among rooms created in this call. */\n nameFor?: (index: number, face: DerivedRoom) => string;\n}\n\n/**\n * Mints a `PlanRoom` for every face that matched nothing.\n *\n * Separate from `derivePlan` so that derivation stays free of id minting and can run on\n * every render without inflating the document. Call it once per committed edit.\n */\nexport function commitDerivation(\n floor: PlanFloor,\n options: CommitDerivationOptions = {},\n): { floor: PlanFloor; created: PlanRoom[] } {\n const { rooms: derived, floor: refreshed } = derivePlan(floor);\n const nextRooms = { ...refreshed.rooms };\n const created: PlanRoom[] = [];\n\n let index = 0;\n const existingNames = new Set(Object.values(nextRooms).map((r) => r.name));\n\n for (const face of derived) {\n if (face.roomId) continue;\n index += 1;\n roomSeq += 1;\n\n let name = options.nameFor?.(index, face);\n if (!name) {\n let n = Object.keys(nextRooms).length + 1;\n name = `Room ${n}`;\n while (existingNames.has(name)) {\n n += 1;\n name = `Room ${n}`;\n }\n }\n existingNames.add(name);\n\n const room: PlanRoom = {\n id: newId('r'),\n name,\n anchor: face.anchor,\n anchorPinned: false,\n seq: roomSeq,\n wallIds: [...new Set(face.wallIds)],\n area: face.area,\n };\n nextRooms[room.id] = room;\n created.push(room);\n }\n\n return { floor: { ...refreshed, rooms: nextRooms }, created };\n}\n\n/** Removes room metadata that matched no face. Never called automatically. */\nexport function pruneUnmatchedRooms(floor: PlanFloor): { floor: PlanFloor; removed: string[] } {\n const { rooms: derived } = derivePlan(floor);\n const matched = new Set(derived.map((d) => d.roomId).filter(Boolean) as string[]);\n const nextRooms: Record<string, PlanRoom> = {};\n const removed: string[] = [];\n for (const room of Object.values(floor.rooms)) {\n if (matched.has(room.id)) nextRooms[room.id] = room;\n else removed.push(room.id);\n }\n return { floor: { ...floor, rooms: nextRooms }, removed };\n}\n\n/** Convenience: the derived room whose polygon contains `point`, if any. */\nexport function roomAtPoint(derived: DerivedRoom[], point: { x: number; y: number }): DerivedRoom | null {\n let best: DerivedRoom | null = null;\n for (const room of derived) {\n if (!pointInRings(point, room.outer, room.holes)) continue;\n // Smallest wins, so a room nested inside another is selectable.\n if (!best || room.area < best.area) best = room;\n }\n return best;\n}\n"],"mappings":"sPAmBA,IAAa,EAAgB,CAE3B,SAAU,EAEV,OAAQ,EAER,KAAM,GACR,EAGa,EAAkB,IA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AK,IAAM,KAAQ,EACZ,EAAa,EAAO,EAAK,MAAO,EAAK,KAAK,IAE3C,CAAC,GAAQ,EAAK,KAAO,EAAK,QAAM,EAAO,GAE7C,OAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{dist as e,pointToSegment as t,projectOnSegment as n,segmentIntersection as r}from"./floorPlan.geometry.mjs";var i=function(e){return e.None=`none`,e.Node=`node`,e.Wall=`wall`,e.Intersection=`intersection`,e.Extension=`extension`,e.Alignment=`alignment`,e.Angle=`angle`,e.Grid=`grid`,e}({}),a={enabled:[`node`,`intersection`,`wall`,`angle`,`extension`,`alignment`,`grid`],gridSize:100,angleStepDeg:0,toleranceScreenPx:10,nodeToleranceScreenPx:12};function o(e){let t=e.getScreenCTM();if(!t)return 1;let n=Math.hypot(t.a,t.b);return n===0?1:1/n}function s(e,t,n,r){return{x:r.x+(e-n.left)/r.zoom,y:r.y+(t-n.top)/r.zoom}}function c(e,t){let n=e.x-t.point.x,r=e.y-t.point.y;return Math.abs(n*t.dir.y-r*t.dir.x)}function l(e,t){let n=e.x-t.point.x,r=e.y-t.point.y,i=n*t.dir.x+r*t.dir.y;return{x:t.point.x+t.dir.x*i,y:t.point.y+t.dir.y*i}}function u(e,t){let n=e.dir.x*t.dir.y-e.dir.y*t.dir.x;if(Math.abs(n)<1e-9)return null;let r=t.point.x-e.point.x,i=t.point.y-e.point.y,a=(r*t.dir.y-i*t.dir.x)/n;return{x:e.point.x+e.dir.x*a,y:e.point.y+e.dir.y*a}}function d(e,t){let n=Math.abs(e.dir.x*t.dir.x+e.dir.y*t.dir.y);return Math.acos(Math.min(1,n))}function f(e,t){return t>0?Math.round(e/t)*t:e}function p(i,o){let s={...a,...o.options},p=new Set(s.enabled),m=e=>{if(!o.origin)return e;let t=e.point.x-o.origin.x,n=e.point.y-o.origin.y;return{...e,angle:Math.atan2(n,t),distance:Math.hypot(t,n)}};if(p.size===0)return m({point:i,kind:`none`,guides:[]});let h=s.toleranceScreenPx*o.pxToWorld,g=(s.nodeToleranceScreenPx??s.toleranceScreenPx)*o.pxToWorld,{floor:_}=o,v=(()=>{if(!p.has(`angle`)||!o.origin||s.angleStepDeg<=0)return null;let e=s.angleStepDeg*Math.PI/180,t=Math.atan2(i.y-o.origin.y,i.x-o.origin.x),n=[{angle:0,relativeTo:`world`}];o.referenceAngle!==void 0&&n.push({angle:o.referenceAngle,relativeTo:`reference`});let r=null;for(let a of n){let n=a.angle+Math.round((t-a.angle)/e)*e,s={x:Math.cos(n),y:Math.sin(n)},l={kind:`angle`,point:o.origin,dir:s,residual:0,relativeTo:a.relativeTo};l.residual=c(i,l),(!r||l.residual<r.residual)&&(r=l)}return r})(),y=e=>!v||c(e,v)<=h;if(p.has(`node`)){let t=null;for(let n of Object.values(_.nodes)){if(o.excludeNodeIds?.has(n.id))continue;let r=e(i,n);r<=g&&y(n)&&(!t||r<t.d)&&(t={id:n.id,point:{x:n.x,y:n.y},d:r})}if(t)return m({point:t.point,kind:`node`,nodeId:t.id,guides:[]})}let b=Object.values(_.walls).filter(e=>!o.excludeWallIds?.has(e.id));if(p.has(`intersection`)){let t=null;for(let n=0;n<b.length;n++)for(let a=n+1;a<b.length;a++){let o=_.nodes[b[n].a],s=_.nodes[b[n].b],c=_.nodes[b[a].a],l=_.nodes[b[a].b];if(!o||!s||!c||!l)continue;let u=r(o,s,c,l);if(!u.point)continue;let d=e(i,u.point);d<=h&&y(u.point)&&(!t||d<t.d)&&(t={point:u.point,d})}if(t)return m({point:t.point,kind:`intersection`,guides:[]})}if(p.has(`wall`)){let e=null;for(let r of b){let a=_.nodes[r.a],o=_.nodes[r.b];if(!a||!o)continue;let s=t(i,a,o);s.dist<=h&&y(s.point)&&(!e||s.dist<e.d)&&(e={wallId:r.id,point:n(i,a,o),t:s.t,d:s.dist})}if(e)return m({point:e.point,kind:`wall`,wallId:e.wallId,t:e.t,guides:[]})}let x=[];if(p.has(`extension`)){let n=null;for(let r of b){let a=_.nodes[r.a],o=_.nodes[r.b];if(!a||!o)continue;let s=e(a,o);if(s<1e-6)continue;let l={x:(o.x-a.x)/s,y:(o.y-a.y)/s},u={kind:`extension`,point:{x:a.x,y:a.y},dir:l,residual:0};u.residual=c(i,u);let d=t(i,a,o).dist<=h;u.residual<=h&&!d&&(!n||u.residual<n.residual)&&(n=u)}n&&x.push(n)}if(p.has(`alignment`)){let e=null,t=null;for(let n of Object.values(_.nodes)){if(o.excludeNodeIds?.has(n.id))continue;let r=Math.abs(i.x-n.x);r<=h&&(!e||r<e.residual)&&(e={kind:`alignment`,point:{x:n.x,y:n.y},dir:{x:0,y:1},residual:r});let a=Math.abs(i.y-n.y);a<=h&&(!t||a<t.residual)&&(t={kind:`alignment`,point:{x:n.x,y:n.y},dir:{x:1,y:0},residual:a})}e&&x.push(e),t&&x.push(t)}let S=(e,t)=>({kind:e.kind,a:{x:t.x-e.dir.x*1e5,y:t.y-e.dir.y*1e5},b:{x:t.x+e.dir.x*1e5,y:t.y+e.dir.y*1e5},infinite:!0});if(v){let t=x.filter(e=>e.residual<=h&&d(v,e)>15*Math.PI/180).sort((e,t)=>e.residual-t.residual)[0];if(t){let n=u(v,t);if(n&&e(n,i)<=h*4)return m({point:n,kind:`angle`,guides:[S(v,n),S(t,n)],angleRelativeTo:v.relativeTo})}let n=l(i,v);if(p.has(`grid`)&&s.gridSize>0){let e=f((n.x-v.point.x)*v.dir.x+(n.y-v.point.y)*v.dir.y,s.gridSize);n={x:v.point.x+v.dir.x*e,y:v.point.y+v.dir.y*e}}return m({point:n,kind:`angle`,guides:[S(v,n)],angleRelativeTo:v.relativeTo})}if(x.length>=2){let[t,n]=[...x].sort((e,t)=>e.residual-t.residual),r=u(t,n);if(r&&d(t,n)>15*Math.PI/180&&e(r,i)<=h*2)return m({point:r,kind:`intersection`,guides:[S(t,r),S(n,r)]})}if(x.length>=1){let e=[...x].sort((e,t)=>e.residual-t.residual)[0],t=l(i,e);if(p.has(`grid`)&&s.gridSize>0){let n=f((t.x-e.point.x)*e.dir.x+(t.y-e.point.y)*e.dir.y,s.gridSize);t={x:e.point.x+e.dir.x*n,y:e.point.y+e.dir.y*n}}return m({point:t,kind:e.kind,guides:[S(e,t)],angleRelativeTo:e.relativeTo})}return p.has(`grid`)&&s.gridSize>0?m({point:{x:f(i.x,s.gridSize),y:f(i.y,s.gridSize)},kind:`grid`,guides:[]}):m({point:i,kind:`none`,guides:[]})}export{a as DEFAULT_SNAP_OPTIONS,i as SnapKind,s as clientToWorld,p as resolveSnap,o as screenScale};
|
|
1
|
+
"use client";import{dist as e,pointToSegment as t,projectOnSegment as n,segmentIntersection as r}from"./floorPlan.geometry.mjs";var i=function(e){return e.None=`none`,e.Node=`node`,e.Wall=`wall`,e.Intersection=`intersection`,e.Extension=`extension`,e.Alignment=`alignment`,e.Angle=`angle`,e.Grid=`grid`,e}({}),a={enabled:[`node`,`intersection`,`wall`,`angle`,`extension`,`alignment`,`grid`],gridSize:100,angleStepDeg:0,toleranceScreenPx:10,nodeToleranceScreenPx:12};function o(e){let t=e.getScreenCTM();if(!t)return 1;let n=Math.hypot(t.a,t.b);return n===0?1:1/n}function s(e,t,n,r){return{x:r.x+(e-n.left)/r.zoom,y:r.y+(t-n.top)/r.zoom}}function c(e,t){let n=e.x-t.point.x,r=e.y-t.point.y;return Math.abs(n*t.dir.y-r*t.dir.x)}function l(e,t){let n=e.x-t.point.x,r=e.y-t.point.y,i=n*t.dir.x+r*t.dir.y;return{x:t.point.x+t.dir.x*i,y:t.point.y+t.dir.y*i}}function u(e,t){let n=e.dir.x*t.dir.y-e.dir.y*t.dir.x;if(Math.abs(n)<1e-9)return null;let r=t.point.x-e.point.x,i=t.point.y-e.point.y,a=(r*t.dir.y-i*t.dir.x)/n;return{x:e.point.x+e.dir.x*a,y:e.point.y+e.dir.y*a}}function d(e,t){let n=Math.abs(e.dir.x*t.dir.x+e.dir.y*t.dir.y);return Math.acos(Math.min(1,n))}function f(e,t){return t>0?Math.round(e/t)*t:e}function p(i,o){let s={...a,...o.options},p=new Set(s.enabled),m=e=>{if(!o.origin)return e;let t=e.point.x-o.origin.x,n=e.point.y-o.origin.y;return{...e,angle:Math.atan2(n,t),distance:Math.hypot(t,n)}};if(p.size===0)return m({point:i,kind:`none`,guides:[]});let h=s.toleranceScreenPx*o.pxToWorld,g=(s.nodeToleranceScreenPx??s.toleranceScreenPx)*o.pxToWorld,{floor:_}=o,v=(()=>{if(!p.has(`angle`)||!o.origin||s.angleStepDeg<=0)return null;let e=s.angleStepDeg*Math.PI/180,t=Math.atan2(i.y-o.origin.y,i.x-o.origin.x),n=[{angle:0,relativeTo:`world`}];o.referenceAngle!==void 0&&n.push({angle:o.referenceAngle,relativeTo:`reference`});let r=null;for(let a of n){let n=a.angle+Math.round((t-a.angle)/e)*e,s={x:Math.cos(n),y:Math.sin(n)},l={kind:`angle`,point:o.origin,dir:s,residual:0,relativeTo:a.relativeTo};l.residual=c(i,l),(!r||l.residual<r.residual)&&(r=l)}return r})(),y=e=>!v||c(e,v)<=h;if(p.has(`node`)){let t=null;for(let n of Object.values(_.nodes)){if(o.excludeNodeIds?.has(n.id))continue;let r=e(i,n);r<=g&&y(n)&&(!t||r<t.d)&&(t={id:n.id,point:{x:n.x,y:n.y},d:r})}if(t)return m({point:t.point,kind:`node`,nodeId:t.id,guides:[]})}let b=Object.values(_.walls).filter(e=>!o.excludeWallIds?.has(e.id));if(p.has(`intersection`)){let t=null;for(let n=0;n<b.length;n++)for(let a=n+1;a<b.length;a++){let o=_.nodes[b[n].a],s=_.nodes[b[n].b],c=_.nodes[b[a].a],l=_.nodes[b[a].b];if(!o||!s||!c||!l)continue;let u=r(o,s,c,l);if(!u.point)continue;let d=e(i,u.point);d<=h&&y(u.point)&&(!t||d<t.d)&&(t={point:u.point,d})}if(t)return m({point:t.point,kind:`intersection`,guides:[]})}if(p.has(`wall`)){let e=null;for(let r of b){let a=_.nodes[r.a],o=_.nodes[r.b];if(!a||!o)continue;let s=t(i,a,o);s.dist<=h&&y(s.point)&&(!e||s.dist<e.d)&&(e={wallId:r.id,point:n(i,a,o),t:s.t,d:s.dist})}if(e)return m({point:e.point,kind:`wall`,wallId:e.wallId,t:e.t,guides:[]})}let x=[];if(p.has(`extension`)){let n=null;for(let r of b){let a=_.nodes[r.a],o=_.nodes[r.b];if(!a||!o)continue;let s=e(a,o);if(s<1e-6)continue;let l={x:(o.x-a.x)/s,y:(o.y-a.y)/s},u={kind:`extension`,point:{x:a.x,y:a.y},dir:l,residual:0};u.residual=c(i,u);let d=t(i,a,o).dist<=h;u.residual<=h&&!d&&(!n||u.residual<n.residual)&&(n=u)}n&&x.push(n)}if(p.has(`alignment`)){let e=null,t=null;for(let n of Object.values(_.nodes)){if(o.excludeNodeIds?.has(n.id))continue;let r=Math.abs(i.x-n.x);r<=h&&(!e||r<e.residual)&&(e={kind:`alignment`,point:{x:n.x,y:n.y},dir:{x:0,y:1},residual:r});let a=Math.abs(i.y-n.y);a<=h&&(!t||a<t.residual)&&(t={kind:`alignment`,point:{x:n.x,y:n.y},dir:{x:1,y:0},residual:a})}e&&x.push(e),t&&x.push(t)}let S=(e,t)=>({kind:e.kind,a:{x:t.x-e.dir.x*1e5,y:t.y-e.dir.y*1e5},b:{x:t.x+e.dir.x*1e5,y:t.y+e.dir.y*1e5},infinite:!0});if(v){let t=x.filter(e=>e.residual<=h&&d(v,e)>15*Math.PI/180).sort((e,t)=>e.residual-t.residual)[0];if(t){let n=u(v,t);if(n&&e(n,i)<=h*4)return m({point:n,kind:`angle`,guides:[S(v,n),S(t,n)],angleRelativeTo:v.relativeTo})}let n=l(i,v);if(p.has(`grid`)&&s.gridSize>0){let e=f((n.x-v.point.x)*v.dir.x+(n.y-v.point.y)*v.dir.y,s.gridSize);n={x:v.point.x+v.dir.x*e,y:v.point.y+v.dir.y*e}}return m({point:n,kind:`angle`,guides:[S(v,n)],angleRelativeTo:v.relativeTo})}if(x.length>=2){let[t,n]=[...x].sort((e,t)=>e.residual-t.residual),r=u(t,n);if(r&&d(t,n)>15*Math.PI/180&&e(r,i)<=h*2)return m({point:r,kind:`intersection`,guides:[S(t,r),S(n,r)]})}if(x.length>=1){let e=[...x].sort((e,t)=>e.residual-t.residual)[0],t=l(i,e);if(p.has(`grid`)&&s.gridSize>0){let n=f((t.x-e.point.x)*e.dir.x+(t.y-e.point.y)*e.dir.y,s.gridSize);t={x:e.point.x+e.dir.x*n,y:e.point.y+e.dir.y*n}}return m({point:t,kind:e.kind,guides:[S(e,t)],angleRelativeTo:e.relativeTo})}return p.has(`grid`)&&s.gridSize>0?m({point:{x:f(i.x,s.gridSize),y:f(i.y,s.gridSize)},kind:`grid`,guides:[]}):m({point:i,kind:`none`,guides:[]})}export{a as DEFAULT_SNAP_OPTIONS,i as SnapKind,s as clientToWorld,p as resolveSnap,o as screenScale};
|
|
2
2
|
//# sourceMappingURL=floorPlan.snap.mjs.map
|