@kensnzk/koyu 0.27.0 → 0.28.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 (136) hide show
  1. package/assets/plan/README.md +18 -0
  2. package/assets/plan/catalog.muro +87 -0
  3. package/assets/plan/library.muro +26 -0
  4. package/assets/plan/svg/bathtub.svg +9 -0
  5. package/assets/plan/svg/bed-double.svg +9 -0
  6. package/assets/plan/svg/bed-single.svg +8 -0
  7. package/assets/plan/svg/cabinet.svg +9 -0
  8. package/assets/plan/svg/chair.svg +8 -0
  9. package/assets/plan/svg/desk.svg +9 -0
  10. package/assets/plan/svg/hedge-2m.svg +7 -0
  11. package/assets/plan/svg/kitchen-sink.svg +10 -0
  12. package/assets/plan/svg/locker.svg +9 -0
  13. package/assets/plan/svg/office-chair.svg +25 -0
  14. package/assets/plan/svg/potted-plant.svg +14 -0
  15. package/assets/plan/svg/refrigerator.svg +10 -0
  16. package/assets/plan/svg/shelf.svg +9 -0
  17. package/assets/plan/svg/shrub-1m.svg +7 -0
  18. package/assets/plan/svg/sofa-2.svg +9 -0
  19. package/assets/plan/svg/sofa-3.svg +9 -0
  20. package/assets/plan/svg/table-rect.svg +7 -0
  21. package/assets/plan/svg/table-round.svg +7 -0
  22. package/assets/plan/svg/tree-3m.svg +8 -0
  23. package/assets/plan/svg/urinal.svg +9 -0
  24. package/assets/plan/svg/washing-machine-pan.svg +13 -0
  25. package/assets/plan/svg/washing-machine.svg +10 -0
  26. package/assets/plan/svg/washstand-500.svg +12 -0
  27. package/assets/plan/svg/washstand.svg +12 -0
  28. package/assets/plan/svg/wc-cabinet.svg +14 -0
  29. package/assets/plan/svg/wc.svg +9 -0
  30. package/dist/cli.js +2 -2
  31. package/dist/cli.js.map +1 -1
  32. package/dist/core/components.d.ts +31 -0
  33. package/dist/core/components.d.ts.map +1 -0
  34. package/dist/core/components.js +167 -0
  35. package/dist/core/components.js.map +1 -0
  36. package/dist/core/derive.d.ts +9 -1
  37. package/dist/core/derive.d.ts.map +1 -1
  38. package/dist/core/derive.js +33 -3
  39. package/dist/core/derive.js.map +1 -1
  40. package/dist/core/diagnose.d.ts +6 -0
  41. package/dist/core/diagnose.d.ts.map +1 -1
  42. package/dist/core/diagnose.js +137 -4
  43. package/dist/core/diagnose.js.map +1 -1
  44. package/dist/core/model.d.ts +5 -5
  45. package/dist/core/model.d.ts.map +1 -1
  46. package/dist/core/model.js +6 -1
  47. package/dist/core/model.js.map +1 -1
  48. package/dist/core/parse.d.ts.map +1 -1
  49. package/dist/core/parse.js +5 -4
  50. package/dist/core/parse.js.map +1 -1
  51. package/dist/core/vocabulary.d.ts +20 -4
  52. package/dist/core/vocabulary.d.ts.map +1 -1
  53. package/dist/core/vocabulary.js +107 -9
  54. package/dist/core/vocabulary.js.map +1 -1
  55. package/dist/draw/component-files.d.ts +8 -0
  56. package/dist/draw/component-files.d.ts.map +1 -0
  57. package/dist/draw/component-files.js +35 -0
  58. package/dist/draw/component-files.js.map +1 -0
  59. package/dist/draw/component-svg.d.ts +14 -0
  60. package/dist/draw/component-svg.d.ts.map +1 -0
  61. package/dist/draw/component-svg.js +67 -0
  62. package/dist/draw/component-svg.js.map +1 -0
  63. package/dist/draw/conventions/architectural.d.ts +32 -0
  64. package/dist/draw/conventions/architectural.d.ts.map +1 -0
  65. package/dist/draw/conventions/architectural.js +29 -0
  66. package/dist/draw/conventions/architectural.js.map +1 -0
  67. package/dist/draw/index.d.ts +1 -1
  68. package/dist/draw/index.d.ts.map +1 -1
  69. package/dist/draw/index.js +1 -1
  70. package/dist/draw/index.js.map +1 -1
  71. package/dist/draw/marks.d.ts +37 -12
  72. package/dist/draw/marks.d.ts.map +1 -1
  73. package/dist/draw/marks.js +508 -38
  74. package/dist/draw/marks.js.map +1 -1
  75. package/dist/draw/plan.d.ts +3 -1
  76. package/dist/draw/plan.d.ts.map +1 -1
  77. package/dist/draw/plan.js +247 -85
  78. package/dist/draw/plan.js.map +1 -1
  79. package/dist/form.d.ts +1 -1
  80. package/dist/form.d.ts.map +1 -1
  81. package/dist/form.js.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/mcp.js +21 -3
  84. package/dist/mcp.js.map +1 -1
  85. package/dist/parse-file.d.ts +1 -0
  86. package/dist/parse-file.d.ts.map +1 -1
  87. package/dist/parse-file.js +1 -0
  88. package/dist/parse-file.js.map +1 -1
  89. package/dist/validate/builtin/index.d.ts +4 -2
  90. package/dist/validate/builtin/index.d.ts.map +1 -1
  91. package/dist/validate/builtin/index.js +9 -2
  92. package/dist/validate/builtin/index.js.map +1 -1
  93. package/dist/validate/builtin/opening-operations.d.ts +63 -0
  94. package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
  95. package/dist/validate/builtin/opening-operations.js +406 -0
  96. package/dist/validate/builtin/opening-operations.js.map +1 -0
  97. package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
  98. package/examples/basement/main.muro +3 -3
  99. package/examples/complex/L1.muro +1 -1
  100. package/examples/complex/assets.muro +2 -2
  101. package/examples/complex/main.muro +1 -1
  102. package/examples/house/L1.muro +3 -3
  103. package/examples/house/L2.muro +2 -2
  104. package/examples/house/assets.muro +8 -8
  105. package/examples/house/main.muro +1 -1
  106. package/examples/house/site.muro +2 -2
  107. package/examples/house.muro +6 -6
  108. package/examples/mansion.muro +1 -1
  109. package/examples/office.muro +1 -1
  110. package/examples/steps/06-finished.muro +1 -1
  111. package/examples/tower/assets.muro +1 -1
  112. package/examples/tower/main.muro +1 -1
  113. package/examples/twin/assets.muro +2 -2
  114. package/examples/twin/main.muro +1 -1
  115. package/examples/two-rooms.canonical.json +1 -1
  116. package/examples/two-rooms.muro +1 -1
  117. package/package.json +7 -4
  118. package/src/cli.ts +2 -2
  119. package/src/core/components.ts +224 -0
  120. package/src/core/derive.ts +47 -4
  121. package/src/core/diagnose.ts +182 -4
  122. package/src/core/model.ts +10 -5
  123. package/src/core/parse.ts +5 -4
  124. package/src/core/vocabulary.ts +115 -9
  125. package/src/draw/component-files.ts +36 -0
  126. package/src/draw/component-svg.ts +79 -0
  127. package/src/draw/conventions/architectural.ts +60 -0
  128. package/src/draw/index.ts +1 -1
  129. package/src/draw/marks.ts +564 -44
  130. package/src/draw/plan.ts +253 -88
  131. package/src/form.ts +1 -0
  132. package/src/index.ts +1 -1
  133. package/src/mcp.ts +21 -3
  134. package/src/parse-file.ts +1 -0
  135. package/src/validate/builtin/index.ts +14 -2
  136. package/src/validate/builtin/opening-operations.ts +519 -0
@@ -1,10 +1,11 @@
1
1
  // koyu — the marks of a plan (`@kensnzk/koyu/draw`)
2
2
  //
3
- // **This copies `Form`'s 2D entities into marks. Not one rule of geometry lives here.** Wall
4
- // thickness, the intervals an opening splits a wall into, a door swing's centre and radius and
5
- // sweep, where a run is cut, the projection of the void above — all of it is already in the `Form`
6
- // that `derive(model)` returns (ADR-0040). What is decided here is *which* of those entities
7
- // becomes a mark and what the mark stands for.
3
+ // **This copies `Form`'s 2D entities into presentation marks.** Wall thickness, the intervals an
4
+ // opening splits a wall into, opening width and direction, where a run is cut and the projection
5
+ // of the void above are already in the `Form` that `derive(model)` returns (ADR-0040). This layer
6
+ // decides which entities become marks and applies drawing-only symbol conventions: the 60mm clear
7
+ // gap of a sliding leaf and the subdivisions named by an explicit multi-leaf style. None of those
8
+ // marks changes building shape, canonical data or the graph.
8
9
  //
9
10
  // **A plan is not a pure section.** Door swings, the projection of the void above, break lines and
10
11
  // the descending run do not fall out of cutting a solid, however exactly it is cut. So `Form` hands
@@ -12,38 +13,406 @@
12
13
  // reads that class rather than re-deciding it.
13
14
  //
14
15
  // **No words and no style.** `Form` carries no colour, no line type and no annotation wording
15
- // (docs/reference/scope.md), and neither does a mark. "UP", "DN", 「上部吹抜け」 and 「12段
16
- // 蹴上180/踏面240」 are the consumer's — three consumers spell three different sets of them today,
16
+ // (docs/reference/scope.md), and neither does a mark. Direction and stair-proportion labels are the
17
+ // consumer's — three consumers spell three different sets of them today,
17
18
  // and a mark that carried one would make koyu's language mix everyone's. A mark carries the seat
18
19
  // (`at`) and the unrounded facts (`note`); the words are put on at the far end.
19
20
  import { band } from "../core/derive.js";
20
21
  import { polyBounds } from "../core/model.js";
22
+ import { toPoint } from "../core/vertical.js";
23
+ import { ARCHITECTURAL_PLAN_CONVENTION } from "./conventions/architectural.js";
21
24
  /**
22
- * Setback of a sliding door's pocket panel from the wall face, mm.
25
+ * Clear distance from a wall face to a sliding door's panel, mm.
23
26
  *
24
27
  * **A drafting convention, not a derivation default.** It is not in the ledger of derivation
25
- * constants because no shape of the building depends on it; all three implementations spell 110.
28
+ * constants because no shape of the building depends on it. The actual offset from the wall
29
+ * centreline is half the opening's wall thickness plus this gap.
26
30
  */
27
- export const SLIDE_POCKET = 110;
31
+ export const SLIDE_GAP = ARCHITECTURAL_PLAN_CONVENTION.openings.slidingGapMm;
28
32
  const unit = (from, to, len) => ({
29
33
  x: (to.x - from.x) / (len || 1),
30
34
  y: (to.y - from.y) / (len || 1),
31
35
  });
32
- /** A sliding or automatic door: no swing trace — a panel set back on the hinge side, and its tail. */
33
- function slideMarks(o, pocket, base) {
36
+ const along = (p, v, d) => ({ x: p.x + v.x * d, y: p.y + v.y * d });
37
+ const seg = (p, q) => ({ x1: p.x, y1: p.y, x2: q.x, y2: q.y });
38
+ function basisOf(o) {
34
39
  const sw = o.swing;
35
40
  if (!sw)
41
+ return undefined;
42
+ return {
43
+ a: unit(sw.hinge, sw.jamb, o.w),
44
+ u: unit(sw.hinge, sw.leaf, o.w),
45
+ start: sw.hinge,
46
+ end: sw.jamb,
47
+ };
48
+ }
49
+ const crossAbout = (centre, from, to) => (from.x - centre.x) * (to.y - centre.y) - (from.y - centre.y) * (to.x - centre.x);
50
+ function arcMark(role, centre, from, to, base) {
51
+ return {
52
+ ...base,
53
+ role,
54
+ arc: {
55
+ cx: centre.x,
56
+ cy: centre.y,
57
+ r: Math.hypot(from.x - centre.x, from.y - centre.y),
58
+ from,
59
+ to,
60
+ ccw: crossAbout(centre, from, to) > 0,
61
+ },
62
+ };
63
+ }
64
+ /** One or two leaves hinged at the opening's jambs. */
65
+ function hingedMarks(o, meeting, leafRole, arcRole, base) {
66
+ const b = basisOf(o);
67
+ if (!b)
68
+ return [];
69
+ if (meeting === undefined) {
70
+ const tip = along(b.start, b.u, o.w);
71
+ return [
72
+ { ...base, role: leafRole, lines: [seg(b.start, tip)] },
73
+ arcMark(arcRole, b.start, tip, b.end, base),
74
+ ];
75
+ }
76
+ const firstWidth = o.w * meeting;
77
+ const secondWidth = o.w - firstWidth;
78
+ const meet = along(b.start, b.a, firstWidth);
79
+ const firstTip = along(b.start, b.u, firstWidth);
80
+ const secondTip = along(b.end, b.u, secondWidth);
81
+ return [
82
+ { ...base, role: leafRole, lines: [seg(b.start, firstTip), seg(b.end, secondTip)] },
83
+ arcMark(arcRole, b.start, firstTip, meet, base),
84
+ arcMark(arcRole, b.end, secondTip, meet, base),
85
+ ];
86
+ }
87
+ /** Sliding leaves, offset from the wall face, with pocket guides where the leaves retract. */
88
+ function slideMarks(o, gap, kind, base) {
89
+ const b = basisOf(o);
90
+ if (!b)
91
+ return [];
92
+ const offset = o.t / 2 + gap;
93
+ const s1 = along(b.start, b.u, offset);
94
+ const s2 = along(b.end, b.u, offset);
95
+ const centre = { x: (s1.x + s2.x) / 2, y: (s1.y + s2.y) / 2 };
96
+ const halfTick = o.t / 2;
97
+ if (kind === "bypass") {
98
+ const overlap = o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.bypassOverlapRatio;
99
+ const other1 = along(b.start, b.u, offset + gap);
100
+ const other2 = along(b.end, b.u, offset + gap);
101
+ const firstEnd = along(s1, b.a, o.w / 2 + overlap);
102
+ const secondStart = along(other1, b.a, o.w / 2 - overlap);
103
+ return [
104
+ { ...base, role: "slide-panel", lines: [seg(s1, firstEnd), seg(secondStart, other2)] },
105
+ { ...base, role: "slide-centre", lines: [seg(centre, along(centre, b.u, gap))] },
106
+ ];
107
+ }
108
+ const panels = kind === "double"
109
+ ? [seg(s1, centre), seg(centre, s2)]
110
+ : [seg(s1, s2)];
111
+ const panelCentres = kind === "double"
112
+ ? [along(s1, b.a, o.w / 4), along(s1, b.a, (o.w * 3) / 4)]
113
+ : [centre];
114
+ const centreMarks = panelCentres.map((point) => seg(along(point, b.u, -halfTick), along(point, b.u, halfTick)));
115
+ const tails = kind === "double"
116
+ ? [seg(along(s1, b.a, -o.w / 2), s1), seg(s2, along(s2, b.a, o.w / 2))]
117
+ : [seg(along(s1, b.a, -o.w), s1)];
118
+ return [
119
+ { ...base, role: "slide-panel", lines: panels },
120
+ { ...base, role: "slide-centre", lines: centreMarks },
121
+ { ...base, role: "slide-tail", lines: tails },
122
+ ];
123
+ }
124
+ function automaticDirectionMarks(o, gap, double, base) {
125
+ const b = basisOf(o);
126
+ if (!b)
127
+ return [];
128
+ const offset = o.t / 2 + gap;
129
+ const start = along(b.start, b.u, offset);
130
+ const points = double ? [along(start, b.a, o.w / 4), along(start, b.a, (o.w * 3) / 4)] : [along(start, b.a, o.w / 2)];
131
+ const dirs = double ? [-1, 1] : [-1];
132
+ const lines = [];
133
+ for (const [i, p] of points.entries()) {
134
+ const tip = along(p, b.a, dirs[i] * o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.automaticDirectionRatio);
135
+ lines.push(seg(along(p, b.u, -o.t / 4), tip), seg(along(p, b.u, o.t / 4), tip));
136
+ }
137
+ return [{ ...base, role: "auto-direction", lines }];
138
+ }
139
+ /** Automatic leaves park behind fixed sidelights inside the opening; no guide extends into the wall. */
140
+ function automaticDoorMarks(o, gap, double, base) {
141
+ const b = basisOf(o);
142
+ if (!b)
143
+ return [];
144
+ const offset = o.t / 2 + gap;
145
+ const start = along(b.start, b.u, offset);
146
+ const divisions = double ? [0, 0.25, 0.5, 0.75, 1] : [0, 0.5, 1];
147
+ const points = divisions.map((ratio) => along(start, b.a, o.w * ratio));
148
+ const panels = points.slice(0, -1).map((point, index) => seg(point, points[index + 1]));
149
+ const halfTick = o.t / 2;
150
+ const ticks = points.slice(1, -1).map((point) => seg(along(point, b.u, -halfTick), along(point, b.u, halfTick)));
151
+ return [
152
+ { ...base, role: "slide-panel", lines: panels },
153
+ ...(ticks.length > 0 ? [{ ...base, role: "slide-centre", lines: ticks }] : []),
154
+ ...automaticDirectionMarks(o, gap, double, base),
155
+ ];
156
+ }
157
+ function entranceMarks(o, base) {
158
+ const b = basisOf(o);
159
+ if (!b)
160
+ return [];
161
+ const half = o.t / 2;
162
+ return [{
163
+ ...base,
164
+ role: "entrance",
165
+ lines: [
166
+ seg(b.start, b.end),
167
+ seg(along(b.start, b.u, -half), along(b.start, b.u, half)),
168
+ seg(along(b.end, b.u, -half), along(b.end, b.u, half)),
169
+ ],
170
+ }];
171
+ }
172
+ function verticalDoorMarks(o, role, base) {
173
+ const b = basisOf(o);
174
+ if (!b)
175
+ return [];
176
+ return [{ ...base, role, lines: [seg(b.start, b.end)] }];
177
+ }
178
+ function gatePostMarks(o, gap, base) {
179
+ const b = basisOf(o);
180
+ if (!b)
181
+ return [];
182
+ const half = o.t / 2 + gap;
183
+ return [{
184
+ ...base,
185
+ role: "gate-post",
186
+ lines: [
187
+ seg(along(b.start, b.u, -half), along(b.start, b.u, half)),
188
+ seg(along(b.end, b.u, -half), along(b.end, b.u, half)),
189
+ ],
190
+ }];
191
+ }
192
+ function windowSlideMarks(o, kind, base) {
193
+ const b = basisOf(o);
194
+ if (!b)
36
195
  return [];
37
- const { hinge } = sw;
38
- const u = unit(hinge, sw.leaf, o.w); // towards the side it opens onto
39
- const a = unit(hinge, sw.jamb, o.w); // along the segment
40
- const s1 = { x: hinge.x - a.x * o.w + u.x * pocket, y: hinge.y - a.y * o.w + u.y * pocket };
41
- const s2 = { x: hinge.x + u.x * pocket, y: hinge.y + u.y * pocket };
196
+ const offset = o.t / 4;
197
+ const nearStart = along(b.start, b.u, offset);
198
+ const nearEnd = along(b.end, b.u, offset);
199
+ const farStart = along(b.start, b.u, -offset);
200
+ const farEnd = along(b.end, b.u, -offset);
201
+ const centre = along(b.start, b.a, o.w / 2);
202
+ if (kind === "bypass") {
203
+ const overlap = o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.bypassOverlapRatio;
204
+ return [
205
+ {
206
+ ...base,
207
+ role: "window-sash",
208
+ lines: [
209
+ seg(nearStart, along(nearStart, b.a, o.w / 2 + overlap)),
210
+ seg(along(farStart, b.a, o.w / 2 - overlap), farEnd),
211
+ ],
212
+ },
213
+ { ...base, role: "window-sash-centre", lines: [seg(along(centre, b.u, -offset), along(centre, b.u, offset))] },
214
+ ];
215
+ }
216
+ const centreNear = along(centre, b.u, offset);
217
+ const panels = kind === "double" ? [seg(nearStart, centreNear), seg(centreNear, nearEnd)] : [seg(nearStart, nearEnd)];
218
+ const sashCentres = kind === "double"
219
+ ? [along(nearStart, b.a, o.w / 4), along(nearStart, b.a, (o.w * 3) / 4)]
220
+ : [centreNear];
221
+ const centreMarks = sashCentres.map((point) => seg(along(point, b.u, -o.t / 4), along(point, b.u, o.t / 4)));
222
+ const tails = kind === "double"
223
+ ? [seg(along(nearStart, b.a, -o.w / 2), nearStart), seg(nearEnd, along(nearEnd, b.a, o.w / 2))]
224
+ : [seg(along(nearStart, b.a, -o.w), nearStart)];
42
225
  return [
43
- { ...base, role: "slide-panel", lines: [{ x1: s1.x, y1: s1.y, x2: s2.x, y2: s2.y }] },
44
- { ...base, role: "slide-tail", lines: [{ x1: s2.x, y1: s2.y, x2: hinge.x, y2: hinge.y }] },
226
+ { ...base, role: "window-sash", lines: panels },
227
+ { ...base, role: "window-sash-centre", lines: centreMarks },
228
+ { ...base, role: "slide-tail", lines: tails },
45
229
  ];
46
230
  }
231
+ function projectingWindowMarks(o, gap, base) {
232
+ const b = basisOf(o);
233
+ if (!b)
234
+ return [];
235
+ const offset = o.t / 2 + gap;
236
+ const p1 = along(b.start, b.u, offset);
237
+ const p2 = along(b.end, b.u, offset);
238
+ return [{ ...base, role: "window-sash", lines: [seg(b.start, p1), seg(p1, p2), seg(p2, b.end)] }];
239
+ }
240
+ function fixedWindowMarks(o, lines, base) {
241
+ const g = lines[0];
242
+ if (!g)
243
+ return [];
244
+ const len = Math.hypot(g.x2 - g.x1, g.y2 - g.y1) || 1;
245
+ const n = { x: -(g.y2 - g.y1) / len, y: (g.x2 - g.x1) / len };
246
+ const centre = { x: (g.x1 + g.x2) / 2, y: (g.y1 + g.y2) / 2 };
247
+ return [{
248
+ ...base,
249
+ role: "window-fixed",
250
+ lines: [seg(along(centre, n, -o.t / 2), along(centre, n, o.t / 2))],
251
+ }];
252
+ }
253
+ function curtainWallMullionMarks(o, base) {
254
+ const panels = o.panels ?? 1;
255
+ if (!Number.isInteger(panels) || panels < 2)
256
+ return [];
257
+ const length = Math.hypot(o.segment.x2 - o.segment.x1, o.segment.y2 - o.segment.y1);
258
+ if (length <= 0)
259
+ return [];
260
+ const axis = {
261
+ x: (o.segment.x2 - o.segment.x1) / length,
262
+ y: (o.segment.y2 - o.segment.y1) / length,
263
+ };
264
+ const marks = [];
265
+ for (let i = 1; i < panels; i += 1) {
266
+ const offset = -o.w / 2 + (o.w * i) / panels;
267
+ const cx = o.cx + axis.x * offset;
268
+ const cy = o.cy + axis.y * offset;
269
+ const normal = { x: -axis.y, y: axis.x };
270
+ marks.push({
271
+ ...base,
272
+ role: "curtain-wall-mullion",
273
+ lines: [seg(along({ x: cx, y: cy }, normal, -o.t / 2), along({ x: cx, y: cy }, normal, o.t / 2))],
274
+ });
275
+ }
276
+ return marks;
277
+ }
278
+ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
279
+ const flightPoint = (run, part, t) => toPoint(run.rect, run.up, t, (part.s0 + part.s1) / 2);
280
+ const flightRise = (run, part) => {
281
+ const from = flightPoint(run, part, part.reversed ? part.t1 : part.t0);
282
+ const to = flightPoint(run, part, part.reversed ? part.t0 : part.t1);
283
+ return seg(from, to);
284
+ };
285
+ /**
286
+ * Stair arrows are presentation symbols built on the run parts Form already supplied.
287
+ *
288
+ * The raw plan entity follows travel on the visible face and stays untouched. The paper arrow
289
+ * instead covers the elevation interval visible on that sheet. A return stair remains one path:
290
+ * its two flight segments are joined across the landing.
291
+ */
292
+ function stairArrowPath(run, plan, entity) {
293
+ const raw = entity.lines?.[0];
294
+ if (!raw)
295
+ return [];
296
+ const flights = run.parts.filter((p) => p.kind === "flight");
297
+ if (flights.length === 0) {
298
+ return entity.anchor?.up === true
299
+ ? [raw]
300
+ : [{ x1: raw.x2, y1: raw.y2, x2: raw.x1, y2: raw.y1 }];
301
+ }
302
+ const cutZ = Math.min(run.z1, run.z0 + plan.cut);
303
+ const zStart = entity.anchor?.up === true ? run.z0 : cutZ;
304
+ const zEnd = entity.anchor?.up === true ? cutZ : run.z1;
305
+ const out = [];
306
+ let previous;
307
+ let previousPart;
308
+ for (const part of flights) {
309
+ const lo = Math.min(part.z0, part.z1);
310
+ const hi = Math.max(part.z0, part.z1);
311
+ const fromZ = Math.max(zStart, lo);
312
+ const toZ = Math.min(zEnd, hi);
313
+ if (toZ - fromZ < 1e-6 || hi - lo < 1e-6)
314
+ continue;
315
+ const whole = flightRise(run, part);
316
+ const point = (z) => {
317
+ const q = (z - lo) / (hi - lo);
318
+ return { x: whole.x1 + (whole.x2 - whole.x1) * q, y: whole.y1 + (whole.y2 - whole.y1) * q };
319
+ };
320
+ const from = point(fromZ);
321
+ const to = point(toZ);
322
+ if (previous && previousPart && distance(previous, from) > 1) {
323
+ const previousIndex = run.parts.indexOf(previousPart);
324
+ const currentIndex = run.parts.indexOf(part);
325
+ const landing = run.parts
326
+ .slice(previousIndex + 1, currentIndex)
327
+ .find((candidate) => candidate.kind === "landing");
328
+ if (landing?.kind === "landing") {
329
+ const previousLocal = runLocal(run, previous);
330
+ const fromLocal = runLocal(run, from);
331
+ const atT0 = Math.abs(previousLocal.t - landing.t0) <= Math.abs(previousLocal.t - landing.t1);
332
+ const joinT = atT0 ? landing.t0 : landing.t1;
333
+ const farT = atT0 ? landing.t1 : landing.t0;
334
+ const flightWidth = Math.min(previousPart.s1 - previousPart.s0, part.s1 - part.s0);
335
+ const ratio = ARCHITECTURAL_PLAN_CONVENTION.stairs.landingOffsetFlightWidthRatio;
336
+ const offset = Math.min(Math.abs(farT - joinT) * ratio, flightWidth * ratio);
337
+ const insideT = joinT + Math.sign(farT - joinT) * offset;
338
+ const insidePrevious = toPoint(run.rect, run.up, insideT, previousLocal.s);
339
+ const insideNext = toPoint(run.rect, run.up, insideT, fromLocal.s);
340
+ out.push(seg(previous, insidePrevious), seg(insidePrevious, insideNext), seg(insideNext, from));
341
+ }
342
+ else {
343
+ out.push(seg(previous, from));
344
+ }
345
+ }
346
+ out.push(seg(from, to));
347
+ previous = to;
348
+ previousPart = part;
349
+ }
350
+ return out;
351
+ }
352
+ function runLocal(run, point) {
353
+ switch (run.up) {
354
+ case "N": return { t: point.y - run.rect.y1, s: point.x - run.rect.x1 };
355
+ case "S": return { t: run.rect.y2 - point.y, s: run.rect.x2 - point.x };
356
+ case "E": return { t: point.x - run.rect.x1, s: run.rect.y2 - point.y };
357
+ case "W": return { t: run.rect.x2 - point.x, s: point.y - run.rect.y1 };
358
+ }
359
+ }
360
+ function stairCutLine(run, cut) {
361
+ const cutZ = Math.min(run.z1, run.z0 + cut);
362
+ for (const part of run.parts) {
363
+ if (part.kind !== "flight")
364
+ continue;
365
+ const lo = Math.min(part.z0, part.z1);
366
+ const hi = Math.max(part.z0, part.z1);
367
+ if (cutZ < lo - 1e-6 || cutZ > hi + 1e-6 || hi - lo < 1e-6)
368
+ continue;
369
+ const q = (cutZ - part.z0) / (part.z1 - part.z0);
370
+ const t = part.t0 + (part.t1 - part.t0) * q;
371
+ const a = toPoint(run.rect, run.up, t, part.s0);
372
+ const b = toPoint(run.rect, run.up, t, part.s1);
373
+ return { x1: a.x, y1: a.y, x2: b.x, y2: b.y };
374
+ }
375
+ return undefined;
376
+ }
377
+ function stairTreadAtOrAboveCut(run, tread, cut) {
378
+ const mid = { x: (tread.x1 + tread.x2) / 2, y: (tread.y1 + tread.y2) / 2 };
379
+ const local = runLocal(run, mid);
380
+ const part = run.parts.find((candidate) => candidate.kind === "flight" &&
381
+ local.t >= candidate.t0 - 1 && local.t <= candidate.t1 + 1 &&
382
+ local.s >= candidate.s0 - 1 && local.s <= candidate.s1 + 1);
383
+ if (!part || part.kind !== "flight" || Math.abs(part.t1 - part.t0) < 1e-6)
384
+ return true;
385
+ const q = (local.t - part.t0) / (part.t1 - part.t0);
386
+ const z = part.z0 + (part.z1 - part.z0) * q;
387
+ return z >= run.z0 + cut - 1e-6;
388
+ }
389
+ function sameLine(a, b) {
390
+ const direct = distance({ x: a.x1, y: a.y1 }, { x: b.x1, y: b.y1 }) < 1 &&
391
+ distance({ x: a.x2, y: a.y2 }, { x: b.x2, y: b.y2 }) < 1;
392
+ const reverse = distance({ x: a.x1, y: a.y1 }, { x: b.x2, y: b.y2 }) < 1 &&
393
+ distance({ x: a.x2, y: a.y2 }, { x: b.x1, y: b.y1 }) < 1;
394
+ return direct || reverse;
395
+ }
396
+ function stairVisibleBoundaryLines(run, plan, entity) {
397
+ const cutZ = Math.min(run.z1, run.z0 + plan.cut);
398
+ const z0 = entity.anchor?.up === true ? run.z0 : cutZ;
399
+ const z1 = entity.anchor?.up === true ? cutZ : run.z1;
400
+ const out = [];
401
+ for (const part of run.parts) {
402
+ if (part.kind !== "flight")
403
+ continue;
404
+ for (const [t, z] of [[part.t0, part.z0], [part.t1, part.z1]]) {
405
+ if (z < z0 - 1e-6 || z > z1 + 1e-6)
406
+ continue;
407
+ const a = toPoint(run.rect, run.up, t, part.s0);
408
+ const b = toPoint(run.rect, run.up, t, part.s1);
409
+ const boundary = { x1: a.x, y1: a.y, x2: b.x, y2: b.y };
410
+ if (!out.some((existing) => sameLine(existing, boundary)))
411
+ out.push(boundary);
412
+ }
413
+ }
414
+ return out;
415
+ }
47
416
  /**
48
417
  * The marks drawn on one level's plan, from `Form`.
49
418
  *
@@ -55,7 +424,7 @@ export function planMarks(form, level, opts) {
55
424
  const plan = form.plans.find((p) => p.level === level);
56
425
  if (!plan)
57
426
  return [];
58
- const pocket = opts?.slidePocket ?? SLIDE_POCKET;
427
+ const gap = opts?.slideGap ?? SLIDE_GAP;
59
428
  const marks = [];
60
429
  const S = new Map(form.spaces.map((s) => [s.path, s]));
61
430
  const B = new Map(form.boundaries.map((b) => [b.ref, b]));
@@ -154,20 +523,78 @@ export function planMarks(form, level, opts) {
154
523
  pair: { a: o.a, b: o.b },
155
524
  };
156
525
  if (e.class === "swing") {
157
- if (o.sliding) {
158
- marks.push(...slideMarks(o, pocket, { ...base, class: "swing" }));
526
+ const symbolBase = { ...base, class: "swing" };
527
+ const style = o.style;
528
+ if (o.kind === "window") {
529
+ if (style === "hinged")
530
+ marks.push(...hingedMarks(o, undefined, "window-leaf", "window-arc", symbolBase));
531
+ else if (style === "hinged-double")
532
+ marks.push(...hingedMarks(o, 0.5, "window-leaf", "window-arc", symbolBase));
533
+ else if (style === "sliding")
534
+ marks.push(...windowSlideMarks(o, "single", symbolBase));
535
+ else if (style === "sliding-double")
536
+ marks.push(...windowSlideMarks(o, "double", symbolBase));
537
+ else if (style === "sliding-bypass")
538
+ marks.push(...windowSlideMarks(o, "bypass", symbolBase));
539
+ else if (style === "projecting")
540
+ marks.push(...projectingWindowMarks(o, gap, symbolBase));
159
541
  continue;
160
542
  }
161
- if (e.lines)
162
- marks.push({ ...base, role: "door-leaf", class: "swing", lines: e.lines });
163
- if (e.arc)
164
- marks.push({ ...base, role: "door-arc", class: "swing", arc: e.arc });
543
+ if (style === undefined || style === "hinged")
544
+ marks.push(...hingedMarks(o, undefined, "door-leaf", "door-arc", symbolBase));
545
+ else if (style === "sliding")
546
+ marks.push(...slideMarks(o, gap, "single", symbolBase));
547
+ else if (style === "sliding-double")
548
+ marks.push(...slideMarks(o, gap, "double", symbolBase));
549
+ else if (style === "sliding-bypass")
550
+ marks.push(...slideMarks(o, gap, "bypass", symbolBase));
551
+ else if (style === "auto-single") {
552
+ marks.push(...automaticDoorMarks(o, gap, false, symbolBase));
553
+ }
554
+ else if (style === "auto" || style === "auto-double") {
555
+ marks.push(...automaticDoorMarks(o, gap, true, symbolBase));
556
+ }
557
+ else if (style === "entrance")
558
+ marks.push(...entranceMarks(o, symbolBase));
559
+ else if (style === "rolling-shutter")
560
+ marks.push(...verticalDoorMarks(o, "rolling-shutter", symbolBase));
561
+ else if (style === "overhead")
562
+ marks.push(...verticalDoorMarks(o, "overhead-door", symbolBase));
563
+ else if (style === "hinged-double")
564
+ marks.push(...hingedMarks(o, 0.5, "door-leaf", "door-arc", symbolBase));
565
+ else if (style === "hinged-unequal")
566
+ marks.push(...hingedMarks(o, ARCHITECTURAL_PLAN_CONVENTION.openings.unequalLeafMeetingRatio, "door-leaf", "door-arc", symbolBase));
567
+ else if (style === "gate-hinged") {
568
+ marks.push(...gatePostMarks(o, gap, symbolBase));
569
+ marks.push(...hingedMarks(o, undefined, "door-leaf", "door-arc", symbolBase));
570
+ }
571
+ else if (style === "gate-hinged-double") {
572
+ marks.push(...gatePostMarks(o, gap, symbolBase));
573
+ marks.push(...hingedMarks(o, 0.5, "door-leaf", "door-arc", symbolBase));
574
+ }
575
+ else if (style === "gate-sliding") {
576
+ marks.push(...gatePostMarks(o, gap, symbolBase));
577
+ marks.push(...slideMarks(o, gap, "single", symbolBase));
578
+ }
165
579
  continue;
166
580
  }
167
581
  // No class filter, so a clerestory above the cut arrives as a `window` too. `Mark.class` puts
168
582
  // that fact in the consumer's hand instead of hiding it.
169
- if (o.kind !== "door" && e.lines)
170
- marks.push({ ...base, role: "window", class: e.class, lines: e.lines });
583
+ if (o.kind !== "door" && e.lines) {
584
+ marks.push({
585
+ ...base,
586
+ role: "window",
587
+ class: e.class,
588
+ lines: e.lines,
589
+ ...(e.polygon ? { polygon: e.polygon } : {}),
590
+ });
591
+ if (o.style === "fixed" && e.class === "cut") {
592
+ marks.push(...fixedWindowMarks(o, e.lines, { ...base, class: "cut" }));
593
+ }
594
+ else if (o.style === "curtain-wall" && e.class === "cut") {
595
+ marks.push(...curtainWallMullionMarks(o, { ...base, class: "cut" }));
596
+ }
597
+ }
171
598
  }
172
599
  // ---- columns (written nowhere — they appear where grid lines meet a floor) ----
173
600
  for (const e of plan.entities) {
@@ -182,19 +609,62 @@ export function planMarks(form, level, opts) {
182
609
  const base = { of: "run", ref: e.ref };
183
610
  if (e.role === "outline" && e.lines)
184
611
  marks.push({ ...base, role: "run-outline", class: e.class, lines: e.lines });
185
- else if (e.role === "tread" && e.lines)
186
- marks.push({ ...base, role: "run-tread", class: e.class, lines: e.lines });
612
+ else if (e.role === "tread" && e.lines) {
613
+ const run = R.get(e.ref);
614
+ const lines = run?.device === "stair" && e.class === "below"
615
+ ? e.lines.filter((tread) => stairTreadAtOrAboveCut(run, tread, plan.cut))
616
+ : e.lines;
617
+ if (lines.length > 0)
618
+ marks.push({ ...base, role: "run-tread", class: e.class, lines });
619
+ }
187
620
  else if (e.role === "break" && e.lines)
188
621
  marks.push({ ...base, role: "run-break", class: "cut", lines: e.lines });
189
622
  else if (e.role === "arrow" && e.lines) {
190
- marks.push({
191
- ...base,
192
- role: "run-arrow",
193
- class: e.class,
194
- lines: e.lines,
195
- ...(e.anchor ? { at: { x: e.anchor.x, y: e.anchor.y } } : {}),
196
- note: { of: "direction", up: e.anchor?.up === true },
197
- });
623
+ const run = R.get(e.ref);
624
+ // Form keeps the direction of travel on each visible face. On a conventional stair plan the
625
+ // presentation arrow means one thing instead: increasing elevation. The run arriving from
626
+ // below therefore starts on its lower visible part and points into this level. Reverse only
627
+ // stair arrows here; escalators retain their actual operating direction.
628
+ const lines = run?.device === "stair" ? stairArrowPath(run, plan, e) : e.lines;
629
+ if (run?.device === "stair" && lines.length > 0) {
630
+ if (e.class === "below") {
631
+ const cut = stairCutLine(run, plan.cut);
632
+ const existingBreaks = marks
633
+ .filter((mark) => mark.role === "run-break")
634
+ .flatMap((mark) => mark.lines ?? []);
635
+ if (cut && !existingBreaks.some((existing) => sameLine(existing, cut))) {
636
+ marks.push({ ...base, role: "run-break", class: "cut", lines: [cut] });
637
+ }
638
+ }
639
+ const existingTreads = marks
640
+ .filter((mark) => mark.role === "run-tread" && mark.ref === e.ref)
641
+ .flatMap((mark) => mark.lines ?? []);
642
+ const boundaries = stairVisibleBoundaryLines(run, plan, e)
643
+ .filter((boundary) => !existingTreads.some((existing) => sameLine(existing, boundary)));
644
+ if (boundaries.length > 0) {
645
+ marks.push({ ...base, role: "run-tread", class: e.class, lines: boundaries });
646
+ }
647
+ marks.push({
648
+ ...base,
649
+ role: "run-arrow",
650
+ class: e.class,
651
+ lines,
652
+ at: { x: lines[0].x1, y: lines[0].y1 },
653
+ note: { of: "direction", up: true },
654
+ });
655
+ }
656
+ else {
657
+ for (const g of lines) {
658
+ marks.push({
659
+ ...base,
660
+ role: "run-arrow",
661
+ class: e.class,
662
+ lines: [g],
663
+ at: { x: g.x1, y: g.y1 },
664
+ note: { of: "direction", up: e.anchor?.up === true },
665
+ });
666
+ }
667
+ }
198
668
  }
199
669
  else if (e.class === "anchor" && e.anchor) {
200
670
  const r = R.get(e.ref);