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

@@ -333,6 +333,48 @@ def make_blocktitle_dxf(path: Path) -> None:
doc.saveas(path)
def make_titleblock_dxf(path: Path) -> None:
"""13号 加长A0 pattern: one ELONGATED sheet holds two towers far apart; the
pitch-sized rough window sees only the tower above the title and the clip
truncates the sheet. Title-block INSERTs (A0+0.5_V1 …) carry the true
frame rect and must define the clip."""
doc = ezdxf.new("R2010", setup=True)
for layer in ("WALL", "DOTE", "PUB_TEXT", "TK"):
doc.layers.add(layer)
msp = doc.modelspace()
pitch = 98100.0
def tower(ox: float, oy: float, bays: tuple) -> None:
outline = [((ox, oy), (ox + 40000, oy)), ((ox + 40000, oy), (ox + 40000, oy + 20000)),
((ox + 40000, oy + 20000), (ox, oy + 20000)), ((ox, oy + 20000), (ox, oy))]
for (sx, sy), (ex, ey) in outline:
msp.add_line((sx, sy), (ex, ey), dxfattribs={"layer": "WALL"})
for b in bays:
msp.add_line((ox + b, oy), (ox + b, oy + 20000), dxfattribs={"layer": "WALL"})
for x in (0, 8000, 19000, 26000, 37000, 40000):
msp.add_line((ox + x, oy - 3000), (ox + x, oy + 26000), dxfattribs={"layer": "DOTE"})
for y in (0, 6000, 10000, 20000):
msp.add_line((ox - 3000, oy + y), (ox + 43000, oy + y), dxfattribs={"layer": "DOTE"})
def frame_block(name: str, w: float, h: float) -> str:
if name not in doc.blocks:
blk = doc.blocks.new(name=name)
blk.add_lwpolyline([(0, 0), (w, 0), (w, h), (0, h)], close=True,
dxfattribs={"layer": "TK"})
return name
# F1: elongated sheet, twin towers 110 m apart inside ONE frame
tower(0.0, 0.0, (8000, 19000, 26000))
tower(110000.0, 0.0, (5000, 14000, 33000))
msp.add_blockref(frame_block("A0+0.5_V1", 179000, 85100), (-12000, -22000))
msp.add_text("一层平面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, -9000))
# F2: normal sheet below, single tower
tower(0.0, -pitch, (8000, 19000, 26000))
msp.add_blockref(frame_block("A1_V1", 85100, 60400), (-12000, -pitch - 22000))
msp.add_text("二层平面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, -pitch - 9000))
doc.saveas(path)
def make_mixedrow_dxf(path: Path) -> None:
"""27号 1#B pattern: main plans stack in a COLUMN, but a couple of stray
same-row detail titles fabricate a bogus (much smaller) x-pitch. clip_w
@@ -867,6 +909,77 @@ def main() -> int:
ok_bt = f2 is not None and abs(f2["offset"][0]) <= 120 and abs(f2["offset"][1] - 98100.0) <= 120
check("block-wrapped frames aligned", ok_bt, str(f2 and f2["offset"]))
# --- title-block INSERTs define clips; elongated sheets must not be halved (13号 加长A0) ---
tb_dir = WORK / "dxf_titleblock"
tb_dir.mkdir(parents=True, exist_ok=True)
make_titleblock_dxf(tb_dir / "titleblock.dxf")
proc = run([
sys.executable, "scripts/detect_sheet_frames.py",
"--dxf", str(tb_dir / "titleblock.dxf"), "--out-config", str(WORK / "frames_tb.json"),
"--out-report", str(WORK / "frames_tb.md"), "--vendor-dir", str(VENDOR),
])
check("detect handles title-block frames", proc.returncode == 0, proc.stderr[-500:])
if proc.returncode == 0:
frames_tb = json.loads((WORK / "frames_tb.json").read_text(encoding="utf-8"))
tb = {f["name"]: f for f in frames_tb["drawings"][0]["floors"]}
f1 = tb.get("一层平面图")
ok_tb = f1 is not None and f1["clip"][0] <= 0 and f1["clip"][2] >= 149000
check("elongated-A0 clip spans both towers", ok_tb, str(f1 and f1["clip"]))
tb_md = (WORK / "frames_tb.md").read_text(encoding="utf-8")
check("frame-block clips reported", "frame-block" in tb_md, tb_md[-300:])
# --- cross-floor datum: self-consistent but misplaced floor must FAIL audit (13号 F3 错槽) ---
cd_dir = WORK / "dxf_crossdatum"
cd_dir.mkdir(parents=True, exist_ok=True)
cd_doc = ezdxf.new("R2010", setup=True)
cd_doc.layers.add("WALL")
cd_msp = cd_doc.modelspace()
def cd_tower(ox: float, bays: tuple) -> None:
for start, end in [((ox, 0), (ox + 20000, 0)), ((ox + 20000, 0), (ox + 20000, 10000)),
((ox + 20000, 10000), (ox, 10000)), ((ox, 10000), (ox, 0))]:
cd_msp.add_line(start, end, dxfattribs={"layer": "WALL"})
for b in bays:
cd_msp.add_line((ox + b, 0), (ox + b, 10000), dxfattribs={"layer": "WALL"})
cd_msp.add_line((ox + 2000, 5200), (ox + 18000, 5200), dxfattribs={"layer": "WALL"})
cd_msp.add_line((ox + 1000, 2600), (ox + 19000, 2600), dxfattribs={"layer": "WALL"})
cd_msp.add_line((ox + bays[0] + 800, 0), (ox + bays[0] + 800, 10000), dxfattribs={"layer": "WALL"})
# F1 sheet: towers A (distinct bays) + B, 36 m apart. F2 sheet at x=100000:
# tower-A pattern that belongs in the A slot.
cd_tower(0.0, (3200, 7500, 16100))
cd_tower(36000.0, (4900, 12300, 17700))
cd_tower(100000.0, (3200, 7500, 16100))
cd_doc.saveas(cd_dir / "crossdatum.dxf")
def cd_audit(tag: str, offset_x: float) -> tuple[int, str]:
cfg = {
"scale": 0.001, "generate_footprints": True,
"drawings": [{"file": "crossdatum.dxf", "floors": [
{"key": "F1", "name": "一层", "z": 0.0, "height": 3.0,
"clip": [-2000.0, -2000.0, 58000.0, 12000.0], "offset": [0.0, 0.0]},
{"key": "F2", "name": "二层", "z": 3.0, "height": 3.0,
"clip": [98000.0, -2000.0, 122000.0, 12000.0], "offset": [offset_x, 0.0]},
]}],
}
cfg_path = WORK / f"cd_config_{tag}.json"
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
spec_path = WORK / f"cd_spec_{tag}.json"
run([sys.executable, "scripts/derive_showcase_spec.py",
"--dxf-dir", str(cd_dir), "--config", str(cfg_path),
"--out", str(spec_path), "--vendor-dir", str(VENDOR)])
proc = run([sys.executable, "scripts/audit_showcase_extraction.py",
"--dxf-dir", str(cd_dir), "--config", str(cfg_path),
"--spec", str(spec_path), "--out", str(WORK / f"cd_audit_{tag}"),
"--vendor-dir", str(VENDOR)])
md = (WORK / f"cd_audit_{tag}" / "extraction_audit.json").read_text(encoding="utf-8")
return proc.returncode, md
rc_bad, md_bad = cd_audit("bad", -64000.0) # A-pattern lands in the B slot (36 m off)
check("misplaced floor FAILs cross-floor datum", rc_bad != 0 and "cross_floor" in md_bad, md_bad[-400:] if rc_bad == 0 else "")
rc_good, md_good = cd_audit("good", -100000.0) # correct slot
check("correct slot PASSes cross-floor datum", rc_good == 0, md_good[-400:] if rc_good != 0 else "")
# --- bogus x-pitch from stray same-row titles must not shrink clips (27号 1#B) ---
mx_dir = WORK / "dxf_mixedrow"
mx_dir.mkdir(parents=True, exist_ok=True)