@kensnzk/koyu 0.11.0 → 0.13.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 +3 -3
- package/README.md +2 -2
- package/dist/axo.d.ts +16 -0
- package/dist/axo.d.ts.map +1 -0
- package/dist/axo.js +211 -0
- package/dist/axo.js.map +1 -0
- package/dist/check.d.ts +78 -3
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +578 -121
- package/dist/check.js.map +1 -1
- package/dist/cli.js +93 -2
- package/dist/cli.js.map +1 -1
- package/dist/diff.d.ts +15 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +68 -7
- package/dist/diff.js.map +1 -1
- package/dist/fabric.d.ts +28 -0
- package/dist/fabric.d.ts.map +1 -0
- package/dist/fabric.js +105 -0
- package/dist/fabric.js.map +1 -0
- package/dist/graph.d.ts +40 -3
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +352 -53
- package/dist/graph.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/light.d.ts.map +1 -1
- package/dist/light.js +4 -6
- package/dist/light.js.map +1 -1
- package/dist/mcp.js +16 -9
- package/dist/mcp.js.map +1 -1
- package/dist/model.d.ts +123 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +171 -68
- package/dist/model.js.map +1 -1
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +123 -5
- package/dist/parse.js.map +1 -1
- package/dist/plan.d.ts +2 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +97 -10
- package/dist/plan.js.map +1 -1
- package/dist/poly.d.ts +78 -0
- package/dist/poly.d.ts.map +1 -0
- package/dist/poly.js +277 -0
- package/dist/poly.js.map +1 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +5 -4
- package/dist/site.js.map +1 -1
- package/dist/vertical.d.ts +176 -0
- package/dist/vertical.d.ts.map +1 -0
- package/dist/vertical.js +669 -0
- package/dist/vertical.js.map +1 -0
- package/examples/basement/main.muro +84 -0
- package/examples/comparison/README.md +48 -0
- package/examples/complex/L1.muro +132 -0
- package/examples/complex/assets.muro +17 -0
- package/examples/complex/basement.muro +40 -0
- package/examples/complex/core.muro +40 -0
- package/examples/complex/hotel.muro +117 -0
- package/examples/complex/main.muro +67 -0
- package/examples/complex/office.muro +41 -0
- package/examples/complex/plant.muro +34 -0
- package/examples/complex/podium.muro +140 -0
- package/examples/complex/site.muro +18 -0
- package/examples/house/L1.muro +1 -1
- package/examples/house/L2.muro +1 -1
- package/examples/house/main.muro +1 -1
- package/examples/house.muro +3 -3
- package/examples/mansion.muro +18 -13
- package/examples/office.muro +1 -1
- package/examples/steps/04-exterior.muro +1 -1
- package/examples/steps/05-two-storeys.muro +2 -2
- package/examples/steps/06-finished.muro +3 -3
- package/examples/tower/L11.muro +4 -2
- package/examples/tower/L2.muro +2 -0
- package/examples/tower/L3.muro +3 -0
- package/examples/tower/assets.muro +1 -0
- package/examples/tower/main.muro +1 -1
- package/examples/tower/typical.muro +16 -9
- package/examples/two-rooms.canonical.json +26 -2
- package/examples/two-rooms.muro +6 -3
- package/package.json +3 -2
- package/src/axo.ts +258 -0
- package/src/check.ts +680 -143
- package/src/cli.ts +100 -2
- package/src/diff.ts +75 -7
- package/src/fabric.ts +123 -0
- package/src/graph.ts +366 -56
- package/src/index.ts +24 -0
- package/src/light.ts +4 -7
- package/src/mcp.ts +17 -10
- package/src/model.ts +256 -66
- package/src/parse.ts +124 -5
- package/src/plan.ts +120 -11
- package/src/poly.ts +295 -0
- package/src/site.ts +6 -6
- package/src/vertical.ts +884 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kensnzk/koyu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "空間を一次要素とするテキストネイティブ建築記述の探求 — writing architecture, not buildings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"prepare": "npm run build",
|
|
34
34
|
"test": "node --import tsx --test test/*.test.ts",
|
|
35
35
|
"typecheck": "tsc --noEmit",
|
|
36
|
-
"check:examples": "for f in examples/two-rooms.muro examples/office.muro examples/mansion.muro examples/house.muro examples/house/main.muro examples/tower/main.muro examples/steps/*.muro; do tsx src/cli.ts check $f || exit 1; done",
|
|
36
|
+
"check:examples": "for f in examples/two-rooms.muro examples/office.muro examples/mansion.muro examples/house.muro examples/house/main.muro examples/tower/main.muro examples/basement/main.muro examples/complex/main.muro examples/steps/*.muro; do tsx src/cli.ts check $f || exit 1; done",
|
|
37
|
+
"gate:examples": "node --import tsx scripts/gate.mjs",
|
|
37
38
|
"plan:examples": "tsx src/cli.ts plan examples/two-rooms.muro -o out/two-rooms.svg"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
package/src/axo.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// koyu — 軸測図 (アクソメ) の生成 (ADR-0026)
|
|
2
|
+
// 平面図が「そのレベルで切った断面」であるのに対し、これは立体をそのまま投影した図である。
|
|
3
|
+
// WebGLも実行環境も要らない — 平面と同じく SVG のテキストが出るので、
|
|
4
|
+
// 生成して見る、という同じ手で立体を確かめられる。
|
|
5
|
+
//
|
|
6
|
+
// 描くのは**生成物だけ**である。床・屋根 (fabric.ts)、壁 (境界から)、柱 (通りの交点から)、
|
|
7
|
+
// 縦動線 (vertical.ts)。どれもソースには無く、規則から現れる。
|
|
8
|
+
|
|
9
|
+
import { slabs } from "./fabric.js";
|
|
10
|
+
import { segmentsFor, type Segment } from "./graph.js";
|
|
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";
|
|
19
|
+
|
|
20
|
+
export interface AxoOptions {
|
|
21
|
+
/** 見る向き — 建物のどの隅から見下ろすか (既定 SE) */
|
|
22
|
+
dir?: "NE" | "NW" | "SE" | "SW";
|
|
23
|
+
/** px per mm (既定 0.02) */
|
|
24
|
+
scale?: number;
|
|
25
|
+
/** 描くレベル (既定すべて) */
|
|
26
|
+
levels?: string[];
|
|
27
|
+
/** 天井も描く (既定 false — 描くと中が見えない) */
|
|
28
|
+
ceilings?: boolean;
|
|
29
|
+
/** 壁を描く (既定 true) */
|
|
30
|
+
walls?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 立体の一片 — 底面の輪郭と、頂点ごとの上端/下端z。箱も傾いた版もこれで足りる */
|
|
34
|
+
interface Prism {
|
|
35
|
+
poly: Pt[];
|
|
36
|
+
top: number[];
|
|
37
|
+
bottom: number[];
|
|
38
|
+
fill: string;
|
|
39
|
+
/** 奥行きの並べ替えに使う代表点 */
|
|
40
|
+
depth: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const INK = "#1f1f1f";
|
|
44
|
+
const PAPER = "#faf8f4";
|
|
45
|
+
const C = {
|
|
46
|
+
floor: "#cfc7b6",
|
|
47
|
+
roof: "#8d8577",
|
|
48
|
+
ceiling: "#e2dbca",
|
|
49
|
+
wall: "#b8b0a0",
|
|
50
|
+
column: "#5d574d",
|
|
51
|
+
run: "#7f8f8a",
|
|
52
|
+
ground: "#eceadf",
|
|
53
|
+
opening: "#f2efe6",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** 軸測図のSVG。ソースに形は無い — ここに出るものはすべて規則からの生成物である */
|
|
57
|
+
export function svgAxo(model: Model, opts: AxoOptions = {}): string {
|
|
58
|
+
const scale = opts.scale ?? 0.02;
|
|
59
|
+
const dir = opts.dir ?? "SE";
|
|
60
|
+
const levels = levelsSorted(model).filter(
|
|
61
|
+
(l) => !opts.levels || opts.levels.includes(l.name),
|
|
62
|
+
);
|
|
63
|
+
const names = new Set(levels.map((l) => l.name));
|
|
64
|
+
|
|
65
|
+
// 見る向き: 平面を90度ずつ回してから等角に落とす
|
|
66
|
+
const turn = { NE: 0, NW: 1, SW: 2, SE: 3 }[dir];
|
|
67
|
+
const rot = (p: Pt): Pt => {
|
|
68
|
+
let { x, y } = p;
|
|
69
|
+
for (let i = 0; i < turn; i++) [x, y] = [y, -x];
|
|
70
|
+
return { x, y };
|
|
71
|
+
};
|
|
72
|
+
const K = Math.cos(Math.PI / 6);
|
|
73
|
+
const S = Math.sin(Math.PI / 6);
|
|
74
|
+
const proj = (p: Pt, z: number): [number, number] => {
|
|
75
|
+
const q = rot(p);
|
|
76
|
+
return [(q.x - q.y) * K, (q.x + q.y) * S - z];
|
|
77
|
+
};
|
|
78
|
+
/** 手前ほど大きい。等角の視線は (1,1,1) なので x+y+z で並べる */
|
|
79
|
+
const depthOf = (p: Pt, z: number): number => {
|
|
80
|
+
const q = rot(p);
|
|
81
|
+
return q.x + q.y + z;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const prisms: Prism[] = [];
|
|
85
|
+
const add = (poly: Pt[], bottom: number | number[], top: number | number[], fill: string) => {
|
|
86
|
+
if (poly.length < 3) return;
|
|
87
|
+
const b = Array.isArray(bottom) ? bottom : poly.map(() => bottom);
|
|
88
|
+
const t = Array.isArray(top) ? top : poly.map(() => top);
|
|
89
|
+
const cx = poly.reduce((a, p) => a + p.x, 0) / poly.length;
|
|
90
|
+
const cy = poly.reduce((a, p) => a + p.y, 0) / poly.length;
|
|
91
|
+
const cz = t.reduce((a, v) => a + v, 0) / t.length;
|
|
92
|
+
prisms.push({ poly, bottom: b, top: t, fill, depth: depthOf({ x: cx, y: cy }, cz) });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ---- 敷地 (地盤面) ----
|
|
96
|
+
for (const poly of model.polygons.values()) add(poly.points, -400, -100, C.ground);
|
|
97
|
+
|
|
98
|
+
// ---- 床・屋根 (ADR-0024) ----
|
|
99
|
+
for (const sl of slabs(model)) {
|
|
100
|
+
if (!names.has(sl.level)) continue;
|
|
101
|
+
if (sl.kind === "ceiling" && !opts.ceilings) continue;
|
|
102
|
+
add(sl.outline, sl.z0, sl.z1, sl.kind === "roof" ? C.roof : sl.kind === "floor" ? C.floor : C.ceiling);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ---- 壁 (境界から生成) と開口 ----
|
|
106
|
+
if (opts.walls !== false) {
|
|
107
|
+
for (const b of model.boundaries) {
|
|
108
|
+
if (b.kind !== "wall") continue;
|
|
109
|
+
const sa = model.spaces.get(b.a);
|
|
110
|
+
const sb = model.spaces.get(b.b);
|
|
111
|
+
const room = sa && sa.rects.length > 0 ? sa : sb;
|
|
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);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ---- 柱 (ADR-0023) ----
|
|
122
|
+
for (const l of levels) {
|
|
123
|
+
const h = pitchOf(model, l.name);
|
|
124
|
+
for (const c of columnsFor(model, l.name)) {
|
|
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
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---- 縦動線 (ADR-0021) — 段は段として、斜路は傾いた版として ----
|
|
135
|
+
for (const run of verticalRuns(model)) {
|
|
136
|
+
if (!names.has(run.level)) continue;
|
|
137
|
+
for (const s of runSolids(run)) {
|
|
138
|
+
if (s.kind === "box") {
|
|
139
|
+
add(rectToPoly(s.rect), s.z0, s.z1, C.run);
|
|
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);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (prisms.length === 0) throw new Error("描くものがありません");
|
|
161
|
+
|
|
162
|
+
// ---- 投影して奥から描く (画家のアルゴリズム) ----
|
|
163
|
+
prisms.sort((a, b) => a.depth - b.depth);
|
|
164
|
+
const pts: Array<[number, number]> = [];
|
|
165
|
+
for (const pr of prisms) {
|
|
166
|
+
for (let i = 0; i < pr.poly.length; i++) {
|
|
167
|
+
pts.push(proj(pr.poly[i]!, pr.top[i]!), proj(pr.poly[i]!, pr.bottom[i]!));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
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
|
+
const M = 40;
|
|
175
|
+
const W = (maxX - minX) * scale + M * 2;
|
|
176
|
+
const H = (maxY - minY) * scale + M * 2;
|
|
177
|
+
const sx = (v: number) => (v - minX) * scale + M;
|
|
178
|
+
const sy = (v: number) => (v - minY) * scale + M;
|
|
179
|
+
|
|
180
|
+
const out: string[] = [
|
|
181
|
+
`<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">`,
|
|
182
|
+
`<rect width="${W}" height="${H}" fill="${PAPER}"/>`,
|
|
183
|
+
];
|
|
184
|
+
const face = (ring: Array<[number, number]>, fill: string, shade: number) => {
|
|
185
|
+
const d = ring.map(([x, y], i) => `${i === 0 ? "M" : "L"} ${r2(sx(x))} ${r2(sy(y))}`).join(" ");
|
|
186
|
+
return `<path d="${d} Z" fill="${tint(fill, shade)}" stroke="${INK}" stroke-width="0.35" stroke-opacity="0.5"/>`;
|
|
187
|
+
};
|
|
188
|
+
for (const pr of prisms) {
|
|
189
|
+
const n = pr.poly.length;
|
|
190
|
+
// 側面: 投影して時計回り (面積が負) のものだけが手前を向く
|
|
191
|
+
for (let i = 0; i < n; i++) {
|
|
192
|
+
const j = (i + 1) % n;
|
|
193
|
+
const quad: Array<[number, number]> = [
|
|
194
|
+
proj(pr.poly[i]!, pr.top[i]!),
|
|
195
|
+
proj(pr.poly[j]!, pr.top[j]!),
|
|
196
|
+
proj(pr.poly[j]!, pr.bottom[j]!),
|
|
197
|
+
proj(pr.poly[i]!, pr.bottom[i]!),
|
|
198
|
+
];
|
|
199
|
+
if (signedArea(quad) <= 0) continue;
|
|
200
|
+
// 面の向きで陰影を変える (東西面と南北面)
|
|
201
|
+
const dx = pr.poly[j]!.x - pr.poly[i]!.x;
|
|
202
|
+
const dy = pr.poly[j]!.y - pr.poly[i]!.y;
|
|
203
|
+
out.push(face(quad, pr.fill, Math.abs(dx) > Math.abs(dy) ? 0.82 : 0.68));
|
|
204
|
+
}
|
|
205
|
+
const top = pr.poly.map((p, i) => proj(p, pr.top[i]!));
|
|
206
|
+
out.push(face(top, pr.fill, 1));
|
|
207
|
+
}
|
|
208
|
+
out.push(
|
|
209
|
+
`<text x="${M - 24}" y="${H - 12}" font-size="11" fill="${INK}">${esc(model.name ?? "無題")} — 軸測 (${dir}から)</text>`,
|
|
210
|
+
`<text x="${W - M + 24}" y="${H - 12}" text-anchor="end" font-size="8.5" fill="#a49b8a">koyu — 空間から生成 (床・屋根・壁・柱・縦動線)</text>`,
|
|
211
|
+
"</svg>",
|
|
212
|
+
);
|
|
213
|
+
return out.join("\n") + "\n";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** レベルの階高 (次のレベルまで)。最上階は天井高+slabで近似 */
|
|
217
|
+
function pitchOf(model: Model, level: string): number {
|
|
218
|
+
const l = model.levels[level]!;
|
|
219
|
+
const up = Object.values(model.levels)
|
|
220
|
+
.filter((o) => o.z > l.z)
|
|
221
|
+
.sort((a, b) => a.z - b.z)[0];
|
|
222
|
+
return up ? up.z - l.z : (l.h ?? 2400) + (l.slab ?? 0);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** 壁芯線分を厚みのある四角形へ (斜めの線分もそのまま扱える) */
|
|
226
|
+
function thicken(seg: Segment, t: number): Pt[] {
|
|
227
|
+
const dx = seg.x2 - seg.x1;
|
|
228
|
+
const dy = seg.y2 - seg.y1;
|
|
229
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
230
|
+
const nx = (-dy / len) * (t / 2);
|
|
231
|
+
const ny = (dx / len) * (t / 2);
|
|
232
|
+
return [
|
|
233
|
+
{ x: seg.x1 + nx, y: seg.y1 + ny },
|
|
234
|
+
{ x: seg.x2 + nx, y: seg.y2 + ny },
|
|
235
|
+
{ x: seg.x2 - nx, y: seg.y2 - ny },
|
|
236
|
+
{ x: seg.x1 - nx, y: seg.y1 - ny },
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function signedArea(ring: Array<[number, number]>): number {
|
|
241
|
+
let a = 0;
|
|
242
|
+
for (let i = 0; i < ring.length; i++) {
|
|
243
|
+
const p = ring[i]!;
|
|
244
|
+
const q = ring[(i + 1) % ring.length]!;
|
|
245
|
+
a += p[0] * q[1] - q[0] * p[1];
|
|
246
|
+
}
|
|
247
|
+
return a / 2;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** 面の向きによる陰影 */
|
|
251
|
+
function tint(hex: string, k: number): string {
|
|
252
|
+
const n = parseInt(hex.slice(1), 16);
|
|
253
|
+
const ch = [n >> 16, (n >> 8) & 255, n & 255].map((v) => Math.round(Math.min(255, v * k)));
|
|
254
|
+
return `#${ch.map((v) => v.toString(16).padStart(2, "0")).join("")}`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const r2 = (v: number): number => Math.round(v * 100) / 100;
|
|
258
|
+
const esc = (s: string): string => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|