derive: trim segments to the frame clip (Liang-Barsky)

Membership by midpoint/endpoint kept whole segments, so long table borders
and annotation rules carried the full sheet width into a floor — 13号's 56m
frame emitted 143m of geometry and footprint hulls grew stray plates.
Segments are now clipped to the frame rect; fully-inside geometry passes
through unchanged. Regression: a 140m line crossing a 40m frame comes out
frame-wide. Dense sheet layouts hit this; 贝昂's wide frame pitch never did.

Round-3 log: tower-1 twin towers aligned and gated (union-clip standard
floors; PH centered on cores, RF parapet bbox-anchored, wing offsets
self-consistent to 50mm); podium F1-F3 zoning still open.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 22:01:20 +08:00
parent bccc9f41d6
commit 39528b38e9
3 changed files with 95 additions and 1 deletions

View File

@@ -152,6 +152,44 @@ def segment_in_clip(start: tuple[float, float], end: tuple[float, float], clip:
return point_in_clip(midpoint, clip) or point_in_clip(start, clip) or point_in_clip(end, clip)
def clip_segment_to_rect(
start: tuple[float, float], end: tuple[float, float], clip: list[float] | None
) -> tuple[tuple[float, float], tuple[float, float]] | None:
"""Trim a segment to the clip rectangle (Liang-Barsky).
Keeping whole segments whose midpoint falls inside the frame lets long
table borders / annotation rules carry the full sheet width into the
floor (13号地块: a 56 m frame emitted 143 m of geometry, and footprint
hulls grew stray plates). Fully-inside segments pass through unchanged.
"""
if not clip:
return start, end
x1, y1, x2, y2 = (float(v) for v in clip)
sx, sy = start
ex, ey = end
dx, dy = ex - sx, ey - sy
t0, t1 = 0.0, 1.0
for p, q in ((-dx, sx - x1), (dx, x2 - sx), (-dy, sy - y1), (dy, y2 - sy)):
if abs(p) < 1e-12:
if q < 0:
return None
continue
r = q / p
if p < 0:
if r > t1:
return None
if r > t0:
t0 = r
else:
if r < t0:
return None
if r < t1:
t1 = r
if t1 - t0 <= 1e-9:
return None
return (sx + t0 * dx, sy + t0 * dy), (sx + t1 * dx, sy + t1 * dy)
def segment_matches_floor(
start: tuple[float, float],
end: tuple[float, float],
@@ -517,7 +555,10 @@ def collect_raw_segments(
for floor, key, offset in floor_specs:
if not segment_matches_floor(start, end, floor, drawing):
continue
seg = cleaned_segment(start, end, offset, min_source, min_meters, scale)
trimmed = clip_segment_to_rect(start, end, floor.get("clip", drawing.get("clip")))
if trimmed is None:
continue
seg = cleaned_segment(trimmed[0], trimmed[1], offset, min_source, min_meters, scale)
if not seg:
continue
clean_start, clean_end = seg