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

@@ -91,6 +91,20 @@ clip 合并——**该能力已存在**:floor_specs 为列表、buckets 按 ke
机房顶 49.8、女儿墙 51.8、B1=-5.95、B2=-9.65;夹层框(F1M/F2M/B1M)与 机房顶 49.8、女儿墙 51.8、B1=-5.95、B2=-9.65;夹层框(F1M/F2M/B1M)与
分区地下框首版跳过;地下体量建议统一由 A-03 地库图集出,避免双份几何。 分区地下框首版跳过;地下体量建议统一由 A-03 地库图集出,避免双份几何。
11. **跨 clip 长线整条渗入楼层**(13号):derive 的 clip 判定是"中点或端点
在框内即整条保留"——表格边框/注记长线把整张图纸宽度带进楼层(56m 框吐出
143m 几何,footprint 凸包长出游离大板,顶视图一片狼藉)。修复:新增
`clip_segment_to_rect`(Liang-Barsky)把线段**裁剪**到 clip 矩形,全内
线段原样通过。回归:40m 框内 140m 穿越线裁到框宽。贝昂框距大未暴露此坑,
图框密排的图集必踩。
13号 一号楼当前状态(round 3):标准层双塔(F4~F10,union-clip 单条目)+
机房/屋顶(塔芯居中/女儿墙 bbox 锚定,两翼 offset 自洽性 50mm)已对齐,
audit 三门禁 PASS,GLB 双塔顶视形态正确(间距 85.8m)。**未决**:F1~F3
裙房与塔楼错位——F1 框仅 88m 宽盖不住 135m 双塔,一层疑似也是分区图
(另一分区待在 45 候选框或 A-03 地库图集中确认);下一轮先解裙房分区,
再做叠图逐层核验与 viewer 目检。
(待续) (待续)
3. **消毒步骤误删 XRECORD 的 999 数值行**(发现于苏州博物馆/test3d-8 首跑): 3. **消毒步骤误删 XRECORD 的 999 数值行**(发现于苏州博物馆/test3d-8 首跑):

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) 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( def segment_matches_floor(
start: tuple[float, float], start: tuple[float, float],
end: tuple[float, float], end: tuple[float, float],
@@ -517,7 +555,10 @@ def collect_raw_segments(
for floor, key, offset in floor_specs: for floor, key, offset in floor_specs:
if not segment_matches_floor(start, end, floor, drawing): if not segment_matches_floor(start, end, floor, drawing):
continue 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: if not seg:
continue continue
clean_start, clean_end = seg clean_start, clean_end = seg

View File

@@ -694,6 +694,45 @@ def main() -> int:
f"glazing={len(glz_off)}", f"glazing={len(glz_off)}",
) )
# --- segments must be TRIMMED to the frame clip, not kept whole ---
# (13号: a 56m-wide frame emitted 143m of geometry because long table/
# border lines with an inside midpoint carried the full sheet width)
trim_dir = WORK / "dxf_trim"
trim_dir.mkdir(parents=True, exist_ok=True)
trim_doc = ezdxf.new("R2010", setup=True)
trim_doc.layers.add("I-WALL")
trim_msp = trim_doc.modelspace()
for start, end in [
((0, 0), (40000, 0)), ((40000, 0), (40000, 20000)),
((40000, 20000), (0, 20000)), ((0, 20000), (0, 0)),
]:
trim_msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
trim_msp.add_line((-50000, 10000), (90000, 10000), dxfattribs={"layer": "I-WALL"})
trim_doc.saveas(trim_dir / "plan.dxf")
trim_cfg = WORK / "trim_config.json"
trim_cfg.write_text(json.dumps({
"scale": 0.001, "drop_isolated_clusters": False,
"drawings": [{"file": "plan.dxf", "floors": [
{"key": "1F", "name": "首层", "z": 0.0, "height": 4.2, "clip": [-1000, -1000, 41000, 21000]},
]}],
}, ensure_ascii=False), encoding="utf-8")
trim_spec_path = WORK / "trim_spec.json"
proc = run([
sys.executable, "scripts/derive_showcase_spec.py",
"--dxf-dir", str(trim_dir), "--config", str(trim_cfg),
"--out", str(trim_spec_path), "--vendor-dir", str(VENDOR),
])
check("derive clip-trim runs", proc.returncode == 0, proc.stderr[-400:])
trim_spec = json.loads(trim_spec_path.read_text(encoding="utf-8"))
trim_walls = trim_spec["floors"]["1F"]["segments"]["walls"]
trim_max_x = max(max(s["start"][0], s["end"][0]) for s in trim_walls)
trim_min_x = min(min(s["start"][0], s["end"][0]) for s in trim_walls)
check(
"crossing line trimmed to the clip window",
len(trim_walls) == 5 and -1.5 <= trim_min_x and trim_max_x <= 42.5,
f"n={len(trim_walls)} x=[{trim_min_x:.1f},{trim_max_x:.1f}]",
)
# --- unsupported roof outlines (黄桥坡屋面: canopy with hatch-only posts) --- # --- unsupported roof outlines (黄桥坡屋面: canopy with hatch-only posts) ---
uns_dir = WORK / "dxf_unsupported" uns_dir = WORK / "dxf_unsupported"
uns_dir.mkdir(parents=True, exist_ok=True) uns_dir.mkdir(parents=True, exist_ok=True)