@kensnzk/koyu 0.14.0 → 0.16.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/README.ja.md +4 -2
- package/README.md +5 -3
- package/dist/cli.js +156 -81
- package/dist/cli.js.map +1 -1
- package/dist/core/derive.d.ts +259 -0
- package/dist/core/derive.d.ts.map +1 -0
- package/dist/core/derive.js +570 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{check.d.ts → core/diagnose.d.ts} +11 -12
- package/dist/core/diagnose.d.ts.map +1 -0
- package/dist/{check.js → core/diagnose.js} +232 -221
- package/dist/core/diagnose.js.map +1 -0
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/{diff.js → core/diff.js} +84 -41
- package/dist/core/diff.js.map +1 -0
- package/dist/{fabric.d.ts → core/fabric.d.ts} +4 -0
- package/dist/core/fabric.d.ts.map +1 -0
- package/dist/{fabric.js → core/fabric.js} +4 -3
- package/dist/core/fabric.js.map +1 -0
- package/dist/{graph.d.ts → core/graph.d.ts} +1 -3
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/{graph.js → core/graph.js} +43 -51
- package/dist/core/graph.js.map +1 -0
- package/dist/core/light.d.ts +24 -0
- package/dist/core/light.d.ts.map +1 -0
- package/dist/{light.js → core/light.js} +15 -10
- package/dist/core/light.js.map +1 -0
- package/dist/{model.d.ts → core/model.d.ts} +124 -13
- package/dist/core/model.d.ts.map +1 -0
- package/dist/{model.js → core/model.js} +193 -50
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/{parse.js → core/parse.js} +528 -116
- package/dist/core/parse.js.map +1 -0
- package/dist/{poly.d.ts → core/poly.d.ts} +3 -2
- package/dist/core/poly.d.ts.map +1 -0
- package/dist/{poly.js → core/poly.js} +8 -9
- package/dist/core/poly.js.map +1 -0
- package/dist/core/site.d.ts.map +1 -0
- package/dist/core/site.js.map +1 -0
- package/dist/core/tolerance.d.ts +26 -0
- package/dist/core/tolerance.d.ts.map +1 -0
- package/dist/core/tolerance.js +48 -0
- package/dist/core/tolerance.js.map +1 -0
- package/dist/{vertical.d.ts → core/vertical.d.ts} +41 -12
- package/dist/core/vertical.d.ts.map +1 -0
- package/dist/{vertical.js → core/vertical.js} +45 -104
- package/dist/core/vertical.js.map +1 -0
- package/dist/core/vocabulary.d.ts +40 -0
- package/dist/core/vocabulary.d.ts.map +1 -0
- package/dist/core/vocabulary.js +164 -0
- package/dist/core/vocabulary.js.map +1 -0
- package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
- package/dist/draw/axo.d.ts.map +1 -0
- package/dist/{axo.js → draw/axo.js} +53 -81
- package/dist/draw/axo.js.map +1 -0
- package/dist/draw/index.d.ts +3 -0
- package/dist/draw/index.d.ts.map +1 -0
- package/dist/draw/index.js +11 -0
- package/dist/draw/index.js.map +1 -0
- package/dist/draw/plan.d.ts +10 -0
- package/dist/draw/plan.d.ts.map +1 -0
- package/dist/draw/plan.js +284 -0
- package/dist/draw/plan.js.map +1 -0
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +71 -40
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -1
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +1 -1
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/access.d.ts +6 -0
- package/dist/validate/access.d.ts.map +1 -0
- package/dist/validate/access.js +238 -0
- package/dist/validate/access.js.map +1 -0
- package/dist/validate/envelope.d.ts +4 -0
- package/dist/validate/envelope.d.ts.map +1 -0
- package/dist/validate/envelope.js +55 -0
- package/dist/validate/envelope.js.map +1 -0
- package/dist/validate/index.d.ts +60 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +77 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/light.d.ts +6 -0
- package/dist/validate/light.d.ts.map +1 -0
- package/dist/validate/light.js +28 -0
- package/dist/validate/light.js.map +1 -0
- package/dist/validate/runs.d.ts +16 -0
- package/dist/validate/runs.d.ts.map +1 -0
- package/dist/validate/runs.js +60 -0
- package/dist/validate/runs.js.map +1 -0
- package/dist/validate/site.d.ts +6 -0
- package/dist/validate/site.d.ts.map +1 -0
- package/dist/validate/site.js +63 -0
- package/dist/validate/site.js.map +1 -0
- package/editors/vscode/.vscodeignore +2 -0
- package/editors/vscode/README.md +28 -0
- package/editors/vscode/extension.js +150 -0
- package/editors/vscode/language-configuration.json +19 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
- package/examples/basement/main.muro +1 -1
- package/examples/complex/main.muro +1 -1
- package/examples/house/main.muro +2 -2
- package/examples/house.muro +2 -2
- package/examples/mansion.muro +2 -2
- package/examples/office.muro +2 -2
- package/examples/steps/01-one-room.muro +1 -1
- package/examples/steps/02-two-rooms.muro +1 -1
- package/examples/steps/03-door.muro +1 -1
- package/examples/steps/04-exterior.muro +1 -1
- package/examples/steps/05-two-storeys.muro +1 -1
- package/examples/steps/06-finished.muro +2 -2
- package/examples/tower/main.muro +1 -1
- package/examples/twin/L1.muro +136 -119
- package/examples/twin/L5.muro +85 -123
- package/examples/twin/assets.muro +10 -8
- package/examples/twin/basement.muro +43 -34
- package/examples/twin/core.muro +148 -65
- package/examples/twin/hotel.muro +66 -107
- package/examples/twin/main.muro +73 -67
- package/examples/twin/office.muro +87 -88
- package/examples/twin/podium.muro +309 -97
- package/examples/twin/residence.muro +61 -116
- package/examples/twin/site.muro +16 -13
- package/examples/two-rooms.canonical.json +4 -2
- package/examples/two-rooms.muro +2 -2
- package/package.json +16 -1
- package/spec/README.md +28 -0
- package/spec/canonical-json.md +98 -0
- package/spec/composition.md +121 -0
- package/spec/derivation.md +393 -0
- package/spec/en/README.md +30 -0
- package/spec/en/canonical-json.md +101 -0
- package/spec/en/composition.md +121 -0
- package/spec/en/derivation.md +393 -0
- package/spec/en/language.md +164 -0
- package/spec/en/notation-v0.md +145 -0
- package/spec/en/scope.md +229 -0
- package/spec/en/semantics.md +132 -0
- package/spec/en/tools.md +108 -0
- package/spec/en/validation.md +79 -0
- package/spec/en/vocabulary.md +103 -0
- package/spec/language.md +163 -0
- package/spec/notation-v0.md +184 -0
- package/spec/scope.md +229 -0
- package/spec/semantics.md +130 -0
- package/spec/tools.md +106 -0
- package/spec/validation.md +79 -0
- package/spec/vocabulary.md +114 -0
- package/src/cli.ts +165 -80
- package/src/core/derive.ts +852 -0
- package/src/{check.ts → core/diagnose.ts} +260 -229
- package/src/{diff.ts → core/diff.ts} +84 -40
- package/src/{fabric.ts → core/fabric.ts} +4 -3
- package/src/{graph.ts → core/graph.ts} +47 -60
- package/src/core/light.ts +69 -0
- package/src/{model.ts → core/model.ts} +236 -52
- package/src/{parse.ts → core/parse.ts} +584 -116
- package/src/{poly.ts → core/poly.ts} +8 -9
- package/src/core/tolerance.ts +55 -0
- package/src/{vertical.ts → core/vertical.ts} +65 -115
- package/src/core/vocabulary.ts +197 -0
- package/src/{axo.ts → draw/axo.ts} +51 -94
- package/src/draw/index.ts +11 -0
- package/src/draw/plan.ts +344 -0
- package/src/index.ts +181 -35
- package/src/mcp.ts +76 -40
- package/src/parse-file.ts +2 -2
- package/src/validate/access.ts +279 -0
- package/src/validate/envelope.ts +59 -0
- package/src/validate/index.ts +107 -0
- package/src/validate/light.ts +43 -0
- package/src/validate/runs.ts +87 -0
- package/src/validate/site.ts +84 -0
- package/dist/axo.d.ts.map +0 -1
- package/dist/axo.js.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fabric.d.ts.map +0 -1
- package/dist/fabric.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/light.d.ts +0 -15
- package/dist/light.d.ts.map +0 -1
- package/dist/light.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js.map +0 -1
- package/dist/plan.d.ts +0 -10
- package/dist/plan.d.ts.map +0 -1
- package/dist/plan.js +0 -354
- package/dist/plan.js.map +0 -1
- package/dist/poly.d.ts.map +0 -1
- package/dist/poly.js.map +0 -1
- package/dist/site.d.ts.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/vertical.d.ts.map +0 -1
- package/dist/vertical.js.map +0 -1
- package/src/light.ts +0 -63
- package/src/plan.ts +0 -472
- /package/dist/{diff.d.ts → core/diff.d.ts} +0 -0
- /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
- /package/dist/{site.d.ts → core/site.d.ts} +0 -0
- /package/dist/{site.js → core/site.js} +0 -0
- /package/src/{site.ts → core/site.ts} +0 -0
|
@@ -3,19 +3,15 @@
|
|
|
3
3
|
// WebGLも実行環境も要らない — 平面と同じく SVG のテキストが出るので、
|
|
4
4
|
// 生成して見る、という同じ手で立体を確かめられる。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// 描くのは**生成物だけ**である。床・屋根、壁 (境界から)、柱 (通りの交点から)、縦動線。
|
|
7
|
+
// どれもソースには無く、規則から現れる。
|
|
8
|
+
//
|
|
9
|
+
// **ここに形の規則は一つも無い** (ADR-0040)。輪郭も厚みも z 範囲も `derive(model)` が返す
|
|
10
|
+
// `Form` に既に入っており、芯線から実体を起こす構成子 (`thicken` / `columnRect` / `runPrism`)
|
|
11
|
+
// も core が唯一の実装を持つ。この頁が決めるのは投影・陰影・重ね順・紙面だけである。
|
|
8
12
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
columnsFor,
|
|
13
|
-
levelsSorted,
|
|
14
|
-
rectToPoly,
|
|
15
|
-
type Model,
|
|
16
|
-
type Pt,
|
|
17
|
-
} from "./model.js";
|
|
18
|
-
import { runSolids, verticalRuns } from "./vertical.js";
|
|
13
|
+
import { columnRect, derive, runPrism, thicken } from "../core/derive.js";
|
|
14
|
+
import { type Model, type Pt } from "../core/model.js";
|
|
19
15
|
|
|
20
16
|
export interface AxoOptions {
|
|
21
17
|
/** 見る向き — 建物のどの隅から見下ろすか (既定 SE) */
|
|
@@ -42,6 +38,9 @@ interface Prism {
|
|
|
42
38
|
|
|
43
39
|
const INK = "#1f1f1f";
|
|
44
40
|
const PAPER = "#faf8f4";
|
|
41
|
+
/** 地盤面を見せる版の下端・上端 mm — 導出値ではなく紙の側の約束 */
|
|
42
|
+
const GROUND_Z0 = -400;
|
|
43
|
+
const GROUND_Z1 = -100;
|
|
45
44
|
const C = {
|
|
46
45
|
floor: "#cfc7b6",
|
|
47
46
|
roof: "#8d8577",
|
|
@@ -50,17 +49,19 @@ const C = {
|
|
|
50
49
|
column: "#5d574d",
|
|
51
50
|
run: "#7f8f8a",
|
|
52
51
|
ground: "#eceadf",
|
|
53
|
-
opening: "#f2efe6",
|
|
54
52
|
};
|
|
55
53
|
|
|
56
54
|
/** 軸測図のSVG。ソースに形は無い — ここに出るものはすべて規則からの生成物である */
|
|
57
55
|
export function svgAxo(model: Model, opts: AxoOptions = {}): string {
|
|
58
56
|
const scale = opts.scale ?? 0.02;
|
|
59
57
|
const dir = opts.dir ?? "SE";
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
|
|
59
|
+
// **形はすべて Form が持つ** (ADR-0040) — 壁の厚みも、開口で割られた区間も、
|
|
60
|
+
// 柱の z 範囲も、段板の立体も。ここが決めるのは投影と陰影と紙面だけである
|
|
61
|
+
const form = derive(model);
|
|
62
|
+
const names = new Set(
|
|
63
|
+
form.levels.filter((l) => !opts.levels || opts.levels.includes(l.name)).map((l) => l.name),
|
|
62
64
|
);
|
|
63
|
-
const names = new Set(levels.map((l) => l.name));
|
|
64
65
|
|
|
65
66
|
// 見る向き: 平面を90度ずつ回してから等角に落とす
|
|
66
67
|
const turn = { NE: 0, NW: 1, SW: 2, SE: 3 }[dir];
|
|
@@ -93,84 +94,64 @@ export function svgAxo(model: Model, opts: AxoOptions = {}): string {
|
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
// ---- 敷地 (地盤面) ----
|
|
96
|
-
|
|
97
|
+
// 地盤に厚みは導出されない (Form が持つのは所与の形だけ) ので、地面をどれだけの
|
|
98
|
+
// 厚みの版として見せるかは**紙の側の判断**である
|
|
99
|
+
for (const poly of form.site) add(poly.points, GROUND_Z0, GROUND_Z1, C.ground);
|
|
97
100
|
|
|
98
101
|
// ---- 床・屋根 (ADR-0024) ----
|
|
99
|
-
for (const sl of slabs
|
|
102
|
+
for (const sl of form.slabs) {
|
|
100
103
|
if (!names.has(sl.level)) continue;
|
|
101
104
|
if (sl.kind === "ceiling" && !opts.ceilings) continue;
|
|
102
105
|
add(sl.outline, sl.z0, sl.z1, sl.kind === "roof" ? C.roof : sl.kind === "floor" ? C.floor : C.ceiling);
|
|
103
106
|
}
|
|
104
107
|
|
|
105
|
-
// ---- 壁 (境界から生成)
|
|
108
|
+
// ---- 壁 (境界から生成) — **開口で割られた区間として立つ** ----
|
|
106
109
|
if (opts.walls !== false) {
|
|
107
|
-
for (const b of
|
|
108
|
-
if (b.
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!room?.level || !names.has(room.level)) continue;
|
|
113
|
-
const z0 = model.levels[room.level]!.z;
|
|
114
|
-
const h = pitchOf(model, room.level);
|
|
115
|
-
const t = b.air ? Math.min(b.t ?? 60, 80) : (b.t ?? 100);
|
|
116
|
-
const top = b.air ? z0 + (typeof b.attrs["h"] === "number" ? (b.attrs["h"] as number) : 1100) : z0 + h;
|
|
117
|
-
for (const seg of segmentsFor(model, b)) add(thicken(seg, t), z0, top, C.wall);
|
|
110
|
+
for (const b of form.boundaries) {
|
|
111
|
+
if (!b.material || (b.level !== undefined && !names.has(b.level))) continue;
|
|
112
|
+
for (const p of b.material.panels) {
|
|
113
|
+
add(thicken(p.x1, p.y1, p.x2, p.y2, b.material.t), p.z0, p.z1, C.wall);
|
|
114
|
+
}
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
// ---- 柱 (ADR-0023) ----
|
|
122
|
-
for (const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
add(
|
|
126
|
-
rectToPoly({ x1: c.x - c.w / 2, y1: c.y - c.d / 2, x2: c.x + c.w / 2, y2: c.y + c.d / 2 }),
|
|
127
|
-
l.z,
|
|
128
|
-
l.z + h,
|
|
129
|
-
C.column,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
119
|
+
for (const c of form.columns) {
|
|
120
|
+
if (!names.has(c.level)) continue;
|
|
121
|
+
add(columnRect(c), c.z0, c.z1, C.column);
|
|
132
122
|
}
|
|
133
123
|
|
|
134
124
|
// ---- 縦動線 (ADR-0021) — 段は段として、斜路は傾いた版として ----
|
|
135
|
-
for (const run of
|
|
125
|
+
for (const run of form.runs) {
|
|
136
126
|
if (!names.has(run.level)) continue;
|
|
137
|
-
for (const s of
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
// 傾いた版: 四隅の高さを走る向きに線形で振る
|
|
143
|
-
const poly = rectToPoly(s.rect);
|
|
144
|
-
const f = (p: Pt): number => {
|
|
145
|
-
const r = s.rect;
|
|
146
|
-
const u =
|
|
147
|
-
s.up === "E"
|
|
148
|
-
? (p.x - r.x1) / Math.max(1, r.x2 - r.x1)
|
|
149
|
-
: s.up === "W"
|
|
150
|
-
? (r.x2 - p.x) / Math.max(1, r.x2 - r.x1)
|
|
151
|
-
: s.up === "N"
|
|
152
|
-
? (p.y - r.y1) / Math.max(1, r.y2 - r.y1)
|
|
153
|
-
: (r.y2 - p.y) / Math.max(1, r.y2 - r.y1);
|
|
154
|
-
return s.z0 + u * (s.z1 - s.z0);
|
|
155
|
-
};
|
|
156
|
-
add(poly, poly.map((p) => f(p) - s.t), poly.map(f), C.run);
|
|
127
|
+
for (const s of run.solids) {
|
|
128
|
+
const pr = runPrism(s);
|
|
129
|
+
add(pr.poly, pr.bottom, pr.top, C.run);
|
|
157
130
|
}
|
|
158
131
|
}
|
|
159
132
|
|
|
160
|
-
if (prisms.length === 0) throw new Error("
|
|
133
|
+
if (prisms.length === 0) throw new Error("There is nothing to draw");
|
|
161
134
|
|
|
162
135
|
// ---- 投影して奥から描く (画家のアルゴリズム) ----
|
|
163
136
|
prisms.sort((a, b) => a.depth - b.depth);
|
|
164
|
-
|
|
137
|
+
// **外接範囲は畳んで取る。**Math.min(...pts) は引数の数がスタックの限界に当たる —
|
|
138
|
+
// 開口で割られた壁は区間ごとに一片なので、大きな例では十万点を超える
|
|
139
|
+
let minX = Infinity;
|
|
140
|
+
let maxX = -Infinity;
|
|
141
|
+
let minY = Infinity;
|
|
142
|
+
let maxY = -Infinity;
|
|
143
|
+
const see = (p: [number, number]): void => {
|
|
144
|
+
if (p[0] < minX) minX = p[0];
|
|
145
|
+
if (p[0] > maxX) maxX = p[0];
|
|
146
|
+
if (p[1] < minY) minY = p[1];
|
|
147
|
+
if (p[1] > maxY) maxY = p[1];
|
|
148
|
+
};
|
|
165
149
|
for (const pr of prisms) {
|
|
166
150
|
for (let i = 0; i < pr.poly.length; i++) {
|
|
167
|
-
|
|
151
|
+
see(proj(pr.poly[i]!, pr.top[i]!));
|
|
152
|
+
see(proj(pr.poly[i]!, pr.bottom[i]!));
|
|
168
153
|
}
|
|
169
154
|
}
|
|
170
|
-
const minX = Math.min(...pts.map((p) => p[0]));
|
|
171
|
-
const maxX = Math.max(...pts.map((p) => p[0]));
|
|
172
|
-
const minY = Math.min(...pts.map((p) => p[1]));
|
|
173
|
-
const maxY = Math.max(...pts.map((p) => p[1]));
|
|
174
155
|
const M = 40;
|
|
175
156
|
const W = (maxX - minX) * scale + M * 2;
|
|
176
157
|
const H = (maxY - minY) * scale + M * 2;
|
|
@@ -211,37 +192,13 @@ export function svgAxo(model: Model, opts: AxoOptions = {}): string {
|
|
|
211
192
|
out.push(face(top, pr.fill, 1));
|
|
212
193
|
}
|
|
213
194
|
out.push(
|
|
214
|
-
`<text x="${M - 24}" y="${H - 12}" font-size="11" fill="${INK}">${esc(model.name ?? "
|
|
215
|
-
`<text x="${W - M + 24}" y="${H - 12}" text-anchor="end" font-size="8.5" fill="#a49b8a">koyu —
|
|
195
|
+
`<text x="${M - 24}" y="${H - 12}" font-size="11" fill="${INK}">${esc(model.name ?? "Untitled")} — axonometric (from ${dir})</text>`,
|
|
196
|
+
`<text x="${W - M + 24}" y="${H - 12}" text-anchor="end" font-size="8.5" fill="#a49b8a">koyu — generated from spaces (floors, roofs, walls, columns, vertical circulation)</text>`,
|
|
216
197
|
"</svg>",
|
|
217
198
|
);
|
|
218
199
|
return out.join("\n") + "\n";
|
|
219
200
|
}
|
|
220
201
|
|
|
221
|
-
/** レベルの階高 (次のレベルまで)。最上階は天井高+slabで近似 */
|
|
222
|
-
function pitchOf(model: Model, level: string): number {
|
|
223
|
-
const l = model.levels[level]!;
|
|
224
|
-
const up = Object.values(model.levels)
|
|
225
|
-
.filter((o) => o.z > l.z)
|
|
226
|
-
.sort((a, b) => a.z - b.z)[0];
|
|
227
|
-
return up ? up.z - l.z : (l.h ?? 2400) + (l.slab ?? 0);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** 壁芯線分を厚みのある四角形へ (斜めの線分もそのまま扱える) */
|
|
231
|
-
function thicken(seg: Segment, t: number): Pt[] {
|
|
232
|
-
const dx = seg.x2 - seg.x1;
|
|
233
|
-
const dy = seg.y2 - seg.y1;
|
|
234
|
-
const len = Math.hypot(dx, dy) || 1;
|
|
235
|
-
const nx = (-dy / len) * (t / 2);
|
|
236
|
-
const ny = (dx / len) * (t / 2);
|
|
237
|
-
return [
|
|
238
|
-
{ x: seg.x1 + nx, y: seg.y1 + ny },
|
|
239
|
-
{ x: seg.x2 + nx, y: seg.y2 + ny },
|
|
240
|
-
{ x: seg.x2 - nx, y: seg.y2 - ny },
|
|
241
|
-
{ x: seg.x1 - nx, y: seg.y1 - ny },
|
|
242
|
-
];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
202
|
function signedArea(ring: Array<[number, number]>): number {
|
|
246
203
|
let a = 0;
|
|
247
204
|
for (let i = 0; i < ring.length; i++) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// koyu — 表現の面 (`@kensnzk/koyu/draw`)
|
|
2
|
+
//
|
|
3
|
+
// **ここは凍らない** (spec/scope.md §8)。サブコマンド `plan` / `axo` の**面** —
|
|
4
|
+
// 名前・引数・終了コード — は凍るが、出てくる SVG の中身は約束の外にある。
|
|
5
|
+
// 見た目は自由に変えてよく、形は変えない。
|
|
6
|
+
//
|
|
7
|
+
// ルートからも同じものが出ている (`@kensnzk/koyu`)。分けてあるのは、
|
|
8
|
+
// **凍る面と凍らない面を、import 一行で見分けられるようにするため**である。
|
|
9
|
+
|
|
10
|
+
export { svgPlan, type PlanOptions } from "./plan.js";
|
|
11
|
+
export { svgAxo, type AxoOptions } from "./axo.js";
|
package/src/draw/plan.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// koyu — 平面図の生成
|
|
2
|
+
//
|
|
3
|
+
// **ここに形の規則は一つも無い。**壁の厚みも、開口の位置も、扉の吊元も、階段がどこで
|
|
4
|
+
// 切れるかも、`derive(model)` が返す `Form` に既に入っている (ADR-0040)。この頁が持つのは
|
|
5
|
+
// 色・線種・線幅・書体・記号・注記の言葉・縮尺・紙面の余白 — すべて**見た目**であり、
|
|
6
|
+
// 消費者ごとに違ってよいものである (spec/scope.md §6)。
|
|
7
|
+
//
|
|
8
|
+
// 形と見た目の線引きはこうである。境界線分の座標・壁の厚み・開口で割られた区間・
|
|
9
|
+
// 扉の軌跡の中心と半径と掃き方向・切断面を跨ぐ位置は Form が持つ。1/4円を破線で描くか、
|
|
10
|
+
// 切断線を平行な二本の斜線として引くか、矢印に "UP" と書くかは、ここが決める。
|
|
11
|
+
|
|
12
|
+
import { band, derive, type PlanEntity } from "../core/derive.js";
|
|
13
|
+
import { canonicalBoundaryOrder, displayName, polyBounds, type Model, type Pt } from "../core/model.js";
|
|
14
|
+
import { slopeText } from "../core/vertical.js";
|
|
15
|
+
|
|
16
|
+
export interface PlanOptions {
|
|
17
|
+
level?: string;
|
|
18
|
+
/** px per mm */
|
|
19
|
+
scale?: number;
|
|
20
|
+
/** 切断面の高さ mm (FLから) — **形を決める引数**なので Form の入力へ渡る */
|
|
21
|
+
cut?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const INK = "#1f1f1f";
|
|
25
|
+
const PAPER = "#faf8f4";
|
|
26
|
+
const ROOM = "#f1ebdd";
|
|
27
|
+
const GRID = "#b5aa94";
|
|
28
|
+
const FAINT = "#b3ab9c";
|
|
29
|
+
|
|
30
|
+
export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
31
|
+
const level = opts.level ?? Object.keys(model.levels)[0];
|
|
32
|
+
if (!level) throw new Error("No level is defined");
|
|
33
|
+
const scale = opts.scale ?? 0.05;
|
|
34
|
+
|
|
35
|
+
const form = derive(model, opts.cut !== undefined ? { cut: opts.cut } : {});
|
|
36
|
+
const plan = form.plans.find((p) => p.level === level);
|
|
37
|
+
const rooms = form.spaces.filter((s) => s.level === level);
|
|
38
|
+
if (!plan || rooms.length === 0) {
|
|
39
|
+
throw new Error(`There is no space with a region on level ${level}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 敷地形状 (ADR-0011) は最下階の平面 (配置図兼用) に敷地境界線として描く — 紙面の構成の判断
|
|
43
|
+
const lowest = form.levels[0]?.name;
|
|
44
|
+
const sitePolys = level === lowest ? form.site : [];
|
|
45
|
+
|
|
46
|
+
// 紙面の外接範囲。**書かれた割付も含める** — 切られた形より外へ割付がはみ出しても紙に載る
|
|
47
|
+
const modelRooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level === level);
|
|
48
|
+
const allRects = modelRooms.flatMap((s) => s.rects);
|
|
49
|
+
const polyPts = [...sitePolys.flatMap((p) => p.points), ...rooms.flatMap((s) => s.outline.flat())];
|
|
50
|
+
const minX = Math.min(...allRects.map((r) => r.x1), ...polyPts.map((p) => p.x));
|
|
51
|
+
const maxX = Math.max(...allRects.map((r) => r.x2), ...polyPts.map((p) => p.x));
|
|
52
|
+
const minY = Math.min(...allRects.map((r) => r.y1), ...polyPts.map((p) => p.y));
|
|
53
|
+
const maxY = Math.max(...allRects.map((r) => r.y2), ...polyPts.map((p) => p.y));
|
|
54
|
+
|
|
55
|
+
const M = 84; // 余白 px (通り芯記号ぶん)
|
|
56
|
+
const W = (maxX - minX) * scale + M * 2;
|
|
57
|
+
const H = (maxY - minY) * scale + M * 2;
|
|
58
|
+
const sx = (x: number) => (x - minX) * scale + M;
|
|
59
|
+
const sy = (y: number) => (maxY - y) * scale + M;
|
|
60
|
+
const path2d = (poly: Pt[]): string =>
|
|
61
|
+
poly.map((p, i) => `${i === 0 ? "M" : "L"} ${sx(p.x)} ${sy(p.y)}`).join(" ") + " Z";
|
|
62
|
+
const line = (g: { x1: number; y1: number; x2: number; y2: number }, stroke: string, w: number, dash = "") =>
|
|
63
|
+
`<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
|
+
const fill = (poly: Pt[], c: string) => `<path d="${path2d(poly)}" fill="${c}"/>`;
|
|
65
|
+
|
|
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}"/>`);
|
|
71
|
+
|
|
72
|
+
// 敷地境界線 (一点二点鎖線 — 作図慣習)。所与の形をそのまま引く
|
|
73
|
+
for (const poly of sitePolys) {
|
|
74
|
+
parts.push(
|
|
75
|
+
`<path d="${path2d(poly.points)}" fill="none" stroke="#8a8171" stroke-width="1.1" stroke-dasharray="14 3 2.5 3 2.5 3"/>`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 空間の面 — 切断面が気積を切った姿。同色・輪郭なしなのでL字も切られた形も一体に見える。
|
|
80
|
+
// 半屋外は淡く塗り分け、屋外であることが図から読めるように
|
|
81
|
+
for (const s of rooms) {
|
|
82
|
+
const isVoid = s.type === "void";
|
|
83
|
+
for (const poly of s.outline) {
|
|
84
|
+
parts.push(fill(poly, isVoid ? PAPER : s.semiOutdoor ? "#f8f5ec" : ROOM));
|
|
85
|
+
if (isVoid) {
|
|
86
|
+
// 吹抜け: 破線の対角線 (作図慣習)
|
|
87
|
+
const r = polyBounds(poly);
|
|
88
|
+
parts.push(
|
|
89
|
+
line({ x1: r.x1, y1: r.y1, x2: r.x2, y2: r.y2 }, FAINT, 0.8, "6 4"),
|
|
90
|
+
line({ x1: r.x1, y1: r.y2, x2: r.x2, y2: r.y1 }, FAINT, 0.8, "6 4"),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 数えない分節 (area): 床材の切替など。書かれた与件をそのまま引く — 導出ではない
|
|
97
|
+
for (const s of modelRooms) {
|
|
98
|
+
for (const a of s.areas) {
|
|
99
|
+
const r = a.rect;
|
|
100
|
+
parts.push(
|
|
101
|
+
`<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"/>`,
|
|
102
|
+
);
|
|
103
|
+
const label = [a.attrs["name"], a.attrs["floor"]]
|
|
104
|
+
.filter((v): v is string => typeof v === "string")
|
|
105
|
+
.join(" · ");
|
|
106
|
+
if (label) {
|
|
107
|
+
parts.push(
|
|
108
|
+
`<text x="${sx(r.x1) + 6}" y="${sy(r.y2) + 12}" font-size="8.5" fill="#8a8171">${esc(label)}</text>`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 通り芯 (与件)
|
|
115
|
+
for (const [i, x] of model.grid.X.coords.entries()) {
|
|
116
|
+
if (x < minX - 1 || x > maxX + 1) continue;
|
|
117
|
+
parts.push(
|
|
118
|
+
`<line x1="${sx(x)}" y1="${M - 26}" x2="${sx(x)}" y2="${H - M + 26}" stroke="${GRID}" stroke-width="0.8" stroke-dasharray="7 3 1.5 3"/>`,
|
|
119
|
+
`<circle cx="${sx(x)}" cy="${M - 40}" r="11" fill="none" stroke="${GRID}" stroke-width="1"/>`,
|
|
120
|
+
`<text x="${sx(x)}" y="${M - 36}" text-anchor="middle" font-size="10" fill="${GRID}">${model.grid.X.names[i]!}</text>`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
for (const [i, y] of model.grid.Y.coords.entries()) {
|
|
124
|
+
if (y < minY - 1 || y > maxY + 1) continue;
|
|
125
|
+
parts.push(
|
|
126
|
+
`<line x1="${M - 26}" y1="${sy(y)}" x2="${W - M + 26}" y2="${sy(y)}" stroke="${GRID}" stroke-width="0.8" stroke-dasharray="7 3 1.5 3"/>`,
|
|
127
|
+
`<circle cx="${M - 40}" cy="${sy(y)}" r="11" fill="none" stroke="${GRID}" stroke-width="1"/>`,
|
|
128
|
+
`<text x="${M - 40}" y="${sy(y) + 3.5}" text-anchor="middle" font-size="10" fill="${GRID}">${model.grid.Y.names[i]!}</text>`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 壁 — Form が返す「開口で割られた区間」をそのまま塗る。
|
|
133
|
+
// **欠き取り (紙の色で塗り潰して穴に見せる手) は無い** — 壁は最初から穴の空いた列である
|
|
134
|
+
const byRef = new Map(form.boundaries.map((b) => [b.ref, b]));
|
|
135
|
+
for (const e of plan.entities) {
|
|
136
|
+
if (e.of !== "boundary") continue;
|
|
137
|
+
const b = byRef.get(e.ref);
|
|
138
|
+
if (!e.polygon) {
|
|
139
|
+
// 物を持たない境界 (open): 構成の線として破線で示す (基本計画の抽象度)
|
|
140
|
+
for (const g of e.lines ?? []) parts.push(line(g, FAINT, 1, "6 4"));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (e.class === "above") continue; // 垂れ壁は切断面より上 — 平面には出ない
|
|
144
|
+
if (b?.air) {
|
|
145
|
+
// 遮蔽しない物 (手すり・柵): 細実線 — 「囲われていない」ことが図から読めるように。
|
|
146
|
+
// 切断面より上でも下でも一本の線で描く (厚みを持たない作図表現)。
|
|
147
|
+
// **芯線は Form が持つ** — 足あとの四辺形から復元しない
|
|
148
|
+
for (const g of e.lines ?? []) parts.push(line(g, INK, 1.4));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// 切断面が切った区間だけを黒帯にする。腰壁 (class:below) は開口の下なので描かない —
|
|
152
|
+
// **これが「欠き取り」の代わりである**。紙の色で塗り潰す操作はもう無い
|
|
153
|
+
if (e.class === "cut") parts.push(fill(e.polygon, INK));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 数えない分節 (seg): 壁材が途中から変わる区間 — 色調を変えて示す。
|
|
157
|
+
// 帯の形は core の構成子が起こす。ここから引くのは注記の言葉 (`spec`) だけで、
|
|
158
|
+
// それは形ではないので Form には載らない — 添字は宣言の並びの位置 = seg の同一性である
|
|
159
|
+
const ordered = canonicalBoundaryOrder(model);
|
|
160
|
+
for (const g of form.segs) {
|
|
161
|
+
if (g.level !== level) continue;
|
|
162
|
+
parts.push(fill(band(g.segment, g.cx, g.cy, g.w, g.t), "#77716a"));
|
|
163
|
+
// `g.boundary` は **Form の境界の添字 = 正準順の添字**である (spec/derivation.md)。
|
|
164
|
+
// 宣言順の配列を引くと、宣言順を入れ替えただけで注記が別の境界のものになる
|
|
165
|
+
const spec = ordered[g.boundary]?.segs[g.index]?.attrs["spec"];
|
|
166
|
+
if (typeof spec === "string") {
|
|
167
|
+
const h = g.segment.horizontal;
|
|
168
|
+
parts.push(
|
|
169
|
+
`<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>`,
|
|
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 };
|
|
191
|
+
parts.push(
|
|
192
|
+
line({ x1: s1.x, y1: s1.y, x2: s2.x, y2: s2.y }, INK, 2),
|
|
193
|
+
line({ x1: s2.x, y1: s2.y, x2: sw.hinge.x, y2: sw.hinge.y }, INK, 0.7),
|
|
194
|
+
);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (e.lines) for (const g of e.lines) parts.push(line(g, INK, 1.4));
|
|
198
|
+
if (e.arc) {
|
|
199
|
+
const r = e.arc.r * scale;
|
|
200
|
+
// 掃引方向: 世界の反時計回りは、y を反転した紙の上では時計回りになる
|
|
201
|
+
const sweep = e.arc.ccw ? 0 : 1;
|
|
202
|
+
parts.push(
|
|
203
|
+
`<path d="M ${sx(e.arc.from.x)} ${sy(e.arc.from.y)} A ${r} ${r} 0 0 ${sweep} ${sx(e.arc.to.x)} ${sy(e.arc.to.y)}" fill="none" stroke="${INK}" stroke-width="0.7" stroke-dasharray="3 2.5"/>`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
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
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// 空間ラベル (最大の凸片の中心に置く)
|
|
242
|
+
for (const s of rooms) {
|
|
243
|
+
const space = model.spaces.get(s.path)!;
|
|
244
|
+
const poly = [...s.outline].sort((a, b) => polyArea(b) - polyArea(a))[0]!;
|
|
245
|
+
const r = polyBounds(poly);
|
|
246
|
+
const cx = sx((r.x1 + r.x2) / 2);
|
|
247
|
+
const cy = sy((r.y1 + r.y2) / 2);
|
|
248
|
+
const sub =
|
|
249
|
+
s.type === "void"
|
|
250
|
+
? "void"
|
|
251
|
+
: `${esc(s.type)} · ${s.areaM2} m2${s.semiOutdoor ? " · semi-outdoor" : ""}`;
|
|
252
|
+
parts.push(
|
|
253
|
+
`<text x="${cx}" y="${cy - 4}" text-anchor="middle" font-size="14" fill="${INK}">${esc(displayName(space))}</text>`,
|
|
254
|
+
`<text x="${cx}" y="${cy + 13}" text-anchor="middle" font-size="10" fill="#8a8171">${sub}</text>`,
|
|
255
|
+
`<text x="${cx}" y="${cy + 27}" text-anchor="middle" font-size="8.5" fill="${FAINT}">${esc(s.path)}</text>`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 切断面より上のものの投影 (上部吹抜け — 作図慣習)
|
|
260
|
+
for (const e of plan.entities) {
|
|
261
|
+
if (e.class !== "above" || e.of !== "space" || !e.polygon) continue;
|
|
262
|
+
const r = polyBounds(e.polygon);
|
|
263
|
+
parts.push(
|
|
264
|
+
`<path d="${path2d(e.polygon)}" fill="none" stroke="${FAINT}" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
265
|
+
`<text x="${sx((r.x1 + r.x2) / 2)}" y="${sy((r.y1 + r.y2) / 2) + 40}" text-anchor="middle" font-size="9" fill="${FAINT}">void above</text>`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 表題
|
|
270
|
+
const title = `${model.name ?? "Untitled"} — ${level} plan`;
|
|
271
|
+
parts.push(
|
|
272
|
+
`<text x="${M - 62}" y="${H - 18}" font-size="12" fill="${INK}">${esc(title)}</text>`,
|
|
273
|
+
`<text x="${W - M + 62}" y="${H - 18}" text-anchor="end" font-size="9" fill="#a49b8a">koyu — generated from spaces (wall centrelines, mm)</text>`,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
parts.push("</svg>");
|
|
277
|
+
return parts.join("\n") + "\n";
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
type Line = (
|
|
281
|
+
g: { x1: number; y1: number; x2: number; y2: number },
|
|
282
|
+
stroke: string,
|
|
283
|
+
w: number,
|
|
284
|
+
dash?: string,
|
|
285
|
+
) => string;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 切断線 — 作図慣習の平行な二本の斜線。Form が持つのは「走りを横切る切断の位置」だけで、
|
|
289
|
+
* 二本にすることも振り分けの寸法も、ここが決める見た目である
|
|
290
|
+
*/
|
|
291
|
+
function breakMark(g: { x1: number; y1: number; x2: number; y2: number }, line: Line): string[] {
|
|
292
|
+
const dx = g.x2 - g.x1;
|
|
293
|
+
const dy = g.y2 - g.y1;
|
|
294
|
+
const width = Math.hypot(dx, dy) || 1;
|
|
295
|
+
// 走る向き (切断線に直交する単位ベクトル)
|
|
296
|
+
const tx = dy / width;
|
|
297
|
+
const ty = -dx / width;
|
|
298
|
+
const s = Math.min(300, width / 4);
|
|
299
|
+
const off = Math.min(220, s);
|
|
300
|
+
const at = (k: number, l: number) => ({
|
|
301
|
+
x1: g.x1 + tx * (k),
|
|
302
|
+
y1: g.y1 + ty * (k),
|
|
303
|
+
x2: g.x2 + tx * (l),
|
|
304
|
+
y2: g.y2 + ty * (l),
|
|
305
|
+
});
|
|
306
|
+
return [line(at(-s - off, s - off), INK, 1.4), line(at(-s + off, s + off), INK, 1.4)];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 矢印 — 三角の頭と "UP"/"DN" の言葉は、どちらも見た目である */
|
|
310
|
+
function arrow(
|
|
311
|
+
e: PlanEntity,
|
|
312
|
+
line: Line,
|
|
313
|
+
sx: (x: number) => number,
|
|
314
|
+
sy: (y: number) => number,
|
|
315
|
+
): string[] {
|
|
316
|
+
const g = e.lines?.[0];
|
|
317
|
+
if (!g) return [];
|
|
318
|
+
const dx = g.x2 - g.x1;
|
|
319
|
+
const dy = g.y2 - g.y1;
|
|
320
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
321
|
+
const hx = (dx / len) * 420;
|
|
322
|
+
const hy = (dy / len) * 420;
|
|
323
|
+
const px = (-dy / len) * 200;
|
|
324
|
+
const py = (dx / len) * 200;
|
|
325
|
+
return [
|
|
326
|
+
line(g, INK, 1),
|
|
327
|
+
`<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}"/>`,
|
|
328
|
+
`<text x="${sx(g.x1) + 4}" y="${sy(g.y1) + 4}" font-size="9" fill="${INK}">${e.anchor?.up ? "UP" : "DN"}</text>`,
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function polyArea(poly: Pt[]): number {
|
|
333
|
+
let s = 0;
|
|
334
|
+
for (let i = 0; i < poly.length; i++) {
|
|
335
|
+
const a = poly[i]!;
|
|
336
|
+
const b = poly[(i + 1) % poly.length]!;
|
|
337
|
+
s += a.x * b.y - b.x * a.y;
|
|
338
|
+
}
|
|
339
|
+
return Math.abs(s / 2);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function esc(s: string): string {
|
|
343
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
344
|
+
}
|