fix: enforce Revit roof views and orphan geometry gates
Some checks failed
ci / test (macos-latest, 3.10) (push) Has been cancelled
ci / test (macos-latest, 3.12) (push) Has been cancelled
ci / test (ubuntu-latest, 3.10) (push) Has been cancelled
ci / test (ubuntu-latest, 3.12) (push) Has been cancelled
ci / test (windows-latest, 3.10) (push) Has been cancelled
ci / test (windows-latest, 3.12) (push) Has been cancelled
ci / browser-smoke (push) Has been cancelled

This commit is contained in:
2026-07-21 13:10:04 +08:00
13 changed files with 857 additions and 67 deletions

View File

@@ -568,6 +568,7 @@ def evaluate_gates(
}
)
gates.append(frame_ledger_gate(config, frames))
gates.append(disconnected_footprints_gate(spec, config))
gates.append(vertical_storey_continuity_gate(spec))
gates.append(declared_area_gate(spec, config))
gates.append(storey_count_gate(spec, config))
@@ -610,15 +611,30 @@ def frame_ledger_gate(config: dict[str, Any], frames: list[dict[str, Any]] | Non
for drawing in fcfg.get("drawings", []) or []:
file = str(drawing.get("file", ""))
cfg_floors = cfg_by_file.get(file, [])
used_cfg: set[int] = set()
for frame in drawing.get("floors", []) or []:
total += 1
name = str(frame.get("name", ""))
key = str(frame.get("key", ""))
clip = frame.get("clip")
if name in discarded:
continue
if clip and any(fl.get("clip") and _rect_overlap_ratio(clip, fl["clip"]) >= 0.3 for fl in cfg_floors):
matches = [
index
for index, floor in enumerate(cfg_floors)
if index not in used_cfg
and str(floor.get("key", "")) == key
and set(frame.get("include_block_names", []) or []).issubset(
set(floor.get("include_block_names", []) or [])
)
and clip
and floor.get("clip")
and _rect_overlap_ratio(clip, floor["clip"]) >= 0.3
]
if matches:
used_cfg.add(matches[0])
continue
unaccounted.append(f"{file}: {frame.get('key', '?')} {name}")
unaccounted.append(f"{file}: {key or '?'} {name}")
if unaccounted:
shown = "; ".join(unaccounted[:12]) + (" …" if len(unaccounted) > 12 else "")
return {
@@ -637,6 +653,93 @@ def frame_ledger_gate(config: dict[str, Any], frames: list[dict[str, Any]] | Non
}
def _polygon_area(points: list[list[float]]) -> float:
if len(points) < 3:
return 0.0
return (
abs(
sum(
float(points[index][0]) * float(points[(index + 1) % len(points)][1])
- float(points[(index + 1) % len(points)][0]) * float(points[index][1])
for index in range(len(points))
)
)
/ 2.0
)
def _polygon_bounds(points: list[list[float]]) -> list[float]:
xs = [float(point[0]) for point in points]
ys = [float(point[1]) for point in points]
return [min(xs), min(ys), max(xs), max(ys)]
def _bounds_gap(a: list[float], b: list[float]) -> float:
dx = max(0.0, max(a[0] - b[2], b[0] - a[2]))
dy = max(0.0, max(a[1] - b[3], b[1] - a[3]))
return math.hypot(dx, dy)
def disconnected_footprints_gate(spec: dict[str, Any], config: dict[str, Any]) -> dict[str, Any]:
"""Reject small, remote footprint islands unless they are explained.
A stray but substantial curtain-wall/component cluster can survive the
line-level isolated-cluster filter and become a tall floating fin. The
generated footprint exposes it deterministically. Legitimate detached
stairs/canopies must be acknowledged with a floor key and reason.
"""
allowed = {
str(item.get("floor_key", ""))
for item in config.get("allowed_disconnected_footprints", []) or []
if isinstance(item, dict) and str(item.get("reason", "")).strip()
}
problems: list[str] = []
checked = 0
for floor_key, floor in spec.get("floors", {}).items():
polygons = [
polygon
for polygon in (floor.get("footprint") or {}).get("polygons", []) or []
if isinstance(polygon, list) and len(polygon) >= 3
]
if len(polygons) < 2 or str(floor_key) in allowed:
continue
checked += 1
measured = sorted(
[(_polygon_area(polygon), _polygon_bounds(polygon)) for polygon in polygons],
key=lambda item: item[0],
reverse=True,
)
main_area, main_bounds = measured[0]
if main_area <= 0:
continue
for area, bounds in measured[1:]:
ratio = area / main_area
gap = _bounds_gap(main_bounds, bounds)
if ratio < 0.05 and gap > 2.0:
problems.append(
f"{floor_key}: {area:.1f} m² island is {ratio:.1%} of the main footprint and {gap:.1f} m away"
)
if problems:
return {
"name": "disconnected_footprints",
"status": "FAIL",
"detail": (
"Small remote footprint islands would render as floating/orphan building parts: "
+ "; ".join(problems)
+ ". Fix the clip/layer/block mapping, or document a legitimate detached element in "
"allowed_disconnected_footprints with floor_key and reason."
),
}
return {
"name": "disconnected_footprints",
"status": "PASS",
"detail": (
f"No unexplained small remote footprint islands across {len(spec.get('floors', {}))} floor(s)"
+ (f" ({checked} multi-component floor(s) checked)." if checked else ".")
),
}
def declared_area_gate(spec: dict[str, Any], config: dict[str, Any]) -> dict[str, Any]:
"""Model footprint areas must match declared areas (经济技术指标表/标注).