From c7408f07b94356e13e75948bdb5972a4d96c7c98 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Mon, 8 Sep 2025 16:20:51 +0530 Subject: [PATCH] refactor: Enhance wall classification logic by improving key generation and adding position pair tracking to prevent duplicates --- .../instance/helpers/useWallClassification.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 7451501..aaa3912 100644 --- a/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts +++ b/app/src/modules/builder/wall/Instances/instance/helpers/useWallClassification.ts @@ -6,9 +6,19 @@ export function useWallClassification(walls: Walls) { if (walls.length < 3) return []; const wallSet = new Map(); + const positionPairSet = new Set(); const makeKey = (p1: Point, p2: Point) => { - return [p1.pointUuid, p2.pointUuid].sort().join("-"); + return [p1.pointUuid, p2.pointUuid].sort((a, b) => a.localeCompare(b)).join("-"); + }; + + const makePositionPairKey = (p1: Point, p2: Point) => { + const sortedPositions = [ + [p1.position[0].toFixed(6), p1.position[2].toFixed(6)], + [p2.position[0].toFixed(6), p2.position[2].toFixed(6)], + ].sort((a, b) => a[0].localeCompare(b[0]) || a[1].localeCompare(b[1])); + + return sortedPositions.map((pos) => pos.join(",")).join("|"); }; for (const wall of walls) { @@ -18,6 +28,14 @@ export function useWallClassification(walls: Walls) { continue; } + const positionPairKey = makePositionPairKey(p1, p2); + + if (positionPairSet.has(positionPairKey)) { + continue; + } + + positionPairSet.add(positionPairKey); + const key = makeKey(p1, p2); if (!wallSet.has(key)) { wallSet.set(key, wall);