@kensnzk/koyu 0.26.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 (146) 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/section.d.ts +27 -2
  52. package/dist/core/section.d.ts.map +1 -1
  53. package/dist/core/section.js +63 -11
  54. package/dist/core/section.js.map +1 -1
  55. package/dist/core/vocabulary.d.ts +20 -4
  56. package/dist/core/vocabulary.d.ts.map +1 -1
  57. package/dist/core/vocabulary.js +107 -9
  58. package/dist/core/vocabulary.js.map +1 -1
  59. package/dist/draw/component-files.d.ts +8 -0
  60. package/dist/draw/component-files.d.ts.map +1 -0
  61. package/dist/draw/component-files.js +35 -0
  62. package/dist/draw/component-files.js.map +1 -0
  63. package/dist/draw/component-svg.d.ts +14 -0
  64. package/dist/draw/component-svg.d.ts.map +1 -0
  65. package/dist/draw/component-svg.js +67 -0
  66. package/dist/draw/component-svg.js.map +1 -0
  67. package/dist/draw/conventions/architectural.d.ts +32 -0
  68. package/dist/draw/conventions/architectural.d.ts.map +1 -0
  69. package/dist/draw/conventions/architectural.js +29 -0
  70. package/dist/draw/conventions/architectural.js.map +1 -0
  71. package/dist/draw/index.d.ts +2 -2
  72. package/dist/draw/index.d.ts.map +1 -1
  73. package/dist/draw/index.js +2 -2
  74. package/dist/draw/index.js.map +1 -1
  75. package/dist/draw/marks.d.ts +37 -12
  76. package/dist/draw/marks.d.ts.map +1 -1
  77. package/dist/draw/marks.js +508 -38
  78. package/dist/draw/marks.js.map +1 -1
  79. package/dist/draw/plan.d.ts +3 -1
  80. package/dist/draw/plan.d.ts.map +1 -1
  81. package/dist/draw/plan.js +247 -85
  82. package/dist/draw/plan.js.map +1 -1
  83. package/dist/draw/section.d.ts +20 -2
  84. package/dist/draw/section.d.ts.map +1 -1
  85. package/dist/draw/section.js +43 -10
  86. package/dist/draw/section.js.map +1 -1
  87. package/dist/form.d.ts +2 -2
  88. package/dist/form.d.ts.map +1 -1
  89. package/dist/form.js.map +1 -1
  90. package/dist/index.js +1 -1
  91. package/dist/mcp.js +21 -3
  92. package/dist/mcp.js.map +1 -1
  93. package/dist/parse-file.d.ts +1 -0
  94. package/dist/parse-file.d.ts.map +1 -1
  95. package/dist/parse-file.js +1 -0
  96. package/dist/parse-file.js.map +1 -1
  97. package/dist/validate/builtin/index.d.ts +4 -2
  98. package/dist/validate/builtin/index.d.ts.map +1 -1
  99. package/dist/validate/builtin/index.js +9 -2
  100. package/dist/validate/builtin/index.js.map +1 -1
  101. package/dist/validate/builtin/opening-operations.d.ts +63 -0
  102. package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
  103. package/dist/validate/builtin/opening-operations.js +406 -0
  104. package/dist/validate/builtin/opening-operations.js.map +1 -0
  105. package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
  106. package/examples/basement/main.muro +3 -3
  107. package/examples/complex/L1.muro +1 -1
  108. package/examples/complex/assets.muro +2 -2
  109. package/examples/complex/main.muro +1 -1
  110. package/examples/house/L1.muro +3 -3
  111. package/examples/house/L2.muro +2 -2
  112. package/examples/house/assets.muro +8 -8
  113. package/examples/house/main.muro +1 -1
  114. package/examples/house/site.muro +2 -2
  115. package/examples/house.muro +6 -6
  116. package/examples/mansion.muro +1 -1
  117. package/examples/office.muro +1 -1
  118. package/examples/steps/06-finished.muro +1 -1
  119. package/examples/tower/assets.muro +1 -1
  120. package/examples/tower/main.muro +1 -1
  121. package/examples/twin/assets.muro +2 -2
  122. package/examples/twin/main.muro +1 -1
  123. package/examples/two-rooms.canonical.json +1 -1
  124. package/examples/two-rooms.muro +1 -1
  125. package/package.json +7 -4
  126. package/src/cli.ts +2 -2
  127. package/src/core/components.ts +224 -0
  128. package/src/core/derive.ts +47 -4
  129. package/src/core/diagnose.ts +182 -4
  130. package/src/core/model.ts +10 -5
  131. package/src/core/parse.ts +5 -4
  132. package/src/core/section.ts +107 -8
  133. package/src/core/vocabulary.ts +115 -9
  134. package/src/draw/component-files.ts +36 -0
  135. package/src/draw/component-svg.ts +79 -0
  136. package/src/draw/conventions/architectural.ts +60 -0
  137. package/src/draw/index.ts +9 -2
  138. package/src/draw/marks.ts +564 -44
  139. package/src/draw/plan.ts +253 -88
  140. package/src/draw/section.ts +78 -14
  141. package/src/form.ts +4 -0
  142. package/src/index.ts +1 -1
  143. package/src/mcp.ts +21 -3
  144. package/src/parse-file.ts +1 -0
  145. package/src/validate/builtin/index.ts +14 -2
  146. package/src/validate/builtin/opening-operations.ts +519 -0
package/src/draw/marks.ts CHANGED
@@ -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,13 +13,14 @@
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
- import { band, type Form, type FormOpening, type PlanClass, type PlanEntity } from "../core/derive.js";
20
+ import { band, type Form, type FormOpening, type FormPlan, type FormRun, type PlanClass, type PlanEntity } from "../core/derive.js";
20
21
  import { polyBounds, type Pt } from "../core/model.js";
21
- import type { RunDevice, Seg2 } from "../core/vertical.js";
22
+ import { toPoint, type RunDevice, type RunPart, type Seg2 } from "../core/vertical.js";
23
+ import { ARCHITECTURAL_PLAN_CONVENTION } from "./conventions/architectural.js";
22
24
 
23
25
  /**
24
26
  * A mark's role. The consumer decides stroke weight, colour, dash and every word from it.
@@ -45,16 +47,40 @@ export type MarkRole =
45
47
  | "open"
46
48
  /** the band of a segment that does not count */
47
49
  | "seg"
48
- /** a non-door opening's centreline */
50
+ /** a window opening, carrying the Form polygon whose two long edges continue the wall faces */
49
51
  | "window"
50
52
  /** hinge to leaf tip */
51
53
  | "door-leaf"
52
54
  /** the swing trace */
53
55
  | "door-arc"
54
- /** a sliding door's pocket panel */
56
+ /** a sliding door's closed leaf */
55
57
  | "slide-panel"
56
- /** its setback line */
58
+ /** the short line across the centre of a sliding leaf */
59
+ | "slide-centre"
60
+ /** its travel into the pocket */
57
61
  | "slide-tail"
62
+ /** the direction in which an automatic door opens */
63
+ | "auto-direction"
64
+ /** a general entrance threshold, without a claimed door operation */
65
+ | "entrance"
66
+ /** a gate jamb or post */
67
+ | "gate-post"
68
+ /** a vertically coiling shutter at the opening line */
69
+ | "rolling-shutter"
70
+ /** a sectional door that rises above the opening */
71
+ | "overhead-door"
72
+ /** an operable window leaf */
73
+ | "window-leaf"
74
+ /** an operable window's swing trace */
75
+ | "window-arc"
76
+ /** a sliding or projecting window sash */
77
+ | "window-sash"
78
+ /** the centre mark of a fixed window */
79
+ | "window-fixed"
80
+ /** a curtain-wall mullion at an explicitly divided panel boundary */
81
+ | "curtain-wall-mullion"
82
+ /** the meeting or overlap mark between window sashes */
83
+ | "window-sash-centre"
58
84
  | "column"
59
85
  | "run-outline"
60
86
  | "run-tread"
@@ -78,7 +104,7 @@ export type MarkSubject = "space" | "boundary" | "opening" | "column" | "run" |
78
104
  * belongs to them, not here.
79
105
  */
80
106
  export type MarkNote =
81
- /** direction of travel at an arrow's tail */
107
+ /** direction shown by an arrow; stair presentation always points towards the upper landing */
82
108
  | { of: "direction"; up: boolean }
83
109
  /** a stair's proportions, exactly as `FormRun` carries them */
84
110
  | { of: "stair"; risers: number; riser: number; tread: number; going: number; rise: number }
@@ -92,7 +118,7 @@ export interface Mark {
92
118
  ref: string;
93
119
  /**
94
120
  * The classification `Form` gave the subject, carried through unchanged. Marks with no backing
95
- * entity (`seg`, `void-hatch`, the two sliding marks) carry `"cut"` — they show at the cut.
121
+ * entity (`seg`, `void-hatch`, the sliding marks) carry `"cut"` — they show at the cut.
96
122
  */
97
123
  class: PlanClass;
98
124
  polygon?: Pt[];
@@ -113,16 +139,17 @@ export interface Mark {
113
139
  }
114
140
 
115
141
  /**
116
- * Setback of a sliding door's pocket panel from the wall face, mm.
142
+ * Clear distance from a wall face to a sliding door's panel, mm.
117
143
  *
118
144
  * **A drafting convention, not a derivation default.** It is not in the ledger of derivation
119
- * constants because no shape of the building depends on it; all three implementations spell 110.
145
+ * constants because no shape of the building depends on it. The actual offset from the wall
146
+ * centreline is half the opening's wall thickness plus this gap.
120
147
  */
121
- export const SLIDE_POCKET = 110;
148
+ export const SLIDE_GAP = ARCHITECTURAL_PLAN_CONVENTION.openings.slidingGapMm;
122
149
 
123
150
  export interface MarkOptions {
124
- /** override `SLIDE_POCKET` */
125
- slidePocket?: number;
151
+ /** override `SLIDE_GAP` */
152
+ slideGap?: number;
126
153
  }
127
154
 
128
155
  const unit = (from: Pt, to: Pt, len: number): Pt => ({
@@ -130,21 +157,425 @@ const unit = (from: Pt, to: Pt, len: number): Pt => ({
130
157
  y: (to.y - from.y) / (len || 1),
131
158
  });
132
159
 
133
- /** A sliding or automatic door: no swing trace — a panel set back on the hinge side, and its tail. */
134
- function slideMarks(o: FormOpening, pocket: number, base: Omit<Mark, "role" | "lines">): Mark[] {
160
+ type SymbolBase = Omit<Mark, "role" | "lines" | "arc">;
161
+
162
+ interface OpeningBasis {
163
+ a: Pt;
164
+ u: Pt;
165
+ start: Pt;
166
+ end: Pt;
167
+ }
168
+
169
+ const along = (p: Pt, v: Pt, d: number): Pt => ({ x: p.x + v.x * d, y: p.y + v.y * d });
170
+ const seg = (p: Pt, q: Pt): Seg2 => ({ x1: p.x, y1: p.y, x2: q.x, y2: q.y });
171
+
172
+ function basisOf(o: FormOpening): OpeningBasis | undefined {
135
173
  const sw = o.swing;
136
- if (!sw) return [];
137
- const { hinge } = sw;
138
- const u = unit(hinge, sw.leaf, o.w); // towards the side it opens onto
139
- const a = unit(hinge, sw.jamb, o.w); // along the segment
140
- const s1 = { x: hinge.x - a.x * o.w + u.x * pocket, y: hinge.y - a.y * o.w + u.y * pocket };
141
- const s2 = { x: hinge.x + u.x * pocket, y: hinge.y + u.y * pocket };
174
+ if (!sw) return undefined;
175
+ return {
176
+ a: unit(sw.hinge, sw.jamb, o.w),
177
+ u: unit(sw.hinge, sw.leaf, o.w),
178
+ start: sw.hinge,
179
+ end: sw.jamb,
180
+ };
181
+ }
182
+
183
+ const crossAbout = (centre: Pt, from: Pt, to: Pt): number =>
184
+ (from.x - centre.x) * (to.y - centre.y) - (from.y - centre.y) * (to.x - centre.x);
185
+
186
+ function arcMark(role: "door-arc" | "window-arc", centre: Pt, from: Pt, to: Pt, base: SymbolBase): Mark {
187
+ return {
188
+ ...base,
189
+ role,
190
+ arc: {
191
+ cx: centre.x,
192
+ cy: centre.y,
193
+ r: Math.hypot(from.x - centre.x, from.y - centre.y),
194
+ from,
195
+ to,
196
+ ccw: crossAbout(centre, from, to) > 0,
197
+ },
198
+ };
199
+ }
200
+
201
+ /** One or two leaves hinged at the opening's jambs. */
202
+ function hingedMarks(
203
+ o: FormOpening,
204
+ meeting: number | undefined,
205
+ leafRole: "door-leaf" | "window-leaf",
206
+ arcRole: "door-arc" | "window-arc",
207
+ base: SymbolBase,
208
+ ): Mark[] {
209
+ const b = basisOf(o);
210
+ if (!b) return [];
211
+ if (meeting === undefined) {
212
+ const tip = along(b.start, b.u, o.w);
213
+ return [
214
+ { ...base, role: leafRole, lines: [seg(b.start, tip)] },
215
+ arcMark(arcRole, b.start, tip, b.end, base),
216
+ ];
217
+ }
218
+ const firstWidth = o.w * meeting;
219
+ const secondWidth = o.w - firstWidth;
220
+ const meet = along(b.start, b.a, firstWidth);
221
+ const firstTip = along(b.start, b.u, firstWidth);
222
+ const secondTip = along(b.end, b.u, secondWidth);
223
+ return [
224
+ { ...base, role: leafRole, lines: [seg(b.start, firstTip), seg(b.end, secondTip)] },
225
+ arcMark(arcRole, b.start, firstTip, meet, base),
226
+ arcMark(arcRole, b.end, secondTip, meet, base),
227
+ ];
228
+ }
229
+
230
+ type SlideKind = "single" | "double" | "bypass";
231
+
232
+ /** Sliding leaves, offset from the wall face, with pocket guides where the leaves retract. */
233
+ function slideMarks(o: FormOpening, gap: number, kind: SlideKind, base: SymbolBase): Mark[] {
234
+ const b = basisOf(o);
235
+ if (!b) return [];
236
+ const offset = o.t / 2 + gap;
237
+ const s1 = along(b.start, b.u, offset);
238
+ const s2 = along(b.end, b.u, offset);
239
+ const centre = { x: (s1.x + s2.x) / 2, y: (s1.y + s2.y) / 2 };
240
+ const halfTick = o.t / 2;
241
+ if (kind === "bypass") {
242
+ const overlap = o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.bypassOverlapRatio;
243
+ const other1 = along(b.start, b.u, offset + gap);
244
+ const other2 = along(b.end, b.u, offset + gap);
245
+ const firstEnd = along(s1, b.a, o.w / 2 + overlap);
246
+ const secondStart = along(other1, b.a, o.w / 2 - overlap);
247
+ return [
248
+ { ...base, role: "slide-panel", lines: [seg(s1, firstEnd), seg(secondStart, other2)] },
249
+ { ...base, role: "slide-centre", lines: [seg(centre, along(centre, b.u, gap))] },
250
+ ];
251
+ }
252
+ const panels =
253
+ kind === "double"
254
+ ? [seg(s1, centre), seg(centre, s2)]
255
+ : [seg(s1, s2)];
256
+ const panelCentres =
257
+ kind === "double"
258
+ ? [along(s1, b.a, o.w / 4), along(s1, b.a, (o.w * 3) / 4)]
259
+ : [centre];
260
+ const centreMarks = panelCentres.map((point) =>
261
+ seg(along(point, b.u, -halfTick), along(point, b.u, halfTick))
262
+ );
263
+ const tails =
264
+ kind === "double"
265
+ ? [seg(along(s1, b.a, -o.w / 2), s1), seg(s2, along(s2, b.a, o.w / 2))]
266
+ : [seg(along(s1, b.a, -o.w), s1)];
267
+ return [
268
+ { ...base, role: "slide-panel", lines: panels },
269
+ { ...base, role: "slide-centre", lines: centreMarks },
270
+ { ...base, role: "slide-tail", lines: tails },
271
+ ];
272
+ }
273
+
274
+ function automaticDirectionMarks(o: FormOpening, gap: number, double: boolean, base: SymbolBase): Mark[] {
275
+ const b = basisOf(o);
276
+ if (!b) return [];
277
+ const offset = o.t / 2 + gap;
278
+ const start = along(b.start, b.u, offset);
279
+ 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)];
280
+ const dirs = double ? [-1, 1] : [-1];
281
+ const lines: Seg2[] = [];
282
+ for (const [i, p] of points.entries()) {
283
+ const tip = along(p, b.a, dirs[i]! * o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.automaticDirectionRatio);
284
+ lines.push(seg(along(p, b.u, -o.t / 4), tip), seg(along(p, b.u, o.t / 4), tip));
285
+ }
286
+ return [{ ...base, role: "auto-direction", lines }];
287
+ }
288
+
289
+ /** Automatic leaves park behind fixed sidelights inside the opening; no guide extends into the wall. */
290
+ function automaticDoorMarks(o: FormOpening, gap: number, double: boolean, base: SymbolBase): Mark[] {
291
+ const b = basisOf(o);
292
+ if (!b) return [];
293
+ const offset = o.t / 2 + gap;
294
+ const start = along(b.start, b.u, offset);
295
+ const divisions = double ? [0, 0.25, 0.5, 0.75, 1] : [0, 0.5, 1];
296
+ const points = divisions.map((ratio) => along(start, b.a, o.w * ratio));
297
+ const panels = points.slice(0, -1).map((point, index) => seg(point, points[index + 1]!));
298
+ const halfTick = o.t / 2;
299
+ const ticks = points.slice(1, -1).map((point) =>
300
+ seg(along(point, b.u, -halfTick), along(point, b.u, halfTick))
301
+ );
142
302
  return [
143
- { ...base, role: "slide-panel", lines: [{ x1: s1.x, y1: s1.y, x2: s2.x, y2: s2.y }] },
144
- { ...base, role: "slide-tail", lines: [{ x1: s2.x, y1: s2.y, x2: hinge.x, y2: hinge.y }] },
303
+ { ...base, role: "slide-panel", lines: panels },
304
+ ...(ticks.length > 0 ? [{ ...base, role: "slide-centre" as const, lines: ticks }] : []),
305
+ ...automaticDirectionMarks(o, gap, double, base),
145
306
  ];
146
307
  }
147
308
 
309
+ function entranceMarks(o: FormOpening, base: SymbolBase): Mark[] {
310
+ const b = basisOf(o);
311
+ if (!b) return [];
312
+ const half = o.t / 2;
313
+ return [{
314
+ ...base,
315
+ role: "entrance",
316
+ lines: [
317
+ seg(b.start, b.end),
318
+ seg(along(b.start, b.u, -half), along(b.start, b.u, half)),
319
+ seg(along(b.end, b.u, -half), along(b.end, b.u, half)),
320
+ ],
321
+ }];
322
+ }
323
+
324
+ function verticalDoorMarks(
325
+ o: FormOpening,
326
+ role: "rolling-shutter" | "overhead-door",
327
+ base: SymbolBase,
328
+ ): Mark[] {
329
+ const b = basisOf(o);
330
+ if (!b) return [];
331
+ return [{ ...base, role, lines: [seg(b.start, b.end)] }];
332
+ }
333
+
334
+ function gatePostMarks(o: FormOpening, gap: number, base: SymbolBase): Mark[] {
335
+ const b = basisOf(o);
336
+ if (!b) return [];
337
+ const half = o.t / 2 + gap;
338
+ return [{
339
+ ...base,
340
+ role: "gate-post",
341
+ lines: [
342
+ seg(along(b.start, b.u, -half), along(b.start, b.u, half)),
343
+ seg(along(b.end, b.u, -half), along(b.end, b.u, half)),
344
+ ],
345
+ }];
346
+ }
347
+
348
+ function windowSlideMarks(o: FormOpening, kind: SlideKind, base: SymbolBase): Mark[] {
349
+ const b = basisOf(o);
350
+ if (!b) return [];
351
+ const offset = o.t / 4;
352
+ const nearStart = along(b.start, b.u, offset);
353
+ const nearEnd = along(b.end, b.u, offset);
354
+ const farStart = along(b.start, b.u, -offset);
355
+ const farEnd = along(b.end, b.u, -offset);
356
+ const centre = along(b.start, b.a, o.w / 2);
357
+ if (kind === "bypass") {
358
+ const overlap = o.w * ARCHITECTURAL_PLAN_CONVENTION.openings.bypassOverlapRatio;
359
+ return [
360
+ {
361
+ ...base,
362
+ role: "window-sash",
363
+ lines: [
364
+ seg(nearStart, along(nearStart, b.a, o.w / 2 + overlap)),
365
+ seg(along(farStart, b.a, o.w / 2 - overlap), farEnd),
366
+ ],
367
+ },
368
+ { ...base, role: "window-sash-centre", lines: [seg(along(centre, b.u, -offset), along(centre, b.u, offset))] },
369
+ ];
370
+ }
371
+ const centreNear = along(centre, b.u, offset);
372
+ const panels = kind === "double" ? [seg(nearStart, centreNear), seg(centreNear, nearEnd)] : [seg(nearStart, nearEnd)];
373
+ const sashCentres =
374
+ kind === "double"
375
+ ? [along(nearStart, b.a, o.w / 4), along(nearStart, b.a, (o.w * 3) / 4)]
376
+ : [centreNear];
377
+ const centreMarks = sashCentres.map((point) =>
378
+ seg(along(point, b.u, -o.t / 4), along(point, b.u, o.t / 4))
379
+ );
380
+ const tails =
381
+ kind === "double"
382
+ ? [seg(along(nearStart, b.a, -o.w / 2), nearStart), seg(nearEnd, along(nearEnd, b.a, o.w / 2))]
383
+ : [seg(along(nearStart, b.a, -o.w), nearStart)];
384
+ return [
385
+ { ...base, role: "window-sash", lines: panels },
386
+ { ...base, role: "window-sash-centre", lines: centreMarks },
387
+ { ...base, role: "slide-tail", lines: tails },
388
+ ];
389
+ }
390
+
391
+ function projectingWindowMarks(o: FormOpening, gap: number, base: SymbolBase): Mark[] {
392
+ const b = basisOf(o);
393
+ if (!b) return [];
394
+ const offset = o.t / 2 + gap;
395
+ const p1 = along(b.start, b.u, offset);
396
+ const p2 = along(b.end, b.u, offset);
397
+ return [{ ...base, role: "window-sash", lines: [seg(b.start, p1), seg(p1, p2), seg(p2, b.end)] }];
398
+ }
399
+
400
+ function fixedWindowMarks(o: FormOpening, lines: Seg2[], base: SymbolBase): Mark[] {
401
+ const g = lines[0];
402
+ if (!g) return [];
403
+ const len = Math.hypot(g.x2 - g.x1, g.y2 - g.y1) || 1;
404
+ const n = { x: -(g.y2 - g.y1) / len, y: (g.x2 - g.x1) / len };
405
+ const centre = { x: (g.x1 + g.x2) / 2, y: (g.y1 + g.y2) / 2 };
406
+ return [{
407
+ ...base,
408
+ role: "window-fixed",
409
+ lines: [seg(along(centre, n, -o.t / 2), along(centre, n, o.t / 2))],
410
+ }];
411
+ }
412
+
413
+ function curtainWallMullionMarks(o: FormOpening, base: SymbolBase): Mark[] {
414
+ const panels = o.panels ?? 1;
415
+ if (!Number.isInteger(panels) || panels < 2) return [];
416
+ const length = Math.hypot(o.segment.x2 - o.segment.x1, o.segment.y2 - o.segment.y1);
417
+ if (length <= 0) return [];
418
+ const axis = {
419
+ x: (o.segment.x2 - o.segment.x1) / length,
420
+ y: (o.segment.y2 - o.segment.y1) / length,
421
+ };
422
+ const marks: Mark[] = [];
423
+ for (let i = 1; i < panels; i += 1) {
424
+ const offset = -o.w / 2 + (o.w * i) / panels;
425
+ const cx = o.cx + axis.x * offset;
426
+ const cy = o.cy + axis.y * offset;
427
+ const normal = { x: -axis.y, y: axis.x };
428
+ marks.push({
429
+ ...base,
430
+ role: "curtain-wall-mullion",
431
+ lines: [seg(along({ x: cx, y: cy }, normal, -o.t / 2), along({ x: cx, y: cy }, normal, o.t / 2))],
432
+ });
433
+ }
434
+ return marks;
435
+ }
436
+
437
+ const distance = (a: Pt, b: Pt): number => Math.hypot(a.x - b.x, a.y - b.y);
438
+
439
+ const flightPoint = (run: FormRun, part: RunPart, t: number): Pt =>
440
+ toPoint(run.rect, run.up, t, (part.s0 + part.s1) / 2);
441
+
442
+ const flightRise = (run: FormRun, part: RunPart): Seg2 => {
443
+ const from = flightPoint(run, part, part.reversed ? part.t1 : part.t0);
444
+ const to = flightPoint(run, part, part.reversed ? part.t0 : part.t1);
445
+ return seg(from, to);
446
+ };
447
+
448
+ /**
449
+ * Stair arrows are presentation symbols built on the run parts Form already supplied.
450
+ *
451
+ * The raw plan entity follows travel on the visible face and stays untouched. The paper arrow
452
+ * instead covers the elevation interval visible on that sheet. A return stair remains one path:
453
+ * its two flight segments are joined across the landing.
454
+ */
455
+ function stairArrowPath(run: FormRun, plan: FormPlan, entity: PlanEntity): Seg2[] {
456
+ const raw = entity.lines?.[0];
457
+ if (!raw) return [];
458
+ const flights = run.parts.filter((p) => p.kind === "flight");
459
+ if (flights.length === 0) {
460
+ return entity.anchor?.up === true
461
+ ? [raw]
462
+ : [{ x1: raw.x2, y1: raw.y2, x2: raw.x1, y2: raw.y1 }];
463
+ }
464
+
465
+ const cutZ = Math.min(run.z1, run.z0 + plan.cut);
466
+ const zStart = entity.anchor?.up === true ? run.z0 : cutZ;
467
+ const zEnd = entity.anchor?.up === true ? cutZ : run.z1;
468
+ const out: Seg2[] = [];
469
+ let previous: Pt | undefined;
470
+ let previousPart: RunPart | undefined;
471
+ for (const part of flights) {
472
+ const lo = Math.min(part.z0, part.z1);
473
+ const hi = Math.max(part.z0, part.z1);
474
+ const fromZ = Math.max(zStart, lo);
475
+ const toZ = Math.min(zEnd, hi);
476
+ if (toZ - fromZ < 1e-6 || hi - lo < 1e-6) continue;
477
+ const whole = flightRise(run, part);
478
+ const point = (z: number): Pt => {
479
+ const q = (z - lo) / (hi - lo);
480
+ return { x: whole.x1 + (whole.x2 - whole.x1) * q, y: whole.y1 + (whole.y2 - whole.y1) * q };
481
+ };
482
+ const from = point(fromZ);
483
+ const to = point(toZ);
484
+ if (previous && previousPart && distance(previous, from) > 1) {
485
+ const previousIndex = run.parts.indexOf(previousPart);
486
+ const currentIndex = run.parts.indexOf(part);
487
+ const landing = run.parts
488
+ .slice(previousIndex + 1, currentIndex)
489
+ .find((candidate) => candidate.kind === "landing");
490
+ if (landing?.kind === "landing") {
491
+ const previousLocal = runLocal(run, previous);
492
+ const fromLocal = runLocal(run, from);
493
+ const atT0 = Math.abs(previousLocal.t - landing.t0) <= Math.abs(previousLocal.t - landing.t1);
494
+ const joinT = atT0 ? landing.t0 : landing.t1;
495
+ const farT = atT0 ? landing.t1 : landing.t0;
496
+ const flightWidth = Math.min(previousPart.s1 - previousPart.s0, part.s1 - part.s0);
497
+ const ratio = ARCHITECTURAL_PLAN_CONVENTION.stairs.landingOffsetFlightWidthRatio;
498
+ const offset = Math.min(Math.abs(farT - joinT) * ratio, flightWidth * ratio);
499
+ const insideT = joinT + Math.sign(farT - joinT) * offset;
500
+ const insidePrevious = toPoint(run.rect, run.up, insideT, previousLocal.s);
501
+ const insideNext = toPoint(run.rect, run.up, insideT, fromLocal.s);
502
+ out.push(seg(previous, insidePrevious), seg(insidePrevious, insideNext), seg(insideNext, from));
503
+ } else {
504
+ out.push(seg(previous, from));
505
+ }
506
+ }
507
+ out.push(seg(from, to));
508
+ previous = to;
509
+ previousPart = part;
510
+ }
511
+ return out;
512
+ }
513
+
514
+ function runLocal(run: FormRun, point: Pt): { t: number; s: number } {
515
+ switch (run.up) {
516
+ case "N": return { t: point.y - run.rect.y1, s: point.x - run.rect.x1 };
517
+ case "S": return { t: run.rect.y2 - point.y, s: run.rect.x2 - point.x };
518
+ case "E": return { t: point.x - run.rect.x1, s: run.rect.y2 - point.y };
519
+ case "W": return { t: run.rect.x2 - point.x, s: point.y - run.rect.y1 };
520
+ }
521
+ }
522
+
523
+ function stairCutLine(run: FormRun, cut: number): Seg2 | undefined {
524
+ const cutZ = Math.min(run.z1, run.z0 + cut);
525
+ for (const part of run.parts) {
526
+ if (part.kind !== "flight") continue;
527
+ const lo = Math.min(part.z0, part.z1);
528
+ const hi = Math.max(part.z0, part.z1);
529
+ if (cutZ < lo - 1e-6 || cutZ > hi + 1e-6 || hi - lo < 1e-6) continue;
530
+ const q = (cutZ - part.z0) / (part.z1 - part.z0);
531
+ const t = part.t0 + (part.t1 - part.t0) * q;
532
+ const a = toPoint(run.rect, run.up, t, part.s0);
533
+ const b = toPoint(run.rect, run.up, t, part.s1);
534
+ return { x1: a.x, y1: a.y, x2: b.x, y2: b.y };
535
+ }
536
+ return undefined;
537
+ }
538
+
539
+ function stairTreadAtOrAboveCut(run: FormRun, tread: Seg2, cut: number): boolean {
540
+ const mid = { x: (tread.x1 + tread.x2) / 2, y: (tread.y1 + tread.y2) / 2 };
541
+ const local = runLocal(run, mid);
542
+ const part = run.parts.find((candidate) =>
543
+ candidate.kind === "flight" &&
544
+ local.t >= candidate.t0 - 1 && local.t <= candidate.t1 + 1 &&
545
+ local.s >= candidate.s0 - 1 && local.s <= candidate.s1 + 1,
546
+ );
547
+ if (!part || part.kind !== "flight" || Math.abs(part.t1 - part.t0) < 1e-6) return true;
548
+ const q = (local.t - part.t0) / (part.t1 - part.t0);
549
+ const z = part.z0 + (part.z1 - part.z0) * q;
550
+ return z >= run.z0 + cut - 1e-6;
551
+ }
552
+
553
+ function sameLine(a: Seg2, b: Seg2): boolean {
554
+ const direct = distance({ x: a.x1, y: a.y1 }, { x: b.x1, y: b.y1 }) < 1 &&
555
+ distance({ x: a.x2, y: a.y2 }, { x: b.x2, y: b.y2 }) < 1;
556
+ const reverse = distance({ x: a.x1, y: a.y1 }, { x: b.x2, y: b.y2 }) < 1 &&
557
+ distance({ x: a.x2, y: a.y2 }, { x: b.x1, y: b.y1 }) < 1;
558
+ return direct || reverse;
559
+ }
560
+
561
+ function stairVisibleBoundaryLines(run: FormRun, plan: FormPlan, entity: PlanEntity): Seg2[] {
562
+ const cutZ = Math.min(run.z1, run.z0 + plan.cut);
563
+ const z0 = entity.anchor?.up === true ? run.z0 : cutZ;
564
+ const z1 = entity.anchor?.up === true ? cutZ : run.z1;
565
+ const out: Seg2[] = [];
566
+ for (const part of run.parts) {
567
+ if (part.kind !== "flight") continue;
568
+ for (const [t, z] of [[part.t0, part.z0], [part.t1, part.z1]] as const) {
569
+ if (z < z0 - 1e-6 || z > z1 + 1e-6) continue;
570
+ const a = toPoint(run.rect, run.up, t, part.s0);
571
+ const b = toPoint(run.rect, run.up, t, part.s1);
572
+ const boundary = { x1: a.x, y1: a.y, x2: b.x, y2: b.y };
573
+ if (!out.some((existing) => sameLine(existing, boundary))) out.push(boundary);
574
+ }
575
+ }
576
+ return out;
577
+ }
578
+
148
579
  /**
149
580
  * The marks drawn on one level's plan, from `Form`.
150
581
  *
@@ -155,7 +586,7 @@ function slideMarks(o: FormOpening, pocket: number, base: Omit<Mark, "role" | "l
155
586
  export function planMarks(form: Form, level: string, opts?: MarkOptions): Mark[] {
156
587
  const plan = form.plans.find((p) => p.level === level);
157
588
  if (!plan) return [];
158
- const pocket = opts?.slidePocket ?? SLIDE_POCKET;
589
+ const gap = opts?.slideGap ?? SLIDE_GAP;
159
590
  const marks: Mark[] = [];
160
591
  const S = new Map(form.spaces.map((s) => [s.path, s]));
161
592
  const B = new Map(form.boundaries.map((b) => [b.ref, b]));
@@ -250,17 +681,64 @@ export function planMarks(form: Form, level: string, opts?: MarkOptions): Mark[]
250
681
  pair: { a: o.a, b: o.b },
251
682
  };
252
683
  if (e.class === "swing") {
253
- if (o.sliding) {
254
- marks.push(...slideMarks(o, pocket, { ...base, class: "swing" }));
684
+ const symbolBase = { ...base, class: "swing" as const };
685
+ const style = o.style;
686
+ if (o.kind === "window") {
687
+ if (style === "hinged") marks.push(...hingedMarks(o, undefined, "window-leaf", "window-arc", symbolBase));
688
+ else if (style === "hinged-double") marks.push(...hingedMarks(o, 0.5, "window-leaf", "window-arc", symbolBase));
689
+ else if (style === "sliding") marks.push(...windowSlideMarks(o, "single", symbolBase));
690
+ else if (style === "sliding-double") marks.push(...windowSlideMarks(o, "double", symbolBase));
691
+ else if (style === "sliding-bypass") marks.push(...windowSlideMarks(o, "bypass", symbolBase));
692
+ else if (style === "projecting") marks.push(...projectingWindowMarks(o, gap, symbolBase));
255
693
  continue;
256
694
  }
257
- if (e.lines) marks.push({ ...base, role: "door-leaf", class: "swing", lines: e.lines });
258
- if (e.arc) marks.push({ ...base, role: "door-arc", class: "swing", arc: e.arc });
695
+ if (style === undefined || style === "hinged") marks.push(...hingedMarks(o, undefined, "door-leaf", "door-arc", symbolBase));
696
+ else if (style === "sliding") marks.push(...slideMarks(o, gap, "single", symbolBase));
697
+ else if (style === "sliding-double") marks.push(...slideMarks(o, gap, "double", symbolBase));
698
+ else if (style === "sliding-bypass") marks.push(...slideMarks(o, gap, "bypass", symbolBase));
699
+ else if (style === "auto-single") {
700
+ marks.push(...automaticDoorMarks(o, gap, false, symbolBase));
701
+ } else if (style === "auto" || style === "auto-double") {
702
+ marks.push(...automaticDoorMarks(o, gap, true, symbolBase));
703
+ } else if (style === "entrance") marks.push(...entranceMarks(o, symbolBase));
704
+ else if (style === "rolling-shutter") marks.push(...verticalDoorMarks(o, "rolling-shutter", symbolBase));
705
+ else if (style === "overhead") marks.push(...verticalDoorMarks(o, "overhead-door", symbolBase));
706
+ else if (style === "hinged-double") marks.push(...hingedMarks(o, 0.5, "door-leaf", "door-arc", symbolBase));
707
+ else if (style === "hinged-unequal") marks.push(...hingedMarks(
708
+ o,
709
+ ARCHITECTURAL_PLAN_CONVENTION.openings.unequalLeafMeetingRatio,
710
+ "door-leaf",
711
+ "door-arc",
712
+ symbolBase,
713
+ ));
714
+ else if (style === "gate-hinged") {
715
+ marks.push(...gatePostMarks(o, gap, symbolBase));
716
+ marks.push(...hingedMarks(o, undefined, "door-leaf", "door-arc", symbolBase));
717
+ } else if (style === "gate-hinged-double") {
718
+ marks.push(...gatePostMarks(o, gap, symbolBase));
719
+ marks.push(...hingedMarks(o, 0.5, "door-leaf", "door-arc", symbolBase));
720
+ } else if (style === "gate-sliding") {
721
+ marks.push(...gatePostMarks(o, gap, symbolBase));
722
+ marks.push(...slideMarks(o, gap, "single", symbolBase));
723
+ }
259
724
  continue;
260
725
  }
261
726
  // No class filter, so a clerestory above the cut arrives as a `window` too. `Mark.class` puts
262
727
  // that fact in the consumer's hand instead of hiding it.
263
- if (o.kind !== "door" && e.lines) marks.push({ ...base, role: "window", class: e.class, lines: e.lines });
728
+ if (o.kind !== "door" && e.lines) {
729
+ marks.push({
730
+ ...base,
731
+ role: "window",
732
+ class: e.class,
733
+ lines: e.lines,
734
+ ...(e.polygon ? { polygon: e.polygon } : {}),
735
+ });
736
+ if (o.style === "fixed" && e.class === "cut") {
737
+ marks.push(...fixedWindowMarks(o, e.lines, { ...base, class: "cut" }));
738
+ } else if (o.style === "curtain-wall" && e.class === "cut") {
739
+ marks.push(...curtainWallMullionMarks(o, { ...base, class: "cut" }));
740
+ }
741
+ }
264
742
  }
265
743
 
266
744
  // ---- columns (written nowhere — they appear where grid lines meet a floor) ----
@@ -275,17 +753,59 @@ export function planMarks(form: Form, level: string, opts?: MarkOptions): Mark[]
275
753
  if (e.of !== "run") continue;
276
754
  const base = { of: "run" as const, ref: e.ref };
277
755
  if (e.role === "outline" && e.lines) marks.push({ ...base, role: "run-outline", class: e.class, lines: e.lines });
278
- else if (e.role === "tread" && e.lines) marks.push({ ...base, role: "run-tread", class: e.class, lines: e.lines });
756
+ else if (e.role === "tread" && e.lines) {
757
+ const run = R.get(e.ref);
758
+ const lines = run?.device === "stair" && e.class === "below"
759
+ ? e.lines.filter((tread) => stairTreadAtOrAboveCut(run, tread, plan.cut))
760
+ : e.lines;
761
+ if (lines.length > 0) marks.push({ ...base, role: "run-tread", class: e.class, lines });
762
+ }
279
763
  else if (e.role === "break" && e.lines) marks.push({ ...base, role: "run-break", class: "cut", lines: e.lines });
280
764
  else if (e.role === "arrow" && e.lines) {
281
- marks.push({
282
- ...base,
283
- role: "run-arrow",
284
- class: e.class,
285
- lines: e.lines,
286
- ...(e.anchor ? { at: { x: e.anchor.x, y: e.anchor.y } } : {}),
287
- note: { of: "direction", up: e.anchor?.up === true },
288
- });
765
+ const run = R.get(e.ref);
766
+ // Form keeps the direction of travel on each visible face. On a conventional stair plan the
767
+ // presentation arrow means one thing instead: increasing elevation. The run arriving from
768
+ // below therefore starts on its lower visible part and points into this level. Reverse only
769
+ // stair arrows here; escalators retain their actual operating direction.
770
+ const lines = run?.device === "stair" ? stairArrowPath(run, plan, e) : e.lines;
771
+ if (run?.device === "stair" && lines.length > 0) {
772
+ if (e.class === "below") {
773
+ const cut = stairCutLine(run, plan.cut);
774
+ const existingBreaks = marks
775
+ .filter((mark) => mark.role === "run-break")
776
+ .flatMap((mark) => mark.lines ?? []);
777
+ if (cut && !existingBreaks.some((existing) => sameLine(existing, cut))) {
778
+ marks.push({ ...base, role: "run-break", class: "cut", lines: [cut] });
779
+ }
780
+ }
781
+ const existingTreads = marks
782
+ .filter((mark) => mark.role === "run-tread" && mark.ref === e.ref)
783
+ .flatMap((mark) => mark.lines ?? []);
784
+ const boundaries = stairVisibleBoundaryLines(run, plan, e)
785
+ .filter((boundary) => !existingTreads.some((existing) => sameLine(existing, boundary)));
786
+ if (boundaries.length > 0) {
787
+ marks.push({ ...base, role: "run-tread", class: e.class, lines: boundaries });
788
+ }
789
+ marks.push({
790
+ ...base,
791
+ role: "run-arrow",
792
+ class: e.class,
793
+ lines,
794
+ at: { x: lines[0]!.x1, y: lines[0]!.y1 },
795
+ note: { of: "direction", up: true },
796
+ });
797
+ } else {
798
+ for (const g of lines) {
799
+ marks.push({
800
+ ...base,
801
+ role: "run-arrow",
802
+ class: e.class,
803
+ lines: [g],
804
+ at: { x: g.x1, y: g.y1 },
805
+ note: { of: "direction", up: e.anchor?.up === true },
806
+ });
807
+ }
808
+ }
289
809
  } else if (e.class === "anchor" && e.anchor) {
290
810
  const r = R.get(e.ref);
291
811
  if (!r) continue;