@kensnzk/koyu 0.11.0 → 0.14.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 +216 -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 +86 -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/twin/L1.muro +139 -0
- package/examples/twin/L5.muro +133 -0
- package/examples/twin/assets.muro +19 -0
- package/examples/twin/basement.muro +48 -0
- package/examples/twin/core.muro +75 -0
- package/examples/twin/hotel.muro +129 -0
- package/examples/twin/main.muro +96 -0
- package/examples/twin/office.muro +104 -0
- package/examples/twin/podium.muro +120 -0
- package/examples/twin/residence.muro +131 -0
- package/examples/twin/site.muro +29 -0
- package/examples/two-rooms.canonical.json +26 -2
- package/examples/two-rooms.muro +6 -3
- package/package.json +3 -2
- package/src/axo.ts +263 -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/src/graph.ts
CHANGED
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
// 変換なしにそのままグラフへの問いになる。
|
|
4
4
|
// 空間の領域は矩形の合併 (L字など)。壁は合併の外周と共有辺から導出される。
|
|
5
5
|
|
|
6
|
-
import type { Boundary, Edge, Model, Opening, Rect, Space } from "./model.js";
|
|
7
|
-
import { srcRef } from "./model.js";
|
|
6
|
+
import type { Boundary, Edge, Model, Opening, Pt, Rect, Space } from "./model.js";
|
|
7
|
+
import { rectToPoly, srcRef } from "./model.js";
|
|
8
|
+
import * as poly from "./poly.js";
|
|
8
9
|
|
|
9
|
-
/** 壁芯線分 (mm)。水平なら y1===y2、垂直なら x1===x2
|
|
10
|
+
/** 壁芯線分 (mm)。水平なら y1===y2、垂直なら x1===x2。
|
|
11
|
+
* 描かれた線 (ADR-0022) は斜めになりうる — その場合 diagonal が立つ */
|
|
10
12
|
export interface Segment {
|
|
11
13
|
x1: number;
|
|
12
14
|
y1: number;
|
|
13
15
|
x2: number;
|
|
14
16
|
y2: number;
|
|
15
17
|
horizontal: boolean;
|
|
18
|
+
/** 軸に平行でない (描かれた線) */
|
|
19
|
+
diagonal?: boolean;
|
|
16
20
|
/** boundary.a 側 (領域を持つ側) の矩形から見た辺 */
|
|
17
21
|
edgeOfA?: Edge;
|
|
18
22
|
}
|
|
@@ -46,36 +50,96 @@ export function sharedSegment(a: Rect, b: Rect): Segment | undefined {
|
|
|
46
50
|
return undefined;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
/**
|
|
54
|
+
* 凸片の軸平行な辺 (向きから N/E/S/W を読む)。頂点列は反時計回りなので、
|
|
55
|
+
* +x へ進む辺が南、+y が東、-x が北、-y が西の面になる。
|
|
56
|
+
* 斜めの辺は返さない — それは描かれた線であり、自分の境界が実現を持っている
|
|
57
|
+
*/
|
|
58
|
+
function polyEdges(poly: Pt[]): Array<{ edge: Edge; fixed: number; lo: number; hi: number }> {
|
|
59
|
+
const out: Array<{ edge: Edge; fixed: number; lo: number; hi: number }> = [];
|
|
60
|
+
for (let i = 0; i < poly.length; i++) {
|
|
61
|
+
const p = poly[i]!;
|
|
62
|
+
const q = poly[(i + 1) % poly.length]!;
|
|
63
|
+
const dx = q.x - p.x;
|
|
64
|
+
const dy = q.y - p.y;
|
|
65
|
+
if (Math.abs(dy) < EPS && Math.abs(dx) > EPS) {
|
|
66
|
+
out.push({
|
|
67
|
+
edge: dx > 0 ? "S" : "N",
|
|
68
|
+
fixed: p.y,
|
|
69
|
+
lo: Math.min(p.x, q.x),
|
|
70
|
+
hi: Math.max(p.x, q.x),
|
|
71
|
+
});
|
|
72
|
+
} else if (Math.abs(dx) < EPS && Math.abs(dy) > EPS) {
|
|
73
|
+
out.push({
|
|
74
|
+
edge: dy > 0 ? "E" : "W",
|
|
75
|
+
fixed: p.x,
|
|
76
|
+
lo: Math.min(p.y, q.y),
|
|
77
|
+
hi: Math.max(p.y, q.y),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const FACING: Record<Edge, Edge> = { N: "S", S: "N", E: "W", W: "E" };
|
|
85
|
+
|
|
86
|
+
/** 凸片の外周のうち、他の空間の凸片と向かい合っていない区間 (= 外部に面する壁) */
|
|
87
|
+
function pieceOutline(pieces: Pt[][], others: Pt[][]): Segment[] {
|
|
88
|
+
const otherEdges = others.flatMap(polyEdges);
|
|
89
|
+
const segs: Segment[] = [];
|
|
90
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
91
|
+
const siblings = pieces.filter((_, k) => k !== i).flatMap(polyEdges);
|
|
92
|
+
for (const e of polyEdges(pieces[i]!)) {
|
|
93
|
+
let intervals: Array<[number, number]> = [[e.lo, e.hi]];
|
|
94
|
+
for (const o of [...otherEdges, ...siblings]) {
|
|
95
|
+
if (o.edge !== FACING[e.edge]) continue;
|
|
96
|
+
if (Math.abs(o.fixed - e.fixed) > EPS) continue;
|
|
97
|
+
intervals = intervals.flatMap(([s, t]) => {
|
|
98
|
+
const cs = Math.max(s, o.lo);
|
|
99
|
+
const ce = Math.min(t, o.hi);
|
|
100
|
+
if (ce - cs <= EPS) return [[s, t] as [number, number]];
|
|
101
|
+
const out: Array<[number, number]> = [];
|
|
102
|
+
if (cs - s > EPS) out.push([s, cs]);
|
|
103
|
+
if (t - ce > EPS) out.push([ce, t]);
|
|
104
|
+
return out;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const horizontal = e.edge === "N" || e.edge === "S";
|
|
108
|
+
for (const [s, t] of intervals) {
|
|
109
|
+
segs.push(
|
|
110
|
+
horizontal
|
|
111
|
+
? { x1: s, y1: e.fixed, x2: t, y2: e.fixed, horizontal: true, edgeOfA: e.edge }
|
|
112
|
+
: { x1: e.fixed, y1: s, x2: e.fixed, y2: t, horizontal: false, edgeOfA: e.edge },
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return segs;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 二つの領域 (凸片の集合) が共有する軸平行な辺。
|
|
122
|
+
* `sharedSegment` の矩形版を凸片へ広げたもので、切られた形にも正しい。
|
|
123
|
+
* 斜めの辺は返さない — それは描かれた線であり、自分の境界が実現を持っている
|
|
124
|
+
*/
|
|
125
|
+
function sharedFromPieces(A: Pt[][], B: Pt[][]): Segment[] {
|
|
126
|
+
const eb = B.flatMap(polyEdges);
|
|
127
|
+
const out: Segment[] = [];
|
|
128
|
+
for (const ea of A.flatMap(polyEdges)) {
|
|
129
|
+
for (const o of eb) {
|
|
130
|
+
if (o.edge !== FACING[ea.edge]) continue;
|
|
131
|
+
if (Math.abs(o.fixed - ea.fixed) > EPS) continue;
|
|
132
|
+
const lo = Math.max(ea.lo, o.lo);
|
|
133
|
+
const hi = Math.min(ea.hi, o.hi);
|
|
134
|
+
if (hi - lo <= EPS) continue;
|
|
135
|
+
out.push(
|
|
136
|
+
ea.edge === "N" || ea.edge === "S"
|
|
137
|
+
? { x1: lo, y1: ea.fixed, x2: hi, y2: ea.fixed, horizontal: true, edgeOfA: ea.edge }
|
|
138
|
+
: { x1: ea.fixed, y1: lo, x2: ea.fixed, y2: hi, horizontal: false, edgeOfA: ea.edge },
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
79
143
|
}
|
|
80
144
|
|
|
81
145
|
/** 共線で連続する線分をまとめる (L字の合併外周を一本の壁にする) */
|
|
@@ -126,7 +190,8 @@ export function deriveDefaultBoundaries(model: Model): void {
|
|
|
126
190
|
if (a.level !== b.level) continue;
|
|
127
191
|
const key = [a.path, b.path].sort().join("|");
|
|
128
192
|
if (declared.has(key)) continue;
|
|
129
|
-
|
|
193
|
+
// 接触は**導出された形**で見る — 線で接触が消えた組に既定の壁を作らない
|
|
194
|
+
if (sharedFromPieces(piecesOf(a), piecesOf(b)).length === 0) continue;
|
|
130
195
|
model.boundaries.push({
|
|
131
196
|
a: a.path,
|
|
132
197
|
b: b.path,
|
|
@@ -142,6 +207,99 @@ export function deriveDefaultBoundaries(model: Model): void {
|
|
|
142
207
|
}
|
|
143
208
|
}
|
|
144
209
|
|
|
210
|
+
/**
|
|
211
|
+
* 描かれた線による領域の切り分け (ADR-0022)。
|
|
212
|
+
*
|
|
213
|
+
* 空間の `rects` は**書かれた割付** (セル) であって形ではない。形は凸片 `pieces` として
|
|
214
|
+
* ここで導かれる — 既定は矩形そのまま、境界に線が描かれていればその半平面で切り直す。
|
|
215
|
+
* 切り直しは「二空間の割付の合併を、線の両側へ分け直す」操作なので、
|
|
216
|
+
* 一方が失う三角形をもう一方が得る (合計面積は保存される)。
|
|
217
|
+
*
|
|
218
|
+
* 線の及ぶ範囲は**書かれた区間の外接矩形**に限る。無限直線として全体を切ると、
|
|
219
|
+
* 離れた翼まで巻き添えにするため。冪等ではないので parse の出口で一度だけ呼ぶ。
|
|
220
|
+
*/
|
|
221
|
+
export function derivePieces(model: Model): void {
|
|
222
|
+
for (const s of model.spaces.values()) s.pieces = s.rects.map(rectToPoly);
|
|
223
|
+
// 線は宣言順に効く。derivePieces は parse の出口で一度だけ呼ぶ (冪等ではない)
|
|
224
|
+
|
|
225
|
+
for (const b of model.boundaries) {
|
|
226
|
+
if (!b.drawn) continue;
|
|
227
|
+
const sa = model.spaces.get(b.a);
|
|
228
|
+
const sb = model.spaces.get(b.b);
|
|
229
|
+
if (!sa || !sb) continue;
|
|
230
|
+
const cut = drawnCut(sa, sb, b.drawn.a, b.drawn.b);
|
|
231
|
+
if (!cut) continue;
|
|
232
|
+
|
|
233
|
+
if (cut.solo) {
|
|
234
|
+
// 外皮を切る線 — 持つ側だけが窓の中で自分の側へ切り落とされる。相手は面積を得ない
|
|
235
|
+
const s = cut.solo;
|
|
236
|
+
const { inside, outside } = poly.splitByRect(s.pieces, cut.window);
|
|
237
|
+
s.pieces = [
|
|
238
|
+
...outside,
|
|
239
|
+
...inside.map((p) => poly.clipHalf(p, b.drawn!.a, b.drawn!.b, cut.sideA > 0)).filter((p) => p.length > 0),
|
|
240
|
+
];
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 二空間の分け直し — 窓の中の割付を合併し、線の両側へ分け直す (合計面積は保存される)
|
|
245
|
+
const splitA = poly.splitByRect(sa.pieces, cut.window);
|
|
246
|
+
const splitB = poly.splitByRect(sb.pieces, cut.window);
|
|
247
|
+
const pool = [...splitA.inside, ...splitB.inside];
|
|
248
|
+
if (pool.length === 0) continue;
|
|
249
|
+
sa.pieces = [
|
|
250
|
+
...splitA.outside,
|
|
251
|
+
...pool.map((p) => poly.clipHalf(p, b.drawn!.a, b.drawn!.b, cut.sideA > 0)).filter((p) => p.length > 0),
|
|
252
|
+
];
|
|
253
|
+
sb.pieces = [
|
|
254
|
+
...splitB.outside,
|
|
255
|
+
...pool.map((p) => poly.clipHalf(p, b.drawn!.a, b.drawn!.b, cut.sideA < 0)).filter((p) => p.length > 0),
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 描かれた線の切り方を一度に決める — 窓・残す側・片側かどうか (ADR-0022 / ADR-0027)。
|
|
262
|
+
*
|
|
263
|
+
* **窓と側は必ず一緒に決める。**別々に決めていたために、側は空間の全割付を無限直線で
|
|
264
|
+
* 測るのに切るのは線の近傍だけ、という母集団のずれが生まれ、線から遠い翼が符号を
|
|
265
|
+
* 支配して、残すつもりだった側が黙って切り落とされた (check は緑のまま)。
|
|
266
|
+
* check の LIN01/LIN03 もこの同じ関数を通す — 判定と操作が食い違わないために。
|
|
267
|
+
*/
|
|
268
|
+
export function drawnCut(
|
|
269
|
+
sa: Space,
|
|
270
|
+
sb: Space,
|
|
271
|
+
a: Pt,
|
|
272
|
+
b: Pt,
|
|
273
|
+
): { window: Rect; sideA: number; solo?: Space } | undefined {
|
|
274
|
+
const ba = poly.boundsOf(sa.pieces);
|
|
275
|
+
const bb = poly.boundsOf(sb.pieces);
|
|
276
|
+
// 片側が領域を持たない (外部) — 外皮を切る線
|
|
277
|
+
if (!ba || !bb) {
|
|
278
|
+
const solo = ba ? sa : bb ? sb : undefined;
|
|
279
|
+
const sb2 = ba ?? bb;
|
|
280
|
+
if (!solo || !sb2) return undefined;
|
|
281
|
+
const w = poly.lineWindow(a, b, sb2);
|
|
282
|
+
if (!poly.validWindow(w)) return undefined;
|
|
283
|
+
const side = poly.sideOfTouching(solo.pieces, w, a, b);
|
|
284
|
+
if (side === 0) return undefined; // 窓の中でちょうど二等分 — 残す側が決まらない (LIN01)
|
|
285
|
+
return { window: w, sideA: solo === sa ? side : -side, solo };
|
|
286
|
+
}
|
|
287
|
+
const w = poly.lineWindow(a, b, ba, bb);
|
|
288
|
+
if (!poly.validWindow(w)) return undefined;
|
|
289
|
+
let ia = poly.sideOfTouching(sa.pieces, w, a, b);
|
|
290
|
+
let ib = poly.sideOfTouching(sb.pieces, w, a, b);
|
|
291
|
+
if (ia === 0 && ib === 0) return undefined; // どちらも偏りなし — 分離が決まらない (LIN01)
|
|
292
|
+
if (ia === 0) ia = -ib;
|
|
293
|
+
if (ib === 0) ib = -ia;
|
|
294
|
+
if (ia === ib) return undefined; // 同じ側 — 分離していない (LIN01)
|
|
295
|
+
return { window: w, sideA: ia };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
145
303
|
/** 境界の壁芯線分を導く。壁の位置は空間の割付から生成される — 壁を置く操作は存在しない */
|
|
146
304
|
export function segmentsFor(model: Model, b: Boundary): Segment[] {
|
|
147
305
|
const sa = model.spaces.get(b.a);
|
|
@@ -151,43 +309,181 @@ export function segmentsFor(model: Model, b: Boundary): Segment[] {
|
|
|
151
309
|
// 垂直境界 (stair/shaft/void/暗黙のslab) は壁線分を持たない
|
|
152
310
|
if (b.kind === "stair" || b.kind === "shaft" || b.kind === "void") return [];
|
|
153
311
|
|
|
312
|
+
// 描かれた線 (ADR-0022): 隣接からの導出ではなく、書かれた線がそのまま境界の実現になる。
|
|
313
|
+
// ただし**一本の設計線は複数の境界に共有されうる** — 貫通通路の壁は、その前を通る
|
|
314
|
+
// 区画の数だけ境界を持つ。この境界が実現するのは、線の両側がちょうど a と b に
|
|
315
|
+
// なっている区間だけであり、線の全長ではない
|
|
316
|
+
if (b.drawn) return drawnShare(model, sa, sb, b.drawn.a, b.drawn.b);
|
|
317
|
+
|
|
154
318
|
let segs: Segment[] = [];
|
|
155
319
|
const aHas = sa.rects.length > 0;
|
|
156
320
|
const bHas = sb.rects.length > 0;
|
|
157
321
|
|
|
158
322
|
if (aHas && bHas) {
|
|
159
323
|
if (sa.level !== sb.level) return []; // 異なるレベル間に壁は立たない
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (s) segs.push(s);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
324
|
+
// 共有辺も**導出された領域** (pieces) から取る。割付から取ると、
|
|
325
|
+
// 描かれた線で切り落とした側にまで壁が立つ (隅切りの外へ壁が飛び出す)
|
|
326
|
+
segs.push(...sharedFromPieces(piecesOf(sa), piecesOf(sb)));
|
|
166
327
|
} else if (aHas || bHas) {
|
|
167
|
-
// 片側が領域を持たない (外部など):
|
|
328
|
+
// 片側が領域を持たない (外部など): 導出された領域の外周から、
|
|
329
|
+
// 同レベルで向かい合う他室の区間を除いた残り。**割付ではなく形の縁を辿る** —
|
|
330
|
+
// 描かれた線で切り落とされた側には壁が立たない (ADR-0022)
|
|
168
331
|
const roomSpace = aHas ? sa : sb;
|
|
169
|
-
const others:
|
|
332
|
+
const others: Pt[][] = [];
|
|
170
333
|
for (const s of model.spaces.values()) {
|
|
171
334
|
if (s === sa || s === sb) continue;
|
|
172
335
|
if (s.level !== roomSpace.level) continue;
|
|
173
|
-
others.push(...s
|
|
174
|
-
}
|
|
175
|
-
for (let ri = 0; ri < roomSpace.rects.length; ri++) {
|
|
176
|
-
const room = roomSpace.rects[ri]!;
|
|
177
|
-
const siblings = roomSpace.rects.filter((_, i) => i !== ri);
|
|
178
|
-
const blockers = [...others, ...siblings];
|
|
179
|
-
for (const e of ["N", "E", "S", "W"] as const) {
|
|
180
|
-
segs.push(...rectPerimeterRemainder(room, e, blockers));
|
|
181
|
-
}
|
|
336
|
+
others.push(...piecesOf(s));
|
|
182
337
|
}
|
|
338
|
+
segs.push(...pieceOutline(piecesOf(roomSpace), others));
|
|
183
339
|
}
|
|
184
340
|
segs = mergeCollinear(segs);
|
|
185
341
|
if (b.edge) segs = segs.filter((s) => s.edgeOfA === b.edge);
|
|
186
342
|
return segs;
|
|
187
343
|
}
|
|
188
344
|
|
|
345
|
+
/**
|
|
346
|
+
* 空間の外周のうち、**何にも面していない**区間 (ADR-0025)。
|
|
347
|
+
* 他の空間とも、宣言された外部境界とも向かい合っていない縁 — 外皮の穴である。
|
|
348
|
+
* 既定境界 (ADR-0014) は領域を持たない空間との間には導かれないので、
|
|
349
|
+
* 外部への境界の書き忘れは黙って壁の不在になる。これを言葉にするための導出。
|
|
350
|
+
*/
|
|
351
|
+
export function envelopeGaps(model: Model, s: Space): Segment[] {
|
|
352
|
+
if (s.rects.length === 0 || !s.level) return [];
|
|
353
|
+
const others: Pt[][] = [];
|
|
354
|
+
for (const o of model.spaces.values()) {
|
|
355
|
+
if (o === s || o.level !== s.level) continue;
|
|
356
|
+
others.push(...piecesOf(o));
|
|
357
|
+
}
|
|
358
|
+
let gaps = pieceOutline(piecesOf(s), others);
|
|
359
|
+
// 宣言された境界 (外部・斜めを含む) が覆う区間を引く
|
|
360
|
+
for (const b of model.boundaries) {
|
|
361
|
+
if (b.a !== s.path && b.b !== s.path) continue;
|
|
362
|
+
if (b.kind === "stair" || b.kind === "shaft" || b.kind === "void") continue;
|
|
363
|
+
for (const seg of segmentsFor(model, b)) {
|
|
364
|
+
gaps = gaps.flatMap((g) => subtractOverlap(g, seg));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return gaps.filter((g) => segmentLength(g) > 1);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** 軸平行の線分から、同一直線上で重なる区間を引く */
|
|
371
|
+
function subtractOverlap(g: Segment, o: Segment): Segment[] {
|
|
372
|
+
if (o.diagonal || g.horizontal !== o.horizontal) return [g];
|
|
373
|
+
const fixedG = g.horizontal ? g.y1 : g.x1;
|
|
374
|
+
const fixedO = o.horizontal ? o.y1 : o.x1;
|
|
375
|
+
if (Math.abs(fixedG - fixedO) > EPS) return [g];
|
|
376
|
+
const [gl, gh] = g.horizontal ? [g.x1, g.x2] : [g.y1, g.y2];
|
|
377
|
+
const [ol, oh] = o.horizontal
|
|
378
|
+
? [Math.min(o.x1, o.x2), Math.max(o.x1, o.x2)]
|
|
379
|
+
: [Math.min(o.y1, o.y2), Math.max(o.y1, o.y2)];
|
|
380
|
+
const cs = Math.max(gl, ol);
|
|
381
|
+
const ce = Math.min(gh, oh);
|
|
382
|
+
if (ce - cs <= EPS) return [g];
|
|
383
|
+
const parts: Array<[number, number]> = [];
|
|
384
|
+
if (cs - gl > EPS) parts.push([gl, cs]);
|
|
385
|
+
if (gh - ce > EPS) parts.push([ce, gh]);
|
|
386
|
+
return parts.map(([a, b]) =>
|
|
387
|
+
g.horizontal
|
|
388
|
+
? { ...g, x1: a, x2: b }
|
|
389
|
+
: { ...g, y1: a, y2: b },
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function piecesOf(s: Space): Pt[][] {
|
|
394
|
+
return s.pieces.length > 0 ? s.pieces : s.rects.map(rectToPoly);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** 線の左右へ少し離れた点。どちらの空間に属するかを見るための探り */
|
|
398
|
+
const PROBE = 5;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* 描かれた線のうち、この二空間が実際に向かい合っている区間だけを返す (ADR-0022)。
|
|
402
|
+
*
|
|
403
|
+
* 一本の設計線は複数の境界に共有される — 貫通通路の壁は、その前を通る区画の数だけ
|
|
404
|
+
* 境界を持つ。各境界が線の全長を実現すると、平面には同じ壁が何本も重なって現れる。
|
|
405
|
+
* 線を両空間の縁で切り、左右がちょうど a と b になっている区間だけを残す。
|
|
406
|
+
*/
|
|
407
|
+
function drawnShare(model: Model, sa: Space, sb: Space, p: Pt, q: Pt): Segment[] {
|
|
408
|
+
const dx = q.x - p.x;
|
|
409
|
+
const dy = q.y - p.y;
|
|
410
|
+
const len = Math.hypot(dx, dy);
|
|
411
|
+
if (len < EPS) return [];
|
|
412
|
+
const nx = -dy / len;
|
|
413
|
+
const ny = dx / len;
|
|
414
|
+
const A = piecesOf(sa);
|
|
415
|
+
const B = piecesOf(sb);
|
|
416
|
+
|
|
417
|
+
// 切り位置: 両空間の凸片の辺と線の交点
|
|
418
|
+
const cuts = new Set<number>([0, 1]);
|
|
419
|
+
for (const poly of [...A, ...B]) {
|
|
420
|
+
for (let i = 0; i < poly.length; i++) {
|
|
421
|
+
const t = lineHit(p, q, poly[i]!, poly[(i + 1) % poly.length]!);
|
|
422
|
+
if (t !== undefined && t > 1e-9 && t < 1 - 1e-9) cuts.add(t);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const ts = [...cuts].sort((x, y) => x - y);
|
|
426
|
+
|
|
427
|
+
const kept: Array<[number, number]> = [];
|
|
428
|
+
for (let i = 0; i + 1 < ts.length; i++) {
|
|
429
|
+
const m = (ts[i]! + ts[i + 1]!) / 2;
|
|
430
|
+
const cx = p.x + m * dx;
|
|
431
|
+
const cy = p.y + m * dy;
|
|
432
|
+
const left = { x: cx + nx * PROBE, y: cy + ny * PROBE };
|
|
433
|
+
const right = { x: cx - nx * PROBE, y: cy - ny * PROBE };
|
|
434
|
+
const inA = (pt: Pt) => A.some((g) => poly.pointIn(pt, g, 0));
|
|
435
|
+
const inB = (pt: Pt) => B.some((g) => poly.pointIn(pt, g, 0));
|
|
436
|
+
// 片側が領域を持たない (外部) 相手なら、持つ側が片側に居るだけで境界になる
|
|
437
|
+
const soloB = sb.rects.length === 0;
|
|
438
|
+
const soloA = sa.rects.length === 0;
|
|
439
|
+
const ok = soloB
|
|
440
|
+
? inA(left) !== inA(right)
|
|
441
|
+
: soloA
|
|
442
|
+
? inB(left) !== inB(right)
|
|
443
|
+
: (inA(left) && inB(right)) || (inB(left) && inA(right));
|
|
444
|
+
if (ok) kept.push([ts[i]!, ts[i + 1]!]);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// 連続する区間をまとめる
|
|
448
|
+
const out: Segment[] = [];
|
|
449
|
+
for (const [a0, a1] of kept) {
|
|
450
|
+
const last = out[out.length - 1];
|
|
451
|
+
const start = { x: p.x + a0 * dx, y: p.y + a0 * dy };
|
|
452
|
+
const end = { x: p.x + a1 * dx, y: p.y + a1 * dy };
|
|
453
|
+
if (last && Math.hypot(last.x2 - start.x, last.y2 - start.y) < EPS) {
|
|
454
|
+
last.x2 = end.x;
|
|
455
|
+
last.y2 = end.y;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const horizontal = Math.abs(dy) < 0.5;
|
|
459
|
+
const vertical = Math.abs(dx) < 0.5;
|
|
460
|
+
out.push({
|
|
461
|
+
x1: start.x,
|
|
462
|
+
y1: start.y,
|
|
463
|
+
x2: end.x,
|
|
464
|
+
y2: end.y,
|
|
465
|
+
horizontal,
|
|
466
|
+
...(horizontal || vertical ? {} : { diagonal: true as const }),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** 無限直線 p→q と線分 u→v の交点の、線側のパラメータ t (平行・範囲外は undefined) */
|
|
473
|
+
function lineHit(p: Pt, q: Pt, u: Pt, v: Pt): number | undefined {
|
|
474
|
+
const rx = q.x - p.x;
|
|
475
|
+
const ry = q.y - p.y;
|
|
476
|
+
const sx = v.x - u.x;
|
|
477
|
+
const sy = v.y - u.y;
|
|
478
|
+
const d = rx * sy - ry * sx;
|
|
479
|
+
if (Math.abs(d) < 1e-9) return undefined;
|
|
480
|
+
const t = ((u.x - p.x) * sy - (u.y - p.y) * sx) / d;
|
|
481
|
+
const w = ((u.x - p.x) * ry - (u.y - p.y) * rx) / d;
|
|
482
|
+
return w >= -1e-9 && w <= 1 + 1e-9 ? t : undefined;
|
|
483
|
+
}
|
|
484
|
+
|
|
189
485
|
export function segmentLength(s: Segment): number {
|
|
190
|
-
return
|
|
486
|
+
return Math.hypot(s.x2 - s.x1, s.y2 - s.y1);
|
|
191
487
|
}
|
|
192
488
|
|
|
193
489
|
/** 平面上の重なり (垂直隣接の導出に使う)。重ならなければ undefined */
|
|
@@ -229,11 +525,16 @@ export interface PlacedBand {
|
|
|
229
525
|
cy: number;
|
|
230
526
|
}
|
|
231
527
|
|
|
528
|
+
/** placeBand が出しうる診断コード (ADR-0016 の台帳の部分集合 — check の emit が型で受ける) */
|
|
529
|
+
export type BandCode =
|
|
530
|
+
| "OPN04" | "OPN05" | "OPN06" | "OPN07" | "OPN08"
|
|
531
|
+
| "SEG04" | "SEG05" | "SEG06" | "SEG07" | "SEG08";
|
|
532
|
+
|
|
232
533
|
/** 帯の配置失敗 — error は互換の完成文 (位置接頭辞つき)。code/line/message は診断契約 (ADR-0016) の材料 */
|
|
233
534
|
export interface BandError {
|
|
234
535
|
error: string;
|
|
235
536
|
/** 診断コード — 開口は OPN04〜08、seg は SEG04〜08 (呼び手のlabelで決まる) */
|
|
236
|
-
code:
|
|
537
|
+
code: BandCode;
|
|
237
538
|
line: number;
|
|
238
539
|
file?: string;
|
|
239
540
|
/** 位置接頭辞を除いた本文 */
|
|
@@ -248,9 +549,9 @@ export function placeBand(
|
|
|
248
549
|
label: string,
|
|
249
550
|
): PlacedBand | BandError {
|
|
250
551
|
// 配置失敗の診断: label が "seg" なら SEG系、開口 (door/window等) なら OPN系のコード
|
|
251
|
-
const fail = (n:
|
|
552
|
+
const fail = (n: "04" | "05" | "06" | "07" | "08", message: string): BandError => ({
|
|
252
553
|
error: `${srcRef(band.line, b.file)}: ${message}`,
|
|
253
|
-
code:
|
|
554
|
+
code: (label === "seg" ? `SEG${n}` : `OPN${n}`) as BandCode,
|
|
254
555
|
line: band.line,
|
|
255
556
|
...(b.file !== undefined ? { file: b.file } : {}),
|
|
256
557
|
message,
|
|
@@ -271,6 +572,13 @@ export function placeBand(
|
|
|
271
572
|
const half = band.w / 2;
|
|
272
573
|
let pos: number;
|
|
273
574
|
if (band.atAbs !== undefined) {
|
|
575
|
+
// 斜めの線分 (描かれた線) の上では、通り参照は一意に位置を定めない — 比率で書く
|
|
576
|
+
if (seg.diagonal) {
|
|
577
|
+
return fail(
|
|
578
|
+
"07",
|
|
579
|
+
`${label} の位置 ${band.atRef} は斜めの線分では使えません (at:0..1 の比率で書きます)`,
|
|
580
|
+
);
|
|
581
|
+
}
|
|
274
582
|
// 明示位置: 通り参照で置かれたものはクランプしない — はみ出しは言葉のエラーになる
|
|
275
583
|
const axisOk = seg.horizontal ? band.atAxis === "X" : band.atAxis === "Y";
|
|
276
584
|
if (!axisOk) {
|
|
@@ -296,10 +604,12 @@ export function placeBand(
|
|
|
296
604
|
} else {
|
|
297
605
|
pos = Math.min(Math.max(band.at * len, half), len - half);
|
|
298
606
|
}
|
|
607
|
+
// 線分上の位置はパラメトリックに取る — 軸平行でも斜めでも同じ一つの式
|
|
608
|
+
const f = len > 0 ? pos / len : 0;
|
|
299
609
|
return {
|
|
300
610
|
segment: seg,
|
|
301
|
-
cx: seg.
|
|
302
|
-
cy: seg.
|
|
611
|
+
cx: seg.x1 + f * (seg.x2 - seg.x1),
|
|
612
|
+
cy: seg.y1 + f * (seg.y2 - seg.y1),
|
|
303
613
|
};
|
|
304
614
|
}
|
|
305
615
|
|
package/src/index.ts
CHANGED
|
@@ -16,5 +16,29 @@ export {
|
|
|
16
16
|
type BoundaryChange,
|
|
17
17
|
} from "./diff.js";
|
|
18
18
|
export { daylight, type DaylightResult } from "./light.js";
|
|
19
|
+
export { slabs, type Slab, type SlabKind } from "./fabric.js";
|
|
20
|
+
export {
|
|
21
|
+
verticalRuns,
|
|
22
|
+
verticalRun,
|
|
23
|
+
runDecls,
|
|
24
|
+
runSolids,
|
|
25
|
+
runDrawsForLevel,
|
|
26
|
+
runIssues,
|
|
27
|
+
slopeText,
|
|
28
|
+
toWorld,
|
|
29
|
+
CUT_HEIGHT,
|
|
30
|
+
RUN_KEYS,
|
|
31
|
+
RUN_FORMS,
|
|
32
|
+
type RunDevice,
|
|
33
|
+
type RunForm,
|
|
34
|
+
type RunPart,
|
|
35
|
+
type VerticalRun,
|
|
36
|
+
type RunSolid,
|
|
37
|
+
type RunDraw,
|
|
38
|
+
type RunArrow,
|
|
39
|
+
type RunIssue,
|
|
40
|
+
type Seg2,
|
|
41
|
+
} from "./vertical.js";
|
|
19
42
|
export { siteReport, type SiteReport, type RoadFrontage } from "./site.js";
|
|
20
43
|
export { svgPlan, type PlanOptions } from "./plan.js";
|
|
44
|
+
export { svgAxo, type AxoOptions } from "./axo.js";
|
package/src/light.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// koyu — 採光の粗い判定 (法規検証の芽・第一号)
|
|
2
|
-
//
|
|
2
|
+
// 採光の対象と宣言された室について 窓面積/床面積 ≥ 1/7 を確かめる。
|
|
3
3
|
// 採光補正係数は掛けない甘い判定であり、基本計画の解像度に合わせた早期警報である。
|
|
4
|
-
//
|
|
4
|
+
// 対象は `daylight:1` を書いた空間だけ — 型からは推定しない (ADR-0020)。
|
|
5
5
|
|
|
6
6
|
import { areaM2, isCoveredAbove, isSemiOutdoor, type Model, type Space } from "./model.js";
|
|
7
7
|
|
|
8
|
-
const HABITABLE = new Set(["unit", "room", "ldk", "bedroom", "living"]);
|
|
9
|
-
|
|
10
8
|
/** 庇下・バルコニー下 (上に空間がある半屋外) 越しの窓の係数 — 縁側補正に倣う粗い値。
|
|
11
9
|
* 上が開いた半屋外 (庭・最上階バルコニー) 越しは 1.0 (ADR-0009) */
|
|
12
10
|
const COVERED_SEMI_FACTOR = 0.7;
|
|
@@ -28,9 +26,8 @@ export function daylight(model: Model): DaylightResult[] {
|
|
|
28
26
|
const out: DaylightResult[] = [];
|
|
29
27
|
for (const s of model.spaces.values()) {
|
|
30
28
|
if (s.rects.length === 0) continue;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!target) continue;
|
|
29
|
+
// 採光の対象は宣言である (ADR-0020) — 型は解釈しない。既定は対象外
|
|
30
|
+
if (s.attrs["daylight"] !== 1) continue;
|
|
34
31
|
const floor = areaM2(s)!;
|
|
35
32
|
let win = 0;
|
|
36
33
|
let missingH = false;
|
package/src/mcp.ts
CHANGED
|
@@ -10,12 +10,14 @@ import { mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from
|
|
|
10
10
|
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
11
11
|
import {
|
|
12
12
|
areaM2,
|
|
13
|
+
isIndoor,
|
|
13
14
|
daylight,
|
|
14
15
|
displayName,
|
|
15
16
|
doorsBetween,
|
|
16
17
|
effectiveUse,
|
|
17
18
|
isSemiOutdoor,
|
|
18
19
|
levelsSorted,
|
|
20
|
+
polygonAreaM2,
|
|
19
21
|
toCanonical,
|
|
20
22
|
zoneAreaM2,
|
|
21
23
|
type Model,
|
|
@@ -47,9 +49,7 @@ function assertInside(entryDir: string, targetDir: string): void {
|
|
|
47
49
|
|
|
48
50
|
function summarize(model: Model, file: string): unknown {
|
|
49
51
|
const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
|
|
50
|
-
const indoor = rooms.filter(
|
|
51
|
-
(s) => s.type !== "void" && s.type !== "exterior" && !isSemiOutdoor(model, s),
|
|
52
|
-
);
|
|
52
|
+
const indoor = rooms.filter((s) => isIndoor(model, s));
|
|
53
53
|
const semi = rooms.filter((s) => s.type !== "void" && isSemiOutdoor(model, s));
|
|
54
54
|
const byLevel: Record<string, { rooms: number; subtotalM2: number }> = {};
|
|
55
55
|
for (const lv of levelsSorted(model)) {
|
|
@@ -78,11 +78,18 @@ function summarize(model: Model, file: string): unknown {
|
|
|
78
78
|
})),
|
|
79
79
|
spaces: model.spaces.size,
|
|
80
80
|
boundaries: model.boundaries.length,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
// 敷地ゾーンに「専有床面積」の言葉は成り立たない — 敷地形状から導いた面積を返す
|
|
82
|
+
// (同じ敷地について 160 と 3854 の二つの数字が返る、という状態を作らない。ADR-0028)
|
|
83
|
+
zones: [...model.zones.values()].map((z) => {
|
|
84
|
+
const site = z.attrs["site"] === 1;
|
|
85
|
+
const poly = site ? model.polygons.get(z.path) : undefined;
|
|
86
|
+
return {
|
|
87
|
+
path: z.path,
|
|
88
|
+
...(typeof z.attrs["name"] === "string" ? { name: z.attrs["name"] } : {}),
|
|
89
|
+
...(site ? { site: true } : {}),
|
|
90
|
+
areaM2: poly ? polygonAreaM2(poly.points) : zoneAreaM2(model, z.path),
|
|
91
|
+
};
|
|
92
|
+
}),
|
|
86
93
|
assets: [...model.assets.values()].map((a) => ({ name: a.name, kind: a.kind, attrs: a.attrs })),
|
|
87
94
|
...(model.polygons.size
|
|
88
95
|
? { sitePolygons: [...model.polygons.keys()] }
|
|
@@ -233,7 +240,7 @@ const TOOLS: Record<string, Tool> = {
|
|
|
233
240
|
},
|
|
234
241
|
},
|
|
235
242
|
light: {
|
|
236
|
-
description: "採光の検査:
|
|
243
|
+
description: "採光の検査: daylight:1 を書いた室で窓面積/床面積 ≥ 1/7 (バルコニー・庇下は0.7掛け)",
|
|
237
244
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
238
245
|
run: (a) => {
|
|
239
246
|
const m = load(str(a.file, "file"));
|
|
@@ -320,7 +327,7 @@ function handle(msg: Json): void {
|
|
|
320
327
|
result(id, {
|
|
321
328
|
protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
|
|
322
329
|
capabilities: { tools: {} },
|
|
323
|
-
serverInfo: { name: "koyu", version: "0.
|
|
330
|
+
serverInfo: { name: "koyu", version: "0.14.0" },
|
|
324
331
|
instructions:
|
|
325
332
|
"空間一次の建築記述koyuのサーバー。model_summaryで建物を掴み、layersで原本 (.muroレイヤー群) を読み、" +
|
|
326
333
|
"write_layerで編集する。checkが一棟のビルドの門番 — エラーは出所レイヤー:行つきで返る。" +
|