From db4ec62af85b29c1b75335d2e35fa226bfc9c632 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Thu, 5 Jun 2025 12:23:29 +0530 Subject: [PATCH] refactor: Update wall rendering and aisle position handling, enhance room filtering logic in wall classification --- app/src/modules/builder/builder.tsx | 2 +- .../modules/builder/groups/floorPlanGroup.tsx | 2 +- app/src/modules/builder/point/point.tsx | 2 +- .../instance/helpers/useWallClassification.ts | 24 +++++++++++++++++-- app/src/store/builder/useAisleStore.ts | 22 ++++++++++------- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/src/modules/builder/builder.tsx b/app/src/modules/builder/builder.tsx index 6a5093f..54884d3 100644 --- a/app/src/modules/builder/builder.tsx +++ b/app/src/modules/builder/builder.tsx @@ -283,7 +283,7 @@ export default function Builder() { plane={plane} /> - {/* */} + diff --git a/app/src/modules/builder/groups/floorPlanGroup.tsx b/app/src/modules/builder/groups/floorPlanGroup.tsx index d9f01c3..193f636 100644 --- a/app/src/modules/builder/groups/floorPlanGroup.tsx +++ b/app/src/modules/builder/groups/floorPlanGroup.tsx @@ -161,7 +161,7 @@ const FloorPlanGroup = ({ floorPlanGroup, floorPlanGroupLine, floorPlanGroupPoin } if (toolMode === "Wall") { - drawWall(raycaster, plane, floorPlanGroupPoint, snappedPoint, isSnapped, isSnappedUUID, line, ispreSnapped, anglesnappedPoint, isAngleSnapped, lines, floorPlanGroupLine, floorPlanGroup, ReferenceLineMesh, LineCreated, currentLayerPoint, dragPointControls, setNewLines, setDeletedLines, activeLayer, socket, projectId); + // drawWall(raycaster, plane, floorPlanGroupPoint, snappedPoint, isSnapped, isSnappedUUID, line, ispreSnapped, anglesnappedPoint, isAngleSnapped, lines, floorPlanGroupLine, floorPlanGroup, ReferenceLineMesh, LineCreated, currentLayerPoint, dragPointControls, setNewLines, setDeletedLines, activeLayer, socket, projectId); } if (toolMode === "Floor") { diff --git a/app/src/modules/builder/point/point.tsx b/app/src/modules/builder/point/point.tsx index 0189d5c..c304b6b 100644 --- a/app/src/modules/builder/point/point.tsx +++ b/app/src/modules/builder/point/point.tsx @@ -97,7 +97,7 @@ function Point({ point }: { readonly point: Point }) { const aisleSnappedPosition = snapPosition(newPosition); const finalSnappedPosition = checkSnapForAisle(aisleSnappedPosition.position); - setAislePosition(point.pointUuid, finalSnappedPosition.position); + const aisle = setAislePosition(point.pointUuid, finalSnappedPosition.position); } } else if (point.pointType === 'Wall') { if (position) { diff --git a/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts b/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts index 4a5c30d..c229ac4 100644 --- a/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts +++ b/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts @@ -68,7 +68,27 @@ export function useWallClassification(walls: Walls) { // Filter out duplicate rooms (same set of points in different orders) const uniqueRooms = removeDuplicateRooms(potentialRooms); - return uniqueRooms; + // Remove rooms that fully contain other rooms (i.e., outer enclosing rooms) + const turfRooms = uniqueRooms.map(room => ({ + points: room, + polygon: createPolygon(room), + })); + + const filteredRooms = turfRooms.filter((roomA, i) => { + // If any other room is strictly inside roomA, mark roomA for deletion + return !turfRooms.some((roomB, j) => { + if (i === j) return false; + // Ensure we’re not comparing same polygon + const areaA = turf.area(roomA.polygon); + const areaB = turf.area(roomB.polygon); + + if (areaB >= areaA) return false; + + return turf.booleanWithin(turf.centerOfMass(roomB.polygon), roomA.polygon); + }); + }); + + return filteredRooms.map(room => room.points); }; // Check if a cycle already exists in our list (considering different orders) @@ -132,7 +152,7 @@ export function useWallClassification(walls: Walls) { // Rest of the implementation remains the same... const rooms = useMemo(() => findRooms(), [walls]); - const createPolygon = (points: Point[]) => { + function createPolygon(points: Point[]) { const coordinates = points.map(p => [p.position[0], p.position[2]]); return turf.polygon([coordinates]); }; diff --git a/app/src/store/builder/useAisleStore.ts b/app/src/store/builder/useAisleStore.ts index bf05851..62980f2 100644 --- a/app/src/store/builder/useAisleStore.ts +++ b/app/src/store/builder/useAisleStore.ts @@ -8,7 +8,7 @@ interface AisleStore { updateAisle: (uuid: string, updated: Partial) => void; removeAisle: (uuid: string) => void; removePoint: (uuid: string) => Aisles; - setPosition: (pointUuid: string, position: [number, number, number]) => void; + setPosition: (pointUuid: string, position: [number, number, number]) => Aisle | undefined; setLayer: (pointUuid: string, layer: number) => void; setColor: (aisleUuid: string, color: AisleColors) => void; @@ -75,14 +75,20 @@ export const useAisleStore = create()( return removedAisles; }, - setPosition: (pointUuid, position) => set((state) => { - for (const aisle of state.aisles) { - const point = aisle.points.find(p => p.pointUuid === pointUuid); - if (point) { - point.position = position; + setPosition: (pointUuid, position) => { + let updatedAisle: Aisle | undefined; + + set((state) => { + for (const aisle of state.aisles) { + const point = aisle.points.find(p => p.pointUuid === pointUuid); + if (point) { + point.position = position; + updatedAisle = JSON.parse(JSON.stringify(aisle)); + } } - } - }), + }) + return updatedAisle; + }, setLayer: (pointUuid, layer) => set((state) => { for (const aisle of state.aisles) {