refactor: Enhance wall classification logic by improving key generation and adding position pair tracking to prevent duplicates

This commit is contained in:
2025-09-08 16:20:51 +05:30
parent 6f0cb56d96
commit c7408f07b9

View File

@@ -6,9 +6,19 @@ export function useWallClassification(walls: Walls) {
if (walls.length < 3) return [];
const wallSet = new Map<string, Wall>();
const positionPairSet = new Set<string>();
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);