@kensnzk/koyu 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.ja.md +5 -5
  2. package/README.md +5 -5
  3. package/dist/cli.js +34 -8
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/derive.d.ts +6 -0
  6. package/dist/core/derive.d.ts.map +1 -1
  7. package/dist/core/derive.js +235 -7
  8. package/dist/core/derive.js.map +1 -1
  9. package/dist/core/diagnose.d.ts +1 -0
  10. package/dist/core/diagnose.d.ts.map +1 -1
  11. package/dist/core/diagnose.js +19 -1
  12. package/dist/core/diagnose.js.map +1 -1
  13. package/dist/core/model.d.ts +15 -3
  14. package/dist/core/model.d.ts.map +1 -1
  15. package/dist/core/model.js +24 -8
  16. package/dist/core/model.js.map +1 -1
  17. package/dist/core/vocabulary.d.ts +16 -0
  18. package/dist/core/vocabulary.d.ts.map +1 -1
  19. package/dist/core/vocabulary.js +11 -2
  20. package/dist/core/vocabulary.js.map +1 -1
  21. package/dist/draw/axo.d.ts.map +1 -1
  22. package/dist/draw/axo.js +15 -13
  23. package/dist/draw/axo.js.map +1 -1
  24. package/dist/mcp.js +37 -10
  25. package/dist/mcp.js.map +1 -1
  26. package/dist/model.d.ts +1 -1
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +1 -1
  29. package/dist/model.js.map +1 -1
  30. package/dist/validate/builtin/access.js +30 -6
  31. package/dist/validate/builtin/access.js.map +1 -1
  32. package/examples/basement/main.muro +9 -9
  33. package/examples/complex/L1.muro +22 -22
  34. package/examples/complex/basement.muro +4 -4
  35. package/examples/complex/core.muro +11 -15
  36. package/examples/complex/hotel.muro +14 -14
  37. package/examples/complex/main.muro +1 -1
  38. package/examples/complex/office.muro +3 -3
  39. package/examples/complex/plant.muro +4 -4
  40. package/examples/complex/podium.muro +23 -23
  41. package/examples/house/main.muro +2 -2
  42. package/examples/house.muro +2 -2
  43. package/examples/mansion.muro +27 -27
  44. package/examples/office.muro +16 -16
  45. package/examples/steps/06-finished.muro +1 -1
  46. package/examples/tower/L1.muro +12 -12
  47. package/examples/tower/L11.muro +4 -4
  48. package/examples/tower/L2.muro +10 -10
  49. package/examples/tower/main.muro +1 -1
  50. package/examples/tower/typical.muro +10 -10
  51. package/examples/twin/L1.muro +29 -29
  52. package/examples/twin/L5.muro +14 -14
  53. package/examples/twin/basement.muro +9 -9
  54. package/examples/twin/core.muro +49 -49
  55. package/examples/twin/hotel.muro +15 -15
  56. package/examples/twin/main.muro +8 -9
  57. package/examples/twin/office.muro +10 -10
  58. package/examples/twin/podium.muro +73 -73
  59. package/examples/twin/residence.muro +10 -10
  60. package/examples/two-rooms.canonical.json +1 -1
  61. package/examples/two-rooms.muro +1 -1
  62. package/package.json +5 -4
  63. package/src/cli.ts +34 -8
  64. package/src/core/derive.ts +292 -6
  65. package/src/core/diagnose.ts +23 -1
  66. package/src/core/model.ts +25 -9
  67. package/src/core/vocabulary.ts +30 -2
  68. package/src/draw/axo.ts +14 -13
  69. package/src/mcp.ts +38 -10
  70. package/src/model.ts +1 -1
  71. package/src/validate/builtin/access.ts +32 -6
@@ -46,7 +46,8 @@ import {
46
46
  isOutside,
47
47
  isVoid
48
48
  } from "./model.js";
49
- import { EPS, SPAN_EPS } from "./tolerance.js";
49
+ import { clipHalf } from "./poly.js";
50
+ import { EPS, PARALLEL_EPS, POINT_EPS, SPAN_EPS } from "./tolerance.js";
50
51
  import {
51
52
  CUT_HEIGHT,
52
53
  ARROW_SPAN_MIN,
@@ -163,6 +164,12 @@ export interface FormPanel {
163
164
  y2: number;
164
165
  z0: number;
165
166
  z1: number;
167
+ /**
168
+ * The body of this interval, with the junctions at both ends resolved. It is the centre line
169
+ * thickened where nothing joins; where walls meet it runs on past the end or stops short of it,
170
+ * so **the centre line above is not the axis of this outline** and cannot be recovered from it
171
+ */
172
+ footprint: Pt[];
166
173
  }
167
174
 
168
175
  /** 境界の実体 — 芯線分と、物があるならその材 */
@@ -371,6 +378,7 @@ const sameSegment = (a: Segment, b: Segment): boolean =>
371
378
  */
372
379
  function panelsOf(
373
380
  seg: Segment,
381
+ t: number,
374
382
  z0: number,
375
383
  z1: number,
376
384
  holes: Array<{ lo: number; hi: number; z0: number; z1: number }>,
@@ -381,7 +389,8 @@ function panelsOf(
381
389
  if (u1 - u0 <= SPAN_EPS || b - a <= SPAN_EPS) return;
382
390
  const p = alongPoint(seg, u0, len);
383
391
  const q = alongPoint(seg, u1, len);
384
- out.push({ x1: p.x, y1: p.y, x2: q.x, y2: q.y, z0: a, z1: b });
392
+ // The body before any junction is resolved — `joinWalls` rewrites the ends that meet a wall
393
+ out.push({ x1: p.x, y1: p.y, x2: q.x, y2: q.y, z0: a, z1: b, footprint: thicken(p.x, p.y, q.x, q.y, t) });
385
394
  };
386
395
  let cursor = 0;
387
396
  for (const h of [...holes].sort((p, q) => p.lo - q.lo)) {
@@ -535,6 +544,276 @@ export function runPrism(s: RunSolid): FormPrism {
535
544
  return { poly, bottom: top.map((z) => z - s.t), top };
536
545
  }
537
546
 
547
+ // ---- Wall joins ----------------------------------------------------------
548
+ //
549
+ // A boundary segment is a centre line, so thickening it about that line leaves the corner of a
550
+ // junction empty. Two walls meeting at a right angle each stop at the point they share, and the
551
+ // square of t/2 by t/2 outside it belongs to neither: `examples/two-rooms.muro` had one such hole
552
+ // at each of the four corners of the building, and `examples/complex` had 206.
553
+ //
554
+ // **Nothing is merged.** A wall stays one body per interval, keeping its own identity, thickness
555
+ // and z range. What the join decides is which of the walls meeting at a point runs through and
556
+ // where the others stop: **the winner runs through, and every wall that ends at the node is cut
557
+ // back to the winner's face.** Two bodies that meet along that face close the corner between them
558
+ // without becoming one body, and the cut is what keeps them from occupying the same matter twice.
559
+ //
560
+ // **The cut is against the winner, and against nothing else.** Two losing ends leaning to the same
561
+ // side of the winner are each cut to that one face and not to each other, so their bodies overlap
562
+ // between the face and the point where their centre lines part. It takes a wall that is neither
563
+ // parallel nor perpendicular to reach that state — with axis-parallel walls a node has at most one
564
+ // end per side — and an overlap is not a hole.
565
+ //
566
+ // The election is a total order, so one model always gives one shape (promise 1 of the shape):
567
+ //
568
+ // 1. a wall that does not end at the node beats one that does — it is already running through
569
+ // 2. the thicker wall wins
570
+ // 3. the centre line that comes first in ascending coordinate order wins
571
+ //
572
+ // Nothing in it reads declaration order, and nothing reads which boundary a segment came from.
573
+
574
+ /** A half plane — the points `x` with `(x − q)·m ≥ 0`. The face a losing end is cut back to */
575
+ interface Trim {
576
+ q: Pt;
577
+ m: Pt;
578
+ /** the z range of the wall that won — a cut reaches only as high as the matter that makes it */
579
+ z0: number;
580
+ z1: number;
581
+ }
582
+
583
+ /** A wall taking part in the joins of one level */
584
+ interface JoinBody {
585
+ panels: FormPanel[];
586
+ /** half the thickness */
587
+ a: number;
588
+ /** the z range of the whole wall */
589
+ z0: number;
590
+ z1: number;
591
+ /** unit direction of the centre line, and the normal to its left */
592
+ u: Pt;
593
+ n: Pt;
594
+ /** the two ends of the centre line, in its own direction */
595
+ ends: [Pt, Pt];
596
+ /** how far the body runs past each end. Only the winner of a node extends */
597
+ ext: [number, number];
598
+ trim: [Trim | undefined, Trim | undefined];
599
+ }
600
+
601
+ /** An end of a wall at a node, or — with no `end` — a wall running through it */
602
+ interface Incident {
603
+ body: JoinBody;
604
+ end?: 0 | 1;
605
+ }
606
+
607
+ const dot = (a: Pt, b: Pt): number => a.x * b.x + a.y * b.y;
608
+ const cross = (a: Pt, b: Pt): number => a.x * b.y - a.y * b.x;
609
+ const along = (p: Pt, d: Pt, k: number): Pt => ({ x: p.x + d.x * k, y: p.y + d.y * k });
610
+ const same = (p: Pt, q: Pt): boolean => Math.abs(p.x - q.x) <= POINT_EPS && Math.abs(p.y - q.y) <= POINT_EPS;
611
+
612
+ /** Where the line through `p` along `d` meets the line through `q` along `e` (parallel: none) */
613
+ function meet(p: Pt, d: Pt, q: Pt, e: Pt): Pt | undefined {
614
+ const den = cross(d, e);
615
+ if (Math.abs(den) < PARALLEL_EPS) return undefined;
616
+ return along(p, d, cross({ x: q.x - p.x, y: q.y - p.y }, e) / den);
617
+ }
618
+
619
+ /** The direction out of a wall at one of its ends (an end runs against it) */
620
+ const outward = (b: JoinBody, end: 0 | 1): Pt =>
621
+ end === 0 ? { x: -b.u.x, y: -b.u.y } : b.u;
622
+
623
+ /** The direction into a wall from one of its ends */
624
+ const inward = (b: JoinBody, end: 0 | 1): Pt => outward(b, end === 0 ? 1 : 0);
625
+
626
+ /** The centre line in ascending coordinate order — the spelling the election breaks ties by */
627
+ function lineKey(b: JoinBody): [number, number, number, number] {
628
+ const [p, q] = b.ends;
629
+ const first = p.x < q.x || (p.x === q.x && p.y <= q.y);
630
+ return first ? [p.x, p.y, q.x, q.y] : [q.x, q.y, p.x, p.y];
631
+ }
632
+
633
+ /** The election. Negative when `x` beats `y` */
634
+ function beats(x: Incident, y: Incident): number {
635
+ if ((x.end === undefined) !== (y.end === undefined)) return x.end === undefined ? -1 : 1;
636
+ if (x.body.a !== y.body.a) return y.body.a - x.body.a;
637
+ const kx = lineKey(x.body);
638
+ const ky = lineKey(y.body);
639
+ for (let i = 0; i < 4; i++) if (kx[i]! !== ky[i]!) return kx[i]! - ky[i]!;
640
+ return 0;
641
+ }
642
+
643
+ /**
644
+ * How far the winner has to run past the node so that its face carries the whole cut edge of a
645
+ * losing end. The loser is cut back to the winner's face, and that cut edge reaches as far as the
646
+ * loser's own sides do — at a right angle exactly half the loser's thickness, further where the
647
+ * loser leans back over the winner. A loser running along the winner needs no extension: the two
648
+ * simply butt.
649
+ */
650
+ function extensionFor(winner: Incident, loser: Incident, p: Pt): number {
651
+ if (winner.end === undefined) return 0;
652
+ const w = outward(winner.body, winner.end);
653
+ const v = inward(loser.body, loser.end!);
654
+ if (Math.abs(cross(winner.body.u, v)) < PARALLEL_EPS) return 0;
655
+ const side = dot(v, winner.body.n) >= 0 ? 1 : -1;
656
+ const face = along(p, winner.body.n, side * winner.body.a);
657
+ let e = 0;
658
+ for (const s of [1, -1]) {
659
+ const q = meet(face, winner.body.u, along(p, loser.body.n, s * loser.body.a), v);
660
+ if (q) e = Math.max(e, dot({ x: q.x - p.x, y: q.y - p.y }, w));
661
+ }
662
+ return e;
663
+ }
664
+
665
+ /** The face a losing end is cut back to — the winner's side, or its end cap when the two run along each other */
666
+ function trimFor(winner: Incident, loser: Incident, p: Pt): Trim | undefined {
667
+ const v = inward(loser.body, loser.end!);
668
+ const z = { z0: winner.body.z0, z1: winner.body.z1 };
669
+ if (Math.abs(cross(winner.body.u, v)) < PARALLEL_EPS) {
670
+ if (winner.end === undefined) return undefined;
671
+ const w = outward(winner.body, winner.end);
672
+ return { q: along(p, w, winner.body.ext[winner.end]), m: w, ...z };
673
+ }
674
+ const side = dot(v, winner.body.n) >= 0 ? 1 : -1;
675
+ return {
676
+ q: along(p, winner.body.n, side * winner.body.a),
677
+ m: { x: winner.body.n.x * side, y: winner.body.n.y * side },
678
+ ...z,
679
+ };
680
+ }
681
+
682
+ /**
683
+ * Whether `p` lies on the centre line of `b` without being one of its ends.
684
+ * **Lying on the line is `EPS`**, the same tolerance the rest of the geometry uses for two edges
685
+ * being collinear — not `POINT_EPS`, which is the wider "on the edge of a region" of a column
686
+ */
687
+ function runsThrough(b: JoinBody, p: Pt): boolean {
688
+ if (same(p, b.ends[0]) || same(p, b.ends[1])) return false;
689
+ const d = { x: p.x - b.ends[0].x, y: p.y - b.ends[0].y };
690
+ const s = dot(d, b.u);
691
+ const len = dot({ x: b.ends[1].x - b.ends[0].x, y: b.ends[1].y - b.ends[0].y }, b.u);
692
+ return s > 0 && s < len && Math.abs(cross(b.u, d)) <= EPS;
693
+ }
694
+
695
+ /** Rounded to the millimetre — coordinates are millimetres, so a node is one cell */
696
+ const cellKey = (p: Pt): string => `${Math.round(p.x)}|${Math.round(p.y)}`;
697
+
698
+ /**
699
+ * Join the walls of one level, in place. Two passes: every winner is elected and extended before
700
+ * any loser is cut back, because a loser is cut back to the winner's **extended** face.
701
+ */
702
+ function joinLevel(bodies: JoinBody[]): void {
703
+ const nodes = new Map<string, { p: Pt; ends: Incident[] }>();
704
+ for (const body of bodies) {
705
+ for (const end of [0, 1] as const) {
706
+ const p = body.ends[end];
707
+ const k = cellKey(p);
708
+ const node = nodes.get(k) ?? { p, ends: [] };
709
+ node.ends.push({ body, end });
710
+ nodes.set(k, node);
711
+ }
712
+ }
713
+
714
+ // Walls that may run through a node without ending there, looked up by the line they lie on
715
+ const byX = new Map<number, JoinBody[]>();
716
+ const byY = new Map<number, JoinBody[]>();
717
+ const oblique: JoinBody[] = [];
718
+ for (const b of bodies) {
719
+ const [p, q] = b.ends;
720
+ const index = Math.abs(p.y - q.y) <= EPS ? byY : Math.abs(p.x - q.x) <= EPS ? byX : undefined;
721
+ if (index === undefined) {
722
+ oblique.push(b);
723
+ continue;
724
+ }
725
+ const at = Math.round(index === byY ? p.y : p.x);
726
+ const g = index.get(at) ?? [];
727
+ g.push(b);
728
+ index.set(at, g);
729
+ }
730
+ const through = (p: Pt): JoinBody[] => {
731
+ const out: JoinBody[] = [];
732
+ for (const d of [-1, 0, 1]) {
733
+ for (const b of byY.get(Math.round(p.y) + d) ?? []) if (runsThrough(b, p)) out.push(b);
734
+ for (const b of byX.get(Math.round(p.x) + d) ?? []) if (runsThrough(b, p)) out.push(b);
735
+ }
736
+ for (const b of oblique) if (runsThrough(b, p)) out.push(b);
737
+ return out;
738
+ };
739
+
740
+ const elected: Array<{ p: Pt; winner: Incident; ends: Incident[] }> = [];
741
+ for (const node of nodes.values()) {
742
+ const incident: Incident[] = [...through(node.p).map((body) => ({ body })), ...node.ends];
743
+ if (incident.length < 2) continue;
744
+ const winner = incident.reduce((best, i) => (beats(i, best) < 0 ? i : best));
745
+ elected.push({ p: node.p, winner, ends: node.ends });
746
+ if (winner.end === undefined) continue;
747
+ let e = winner.body.ext[winner.end];
748
+ for (const loser of node.ends) {
749
+ if (loser.body === winner.body && loser.end === winner.end) continue;
750
+ e = Math.max(e, extensionFor(winner, loser, node.p));
751
+ }
752
+ winner.body.ext[winner.end] = e;
753
+ }
754
+
755
+ for (const { p, winner, ends } of elected) {
756
+ for (const loser of ends) {
757
+ if (loser.body === winner.body && loser.end === winner.end) continue;
758
+ loser.body.trim[loser.end!] = trimFor(winner, loser, p);
759
+ }
760
+ }
761
+
762
+ for (const body of bodies) {
763
+ if (body.ext[0] === 0 && body.ext[1] === 0 && !body.trim[0] && !body.trim[1]) continue;
764
+ for (const panel of body.panels) {
765
+ const at: [boolean, boolean] = [
766
+ same({ x: panel.x1, y: panel.y1 }, body.ends[0]),
767
+ same({ x: panel.x2, y: panel.y2 }, body.ends[1]),
768
+ ];
769
+ const s = at[0] ? along({ x: panel.x1, y: panel.y1 }, body.u, -body.ext[0]) : { x: panel.x1, y: panel.y1 };
770
+ const t = at[1] ? along({ x: panel.x2, y: panel.y2 }, body.u, body.ext[1]) : { x: panel.x2, y: panel.y2 };
771
+ let foot = thicken(s.x, s.y, t.x, t.y, body.a * 2);
772
+ for (const end of [0, 1] as const) {
773
+ const cut = at[end] ? body.trim[end] : undefined;
774
+ if (!cut) continue;
775
+ // **A cut reaches only as high as the wall that made it.** A rail wins a junction against
776
+ // a wall thinner than itself, and cutting the wall back over its whole height would take
777
+ // a slice out of it above the rail's own top and leave a notch there. Where the winner
778
+ // does not span the interval, the interval keeps its body and the two overlap instead
779
+ if (panel.z0 < cut.z0 - SPAN_EPS || panel.z1 > cut.z1 + SPAN_EPS) continue;
780
+ // The directed line whose left side is `m`. **A cut that would leave nothing does not
781
+ // happen** — a wall swallowed whole by the one it runs into keeps the body it had
782
+ const kept = clipHalf(foot, cut.q, { x: cut.q.x + cut.m.y, y: cut.q.y - cut.m.x }, true);
783
+ if (kept.length >= 3) foot = kept;
784
+ }
785
+ panel.footprint = foot;
786
+ }
787
+ }
788
+ }
789
+
790
+ /** Close the junctions of every wall of the model. Levels are joined independently */
791
+ function joinWalls(boundaries: FormBoundary[]): void {
792
+ const byLevel = new Map<string, JoinBody[]>();
793
+ for (const b of boundaries) {
794
+ if (!b.material || b.material.panels.length === 0) continue;
795
+ const seg = b.segment;
796
+ const len = segmentLength(seg);
797
+ if (len <= EPS) continue;
798
+ const u = { x: (seg.x2 - seg.x1) / len, y: (seg.y2 - seg.y1) / len };
799
+ const k = b.level ?? "";
800
+ const g = byLevel.get(k) ?? [];
801
+ g.push({
802
+ panels: b.material.panels,
803
+ a: b.material.t / 2,
804
+ z0: b.material.z0,
805
+ z1: b.material.z1,
806
+ u,
807
+ n: { x: -u.y, y: u.x },
808
+ ends: [{ x: seg.x1, y: seg.y1 }, { x: seg.x2, y: seg.y2 }],
809
+ ext: [0, 0],
810
+ trim: [undefined, undefined],
811
+ });
812
+ byLevel.set(k, g);
813
+ }
814
+ for (const bodies of byLevel.values()) joinLevel(bodies);
815
+ }
816
+
538
817
  const spans = (z0: number, z1: number, z: number): boolean => z >= z0 - SPAN_EPS && z <= z1 + SPAN_EPS;
539
818
 
540
819
  /**
@@ -691,12 +970,16 @@ export function derive(model: Model, opts: DeriveOptions = {}): Form {
691
970
  air: b.air === true,
692
971
  segment: seg,
693
972
  ...(b.kind === "wall" && z0 !== undefined && top !== undefined && len > EPS
694
- ? { material: { t, z0, z1: top, panels: panelsOf(seg, z0, top, holes) } }
973
+ ? { material: { t, z0, z1: top, panels: panelsOf(seg, t, z0, top, holes) } }
695
974
  : {}),
696
975
  });
697
976
  }
698
977
  }
699
978
 
979
+ // The bodies of the walls are settled here, once every wall of every level is known — a
980
+ // junction is a fact about two walls, so no single boundary can answer it on its own
981
+ joinWalls(boundaries);
982
+
700
983
  // ---- 柱 ----
701
984
  const columns: FormColumn[] = [];
702
985
  for (const l of levels) {
@@ -771,14 +1054,17 @@ function planOf(
771
1054
  });
772
1055
  continue;
773
1056
  }
774
- // 区間は**足あと (厚みのある四辺形) と芯線の両方**を持つ。厚みを持つものとして描くか
775
- // 一本の線として描くか (遮蔽しない手すり・柵) は見た目の判断なので、消費者が選ぶ
1057
+ // An interval carries **both the footprint (its body, with the junctions settled) and the
1058
+ // centre line**. Whether to draw it as something thick or as a single line (a rail or a fence
1059
+ // that does not enclose) is a judgement about appearance, so the consumer chooses.
1060
+ // The junction takes the axis of the body off the centre line, so the centre line cannot be
1061
+ // recovered from the outline
776
1062
  for (const p of b.material.panels) {
777
1063
  entities.push({
778
1064
  class: spans(p.z0, p.z1, cutZ) ? "cut" : p.z1 < cutZ ? "below" : "above",
779
1065
  of: "boundary",
780
1066
  ref: b.ref,
781
- polygon: thicken(p.x1, p.y1, p.x2, p.y2, b.material.t),
1067
+ polygon: p.footprint,
782
1068
  lines: [{ x1: p.x1, y1: p.y1, x2: p.x2, y2: p.y2 }],
783
1069
  });
784
1070
  }
@@ -127,6 +127,7 @@ export const DIAGNOSTIC_CODES = {
127
127
  VER04: "error", // koyu 0.5以前のファイルに1.0の語 (over・drop・集合編集 — ADR-0035/0038)
128
128
  VER05: "error", // koyu 1.0以前のファイルの型の位置に exterior / void (ADR-0051)
129
129
  VER06: "error", // the file declares a language version newer than this build reads
130
+ VER07: "error", // the file declares a version in which a key it writes is retired (ADR-0061)
130
131
  SYN01: "error", // 構文・合成エラー (SourceError の写し — check --json のみ)
131
132
  } as const satisfies Record<string, "error" | "warning">;
132
133
 
@@ -602,7 +603,7 @@ function checkColumns(ctx: Ctx): void {
602
603
  }
603
604
  }
604
605
 
605
- /** 言語版の受理条件 — VER01〜VER05 */
606
+ /** 言語版の受理条件 — VER01〜VER05 と VER07 (VER06 は parse が投げる) */
606
607
  function checkLanguageVersion(ctx: Ctx): void {
607
608
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
608
609
  // 言語版の受理条件 (ADR-0017): 旧版は意味保存の場合のみ受理する。
@@ -722,6 +723,27 @@ function checkLanguageVersion(ctx: Ctx): void {
722
723
  });
723
724
  }
724
725
  }
726
+
727
+ // A retired key is VER03/VER04 read from the other end. Those fire when a file declares an old
728
+ // version and writes a word that version does not yet have; this one fires when a file declares
729
+ // a new version and writes a word that version no longer has. Both say the same thing — the
730
+ // declared version and the vocabulary have to agree (ADR-0061).
731
+ //
732
+ // **The comparison runs the other way round from the three guards above.** They ask "is this
733
+ // file older than X", so the file's version sits on the left. Here the question is "has the
734
+ // file moved past the version this key was retired after", so the ledger's version sits on the
735
+ // left and the file's on the right.
736
+ for (const [where, subj, at] of attrSubjects(model)) {
737
+ for (const key of Object.keys(subj.of)) {
738
+ const gone = attrSpec(subj.elem, key)?.retired;
739
+ if (!gone || !olderThan(gone.after, model.version)) continue;
740
+ emit(
741
+ "VER07",
742
+ `A muro ${model.version} file carries ${key}: on ${where} — ${key} is retired after muro ${gone.after}. Write ${gone.instead} instead, or keep the file at muro ${gone.after}`,
743
+ at,
744
+ );
745
+ }
746
+ }
725
747
  }
726
748
 
727
749
  /** 同一性 — UID01〜UID04 */
package/src/core/model.ts CHANGED
@@ -43,6 +43,10 @@ export const MURO_SUPPORT: readonly { muro: string; since: string; until: string
43
43
  { muro: "1.1", since: "0.17.0", until: null },
44
44
  // The version line stops answering to the implementation's name: `muro 1.2`, not `koyu 1.2`.
45
45
  { muro: "1.2", since: "0.20.0", until: null },
46
+ // 1.3 adds no notation. It retires `use`, whose job was never a use — it held one grouping per
47
+ // space, so tenancy, fire compartment and department all competed for it. VER07 stops it here;
48
+ // the ledger row stays so that every version up to 1.2 goes on reading it (ADR-0061).
49
+ { muro: "1.3", since: "0.21.0", until: null },
46
50
  ];
47
51
 
48
52
  /** The word a version line is written with from 1.2 on. */
@@ -69,7 +73,7 @@ export const LAST_KOYU_SPELLED_VERSION = "1.1";
69
73
  * `since` column is written in this vocabulary, and every surface that answers "which muro
70
74
  * does this build speak" needs both halves at once.
71
75
  */
72
- export const KOYU_VERSION = "0.20.0";
76
+ export const KOYU_VERSION = "0.22.0";
73
77
 
74
78
  /**
75
79
  * Whether `a` names a later language version than `b`.
@@ -846,17 +850,29 @@ export function isIndoor(model: Model, s: Space): boolean {
846
850
  return !isSemiOutdoor(model, s);
847
851
  }
848
852
 
849
- /** 実効use属性 — 自分に無ければ、最も深いゾーン祖先から継承する */
850
- export function effectiveUse(model: Model, s: Space): string | undefined {
851
- const own = s.attrs["use"];
852
- if (typeof own === "string") return own;
853
- let best: string | undefined;
853
+ /**
854
+ * The value a space carries for `key`: its own declaration, else the one on the deepest zone
855
+ * whose path is a prefix of the space's.
856
+ *
857
+ * **The caller names the key, and core forms no opinion about what it means.** That is what
858
+ * makes this legitimate for a carried namespaced key such as `lease.category`: asking is not
859
+ * reading. Core still gives the key no meaning, decides nothing by it, and would answer the
860
+ * same way for a key it has never seen.
861
+ *
862
+ * The resolution is the one `use` had before it was retired, with the literal `"use"` moved out
863
+ * to the caller. Non-string values resolve too — a space that writes `dept.name:2024` now
864
+ * answers with the number rather than falling through to its zone, which is what was written.
865
+ */
866
+ export function effectiveAttr(model: Model, s: Space, key: string): AttrValue | undefined {
867
+ const own = s.attrs[key];
868
+ if (own !== undefined) return own;
869
+ let best: AttrValue | undefined;
854
870
  let bestLen = -1;
855
871
  for (const z of model.zones.values()) {
856
872
  if (s.path.startsWith(z.path + "/") && z.path.length > bestLen) {
857
- const u = z.attrs["use"];
858
- if (typeof u === "string") {
859
- best = u;
873
+ const v = z.attrs[key];
874
+ if (v !== undefined) {
875
+ best = v;
860
876
  bestLen = z.path.length;
861
877
  }
862
878
  }
@@ -33,6 +33,19 @@ export interface AttrSpec {
33
33
  of?: Array<string | number>;
34
34
  /** 正の数値でなければ ATT01 */
35
35
  num?: true;
36
+ /**
37
+ * The key may be written up to and including muro `after`, and not after it.
38
+ *
39
+ * **A retired key stays in the ledger.** Taking the row out would make the key unknown at
40
+ * every version at once, because `checkAttrValues` reads `attrSpec` alone and never sees
41
+ * `model.version` — a file declaring an older version would start failing with ATT03 for a
42
+ * word that version legitimately has. The row is what keeps the old reading alive; VER07 is
43
+ * what stops the new one.
44
+ *
45
+ * `instead` names what to write from the next version, and is carried here so that no state
46
+ * exists where a key is retired with nothing offered in its place.
47
+ */
48
+ retired?: { after: string; instead: string };
36
49
  }
37
50
 
38
51
  /** 台帳を読みやすく書くための小道具 */
@@ -41,6 +54,10 @@ const one = (...of: Array<string | number>): AttrSpec => ({ tier: "interpreted",
41
54
  const free = (): AttrSpec => ({ tier: "interpreted" });
42
55
  const carry = (): AttrSpec => ({ tier: "carry" });
43
56
  const structure = (): AttrSpec => ({ tier: "structure" });
57
+ const retired = (after: string, instead: string, base: AttrSpec = free()): AttrSpec => ({
58
+ ...base,
59
+ retired: { after, instead },
60
+ });
44
61
 
45
62
  /**
46
63
  * 運搬層の名前空間の綴り — **ドット区切り** (`acme.sensor` `bems.temp` `survey.measured`)。
@@ -86,7 +103,14 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
86
103
 
87
104
  // 解釈 — core が読む
88
105
  h: num(), // 天井高 mm。高さ不変量と矩計が読む
89
- use: free(), // 集計軸。zone から継承
106
+ // Retired after muro 1.2. It was never a use: ADR-0005 introduced it to answer the ratio of
107
+ // common to exclusive area, and it held one grouping per space, so tenancy, fire compartment
108
+ // and department all competed for it. A room's purpose is the type position; any other
109
+ // division of the building is a namespaced key, of which a space may carry as many as it likes.
110
+ use: retired(
111
+ "1.2",
112
+ "a namespaced key of your own (lease.category:, fire.compartment:, dept.name:)",
113
+ ),
90
114
  road: num(), // outside:1 の幅員 mm。接道の導出
91
115
  daylight: free(), // 採光の問いの対象 (ADR-0020)。値域は DAY01 が守るので台帳では重ねない
92
116
  ceiling: one(0, 1), // 0 = 天井を張らない (ADR-0024)
@@ -114,7 +138,11 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
114
138
 
115
139
  zone: {
116
140
  name: free(),
117
- use: free(), // 配下へ継承される集計軸
141
+ // Retired after muro 1.2, for the reason given on the space row above.
142
+ use: retired(
143
+ "1.2",
144
+ "a namespaced key of your own (lease.category:, fire.compartment:, dept.name:)",
145
+ ),
118
146
  site: one(0, 1), // 敷地の集約 (ADR-0009)
119
147
  area: num(), // 敷地の宣言面積 ㎡ (測量値)
120
148
  uid: free(),
package/src/draw/axo.ts CHANGED
@@ -1,16 +1,19 @@
1
- // koyu — 軸測図 (アクソメ) の生成 (ADR-0026)
2
- // 平面図が「そのレベルで切った断面」であるのに対し、これは立体をそのまま投影した図である。
3
- // WebGLも実行環境も要らない — 平面と同じく SVG のテキストが出るので、
4
- // 生成して見る、という同じ手で立体を確かめられる。
1
+ // koyu — the axonometric (ADR-0026)
2
+ // A plan is "the section cut at that level"; this is the solid itself, projected. It needs neither
3
+ // WebGL nor a runtime — the text of an SVG comes out, exactly as it does for a plan, so a solid is
4
+ // checked by the same move: generate it and look.
5
5
  //
6
- // 描くのは**生成物だけ**である。床・屋根、壁 (境界から)、柱 (通りの交点から)、縦動線。
7
- // どれもソースには無く、規則から現れる。
6
+ // **Only what is generated is drawn.** Floors and roofs, walls (from the boundaries), columns
7
+ // (from the grid intersections), vertical circulation. None of it is in the source; all of it
8
+ // appears out of the rules.
8
9
  //
9
- // **ここに形の規則は一つも無い** (ADR-0040)。輪郭も厚みも z 範囲も `derive(model)` が返す
10
- // `Form` に既に入っており、芯線から実体を起こす構成子 (`thicken` / `columnRect` / `runPrism`)
11
- // も core が唯一の実装を持つ。この頁が決めるのは投影・陰影・重ね順・紙面だけである。
10
+ // **There is not one rule of shape here** (ADR-0040). Outlines, thicknesses and z ranges are
11
+ // already in the `Form` that `derive(model)` returns, and the constructors that raise matter from
12
+ // a centre line (`columnRect` / `runPrism`) have their one implementation in core. A wall arrives
13
+ // as a body with its junctions already settled — there is no corner to repair here. What this page
14
+ // decides is the projection, the shading, the stacking order and the page.
12
15
 
13
- import { columnRect, derive, runPrism, thicken } from "../core/derive.js";
16
+ import { columnRect, derive, runPrism } from "../core/derive.js";
14
17
  import { type Model, type Pt } from "../core/model.js";
15
18
 
16
19
  export interface AxoOptions {
@@ -109,9 +112,7 @@ export function svgAxo(model: Model, opts: AxoOptions = {}): string {
109
112
  if (opts.walls !== false) {
110
113
  for (const b of form.boundaries) {
111
114
  if (!b.material || (b.level !== undefined && !names.has(b.level))) continue;
112
- for (const p of b.material.panels) {
113
- add(thicken(p.x1, p.y1, p.x2, p.y2, b.material.t), p.z0, p.z1, C.wall);
114
- }
115
+ for (const p of b.material.panels) add(p.footprint, p.z0, p.z1, C.wall);
115
116
  }
116
117
  }
117
118
 
package/src/mcp.ts CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  areaM2,
28
28
  isIndoor,
29
29
  displayName,
30
- effectiveUse,
30
+ effectiveAttr,
31
31
  isOutside,
32
32
  isSemiOutdoor,
33
33
  isVoid,
@@ -80,7 +80,7 @@ function assertInside(entryDir: string, targetDir: string): void {
80
80
  }
81
81
  }
82
82
 
83
- function summarize(model: Model, file: string): unknown {
83
+ function summarize(model: Model, file: string, by: readonly string[] = []): unknown {
84
84
  const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
85
85
  const indoor = rooms.filter((s) => isIndoor(model, s));
86
86
  const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
@@ -93,10 +93,17 @@ function summarize(model: Model, file: string): unknown {
93
93
  subtotalM2: Math.round(rs.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
94
94
  };
95
95
  }
96
- const byUse: Record<string, number> = {};
97
- for (const s of indoor) {
98
- const u = effectiveUse(model, s) ?? "(unspecified)";
99
- byUse[u] = Math.round(((byUse[u] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
96
+ // One grouping per key the caller asked for, and none at all when it asked for none.
97
+ // A default key would put back the single privileged grouping that `use` was.
98
+ const byM2: Record<string, Record<string, number>> = {};
99
+ for (const key of by) {
100
+ const bucket: Record<string, number> = {};
101
+ for (const s of indoor) {
102
+ const v = effectiveAttr(model, s, key);
103
+ const label = v === undefined ? "(unspecified)" : String(v);
104
+ bucket[label] = Math.round(((bucket[label] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
105
+ }
106
+ byM2[key] = bucket;
100
107
  }
101
108
  const r = check(model);
102
109
  return {
@@ -145,7 +152,7 @@ function summarize(model: Model, file: string): unknown {
145
152
  totalFloorM2: Math.round(indoor.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
146
153
  semiOutdoorM2: Math.round(semi.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
147
154
  floorsM2: byLevel,
148
- byUseM2: byUse,
155
+ ...(by.length > 0 ? { byM2 } : {}),
149
156
  check: { errors: r.errors.length, warnings: r.warnings.length },
150
157
  hint: "Read layer contents with layers, check with check, and edit with write_layer (check is the gatekeeper). Architectural verdicts come from validate.",
151
158
  };
@@ -184,14 +191,35 @@ const str = (v: unknown, name: string): string => {
184
191
  return v;
185
192
  };
186
193
 
194
+ /** An optional array of attribute keys. Absent is not the same as empty, but both group nothing. */
195
+ const keys = (v: unknown, name: string): string[] => {
196
+ if (v === undefined) return [];
197
+ if (!Array.isArray(v) || v.some((k) => typeof k !== "string" || !k)) {
198
+ throw new Error(`${name} (an array of attribute keys) must hold non-empty strings`);
199
+ }
200
+ return v as string[];
201
+ };
202
+
187
203
  const TOOLS: Record<string, Tool> = {
188
204
  model_summary: {
189
205
  description:
190
- "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first",
191
- schema: { type: "object", properties: FILE_PROP, required: ["file"] },
206
+ "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first. Pass by:[\"lease.category\"] to also get floor area grouped by those attribute keys",
207
+ schema: {
208
+ type: "object",
209
+ properties: {
210
+ ...FILE_PROP,
211
+ by: {
212
+ type: "array",
213
+ items: { type: "string" },
214
+ description:
215
+ "Attribute keys to group indoor floor area by, e.g. [\"lease.category\"]. A space's own declaration wins, otherwise the deepest zone above it supplies the value; a space with no value falls into \"(unspecified)\". Omit for no grouping — there is no default key",
216
+ },
217
+ },
218
+ required: ["file"],
219
+ },
192
220
  run: (a) => {
193
221
  const file = str(a.file, "file");
194
- return summarize(load(file), file);
222
+ return summarize(load(file), file, keys(a.by, "by"));
195
223
  },
196
224
  },
197
225
  check: {
package/src/model.ts CHANGED
@@ -30,7 +30,7 @@ export {
30
30
  areaM2,
31
31
  DEFAULT_LANGUAGE_VERSION,
32
32
  displayName,
33
- effectiveUse,
33
+ effectiveAttr,
34
34
  heff,
35
35
  isCoveredAbove,
36
36
  isIndoor,