From 16ba5bf9c66e9d14c97d122cd59f947a4d60ca13 Mon Sep 17 00:00:00 2001 From: wass08 Date: Mon, 23 Feb 2026 08:22:06 +0900 Subject: [PATCH] fiix adjacent walls pushed up --- .../spatial-grid/spatial-grid-manager.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/core/src/hooks/spatial-grid/spatial-grid-manager.ts b/packages/core/src/hooks/spatial-grid/spatial-grid-manager.ts index 8138efe9..9d12f57a 100644 --- a/packages/core/src/hooks/spatial-grid/spatial-grid-manager.ts +++ b/packages/core/src/hooks/spatial-grid/spatial-grid-manager.ts @@ -183,11 +183,24 @@ export function wallOverlapsPolygon( end: [number, number], polygon: Array<[number, number]>, ): boolean { - const startInside = pointInPolygon(start[0], start[1], polygon) - const endInside = pointInPolygon(end[0], end[1], polygon) + const dx = end[0] - start[0] + const dz = end[1] - start[1] + const len = Math.sqrt(dx * dx + dz * dz) - // At least one endpoint strictly inside the polygon - if (startInside || endInside) return true + // Nudge endpoint test points a tiny step inward along the wall direction before + // testing containment. pointInPolygon (ray casting) produces false positives for + // points exactly on polygon vertices or edges — specifically the minimum-z corner + // of an axis-aligned polygon returns "inside" because the ray hits the opposite + // vertical edge exactly at its base. Nudging by 1e-6 m avoids this: a wall that + // merely starts at a slab corner and extends outward will have its nudged point + // clearly outside, while a wall that genuinely starts inside stays inside. + if (len > 1e-10) { + const step = Math.min(1e-6, len * 0.01) + const nx = (dx / len) * step + const nz = (dz / len) * step + if (pointInPolygon(start[0] + nx, start[1] + nz, polygon)) return true + if (pointInPolygon(end[0] - nx, end[1] - nz, polygon)) return true + } // Check if midpoint is inside (catches walls crossing through) const midX = (start[0] + end[0]) / 2