@kensnzk/koyu 0.22.0 → 0.24.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.
- package/dist/cli.js +51 -2
- package/dist/cli.js.map +1 -1
- package/dist/core/bodies.d.ts +26 -0
- package/dist/core/bodies.d.ts.map +1 -0
- package/dist/core/bodies.js +67 -0
- package/dist/core/bodies.js.map +1 -0
- package/dist/core/model.d.ts +20 -1
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +27 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +11 -13
- package/dist/core/parse.js.map +1 -1
- package/dist/core/poly.d.ts +35 -0
- package/dist/core/poly.d.ts.map +1 -1
- package/dist/core/poly.js +67 -0
- package/dist/core/poly.js.map +1 -1
- package/dist/core/section.d.ts +88 -0
- package/dist/core/section.d.ts.map +1 -0
- package/dist/core/section.js +247 -0
- package/dist/core/section.js.map +1 -0
- package/dist/draw/axo.d.ts.map +1 -1
- package/dist/draw/axo.js +13 -31
- package/dist/draw/axo.js.map +1 -1
- package/dist/draw/index.d.ts +4 -0
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js +4 -0
- package/dist/draw/index.js.map +1 -1
- package/dist/draw/marks.d.ts +126 -0
- package/dist/draw/marks.d.ts.map +1 -0
- package/dist/draw/marks.js +227 -0
- package/dist/draw/marks.js.map +1 -0
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +117 -133
- package/dist/draw/plan.js.map +1 -1
- package/dist/draw/scene.d.ts +133 -0
- package/dist/draw/scene.d.ts.map +1 -0
- package/dist/draw/scene.js +251 -0
- package/dist/draw/scene.js.map +1 -0
- package/dist/draw/section.d.ts +23 -0
- package/dist/draw/section.d.ts.map +1 -0
- package/dist/draw/section.js +168 -0
- package/dist/draw/section.js.map +1 -0
- package/dist/draw/sheet.d.ts +40 -0
- package/dist/draw/sheet.d.ts.map +1 -0
- package/dist/draw/sheet.js +93 -0
- package/dist/draw/sheet.js.map +1 -0
- package/dist/draw/written.d.ts +27 -0
- package/dist/draw/written.d.ts.map +1 -0
- package/dist/draw/written.js +50 -0
- package/dist/draw/written.js.map +1 -0
- package/dist/form.d.ts +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +4 -0
- package/dist/form.js.map +1 -1
- package/dist/mcp.js +67 -3
- package/dist/mcp.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +57 -1
- package/src/core/bodies.ts +90 -0
- package/src/core/model.ts +32 -1
- package/src/core/parse.ts +13 -12
- package/src/core/poly.ts +76 -0
- package/src/core/section.ts +311 -0
- package/src/draw/axo.ts +13 -29
- package/src/draw/index.ts +24 -0
- package/src/draw/marks.ts +315 -0
- package/src/draw/plan.ts +111 -130
- package/src/draw/scene.ts +389 -0
- package/src/draw/section.ts +224 -0
- package/src/draw/sheet.ts +102 -0
- package/src/draw/written.ts +64 -0
- package/src/form.ts +18 -0
- package/src/mcp.ts +75 -2
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// koyu — the marks of a plan (`@kensnzk/koyu/draw`)
|
|
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.
|
|
8
|
+
//
|
|
9
|
+
// **A plan is not a pure section.** Door swings, the projection of the void above, break lines and
|
|
10
|
+
// the descending run do not fall out of cutting a solid, however exactly it is cut. So `Form` hands
|
|
11
|
+
// the plan over as entities carrying a class (cut / below / above / swing / anchor), and this page
|
|
12
|
+
// reads that class rather than re-deciding it.
|
|
13
|
+
//
|
|
14
|
+
// **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,
|
|
17
|
+
// and a mark that carried one would make koyu's language mix everyone's. A mark carries the seat
|
|
18
|
+
// (`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 { polyBounds, type Pt } from "../core/model.js";
|
|
21
|
+
import type { RunDevice, Seg2 } from "../core/vertical.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A mark's role. The consumer decides stroke weight, colour, dash and every word from it.
|
|
25
|
+
*
|
|
26
|
+
* **Closed, and meant to be.** A consumer that spells `Record<MarkRole, …>` stops compiling when
|
|
27
|
+
* koyu adds one, which is the point — the alternative is a mark that silently never appears.
|
|
28
|
+
*/
|
|
29
|
+
export type MarkRole =
|
|
30
|
+
/** a space's face, cut by the plane */
|
|
31
|
+
| "space"
|
|
32
|
+
/** the same, where the space is declared semi-outdoor */
|
|
33
|
+
| "space-semi-outdoor"
|
|
34
|
+
/** a void's face — no floor, so no room */
|
|
35
|
+
| "space-void"
|
|
36
|
+
/** the void's two bounding-box diagonals (a drafting convention, not a shape of the building) */
|
|
37
|
+
| "void-hatch"
|
|
38
|
+
/** the body of a wall interval the plane cut */
|
|
39
|
+
| "wall"
|
|
40
|
+
/** the centreline of something that does not enclose (`air:1`) */
|
|
41
|
+
| "rail"
|
|
42
|
+
/** a relation with no matter (`type:open`) — a centreline and nothing else */
|
|
43
|
+
| "open"
|
|
44
|
+
/** the band of a segment that does not count */
|
|
45
|
+
| "seg"
|
|
46
|
+
/** a non-door opening's centreline */
|
|
47
|
+
| "window"
|
|
48
|
+
/** hinge to leaf tip */
|
|
49
|
+
| "door-leaf"
|
|
50
|
+
/** the swing trace */
|
|
51
|
+
| "door-arc"
|
|
52
|
+
/** a sliding door's pocket panel */
|
|
53
|
+
| "slide-panel"
|
|
54
|
+
/** its setback line */
|
|
55
|
+
| "slide-tail"
|
|
56
|
+
| "column"
|
|
57
|
+
| "run-outline"
|
|
58
|
+
| "run-tread"
|
|
59
|
+
/** where the plane crosses the run — one line; making two of it is the consumer's convention */
|
|
60
|
+
| "run-break"
|
|
61
|
+
| "run-arrow"
|
|
62
|
+
/** a seat only. The note has no geometry, and no words either */
|
|
63
|
+
| "run-note"
|
|
64
|
+
/** the projection of an upper void onto the plan below */
|
|
65
|
+
| "void-above";
|
|
66
|
+
|
|
67
|
+
/** Pinned to `Form` by construction, so it cannot drift from what `derive` produced. */
|
|
68
|
+
export type MarkArc = NonNullable<PlanEntity["arc"]>;
|
|
69
|
+
|
|
70
|
+
/** What a mark stands for. `PlanSubject` plus the two Form arrays that make marks without entities. */
|
|
71
|
+
export type MarkSubject = "space" | "boundary" | "opening" | "column" | "run" | "seg";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The facts an annotation is worded from. **No wording, no units, no rounding** — a ramp at
|
|
75
|
+
* `slope = 1/12.5` is "1/13" to one consumer and "1/12.5" to another, and that disagreement
|
|
76
|
+
* belongs to them, not here.
|
|
77
|
+
*/
|
|
78
|
+
export type MarkNote =
|
|
79
|
+
/** direction of travel at an arrow's tail */
|
|
80
|
+
| { of: "direction"; up: boolean }
|
|
81
|
+
/** a stair's proportions, exactly as `FormRun` carries them */
|
|
82
|
+
| { of: "stair"; risers: number; riser: number; tread: number; going: number; rise: number }
|
|
83
|
+
/** a ramp, escalator or lift. `slope` is rise over run; "1/N" is a spelling, not a number */
|
|
84
|
+
| { of: "incline"; device: RunDevice; lanes: number; slope: number; rise: number };
|
|
85
|
+
|
|
86
|
+
export interface Mark {
|
|
87
|
+
role: MarkRole;
|
|
88
|
+
of: MarkSubject;
|
|
89
|
+
/** the subject's identity: a space's or run's `path`, otherwise the Form `ref` */
|
|
90
|
+
ref: string;
|
|
91
|
+
/**
|
|
92
|
+
* The classification `Form` gave the subject, carried through unchanged. Marks with no backing
|
|
93
|
+
* entity (`seg`, `void-hatch`, the two sliding marks) carry `"cut"` — they show at the cut.
|
|
94
|
+
*/
|
|
95
|
+
class: PlanClass;
|
|
96
|
+
polygon?: Pt[];
|
|
97
|
+
lines?: Seg2[];
|
|
98
|
+
arc?: MarkArc;
|
|
99
|
+
/** where a symbol or annotation is seated. A point, never a string */
|
|
100
|
+
at?: Pt;
|
|
101
|
+
note?: MarkNote;
|
|
102
|
+
/**
|
|
103
|
+
* Place in the canonical order — the only route back to what was written. `boundary` indexes
|
|
104
|
+
* `canonicalBoundaryOrder(model)`, **never `model.boundaries`** (ADR-0041): declaration order is
|
|
105
|
+
* information the canonical form discards, so indexing by it reads a different boundary's `spec`
|
|
106
|
+
* and nothing throws. Never parse `ref` for this.
|
|
107
|
+
*/
|
|
108
|
+
written?: { boundary: number; index?: number };
|
|
109
|
+
/** the two spaces a boundary-derived mark relates */
|
|
110
|
+
pair?: { a: string; b: string };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Setback of a sliding door's pocket panel from the wall face, mm.
|
|
115
|
+
*
|
|
116
|
+
* **A drafting convention, not a derivation default.** It is not in the ledger of derivation
|
|
117
|
+
* constants because no shape of the building depends on it; all three implementations spell 110.
|
|
118
|
+
*/
|
|
119
|
+
export const SLIDE_POCKET = 110;
|
|
120
|
+
|
|
121
|
+
export interface MarkOptions {
|
|
122
|
+
/** override `SLIDE_POCKET` */
|
|
123
|
+
slidePocket?: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const unit = (from: Pt, to: Pt, len: number): Pt => ({
|
|
127
|
+
x: (to.x - from.x) / (len || 1),
|
|
128
|
+
y: (to.y - from.y) / (len || 1),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** A sliding or automatic door: no swing trace — a panel set back on the hinge side, and its tail. */
|
|
132
|
+
function slideMarks(o: FormOpening, pocket: number, base: Omit<Mark, "role" | "lines">): Mark[] {
|
|
133
|
+
const sw = o.swing;
|
|
134
|
+
if (!sw) return [];
|
|
135
|
+
const { hinge } = sw;
|
|
136
|
+
const u = unit(hinge, sw.leaf, o.w); // towards the side it opens onto
|
|
137
|
+
const a = unit(hinge, sw.jamb, o.w); // along the segment
|
|
138
|
+
const s1 = { x: hinge.x - a.x * o.w + u.x * pocket, y: hinge.y - a.y * o.w + u.y * pocket };
|
|
139
|
+
const s2 = { x: hinge.x + u.x * pocket, y: hinge.y + u.y * pocket };
|
|
140
|
+
return [
|
|
141
|
+
{ ...base, role: "slide-panel", lines: [{ x1: s1.x, y1: s1.y, x2: s2.x, y2: s2.y }] },
|
|
142
|
+
{ ...base, role: "slide-tail", lines: [{ x1: s2.x, y1: s2.y, x2: hinge.x, y2: hinge.y }] },
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The marks drawn on one level's plan, from `Form`.
|
|
148
|
+
*
|
|
149
|
+
* **The model is not read.** Grid lines, `area` frames, space names, the north arrow and the sheet
|
|
150
|
+
* title are written givens, and the consumer draws them separately from what it wrote. Returns an
|
|
151
|
+
* empty list where the level has no plan.
|
|
152
|
+
*/
|
|
153
|
+
export function planMarks(form: Form, level: string, opts?: MarkOptions): Mark[] {
|
|
154
|
+
const plan = form.plans.find((p) => p.level === level);
|
|
155
|
+
if (!plan) return [];
|
|
156
|
+
const pocket = opts?.slidePocket ?? SLIDE_POCKET;
|
|
157
|
+
const marks: Mark[] = [];
|
|
158
|
+
const S = new Map(form.spaces.map((s) => [s.path, s]));
|
|
159
|
+
const B = new Map(form.boundaries.map((b) => [b.ref, b]));
|
|
160
|
+
const O = new Map(form.openings.map((o) => [o.ref, o]));
|
|
161
|
+
const R = new Map(form.runs.map((r) => [r.path, r]));
|
|
162
|
+
|
|
163
|
+
// ---- spaces ----
|
|
164
|
+
for (const e of plan.entities) {
|
|
165
|
+
if (e.of !== "space" || e.class !== "cut" || !e.polygon) continue;
|
|
166
|
+
const s = S.get(e.ref);
|
|
167
|
+
// A void is a **declaration** (`void:1`), not a word in the type vocabulary (ADR-0051), and
|
|
168
|
+
// `Form` carries that fact through as `FormSpace.void`.
|
|
169
|
+
if (s?.void) {
|
|
170
|
+
const r = polyBounds(e.polygon);
|
|
171
|
+
marks.push({ role: "space-void", of: "space", ref: e.ref, class: "cut", polygon: e.polygon });
|
|
172
|
+
marks.push({
|
|
173
|
+
role: "void-hatch",
|
|
174
|
+
of: "space",
|
|
175
|
+
ref: e.ref,
|
|
176
|
+
class: "cut",
|
|
177
|
+
lines: [
|
|
178
|
+
{ x1: r.x1, y1: r.y1, x2: r.x2, y2: r.y2 },
|
|
179
|
+
{ x1: r.x1, y1: r.y2, x2: r.x2, y2: r.y1 },
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
marks.push({
|
|
185
|
+
role: s?.semiOutdoor ? "space-semi-outdoor" : "space",
|
|
186
|
+
of: "space",
|
|
187
|
+
ref: e.ref,
|
|
188
|
+
class: "cut",
|
|
189
|
+
polygon: e.polygon,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ---- boundaries ----
|
|
194
|
+
// **What says a boundary has matter is the presence of `polygon`, not a lookup on the boundary.**
|
|
195
|
+
// Read `lines` first and every wall falls into the `open` branch — the whole drawing turns to
|
|
196
|
+
// dashes with not one black band in it. That regression is real; it has happened.
|
|
197
|
+
//
|
|
198
|
+
// The order matters as much. Asking "is this class dropped?" before "is this a rail?" draws no
|
|
199
|
+
// handrail at all: a rail stands 1100 high and the plane cuts at 1200, so every rail interval is
|
|
200
|
+
// classified `below` and a class-first branch discards the lot in silence.
|
|
201
|
+
for (const e of plan.entities) {
|
|
202
|
+
if (e.of !== "boundary") continue;
|
|
203
|
+
const b = B.get(e.ref);
|
|
204
|
+
const base = {
|
|
205
|
+
of: "boundary" as const,
|
|
206
|
+
ref: e.ref,
|
|
207
|
+
...(b ? { written: { boundary: b.boundary }, pair: { a: b.a, b: b.b } } : {}),
|
|
208
|
+
};
|
|
209
|
+
if (!e.polygon) {
|
|
210
|
+
if (e.lines) marks.push({ ...base, role: "open", class: e.class, lines: e.lines });
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (b?.air) {
|
|
214
|
+
// Something that does not enclose is drawn as its axis, not as a body — that the space is
|
|
215
|
+
// not shut is readable from the drawing. `Form` carries the axis, so it is never recovered
|
|
216
|
+
// from the footprint.
|
|
217
|
+
if (e.class !== "above" && e.lines) marks.push({ ...base, role: "rail", class: e.class, lines: e.lines });
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (e.class === "cut") marks.push({ ...base, role: "wall", class: "cut", polygon: e.polygon });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ---- segments that do not count — no area, no graph, but a derived position ----
|
|
224
|
+
for (const g of form.segs) {
|
|
225
|
+
if (g.level !== level) continue;
|
|
226
|
+
marks.push({
|
|
227
|
+
role: "seg",
|
|
228
|
+
of: "seg",
|
|
229
|
+
ref: g.ref,
|
|
230
|
+
class: "cut",
|
|
231
|
+
polygon: band(g.segment, g.cx, g.cy, g.w, g.t),
|
|
232
|
+
written: { boundary: g.boundary, index: g.index },
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ---- openings ----
|
|
237
|
+
for (const e of plan.entities) {
|
|
238
|
+
if (e.of !== "opening") continue;
|
|
239
|
+
const o = O.get(e.ref);
|
|
240
|
+
if (!o) continue;
|
|
241
|
+
const base = {
|
|
242
|
+
of: "opening" as const,
|
|
243
|
+
ref: e.ref,
|
|
244
|
+
written: { boundary: o.boundary, index: o.index },
|
|
245
|
+
pair: { a: o.a, b: o.b },
|
|
246
|
+
};
|
|
247
|
+
if (e.class === "swing") {
|
|
248
|
+
if (o.sliding) {
|
|
249
|
+
marks.push(...slideMarks(o, pocket, { ...base, class: "swing" }));
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (e.lines) marks.push({ ...base, role: "door-leaf", class: "swing", lines: e.lines });
|
|
253
|
+
if (e.arc) marks.push({ ...base, role: "door-arc", class: "swing", arc: e.arc });
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
// No class filter, so a clerestory above the cut arrives as a `window` too. `Mark.class` puts
|
|
257
|
+
// that fact in the consumer's hand instead of hiding it.
|
|
258
|
+
if (o.kind !== "door" && e.lines) marks.push({ ...base, role: "window", class: e.class, lines: e.lines });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ---- columns (written nowhere — they appear where grid lines meet a floor) ----
|
|
262
|
+
for (const e of plan.entities) {
|
|
263
|
+
if (e.of === "column" && e.polygon) {
|
|
264
|
+
marks.push({ role: "column", of: "column", ref: e.ref, class: e.class, polygon: e.polygon });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ---- vertical circulation — the ascending run is cut, and beyond it the descending run shows ----
|
|
269
|
+
for (const e of plan.entities) {
|
|
270
|
+
if (e.of !== "run") continue;
|
|
271
|
+
const base = { of: "run" as const, ref: e.ref };
|
|
272
|
+
if (e.role === "outline" && e.lines) marks.push({ ...base, role: "run-outline", class: e.class, lines: e.lines });
|
|
273
|
+
else if (e.role === "tread" && e.lines) marks.push({ ...base, role: "run-tread", class: e.class, lines: e.lines });
|
|
274
|
+
else if (e.role === "break" && e.lines) marks.push({ ...base, role: "run-break", class: "cut", lines: e.lines });
|
|
275
|
+
else if (e.role === "arrow" && e.lines) {
|
|
276
|
+
marks.push({
|
|
277
|
+
...base,
|
|
278
|
+
role: "run-arrow",
|
|
279
|
+
class: e.class,
|
|
280
|
+
lines: e.lines,
|
|
281
|
+
...(e.anchor ? { at: { x: e.anchor.x, y: e.anchor.y } } : {}),
|
|
282
|
+
note: { of: "direction", up: e.anchor?.up === true },
|
|
283
|
+
});
|
|
284
|
+
} else if (e.class === "anchor" && e.anchor) {
|
|
285
|
+
const r = R.get(e.ref);
|
|
286
|
+
if (!r) continue;
|
|
287
|
+
marks.push({
|
|
288
|
+
...base,
|
|
289
|
+
role: "run-note",
|
|
290
|
+
class: "anchor",
|
|
291
|
+
at: { x: e.anchor.x, y: e.anchor.y },
|
|
292
|
+
note:
|
|
293
|
+
r.device === "stair"
|
|
294
|
+
? { of: "stair", risers: r.risers, riser: r.riser, tread: r.tread, going: r.going, rise: r.rise }
|
|
295
|
+
: { of: "incline", device: r.device, lanes: r.lanes, slope: r.slope, rise: r.rise },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ---- the void above, dropped onto the plan below ----
|
|
301
|
+
for (const e of plan.entities) {
|
|
302
|
+
if (e.class !== "above" || e.of !== "space" || !e.polygon) continue;
|
|
303
|
+
const r = polyBounds(e.polygon);
|
|
304
|
+
marks.push({
|
|
305
|
+
role: "void-above",
|
|
306
|
+
of: "space",
|
|
307
|
+
ref: e.ref,
|
|
308
|
+
class: "above",
|
|
309
|
+
polygon: e.polygon,
|
|
310
|
+
at: { x: (r.x1 + r.x2) / 2, y: (r.y1 + r.y2) / 2 },
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return marks;
|
|
315
|
+
}
|
package/src/draw/plan.ts
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
// 扉の軌跡の中心と半径と掃き方向・切断面を跨ぐ位置は Form が持つ。1/4円を破線で描くか、
|
|
10
10
|
// 切断線を平行な二本の斜線として引くか、矢印に "UP" と書くかは、ここが決める。
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { derive } from "../core/derive.js";
|
|
13
|
+
import { displayName, polyBounds, type Model, type Pt } from "../core/model.js";
|
|
14
14
|
import { slopeText } from "../core/vertical.js";
|
|
15
|
+
import { planMarks, type Mark } from "./marks.js";
|
|
16
|
+
import { esc, Extent, FAINT, GRID, INK, openSheet, PAPER, ROOM } from "./sheet.js";
|
|
17
|
+
import { writtenOf } from "./written.js";
|
|
15
18
|
|
|
16
19
|
export interface PlanOptions {
|
|
17
20
|
level?: string;
|
|
@@ -21,12 +24,6 @@ export interface PlanOptions {
|
|
|
21
24
|
cut?: number;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
const INK = "#1f1f1f";
|
|
25
|
-
const PAPER = "#faf8f4";
|
|
26
|
-
const ROOM = "#f1ebdd";
|
|
27
|
-
const GRID = "#b5aa94";
|
|
28
|
-
const FAINT = "#b3ab9c";
|
|
29
|
-
|
|
30
27
|
export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
31
28
|
const level = opts.level ?? Object.keys(model.levels)[0];
|
|
32
29
|
if (!level) throw new Error("No level is defined");
|
|
@@ -47,10 +44,17 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
47
44
|
const modelRooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level === level);
|
|
48
45
|
const allRects = modelRooms.flatMap((s) => s.rects);
|
|
49
46
|
const polyPts = [...sitePolys.flatMap((p) => p.points), ...rooms.flatMap((s) => s.outline.flat())];
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
47
|
+
// **畳んで取る** (Extent) — 引数を展開すると、大きな階では点の数がスタックの限界に当たる
|
|
48
|
+
const ext = new Extent();
|
|
49
|
+
for (const r of allRects) {
|
|
50
|
+
ext.see(r.x1, r.y1);
|
|
51
|
+
ext.see(r.x2, r.y2);
|
|
52
|
+
}
|
|
53
|
+
for (const p of polyPts) ext.see(p.x, p.y);
|
|
54
|
+
const minX = ext.min0;
|
|
55
|
+
const maxX = ext.max0;
|
|
56
|
+
const minY = ext.min1;
|
|
57
|
+
const maxY = ext.max1;
|
|
54
58
|
|
|
55
59
|
const M = 84; // 余白 px (通り芯記号ぶん)
|
|
56
60
|
const W = (maxX - minX) * scale + M * 2;
|
|
@@ -63,11 +67,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
63
67
|
`<line x1="${sx(g.x1)}" y1="${sy(g.y1)}" x2="${sx(g.x2)}" y2="${sy(g.y2)}" stroke="${stroke}" stroke-width="${w}"${dash ? ` stroke-dasharray="${dash}"` : ""}/>`;
|
|
64
68
|
const fill = (poly: Pt[], c: string) => `<path d="${path2d(poly)}" fill="${c}"/>`;
|
|
65
69
|
|
|
66
|
-
const parts: string[] =
|
|
67
|
-
parts.push(
|
|
68
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="'Hiragino Sans','Noto Sans JP',sans-serif">`,
|
|
69
|
-
);
|
|
70
|
-
parts.push(`<rect width="${W}" height="${H}" fill="${PAPER}"/>`);
|
|
70
|
+
const parts: string[] = openSheet(W, H);
|
|
71
71
|
|
|
72
72
|
// 敷地境界線 (一点二点鎖線 — 作図慣習)。所与の形をそのまま引く
|
|
73
73
|
for (const poly of sitePolys) {
|
|
@@ -129,112 +129,100 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
// 印 — 形の写しは `planMarks` にある。**この頁が足すのは色・線幅・線種・記号・注記の言葉だけ**
|
|
133
|
+
// である。ugatsu も architype も同じ印から別の見た目を引く。
|
|
134
|
+
const marks = planMarks(form, level);
|
|
135
|
+
const written = writtenOf(model);
|
|
136
|
+
const segByRef = new Map(form.segs.map((g) => [g.ref, g]));
|
|
137
|
+
for (const k of marks) {
|
|
138
|
+
switch (k.role) {
|
|
139
|
+
// 空間の面と分節の帯は下 (`rooms` / `form.segs`) から引く — 切られた面ではなく外形を塗り、
|
|
140
|
+
// 分節には Form しか持たない座と向きが要るため。上部吹抜けは空間ラベルより後ろに置く
|
|
141
|
+
case "space":
|
|
142
|
+
case "space-semi-outdoor":
|
|
143
|
+
case "space-void":
|
|
144
|
+
case "void-hatch":
|
|
145
|
+
case "void-above":
|
|
146
|
+
break;
|
|
147
|
+
// 数えない分節 (seg): 壁材が途中から変わる区間 — 色調を変えて示す。
|
|
148
|
+
// ここから引くのは注記の言葉 (`spec`) だけで、それは形ではないので Form には載らない。
|
|
149
|
+
// **`written.boundary` は正準順の添字である** — 宣言順の配列を引くと、並べ替えただけで
|
|
150
|
+
// 注記が別の境界のものになる
|
|
151
|
+
case "seg": {
|
|
152
|
+
parts.push(fill(k.polygon!, "#77716a"));
|
|
153
|
+
const spec = written.segSpec(k.written!.boundary, k.written!.index!);
|
|
154
|
+
const g = segByRef.get(k.ref);
|
|
155
|
+
if (typeof spec === "string" && g) {
|
|
156
|
+
const h = g.segment.horizontal;
|
|
157
|
+
parts.push(
|
|
158
|
+
`<text x="${sx(g.cx) + (h ? 0 : 8)}" y="${sy(g.cy) + (h ? -7 : 3)}" text-anchor="${h ? "middle" : "start"}" font-size="8" fill="#77716a">${esc(spec)}</text>`,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
139
163
|
// 物を持たない境界 (open): 構成の線として破線で示す (基本計画の抽象度)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (e.class === "above") continue; // 垂れ壁は切断面より上 — 平面には出ない
|
|
144
|
-
if (b?.air) {
|
|
164
|
+
case "open":
|
|
165
|
+
for (const g of k.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
|
|
166
|
+
break;
|
|
145
167
|
// 遮蔽しない物 (手すり・柵): 細実線 — 「囲われていない」ことが図から読めるように。
|
|
146
|
-
// 切断面より上でも下でも一本の線で描く (厚みを持たない作図表現)。
|
|
147
168
|
// **芯線は Form が持つ** — 足あとの四辺形から復元しない
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// 開口 — 窓は芯線一本、扉は葉と軌跡 (1/4円の破線)
|
|
175
|
-
const openings = new Map(form.openings.map((o) => [o.ref, o]));
|
|
176
|
-
for (const e of plan.entities) {
|
|
177
|
-
if (e.of !== "opening") continue;
|
|
178
|
-
const o = openings.get(e.ref);
|
|
179
|
-
if (!o) continue;
|
|
180
|
-
if (e.class === "swing") {
|
|
181
|
-
if (o.sliding) {
|
|
182
|
-
// 引戸・自動ドア: 開き軌跡ではなく吊元側の控え (戸袋側) にパネルを描く
|
|
183
|
-
const off = 110; // 壁面からの控え mm (作図表現)
|
|
184
|
-
const sw = o.swing!;
|
|
185
|
-
const ux = (sw.leaf.x - sw.hinge.x) / o.w;
|
|
186
|
-
const uy = (sw.leaf.y - sw.hinge.y) / o.w;
|
|
187
|
-
const ax = (sw.jamb.x - sw.hinge.x) / o.w;
|
|
188
|
-
const ay = (sw.jamb.y - sw.hinge.y) / o.w;
|
|
189
|
-
const s1 = { x: sw.hinge.x - ax * o.w + ux * off, y: sw.hinge.y - ay * o.w + uy * off };
|
|
190
|
-
const s2 = { x: sw.hinge.x + ux * off, y: sw.hinge.y + uy * off };
|
|
169
|
+
case "rail":
|
|
170
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
|
|
171
|
+
break;
|
|
172
|
+
// 切断面が切った区間と柱を黒帯にする。腰壁は開口の下なので印にならない —
|
|
173
|
+
// **これが「欠き取り」の代わりである**。紙の色で塗り潰す操作はもう無い
|
|
174
|
+
case "wall":
|
|
175
|
+
case "column":
|
|
176
|
+
parts.push(fill(k.polygon!, INK));
|
|
177
|
+
break;
|
|
178
|
+
// 引戸・自動ドア: 開き軌跡ではなく吊元側の控え (戸袋側) にパネルを描く
|
|
179
|
+
case "slide-panel":
|
|
180
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
|
|
181
|
+
break;
|
|
182
|
+
case "slide-tail":
|
|
183
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
184
|
+
break;
|
|
185
|
+
case "door-leaf":
|
|
186
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.4));
|
|
187
|
+
break;
|
|
188
|
+
case "door-arc": {
|
|
189
|
+
const a = k.arc!;
|
|
190
|
+
const r = a.r * scale;
|
|
191
|
+
// 掃引方向: 世界の反時計回りは、y を反転した紙の上では時計回りになる
|
|
192
|
+
const sweep = a.ccw ? 0 : 1;
|
|
191
193
|
parts.push(
|
|
192
|
-
|
|
193
|
-
line({ x1: s2.x, y1: s2.y, x2: sw.hinge.x, y2: sw.hinge.y }, INK, 0.7),
|
|
194
|
+
`<path d="M ${sx(a.from.x)} ${sy(a.from.y)} A ${r} ${r} 0 0 ${sweep} ${sx(a.to.x)} ${sy(a.to.y)}" fill="none" stroke="${INK}" stroke-width="0.7" stroke-dasharray="3 2.5"/>`,
|
|
194
195
|
);
|
|
195
|
-
|
|
196
|
+
break;
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
198
|
+
case "window":
|
|
199
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1));
|
|
200
|
+
break;
|
|
201
|
+
case "run-outline":
|
|
202
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
|
|
203
|
+
break;
|
|
204
|
+
case "run-tread":
|
|
205
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
206
|
+
break;
|
|
207
|
+
case "run-break":
|
|
208
|
+
for (const g of k.lines ?? []) parts.push(...breakMark(g, line));
|
|
209
|
+
break;
|
|
210
|
+
case "run-arrow":
|
|
211
|
+
parts.push(...arrow(k, line, sx, sy));
|
|
212
|
+
break;
|
|
213
|
+
// 注記の言葉と丸めはここで初めて生まれる — 印が運ぶのは丸めない事実だけである
|
|
214
|
+
case "run-note": {
|
|
215
|
+
const n = k.note;
|
|
216
|
+
if (!n || n.of === "direction") break; // 座の注記は向きではない
|
|
217
|
+
const text =
|
|
218
|
+
n.of === "stair"
|
|
219
|
+
? `${n.risers}段 蹴上${Math.round(n.riser)}/踏面${Math.round(n.tread)}`
|
|
220
|
+
: `${n.lanes > 1 ? `${n.lanes}台 ` : ""}勾配 ${slopeText(n.slope)}`;
|
|
202
221
|
parts.push(
|
|
203
|
-
`<
|
|
222
|
+
`<text x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(text)}</text>`,
|
|
204
223
|
);
|
|
224
|
+
break;
|
|
205
225
|
}
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
if (o.kind !== "door" && e.lines) {
|
|
209
|
-
// 窓: 芯線一本
|
|
210
|
-
for (const g of e.lines) parts.push(line(g, INK, 1));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// 柱 (ADR-0023) — 位置はどこにも書かれていない。通り芯の交点と床の交わりから現れる
|
|
215
|
-
for (const e of plan.entities) {
|
|
216
|
-
if (e.of === "column" && e.polygon) parts.push(fill(e.polygon, INK));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// 縦動線 (ADR-0021) — そのレベルで切った姿。上る走りは切断線で切れ、
|
|
220
|
-
// その先には下りる走り (下階の走りを上から見たもの) が現れる
|
|
221
|
-
const runs = new Map(form.runs.map((r) => [r.path, r]));
|
|
222
|
-
for (const e of plan.entities) {
|
|
223
|
-
if (e.of !== "run") continue;
|
|
224
|
-
if (e.role === "outline") for (const g of e.lines ?? []) parts.push(line(g, INK, 1.1));
|
|
225
|
-
else if (e.role === "tread") for (const g of e.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
226
|
-
else if (e.role === "break") for (const g of e.lines ?? []) parts.push(...breakMark(g, line));
|
|
227
|
-
else if (e.role === "arrow") parts.push(...arrow(e, line, sx, sy));
|
|
228
|
-
else if (e.class === "anchor" && e.anchor) {
|
|
229
|
-
const r = runs.get(e.ref);
|
|
230
|
-
if (!r) continue;
|
|
231
|
-
const text =
|
|
232
|
-
r.device === "stair"
|
|
233
|
-
? `${r.risers}段 蹴上${Math.round(r.riser)}/踏面${Math.round(r.tread)}`
|
|
234
|
-
: `${r.lanes > 1 ? `${r.lanes}台 ` : ""}勾配 ${slopeText(r.slope)}`;
|
|
235
|
-
parts.push(
|
|
236
|
-
`<text x="${sx(e.anchor.x)}" y="${sy(e.anchor.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(text)}</text>`,
|
|
237
|
-
);
|
|
238
226
|
}
|
|
239
227
|
}
|
|
240
228
|
|
|
@@ -256,13 +244,12 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
256
244
|
);
|
|
257
245
|
}
|
|
258
246
|
|
|
259
|
-
// 切断面より上のものの投影 (上部吹抜け — 作図慣習)
|
|
260
|
-
for (const
|
|
261
|
-
if (
|
|
262
|
-
const r = polyBounds(e.polygon);
|
|
247
|
+
// 切断面より上のものの投影 (上部吹抜け — 作図慣習)。空間ラベルの後に置く
|
|
248
|
+
for (const k of marks) {
|
|
249
|
+
if (k.role !== "void-above") continue;
|
|
263
250
|
parts.push(
|
|
264
|
-
`<path d="${path2d(
|
|
265
|
-
`<text x="${sx(
|
|
251
|
+
`<path d="${path2d(k.polygon!)}" fill="none" stroke="${FAINT}" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
252
|
+
`<text x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 40}" text-anchor="middle" font-size="9" fill="${FAINT}">void above</text>`,
|
|
266
253
|
);
|
|
267
254
|
}
|
|
268
255
|
|
|
@@ -299,10 +286,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
299
286
|
|
|
300
287
|
// 表題
|
|
301
288
|
const title = `${model.name ?? "Untitled"} — ${level} plan`;
|
|
302
|
-
parts.push(
|
|
303
|
-
`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`,
|
|
304
|
-
`<text x="${W - M + 62}" y="${H - 18}" text-anchor="end" font-size="9" fill="#a49b8a">koyu — generated from spaces (wall centrelines, mm)</text>`,
|
|
305
|
-
);
|
|
289
|
+
parts.push(`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`);
|
|
306
290
|
|
|
307
291
|
parts.push("</svg>");
|
|
308
292
|
return parts.join("\n") + "\n";
|
|
@@ -339,12 +323,12 @@ function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line:
|
|
|
339
323
|
|
|
340
324
|
/** 矢印 — 三角の頭と "UP"/"DN" の言葉は、どちらも見た目である */
|
|
341
325
|
function arrow(
|
|
342
|
-
|
|
326
|
+
k: Mark,
|
|
343
327
|
line: Line,
|
|
344
328
|
sx: (x: number) => number,
|
|
345
329
|
sy: (y: number) => number,
|
|
346
330
|
): string[] {
|
|
347
|
-
const g =
|
|
331
|
+
const g = k.lines?.[0];
|
|
348
332
|
if (!g) return [];
|
|
349
333
|
const dx = g.x2 - g.x1;
|
|
350
334
|
const dy = g.y2 - g.y1;
|
|
@@ -356,7 +340,7 @@ function arrow(
|
|
|
356
340
|
return [
|
|
357
341
|
line(g, INK, 1),
|
|
358
342
|
`<path d="M ${sx(g.x2)} ${sy(g.y2)} L ${sx(g.x2 - hx + px)} ${sy(g.y2 - hy + py)} L ${sx(g.x2 - hx - px)} ${sy(g.y2 - hy - py)} Z" fill="${INK}"/>`,
|
|
359
|
-
`<text x="${sx(g.x1) + 4}" y="${sy(g.y1) + 4}" font-size="9" fill="${INK}">${
|
|
343
|
+
`<text x="${sx(g.x1) + 4}" y="${sy(g.y1) + 4}" font-size="9" fill="${INK}">${k.note?.of === "direction" && k.note.up ? "UP" : "DN"}</text>`,
|
|
360
344
|
];
|
|
361
345
|
}
|
|
362
346
|
|
|
@@ -370,6 +354,3 @@ function polyArea(poly: Pt[]): number {
|
|
|
370
354
|
return Math.abs(s / 2);
|
|
371
355
|
}
|
|
372
356
|
|
|
373
|
-
function esc(s: string): string {
|
|
374
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
375
|
-
}
|