@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.
- package/assets/plan/README.md +18 -0
- package/assets/plan/catalog.muro +87 -0
- package/assets/plan/library.muro +26 -0
- package/assets/plan/svg/bathtub.svg +9 -0
- package/assets/plan/svg/bed-double.svg +9 -0
- package/assets/plan/svg/bed-single.svg +8 -0
- package/assets/plan/svg/cabinet.svg +9 -0
- package/assets/plan/svg/chair.svg +8 -0
- package/assets/plan/svg/desk.svg +9 -0
- package/assets/plan/svg/hedge-2m.svg +7 -0
- package/assets/plan/svg/kitchen-sink.svg +10 -0
- package/assets/plan/svg/locker.svg +9 -0
- package/assets/plan/svg/office-chair.svg +25 -0
- package/assets/plan/svg/potted-plant.svg +14 -0
- package/assets/plan/svg/refrigerator.svg +10 -0
- package/assets/plan/svg/shelf.svg +9 -0
- package/assets/plan/svg/shrub-1m.svg +7 -0
- package/assets/plan/svg/sofa-2.svg +9 -0
- package/assets/plan/svg/sofa-3.svg +9 -0
- package/assets/plan/svg/table-rect.svg +7 -0
- package/assets/plan/svg/table-round.svg +7 -0
- package/assets/plan/svg/tree-3m.svg +8 -0
- package/assets/plan/svg/urinal.svg +9 -0
- package/assets/plan/svg/washing-machine-pan.svg +13 -0
- package/assets/plan/svg/washing-machine.svg +10 -0
- package/assets/plan/svg/washstand-500.svg +12 -0
- package/assets/plan/svg/washstand.svg +12 -0
- package/assets/plan/svg/wc-cabinet.svg +14 -0
- package/assets/plan/svg/wc.svg +9 -0
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/core/components.d.ts +31 -0
- package/dist/core/components.d.ts.map +1 -0
- package/dist/core/components.js +167 -0
- package/dist/core/components.js.map +1 -0
- package/dist/core/derive.d.ts +9 -1
- package/dist/core/derive.d.ts.map +1 -1
- package/dist/core/derive.js +33 -3
- package/dist/core/derive.js.map +1 -1
- package/dist/core/diagnose.d.ts +6 -0
- package/dist/core/diagnose.d.ts.map +1 -1
- package/dist/core/diagnose.js +137 -4
- package/dist/core/diagnose.js.map +1 -1
- package/dist/core/model.d.ts +5 -5
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +6 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +5 -4
- package/dist/core/parse.js.map +1 -1
- package/dist/core/section.d.ts +27 -2
- package/dist/core/section.d.ts.map +1 -1
- package/dist/core/section.js +63 -11
- package/dist/core/section.js.map +1 -1
- package/dist/core/vocabulary.d.ts +20 -4
- package/dist/core/vocabulary.d.ts.map +1 -1
- package/dist/core/vocabulary.js +107 -9
- package/dist/core/vocabulary.js.map +1 -1
- package/dist/draw/component-files.d.ts +8 -0
- package/dist/draw/component-files.d.ts.map +1 -0
- package/dist/draw/component-files.js +35 -0
- package/dist/draw/component-files.js.map +1 -0
- package/dist/draw/component-svg.d.ts +14 -0
- package/dist/draw/component-svg.d.ts.map +1 -0
- package/dist/draw/component-svg.js +67 -0
- package/dist/draw/component-svg.js.map +1 -0
- package/dist/draw/conventions/architectural.d.ts +32 -0
- package/dist/draw/conventions/architectural.d.ts.map +1 -0
- package/dist/draw/conventions/architectural.js +29 -0
- package/dist/draw/conventions/architectural.js.map +1 -0
- package/dist/draw/index.d.ts +2 -2
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js +2 -2
- package/dist/draw/index.js.map +1 -1
- package/dist/draw/marks.d.ts +37 -12
- package/dist/draw/marks.d.ts.map +1 -1
- package/dist/draw/marks.js +508 -38
- package/dist/draw/marks.js.map +1 -1
- package/dist/draw/plan.d.ts +3 -1
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +247 -85
- package/dist/draw/plan.js.map +1 -1
- package/dist/draw/section.d.ts +20 -2
- package/dist/draw/section.d.ts.map +1 -1
- package/dist/draw/section.js +43 -10
- package/dist/draw/section.js.map +1 -1
- package/dist/form.d.ts +2 -2
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.js +21 -3
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -0
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +1 -0
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/builtin/index.d.ts +4 -2
- package/dist/validate/builtin/index.d.ts.map +1 -1
- package/dist/validate/builtin/index.js +9 -2
- package/dist/validate/builtin/index.js.map +1 -1
- package/dist/validate/builtin/opening-operations.d.ts +63 -0
- package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
- package/dist/validate/builtin/opening-operations.js +406 -0
- package/dist/validate/builtin/opening-operations.js.map +1 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
- package/examples/basement/main.muro +3 -3
- package/examples/complex/L1.muro +1 -1
- package/examples/complex/assets.muro +2 -2
- package/examples/complex/main.muro +1 -1
- package/examples/house/L1.muro +3 -3
- package/examples/house/L2.muro +2 -2
- package/examples/house/assets.muro +8 -8
- package/examples/house/main.muro +1 -1
- package/examples/house/site.muro +2 -2
- package/examples/house.muro +6 -6
- package/examples/mansion.muro +1 -1
- package/examples/office.muro +1 -1
- package/examples/steps/06-finished.muro +1 -1
- package/examples/tower/assets.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/twin/assets.muro +2 -2
- package/examples/twin/main.muro +1 -1
- package/examples/two-rooms.canonical.json +1 -1
- package/examples/two-rooms.muro +1 -1
- package/package.json +7 -4
- package/src/cli.ts +2 -2
- package/src/core/components.ts +224 -0
- package/src/core/derive.ts +47 -4
- package/src/core/diagnose.ts +182 -4
- package/src/core/model.ts +10 -5
- package/src/core/parse.ts +5 -4
- package/src/core/section.ts +107 -8
- package/src/core/vocabulary.ts +115 -9
- package/src/draw/component-files.ts +36 -0
- package/src/draw/component-svg.ts +79 -0
- package/src/draw/conventions/architectural.ts +60 -0
- package/src/draw/index.ts +9 -2
- package/src/draw/marks.ts +564 -44
- package/src/draw/plan.ts +253 -88
- package/src/draw/section.ts +78 -14
- package/src/form.ts +4 -0
- package/src/index.ts +1 -1
- package/src/mcp.ts +21 -3
- package/src/parse-file.ts +1 -0
- package/src/validate/builtin/index.ts +14 -2
- package/src/validate/builtin/opening-operations.ts +519 -0
package/src/draw/plan.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
// koyu —
|
|
1
|
+
// koyu — plan SVG generation
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// **No rule of building shape lives here.** Wall thickness, opening position, door hinge and stair
|
|
4
|
+
// cut are already in the `Form` returned by `derive(model)` (ADR-0040). This page owns colour,
|
|
5
|
+
// line type, line weight, typography, symbols, annotation wording, scale and sheet margins — all
|
|
6
|
+
// presentation, and all allowed to differ by consumer (docs/reference/scope.md).
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// Form carries boundary coordinates, wall thickness, opening intervals, door-arc geometry and
|
|
9
|
+
// the position where a cut crosses a run. The architectural convention and this renderer decide
|
|
10
|
+
// whether a break becomes a diagonal zigzag and whether an arrowhead is open.
|
|
11
11
|
|
|
12
12
|
import { derive } from "../core/derive.js";
|
|
13
13
|
import { displayName, polyBounds, type Model, type Pt } from "../core/model.js";
|
|
14
14
|
import { slopeText } from "../core/vertical.js";
|
|
15
15
|
import { planMarks, type Mark } from "./marks.js";
|
|
16
|
+
import { ARCHITECTURAL_PLAN_CONVENTION } from "./conventions/architectural.js";
|
|
17
|
+
import { componentSvg } from "./component-svg.js";
|
|
16
18
|
import { esc, Extent, FAINT, GRID, INK, openSheet, OUTDOOR, PAPER, ROOM, SEMI_OUTDOOR } from "./sheet.js";
|
|
17
19
|
import { writtenOf } from "./written.js";
|
|
18
20
|
|
|
@@ -20,8 +22,10 @@ export interface PlanOptions {
|
|
|
20
22
|
level?: string;
|
|
21
23
|
/** px per mm */
|
|
22
24
|
scale?: number;
|
|
23
|
-
/**
|
|
25
|
+
/** Cut height above finished floor, mm. It changes the slice, so it is passed into Form. */
|
|
24
26
|
cut?: number;
|
|
27
|
+
/** Plan SVG bytes keyed by component asset name, for models made with the pure `parse` entry. */
|
|
28
|
+
componentSvgs?: Readonly<Record<string, string>>;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
@@ -36,15 +40,15 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
36
40
|
throw new Error(`There is no space with a region on level ${level}`);
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
//
|
|
43
|
+
// Site geometry (ADR-0011) appears on the lowest plan, which also serves as the site plan.
|
|
40
44
|
const lowest = form.levels[0]?.name;
|
|
41
45
|
const sitePolys = level === lowest ? form.site : [];
|
|
42
46
|
|
|
43
|
-
//
|
|
47
|
+
// Sheet extent includes written allocation, even where it reaches outside the cut shape.
|
|
44
48
|
const modelRooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level === level);
|
|
45
49
|
const allRects = modelRooms.flatMap((s) => s.rects);
|
|
46
50
|
const polyPts = [...sitePolys.flatMap((p) => p.points), ...rooms.flatMap((s) => s.outline.flat())];
|
|
47
|
-
//
|
|
51
|
+
// Fold through Extent: spreading every point can hit the call-stack limit on a large storey.
|
|
48
52
|
const ext = new Extent();
|
|
49
53
|
for (const r of allRects) {
|
|
50
54
|
ext.see(r.x1, r.y1);
|
|
@@ -56,7 +60,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
56
60
|
const minY = ext.min1;
|
|
57
61
|
const maxY = ext.max1;
|
|
58
62
|
|
|
59
|
-
const M = 84; //
|
|
63
|
+
const M = 84; // sheet margin in px, including grid bubbles
|
|
60
64
|
const W = (maxX - minX) * scale + M * 2;
|
|
61
65
|
const H = (maxY - minY) * scale + M * 2;
|
|
62
66
|
const sx = (x: number) => (x - minX) * scale + M;
|
|
@@ -69,22 +73,21 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
69
73
|
|
|
70
74
|
const parts: string[] = openSheet(W, H);
|
|
71
75
|
|
|
72
|
-
//
|
|
76
|
+
// Site boundary: a drafting dash pattern applied to the supplied geometry.
|
|
73
77
|
for (const poly of sitePolys) {
|
|
74
78
|
parts.push(
|
|
75
79
|
`<path d="${path2d(poly.points)}" fill="none" stroke="#8a8171" stroke-width="1.1" stroke-dasharray="14 3 2.5 3 2.5 3"/>`,
|
|
76
80
|
);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
// 前庭と玄関ホールが同じ一枚のクリームに見えていた状態を分ける
|
|
83
|
+
// Space faces are the cut through volume. A shared fill and no outline make split convex pieces
|
|
84
|
+
// read as one room. Warm denotes indoors; cooler tones separate outside and semi-outdoor space.
|
|
82
85
|
for (const s of rooms) {
|
|
83
86
|
const isVoid = s.void;
|
|
84
87
|
for (const poly of s.outline) {
|
|
85
88
|
parts.push(fill(poly, isVoid ? PAPER : s.outside ? OUTDOOR : s.semiOutdoor ? SEMI_OUTDOOR : ROOM));
|
|
86
89
|
if (isVoid) {
|
|
87
|
-
//
|
|
90
|
+
// Void: dashed diagonals are a paper convention.
|
|
88
91
|
const r = polyBounds(poly);
|
|
89
92
|
parts.push(
|
|
90
93
|
line({ x1: r.x1, y1: r.y1, x2: r.x2, y2: r.y2 }, FAINT, 0.8, "6 4"),
|
|
@@ -94,14 +97,18 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
//
|
|
100
|
+
// Uncounted area subdivisions, such as a floor-finish change, reproduce the written input.
|
|
98
101
|
for (const s of modelRooms) {
|
|
99
102
|
for (const a of s.areas) {
|
|
100
103
|
const r = a.rect;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
104
|
+
const componentHost = a.attrs["asset"] !== undefined;
|
|
105
|
+
const visibleSubdivision = a.attrs["floor"] !== undefined || a.attrs["spec"] !== undefined;
|
|
106
|
+
if (!componentHost || visibleSubdivision) {
|
|
107
|
+
parts.push(
|
|
108
|
+
`<rect x="${sx(r.x1)}" y="${sy(r.y2)}" width="${(r.x2 - r.x1) * scale}" height="${(r.y2 - r.y1) * scale}" fill="#e7dfcc" fill-opacity="0.55" stroke="${FAINT}" stroke-width="0.8" stroke-dasharray="4 3"/>`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const label = [componentHost ? undefined : a.attrs["name"], a.attrs["floor"]]
|
|
105
112
|
.filter((v): v is string => typeof v === "string")
|
|
106
113
|
.join(" · ");
|
|
107
114
|
if (label) {
|
|
@@ -112,7 +119,29 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
//
|
|
122
|
+
// Components are below cut matter and room labels. The source SVG remains isolated as an image,
|
|
123
|
+
// preserving its defs and IDs while the Form supplies all placement geometry.
|
|
124
|
+
for (const component of form.components ?? []) {
|
|
125
|
+
if (component.level !== level) continue;
|
|
126
|
+
const asset = model.assets.get(component.asset);
|
|
127
|
+
if (!asset || asset.kind !== "component") continue;
|
|
128
|
+
const source = opts.componentSvgs?.[asset.name];
|
|
129
|
+
if (!source) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Component asset ${asset.name} has no plan SVG bytes; pass PlanOptions.componentSvgs`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const artwork = componentSvg(asset, source);
|
|
135
|
+
const cx = sx(component.centre.x);
|
|
136
|
+
const cy = sy(component.centre.y);
|
|
137
|
+
const width = component.w * scale;
|
|
138
|
+
const height = component.d * scale;
|
|
139
|
+
parts.push(
|
|
140
|
+
`<image class="component-asset" data-asset="${esc(asset.name)}" x="${cx - width / 2}" y="${cy - height / 2}" width="${width}" height="${height}" preserveAspectRatio="none" href="${artwork.dataUri}" transform="rotate(${-component.rotation} ${cx} ${cy})"/>`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Written grid axes.
|
|
116
145
|
for (const [i, x] of model.grid.X.coords.entries()) {
|
|
117
146
|
if (x < minX - 1 || x > maxX + 1) continue;
|
|
118
147
|
parts.push(
|
|
@@ -130,15 +159,34 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
130
159
|
);
|
|
131
160
|
}
|
|
132
161
|
|
|
133
|
-
//
|
|
134
|
-
//
|
|
162
|
+
// Marks copy Form geometry. This page adds only colour, weight, dash, glyph and wording; another
|
|
163
|
+
// consumer can render the same marks differently.
|
|
135
164
|
const marks = planMarks(form, level);
|
|
136
165
|
const written = writtenOf(model);
|
|
137
166
|
const segByRef = new Map(form.segs.map((g) => [g.ref, g]));
|
|
167
|
+
// A generic room label over a stair repeats what the treads already say and obscures the arrow.
|
|
168
|
+
// Seed the set from actual stair runs, then follow only vertical boundaries connected to them so
|
|
169
|
+
// ramps, escalators and lift shafts keep their existing labels.
|
|
170
|
+
const stairSpaces = new Set(form.runs.filter((r) => r.device === "stair").map((r) => r.path));
|
|
171
|
+
let grew = true;
|
|
172
|
+
while (grew) {
|
|
173
|
+
grew = false;
|
|
174
|
+
for (const b of model.boundaries) {
|
|
175
|
+
if (b.kind !== "stair" || (!stairSpaces.has(b.a) && !stairSpaces.has(b.b))) continue;
|
|
176
|
+
if (!stairSpaces.has(b.a)) {
|
|
177
|
+
stairSpaces.add(b.a);
|
|
178
|
+
grew = true;
|
|
179
|
+
}
|
|
180
|
+
if (!stairSpaces.has(b.b)) {
|
|
181
|
+
stairSpaces.add(b.b);
|
|
182
|
+
grew = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
138
186
|
for (const k of marks) {
|
|
139
187
|
switch (k.role) {
|
|
140
|
-
//
|
|
141
|
-
//
|
|
188
|
+
// Space faces and subdivision bands are rendered from their full outlines elsewhere. Upper
|
|
189
|
+
// void projections are deliberately placed behind space labels.
|
|
142
190
|
case "space":
|
|
143
191
|
case "space-semi-outdoor":
|
|
144
192
|
case "space-outdoor":
|
|
@@ -146,10 +194,9 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
146
194
|
case "void-hatch":
|
|
147
195
|
case "void-above":
|
|
148
196
|
break;
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
// 注記が別の境界のものになる
|
|
197
|
+
// An uncounted segment can mark a wall specification change. Only the annotation wording is
|
|
198
|
+
// recovered from the source. `written.boundary` indexes canonical order, never declaration
|
|
199
|
+
// order, so a harmless source reorder cannot move the note to another boundary.
|
|
153
200
|
case "seg": {
|
|
154
201
|
parts.push(fill(k.polygon!, "#77716a"));
|
|
155
202
|
const spec = written.segSpec(k.written!.boundary, k.written!.index!);
|
|
@@ -162,43 +209,135 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
162
209
|
}
|
|
163
210
|
break;
|
|
164
211
|
}
|
|
165
|
-
//
|
|
212
|
+
// A boundary with no matter remains legible as a light dashed relation.
|
|
166
213
|
case "open":
|
|
167
214
|
for (const g of k.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
|
|
168
215
|
break;
|
|
169
|
-
//
|
|
170
|
-
//
|
|
216
|
+
// A rail stays lighter than a wall, while the endpoint posts keep a short rail from reading
|
|
217
|
+
// as an accidental construction line. The axis itself comes from Form; the circles are a
|
|
218
|
+
// paper convention and add no building geometry.
|
|
171
219
|
case "rail":
|
|
172
|
-
|
|
220
|
+
parts.push(`<g class="boundary-rail">`);
|
|
221
|
+
for (const g of k.lines ?? []) {
|
|
222
|
+
parts.push(line(g, INK, 1.1));
|
|
223
|
+
parts.push(
|
|
224
|
+
`<circle class="boundary-rail-post" cx="${sx(g.x1)}" cy="${sy(g.y1)}" r="1.45" fill="${INK}"/>`,
|
|
225
|
+
`<circle class="boundary-rail-post" cx="${sx(g.x2)}" cy="${sy(g.y2)}" r="1.45" fill="${INK}"/>`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
parts.push(`</g>`);
|
|
173
229
|
break;
|
|
174
|
-
//
|
|
175
|
-
//
|
|
230
|
+
// Only intervals and columns cut by the plane become black bodies. Sill walls lie below the
|
|
231
|
+
// cut; no paper-coloured mask is needed to erase openings.
|
|
176
232
|
case "wall":
|
|
177
233
|
case "column":
|
|
178
234
|
parts.push(fill(k.polygon!, INK));
|
|
179
235
|
break;
|
|
180
|
-
//
|
|
236
|
+
// A sliding leaf has no swing trace. Its solid line closes the opening; the thin dashed
|
|
237
|
+
// continuation says which way it retracts without turning the opening into a box.
|
|
181
238
|
case "slide-panel":
|
|
182
|
-
|
|
239
|
+
parts.push(`<g class="opening-slide-panel">`);
|
|
240
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.2));
|
|
241
|
+
parts.push(`</g>`);
|
|
183
242
|
break;
|
|
184
|
-
case "slide-
|
|
243
|
+
case "slide-centre":
|
|
244
|
+
parts.push(`<g class="opening-slide-centre">`);
|
|
185
245
|
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
246
|
+
parts.push(`</g>`);
|
|
247
|
+
break;
|
|
248
|
+
case "slide-tail":
|
|
249
|
+
parts.push(`<g class="opening-slide-guide">`);
|
|
250
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65, "5 3"));
|
|
251
|
+
parts.push(`</g>`);
|
|
252
|
+
break;
|
|
253
|
+
case "auto-direction":
|
|
254
|
+
parts.push(`<g class="opening-auto-direction">`);
|
|
255
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
|
|
256
|
+
parts.push(`</g>`);
|
|
257
|
+
break;
|
|
258
|
+
case "entrance":
|
|
259
|
+
parts.push(`<g class="opening-entrance">`);
|
|
260
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.75));
|
|
261
|
+
parts.push(`</g>`);
|
|
262
|
+
break;
|
|
263
|
+
case "gate-post":
|
|
264
|
+
parts.push(`<g class="opening-gate-post">`);
|
|
265
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 2));
|
|
266
|
+
parts.push(`</g>`);
|
|
267
|
+
break;
|
|
268
|
+
case "rolling-shutter":
|
|
269
|
+
parts.push(`<g class="opening-rolling-shutter">`);
|
|
270
|
+
for (const g of k.lines ?? []) {
|
|
271
|
+
parts.push(line(g, INK, 1));
|
|
272
|
+
parts.push(
|
|
273
|
+
`<rect x="${sx(g.x1) - 1.5}" y="${sy(g.y1) - 1.5}" width="3" height="3" fill="${INK}"/>`,
|
|
274
|
+
`<rect x="${sx(g.x2) - 1.5}" y="${sy(g.y2) - 1.5}" width="3" height="3" fill="${INK}"/>`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
parts.push(`</g>`);
|
|
278
|
+
break;
|
|
279
|
+
case "overhead-door":
|
|
280
|
+
parts.push(`<g class="opening-overhead-door">`);
|
|
281
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1, "2 1"));
|
|
282
|
+
parts.push(`</g>`);
|
|
186
283
|
break;
|
|
187
284
|
case "door-leaf":
|
|
188
|
-
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.
|
|
285
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
|
|
286
|
+
break;
|
|
287
|
+
case "window-leaf":
|
|
288
|
+
parts.push(`<g class="opening-window-leaf">`);
|
|
289
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.8));
|
|
290
|
+
parts.push(`</g>`);
|
|
189
291
|
break;
|
|
190
|
-
case "door-arc":
|
|
292
|
+
case "door-arc":
|
|
293
|
+
case "window-arc": {
|
|
191
294
|
const a = k.arc!;
|
|
192
295
|
const r = a.r * scale;
|
|
193
|
-
//
|
|
296
|
+
// World counter-clockwise becomes clockwise after the SVG y-axis is inverted.
|
|
194
297
|
const sweep = a.ccw ? 0 : 1;
|
|
298
|
+
const window = k.role === "window-arc";
|
|
195
299
|
parts.push(
|
|
196
|
-
`<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.
|
|
300
|
+
`<path class="${window ? "opening-window-arc" : "opening-door-arc"}" 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="${window ? 0.55 : 0.7}"/>`,
|
|
197
301
|
);
|
|
198
302
|
break;
|
|
199
303
|
}
|
|
200
|
-
case "window":
|
|
201
|
-
|
|
304
|
+
case "window": {
|
|
305
|
+
const cut = k.class === "cut";
|
|
306
|
+
const stroke = cut ? INK : FAINT;
|
|
307
|
+
const dash = cut ? "" : "5 3";
|
|
308
|
+
parts.push(`<g class="opening-window">`);
|
|
309
|
+
if (k.polygon && k.polygon.length >= 4) {
|
|
310
|
+
const p = k.polygon;
|
|
311
|
+
// A window continues the two faces of the wall as unfilled lines. Closing this path
|
|
312
|
+
// would add jamb caps and turn the window back into a boxed door opening.
|
|
313
|
+
parts.push(
|
|
314
|
+
`<path d="M ${sx(p[0]!.x)} ${sy(p[0]!.y)} L ${sx(p[1]!.x)} ${sy(p[1]!.y)} M ${sx(p[3]!.x)} ${sy(p[3]!.y)} L ${sx(p[2]!.x)} ${sy(p[2]!.y)}" fill="none" stroke="${stroke}" stroke-width="0.8"${dash ? ` stroke-dasharray="${dash}"` : ""}/>`,
|
|
315
|
+
);
|
|
316
|
+
} else {
|
|
317
|
+
for (const g of k.lines ?? []) parts.push(line(g, stroke, 0.55, dash));
|
|
318
|
+
}
|
|
319
|
+
parts.push(`</g>`);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case "window-sash":
|
|
323
|
+
parts.push(`<g class="opening-window-sash">`);
|
|
324
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.7));
|
|
325
|
+
parts.push(`</g>`);
|
|
326
|
+
break;
|
|
327
|
+
case "window-fixed":
|
|
328
|
+
parts.push(`<g class="opening-window-fixed">`);
|
|
329
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.65));
|
|
330
|
+
parts.push(`</g>`);
|
|
331
|
+
break;
|
|
332
|
+
case "curtain-wall-mullion":
|
|
333
|
+
parts.push(`<g class="opening-curtain-wall-mullion">`);
|
|
334
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
|
|
335
|
+
parts.push(`</g>`);
|
|
336
|
+
break;
|
|
337
|
+
case "window-sash-centre":
|
|
338
|
+
parts.push(`<g class="opening-window-sash-centre">`);
|
|
339
|
+
for (const g of k.lines ?? []) parts.push(line(g, INK, 0.55));
|
|
340
|
+
parts.push(`</g>`);
|
|
202
341
|
break;
|
|
203
342
|
case "run-outline":
|
|
204
343
|
for (const g of k.lines ?? []) parts.push(line(g, INK, 1.1));
|
|
@@ -212,24 +351,22 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
212
351
|
case "run-arrow":
|
|
213
352
|
parts.push(...arrow(k, line, sx, sy));
|
|
214
353
|
break;
|
|
215
|
-
//
|
|
354
|
+
// Wording and rounding begin here; the mark carries only unrounded facts.
|
|
216
355
|
case "run-note": {
|
|
217
356
|
const n = k.note;
|
|
218
|
-
if (!n || n.of === "direction") break;
|
|
219
|
-
const text =
|
|
220
|
-
n.of === "stair"
|
|
221
|
-
? `${n.risers}段 蹴上${Math.round(n.riser)}/踏面${Math.round(n.tread)}`
|
|
222
|
-
: `${n.lanes > 1 ? `${n.lanes}台 ` : ""}勾配 ${slopeText(n.slope)}`;
|
|
357
|
+
if (!n || n.of === "direction" || n.of === "stair") break;
|
|
358
|
+
const text = `${n.lanes > 1 ? `${n.lanes} units ` : ""}slope ${slopeText(n.slope)}`;
|
|
223
359
|
parts.push(
|
|
224
|
-
`<text x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(text)}</text>`,
|
|
360
|
+
`<text class="run-note" x="${sx(k.at!.x)}" y="${sy(k.at!.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171" stroke="${PAPER}" stroke-width="3" paint-order="stroke">${esc(text)}</text>`,
|
|
225
361
|
);
|
|
226
362
|
break;
|
|
227
363
|
}
|
|
228
364
|
}
|
|
229
365
|
}
|
|
230
366
|
|
|
231
|
-
//
|
|
367
|
+
// Place a space label at the centre of its largest convex piece.
|
|
232
368
|
for (const s of rooms) {
|
|
369
|
+
if (stairSpaces.has(s.path)) continue;
|
|
233
370
|
const space = model.spaces.get(s.path)!;
|
|
234
371
|
const poly = [...s.outline].sort((a, b) => polyArea(b) - polyArea(a))[0]!;
|
|
235
372
|
const r = polyBounds(poly);
|
|
@@ -246,7 +383,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
246
383
|
);
|
|
247
384
|
}
|
|
248
385
|
|
|
249
|
-
//
|
|
386
|
+
// Projection from above the cut, including an upper void, drawn after space labels.
|
|
250
387
|
for (const k of marks) {
|
|
251
388
|
if (k.role !== "void-above") continue;
|
|
252
389
|
parts.push(
|
|
@@ -255,19 +392,19 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
255
392
|
);
|
|
256
393
|
}
|
|
257
394
|
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
//
|
|
395
|
+
// North arrow (ADR-0057): drawn only when azimuth is written. It is presentation rather than
|
|
396
|
+
// shape, so it is placed directly in sheet coordinates instead of entering Form. The picture
|
|
397
|
+
// exposes a reversed bearing, a complementary angle or copied magnetic north.
|
|
261
398
|
//
|
|
262
|
-
//
|
|
399
|
+
// On screen model +Y is up and +X is right; true azimuth remains clockwise from +Y.
|
|
263
400
|
if (model.azimuth) {
|
|
264
401
|
const rad = (model.azimuth.deg * Math.PI) / 180;
|
|
265
402
|
const nx = Math.sin(rad);
|
|
266
403
|
const ny = -Math.cos(rad);
|
|
267
|
-
const cx = W - M / 2; //
|
|
404
|
+
const cx = W - M / 2; // centre of the right margin, separated from the grid bubbles
|
|
268
405
|
const cy = M / 2;
|
|
269
406
|
const R = 21;
|
|
270
|
-
const px = -ny; //
|
|
407
|
+
const px = -ny; // perpendicular direction for the arrowhead base
|
|
271
408
|
const py = nx;
|
|
272
409
|
const r2 = (n: number): string => String(Math.round(n * 100) / 100);
|
|
273
410
|
const head = [
|
|
@@ -286,7 +423,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
286
423
|
);
|
|
287
424
|
}
|
|
288
425
|
|
|
289
|
-
//
|
|
426
|
+
// Sheet title.
|
|
290
427
|
const title = `${model.name ?? "Untitled"} — ${level} plan`;
|
|
291
428
|
parts.push(`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`);
|
|
292
429
|
|
|
@@ -302,47 +439,76 @@ type Line = (
|
|
|
302
439
|
) => string;
|
|
303
440
|
|
|
304
441
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
442
|
+
* Form supplies the segment crossing the flight. The renderer scales the supplied 10 by 40 break
|
|
443
|
+
* glyph to that width and rotates it 30 degrees as a paper convention.
|
|
307
444
|
*/
|
|
308
445
|
function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line: Line): string[] {
|
|
446
|
+
const glyph = ARCHITECTURAL_PLAN_CONVENTION.stairs.breakGlyph;
|
|
309
447
|
const dx = g.x2 - g.x1;
|
|
310
448
|
const dy = g.y2 - g.y1;
|
|
311
449
|
const width = Math.hypot(dx, dy) || 1;
|
|
312
|
-
|
|
450
|
+
const ax = dx / width;
|
|
451
|
+
const ay = dy / width;
|
|
313
452
|
const tx = dy / width;
|
|
314
453
|
const ty = -dx / width;
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
454
|
+
const cx = (g.x1 + g.x2) / 2;
|
|
455
|
+
const cy = (g.y1 + g.y2) / 2;
|
|
456
|
+
const angle = glyph.angleDegrees * Math.PI / 180;
|
|
457
|
+
const longX = ax * Math.cos(angle) + tx * Math.sin(angle);
|
|
458
|
+
const longY = ay * Math.cos(angle) + ty * Math.sin(angle);
|
|
459
|
+
const crossX = -ax * Math.sin(angle) + tx * Math.cos(angle);
|
|
460
|
+
const crossY = -ay * Math.sin(angle) + ty * Math.cos(angle);
|
|
461
|
+
const scale = width / (glyph.height * Math.cos(angle));
|
|
462
|
+
const point = (x: number, y: number) => ({
|
|
463
|
+
x: cx + (longX * y + crossX * x) * scale,
|
|
464
|
+
y: cy + (longY * y + crossY * x) * scale,
|
|
322
465
|
});
|
|
323
|
-
|
|
466
|
+
const halfHeight = glyph.height / 2;
|
|
467
|
+
// Exact geometry of the convention's break glyph, centred and rotated on the flight.
|
|
468
|
+
const paths = [
|
|
469
|
+
[point(0, -halfHeight), point(0, -glyph.notch), point(-glyph.notch, -glyph.notch), point(0, 0)],
|
|
470
|
+
[point(0, 0), point(glyph.notch, glyph.notch), point(0, glyph.notch), point(0, halfHeight)],
|
|
471
|
+
];
|
|
472
|
+
return [
|
|
473
|
+
`<g class="run-break-zigzag">`,
|
|
474
|
+
...paths.flatMap((points) =>
|
|
475
|
+
points.slice(0, -1).map((p, i) =>
|
|
476
|
+
line({ x1: p.x, y1: p.y, x2: points[i + 1]!.x, y2: points[i + 1]!.y }, INK, 1.35),
|
|
477
|
+
),
|
|
478
|
+
),
|
|
479
|
+
`</g>`,
|
|
480
|
+
];
|
|
324
481
|
}
|
|
325
482
|
|
|
326
|
-
/**
|
|
483
|
+
/** A light, open direction arrow. Its line already points where the presentation mark intends. */
|
|
327
484
|
function arrow(
|
|
328
485
|
k: Mark,
|
|
329
486
|
line: Line,
|
|
330
487
|
sx: (x: number) => number,
|
|
331
488
|
sy: (y: number) => number,
|
|
332
489
|
): string[] {
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
490
|
+
const lines = k.lines ?? [];
|
|
491
|
+
const first = lines[0];
|
|
492
|
+
const g = lines[lines.length - 1];
|
|
493
|
+
if (!first || !g) return [];
|
|
494
|
+
// The head is paper-sized, not a dimension of the building. Keeping it in SVG coordinates
|
|
495
|
+
// makes the same stair legible on a compact house and a large floor plate.
|
|
496
|
+
const screenLen = Math.hypot(sx(g.x2) - sx(g.x1), sy(g.y2) - sy(g.y1)) || 1;
|
|
497
|
+
const vx = (sx(g.x2) - sx(g.x1)) / screenLen;
|
|
498
|
+
const vy = (sy(g.y2) - sy(g.y1)) / screenLen;
|
|
499
|
+
const px = -vy;
|
|
500
|
+
const py = vx;
|
|
501
|
+
const head = ARCHITECTURAL_PLAN_CONVENTION.stairs.arrowHead;
|
|
502
|
+
const tip = { x: sx(g.x2), y: sy(g.y2) };
|
|
503
|
+
const back = { x: tip.x - vx * head.length, y: tip.y - vy * head.length };
|
|
342
504
|
return [
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
505
|
+
`<g class="run-direction-arrow">`,
|
|
506
|
+
...lines.map((segment) => line(segment, INK, 0.8)),
|
|
507
|
+
...(k.class === "below"
|
|
508
|
+
? []
|
|
509
|
+
: [`<circle class="run-direction-arrow-start" cx="${sx(first.x1)}" cy="${sy(first.y1)}" r="${head.startRadius}" fill="${PAPER}" stroke="${INK}" stroke-width="0.8"/>`]),
|
|
510
|
+
`<path class="run-direction-arrow-head" d="M ${back.x + px * head.halfWidth} ${back.y + py * head.halfWidth} L ${tip.x} ${tip.y} L ${back.x - px * head.halfWidth} ${back.y - py * head.halfWidth}" fill="none" stroke="${INK}" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"/>`,
|
|
511
|
+
`</g>`,
|
|
346
512
|
];
|
|
347
513
|
}
|
|
348
514
|
|
|
@@ -355,4 +521,3 @@ function polyArea(poly: Pt[]): number {
|
|
|
355
521
|
}
|
|
356
522
|
return Math.abs(s / 2);
|
|
357
523
|
}
|
|
358
|
-
|