refactor(understand): one reading of units, plan copies, scale and rooms

Groups U and N were built side by side, so the takeoffs carried narrow
stand-ins for what group U reads properly. On main they read through U:

- describe.drawing_units is the one call every reader makes (kept records,
  labelled room faces as evidence); describe, scale_check and the takeoffs
  all use it. Without the room faces, a layout that declares inches over
  millimetres can tie three ways and fall to the header.
- layout_tags takes its plan copies from describe.prepare, room_regions its
  rooms from describe.find_rooms, and pipe_rows its scale from scale_check,
  per-room groups included. scale_stand_in and the takeoff's own unit bands
  and cluster grid are gone.
- test_understand_one_reading pins the agreement: one unit, one plan copy,
  one verdict and one set of rooms per drawing, across drawing_understand,
  drawing_scale_check and the two takeoffs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-24 14:45:27 +03:00
co-authored by Claude Opus 5.5
parent c4759e696d
commit 8c1a6cb27c
6 changed files with 244 additions and 347 deletions
+21 -5
View File
@@ -39,6 +39,7 @@ from engineering.understand.vocab import classify_layer, room_label
__all__ = [
"describe",
"drawing_units",
"find_rooms",
"prepare",
"tag_occurrences",
@@ -232,6 +233,25 @@ def find_rooms(records: Sequence[EntityRecord], *, tol: float, membership: dict)
}
def drawing_units(snap: Snapshot, *, prep: dict | None = None, rooms: dict | None = None) -> dict:
"""`units.infer_units` the one way every reader calls it: on the records kept
after the outliers, with the labelled room faces as evidence.
`describe`, `scale.scale_check` and the takeoffs all read a drawing's unit
here, so no two tools report two units for one drawing. ``prep`` and
``rooms`` are a `prepare` / `find_rooms` result the caller already holds.
"""
prep = prep or prepare(snap)
if rooms is None:
tol = prep["diag"] * FACE_TOL_FRACTION if prep["diag"] > 0 else 1.0
rooms = find_rooms(prep["kept"], tol=tol, membership=prep["membership"])
return infer_units(
snap,
records=prep["kept"],
room_areas=[row["face"]["area"] for row, _face in rooms["labelled"]],
)
def text_language(text: str) -> str:
"""``cyrillic`` | ``turkish`` | ``latin`` | ``none`` by character class, in
that precedence (a Russian label with a Latin tag in it is Cyrillic)."""
@@ -385,11 +405,7 @@ def describe(snap: Snapshot) -> dict:
warnings: list[str] = []
tol = prep["diag"] * FACE_TOL_FRACTION if prep["diag"] > 0 else 1.0
rooms = find_rooms(prep["kept"], tol=tol, membership=prep["membership"])
units = infer_units(
snap,
records=prep["kept"],
room_areas=[row["face"]["area"] for row, _face in rooms["labelled"]],
)
units = drawing_units(snap, prep=prep, rooms=rooms)
if units["warning"]:
warnings.append(units["warning"])
extents = dict(prep["extents"])