Land the two deferred gaps: title-block frame clips + cross-floor datum gate

- detect_sheet_frames: title-block INSERTs (A0_V1/A0+0.5_V1/*图框*) define the
  clip window when they contain the title — pitch windows halved elongated
  sheets (13号 加长A0, one frame holding both towers); wall refine is clamped
  inside the frame rect; 13号 b1 real data: all 45 frames rect-clipped
- audit floors_aligned: cross-floor wall-profile datum check catches
  "self-consistent but misplaced" floors (13号 F3 错槽 85.8m that envelope
  centers PASSed); zero-shift guard kills the dense-podium false positive
  (27号 1#A PH matched "better" 1.5m off while already fitting in place)
- 门卫 size mismatch root-caused as representation granularity (gate compound
  vs kiosk symbol), not an extraction bug — closed in the log
- regression suite +6 checks (titleblock / crossdatum bad+good), all three
  projects re-audited with no false positives

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 08:05:57 +08:00
parent 1e11d38fa9
commit 9729857549
5 changed files with 239 additions and 13 deletions

View File

@@ -205,7 +205,7 @@ def title_qualifier(name: str) -> str:
return name if m is None else name[: m.start()]
def wall_profile(segs, axis: int):
def wall_profile(segs, axis: int, axis_tol: float = 2.0, min_len: float = 400.0):
"""Length-weighted axis positions of straight walls.
axis=0: vertical segments -> x positions; axis=1: horizontal -> y.
@@ -213,13 +213,14 @@ def wall_profile(segs, axis: int):
in the frame (13号 tower / 27号 2#): correlating profiles between
frames recovers the true translation where clip-corner anchoring is
off by whole bays (wall bbox min-corner varies with balconies).
Defaults are mm-scale; pass axis_tol/min_len in meters for spec-space use.
"""
out = []
for sx, sy, ex, ey in segs:
dx, dy = abs(ex - sx), abs(ey - sy)
if axis == 0 and dx < 2.0 and dy > 400:
if axis == 0 and dx < axis_tol and dy > min_len:
out.append(((sx + ex) / 2, dy))
elif axis == 1 and dy < 2.0 and dx > 400:
elif axis == 1 and dy < axis_tol and dx > min_len:
out.append(((sy + ey) / 2, dx))
return out
@@ -368,6 +369,34 @@ def main() -> int:
elif OTHER_TITLE.search(content) and not match_any(layer, title_excludes):
others.append({"name": content, "x": x, "y": y, "h": height})
# Title-block frame INSERTs (A0_V1 / A0+0.5_V1 / *图框* …) carry the TRUE
# sheet rect. Pitch-sized windows halve elongated sheets (13号 加长A0 held
# both towers in one frame and F1 lost a tower) — prefer the block rect.
frame_block_re = re.compile(r"(?i)(^A[0-4](\+[0-9.]+)?([_\-]|$))|图框|图签|(^TK([_\-]|$))")
frame_rects: list[tuple[float, float, float, float]] = []
for entity in msp.query("INSERT"):
name = str(entity.dxf.name)
if not frame_block_re.search(name):
continue
xs_fb: list[float] = []
ys_fb: list[float] = []
try:
for ve in entity.virtual_entities():
vk = ve.dxftype()
if vk == "LINE":
for p in (ve.dxf.start, ve.dxf.end):
xs_fb.append(float(p.x)); ys_fb.append(float(p.y))
elif vk == "LWPOLYLINE":
for px, py in ve.get_points("xy"):
xs_fb.append(float(px)); ys_fb.append(float(py))
except Exception:
continue
if not xs_fb:
continue
w, h = max(xs_fb) - min(xs_fb), max(ys_fb) - min(ys_fb)
if w >= 20000 and h >= 15000 and 0.3 <= (w / h) <= 4.0: # plausible sheet
frame_rects.append((min(xs_fb), min(ys_fb), max(xs_fb), max(ys_fb)))
for entity in msp:
kind = entity.dxftype()
if kind == "INSERT":
@@ -439,6 +468,13 @@ def main() -> int:
if pitch_x and not pitch_y:
# row layout: title x may sit anywhere under its frame; centre on it
rough = [t["x"] - clip_w * 0.6, t["y"] - clip_h * 0.04, t["x"] + clip_w * 0.6, t["y"] + clip_h]
frame_rect = next((r for r in frame_rects
if r[0] <= t["x"] <= r[2] and r[1] <= t["y"] <= r[3]), None)
if frame_rect is not None:
fw, fh = frame_rect[2] - frame_rect[0], frame_rect[3] - frame_rect[1]
rough = [frame_rect[0] + fw * 0.01, frame_rect[1] + fh * 0.01,
frame_rect[2] - fw * 0.01, frame_rect[3] - fh * 0.01]
notes.append(f"{t['name']}: frame-block rect used for clip window ({fw / 1000:.1f}x{fh / 1000:.1f} m)")
clip = None
for group in refine_groups:
found = segments_in(lines, rough, group)
@@ -447,10 +483,14 @@ def main() -> int:
ys_ = [v for s in found for v in (s[1], s[3])]
margin = pitch * 0.06
clip = [min(xs) - margin, min(ys_) - margin, max(xs) + margin, max(ys_) + margin]
if frame_rect is not None: # never swallow the neighbour sheet
clip = [max(clip[0], rough[0]), max(clip[1], rough[1]),
min(clip[2], rough[2]), min(clip[3], rough[3])]
break
if clip is None:
clip = rough
notes.append(f"{t['name']}: no wall/roof geometry in rough clip; using pitch-based clip")
if frame_rect is None:
notes.append(f"{t['name']}: no wall/roof geometry in rough clip; using pitch-based clip")
# Axis geometry lives OUTSIDE the wall-tight clip (axis-number stubs sit
# beyond the facade), so collect grid candidates in an expanded window.
axis_margin = pitch * 0.16