homemaker-layout/experiments/dump_areas.py
Bruno Postle 0366392da4 Scaffold homemaker-py with validated geometry port
Clean-room Python successor to Urb for programme-driven layout search.
This initial commit establishes the .dom bridge format and a faithful
port of Urb's top-down quad geometry, validated byte-identical against
Urb across all 35 programme-house example files (including the wall
inset and multi-storey wall-stacking inheritance).

- dom.py: .dom YAML <-> Node tree, parent/below/position linkage,
  wall_outer inset on load, raw-corner stash for round-tripping
- geometry.py: Coordinate/Coordinate_a/_b/Area/Length + Coordinate_Offset
- experiments/dump_areas.{py,pl}: geometry regression harness
2026-06-10 20:50:20 +01:00

26 lines
744 B
Python

"""Dump per-leaf areas from a .dom using the Python geometry port.
Used to validate the port against a Perl dump from Urb (see the sibling
``dump_areas.pl``). Output: one line per leaf, ``level/idpath type area``,
sorted for a stable diff.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from homemaker import dom, geometry # noqa: E402
def main(path: str) -> None:
root = dom.load(path)
rows = []
for level_idx, lvl in enumerate(dom.levels(root)):
for leaf in lvl.leaves():
rows.append(f"{level_idx}/{leaf.id} {leaf.type or '?'} {geometry.area(leaf):.4f}")
print("\n".join(sorted(rows)))
if __name__ == "__main__":
main(sys.argv[1])