@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/src/plan.ts
CHANGED
|
@@ -5,17 +5,26 @@
|
|
|
5
5
|
import { placeBand, placeOpening, segmentsFor, type Segment } from "./graph.js";
|
|
6
6
|
import {
|
|
7
7
|
areaM2,
|
|
8
|
+
columnsFor,
|
|
8
9
|
displayName,
|
|
10
|
+
regionOf,
|
|
9
11
|
isSemiOutdoor,
|
|
12
|
+
polygonAreaM2,
|
|
13
|
+
polyBounds,
|
|
14
|
+
rectToPoly,
|
|
10
15
|
type Boundary,
|
|
11
16
|
type Model,
|
|
12
17
|
type Opening,
|
|
18
|
+
type Pt,
|
|
13
19
|
} from "./model.js";
|
|
20
|
+
import { runDrawsForLevel, CUT_HEIGHT } from "./vertical.js";
|
|
14
21
|
|
|
15
22
|
export interface PlanOptions {
|
|
16
23
|
level?: string;
|
|
17
24
|
/** px per mm */
|
|
18
25
|
scale?: number;
|
|
26
|
+
/** 切断面の高さ mm (FLから) — 縦動線がどこで切れるかを決める */
|
|
27
|
+
cut?: number;
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
const WALL_DEFAULT_T = 100;
|
|
@@ -39,7 +48,10 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
39
48
|
const sitePolys = level === lowest ? [...model.polygons.values()] : [];
|
|
40
49
|
|
|
41
50
|
const allRects = rooms.flatMap((s) => s.rects);
|
|
42
|
-
const polyPts =
|
|
51
|
+
const polyPts = [
|
|
52
|
+
...sitePolys.flatMap((p) => p.points),
|
|
53
|
+
...rooms.flatMap((s) => s.pieces.flat()),
|
|
54
|
+
];
|
|
43
55
|
const minX = Math.min(...allRects.map((r) => r.x1), ...polyPts.map((p) => p.x));
|
|
44
56
|
const maxX = Math.max(...allRects.map((r) => r.x2), ...polyPts.map((p) => p.x));
|
|
45
57
|
const minY = Math.min(...allRects.map((r) => r.y1), ...polyPts.map((p) => p.y));
|
|
@@ -65,17 +77,21 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
65
77
|
);
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
// 空間の面 (
|
|
80
|
+
// 空間の面 — 導出された凸片 (ADR-0022)。描かれた線で切られていれば斜めの面になる。
|
|
81
|
+
// 同色・輪郭なしなのでL字も切られた形も一体に見える。
|
|
69
82
|
// 半屋外 (外部にopen/railで接する空間) は淡く塗り分け、屋外であることが図から読めるように
|
|
83
|
+
const path2d = (poly: Pt[]): string =>
|
|
84
|
+
poly.map((p, i) => `${i === 0 ? "M" : "L"} ${sx(p.x)} ${sy(p.y)}`).join(" ") + " Z";
|
|
70
85
|
for (const s of rooms) {
|
|
71
86
|
const isVoid = s.type === "void";
|
|
72
87
|
const semi = isSemiOutdoor(model, s);
|
|
73
|
-
for (const
|
|
88
|
+
for (const poly of regionOf(s)) {
|
|
74
89
|
parts.push(
|
|
75
|
-
`<
|
|
90
|
+
`<path d="${path2d(poly)}" fill="${isVoid ? PAPER : semi ? "#f8f5ec" : ROOM}"/>`,
|
|
76
91
|
);
|
|
77
92
|
if (isVoid) {
|
|
78
93
|
// 吹抜け: 破線の対角線 (作図慣習)
|
|
94
|
+
const r = polyBounds(poly);
|
|
79
95
|
parts.push(
|
|
80
96
|
`<line x1="${sx(r.x1)}" y1="${sy(r.y1)}" x2="${sx(r.x2)}" y2="${sy(r.y2)}" stroke="#b3ab9c" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
81
97
|
`<line x1="${sx(r.x1)}" y1="${sy(r.y2)}" x2="${sx(r.x2)}" y2="${sy(r.y1)}" stroke="#b3ab9c" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
@@ -203,11 +219,57 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
203
219
|
}
|
|
204
220
|
}
|
|
205
221
|
|
|
206
|
-
//
|
|
222
|
+
// 柱 (ADR-0023) — 位置はどこにも書かれていない。通り芯の交点と床の交わりから現れる
|
|
223
|
+
for (const c of columnsFor(model, level)) {
|
|
224
|
+
parts.push(
|
|
225
|
+
`<rect x="${sx(c.x - c.w / 2)}" y="${sy(c.y + c.d / 2)}" width="${c.w * scale}" height="${c.d * scale}" fill="${INK}"/>`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 縦動線 (ADR-0021) — そのレベルで切った姿。上る走りは切断線で切れ、
|
|
230
|
+
// その先には下りる走り (下階の走りを上から見たもの) が現れる。
|
|
231
|
+
// 階段が階ごとに違う顔をするのは、平面図が「切った断面」だという事実そのものである
|
|
232
|
+
for (const d of runDrawsForLevel(model, level, opts.cut ?? CUT_HEIGHT)) {
|
|
233
|
+
for (const g of d.outline) {
|
|
234
|
+
parts.push(
|
|
235
|
+
`<line x1="${sx(g.x1)}" y1="${sy(g.y1)}" x2="${sx(g.x2)}" y2="${sy(g.y2)}" stroke="${INK}" stroke-width="1.1"/>`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
for (const g of d.treads) {
|
|
239
|
+
parts.push(
|
|
240
|
+
`<line x1="${sx(g.x1)}" y1="${sy(g.y1)}" x2="${sx(g.x2)}" y2="${sy(g.y2)}" stroke="${INK}" stroke-width="0.7"/>`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
for (const g of d.breaks) {
|
|
244
|
+
parts.push(
|
|
245
|
+
`<line x1="${sx(g.x1)}" y1="${sy(g.y1)}" x2="${sx(g.x2)}" y2="${sy(g.y2)}" stroke="${INK}" stroke-width="1.4"/>`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
for (const a of d.arrows) {
|
|
249
|
+
const dx = a.x2 - a.x1;
|
|
250
|
+
const dy = a.y2 - a.y1;
|
|
251
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
252
|
+
const hx = (dx / len) * 420;
|
|
253
|
+
const hy = (dy / len) * 420;
|
|
254
|
+
const px = (-dy / len) * 200;
|
|
255
|
+
const py = (dx / len) * 200;
|
|
256
|
+
parts.push(
|
|
257
|
+
`<line x1="${sx(a.x1)}" y1="${sy(a.y1)}" x2="${sx(a.x2)}" y2="${sy(a.y2)}" stroke="${INK}" stroke-width="1"/>`,
|
|
258
|
+
`<path d="M ${sx(a.x2)} ${sy(a.y2)} L ${sx(a.x2 - hx + px)} ${sy(a.y2 - hy + py)} L ${sx(a.x2 - hx - px)} ${sy(a.y2 - hy - py)} Z" fill="${INK}"/>`,
|
|
259
|
+
`<text x="${sx(a.x1) + 4}" y="${sy(a.y1) + 4}" font-size="9" fill="${INK}">${a.label}</text>`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
for (const n of d.notes) {
|
|
263
|
+
parts.push(
|
|
264
|
+
`<text x="${sx(n.x)}" y="${sy(n.y) + 42}" text-anchor="middle" font-size="8" fill="#8a8171">${esc(n.text)}</text>`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 空間ラベル (最大の凸片の中心に置く)
|
|
207
270
|
for (const s of rooms) {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
)[0]!;
|
|
271
|
+
const poly = [...regionOf(s)].sort((a, b) => polygonAreaM2(b) - polygonAreaM2(a))[0]!;
|
|
272
|
+
const r = polyBounds(poly);
|
|
211
273
|
const cx = sx((r.x1 + r.x2) / 2);
|
|
212
274
|
const cy = sy((r.y1 + r.y2) / 2);
|
|
213
275
|
const sub =
|
|
@@ -233,9 +295,11 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
233
295
|
const lower = za < zb ? sa : sb;
|
|
234
296
|
const upper = za < zb ? sb : sa;
|
|
235
297
|
if (lower.level !== level) continue;
|
|
236
|
-
|
|
298
|
+
// 上階の**導出された形**を落とす — 割付で描くと、切られた吹抜けが切られる前の姿で出る
|
|
299
|
+
for (const poly of regionOf(upper)) {
|
|
300
|
+
const r = polyBounds(poly);
|
|
237
301
|
parts.push(
|
|
238
|
-
`<
|
|
302
|
+
`<path d="${path2d(poly)}" fill="none" stroke="#b3ab9c" stroke-width="0.8" stroke-dasharray="6 4"/>`,
|
|
239
303
|
`<text x="${sx((r.x1 + r.x2) / 2)}" y="${sy((r.y1 + r.y2) / 2) + 40}" text-anchor="middle" font-size="9" fill="#b3ab9c">上部吹抜け</text>`,
|
|
240
304
|
);
|
|
241
305
|
}
|
|
@@ -259,6 +323,22 @@ function wallRect(
|
|
|
259
323
|
sx: (x: number) => number,
|
|
260
324
|
sy: (y: number) => number,
|
|
261
325
|
): string {
|
|
326
|
+
if (seg.diagonal) {
|
|
327
|
+
// 斜めの壁 (描かれた線 — ADR-0022): 芯線に対して法線方向へ t/2 ずつ振り分けた四辺形
|
|
328
|
+
const dx = seg.x2 - seg.x1;
|
|
329
|
+
const dy = seg.y2 - seg.y1;
|
|
330
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
331
|
+
const nx = (-dy / len) * (t / 2);
|
|
332
|
+
const ny = (dx / len) * (t / 2);
|
|
333
|
+
const q: Array<[number, number]> = [
|
|
334
|
+
[seg.x1 + nx, seg.y1 + ny],
|
|
335
|
+
[seg.x2 + nx, seg.y2 + ny],
|
|
336
|
+
[seg.x2 - nx, seg.y2 - ny],
|
|
337
|
+
[seg.x1 - nx, seg.y1 - ny],
|
|
338
|
+
];
|
|
339
|
+
const d = q.map(([x, y], i) => `${i === 0 ? "M" : "L"} ${sx(x)} ${sy(y)}`).join(" ");
|
|
340
|
+
return `<path d="${d} Z" fill="${INK}"/>`;
|
|
341
|
+
}
|
|
262
342
|
if (seg.horizontal) {
|
|
263
343
|
const x = sx(seg.x1);
|
|
264
344
|
const y = sy(seg.y1 + t / 2);
|
|
@@ -280,6 +360,23 @@ function bandRect(
|
|
|
280
360
|
sy: (y: number) => number,
|
|
281
361
|
fill: string,
|
|
282
362
|
): string {
|
|
363
|
+
if (seg.diagonal) {
|
|
364
|
+
const dx = seg.x2 - seg.x1;
|
|
365
|
+
const dy = seg.y2 - seg.y1;
|
|
366
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
367
|
+
const ux = (dx / len) * (w / 2);
|
|
368
|
+
const uy = (dy / len) * (w / 2);
|
|
369
|
+
const nx = (-dy / len) * (t / 2);
|
|
370
|
+
const ny = (dx / len) * (t / 2);
|
|
371
|
+
const q: Array<[number, number]> = [
|
|
372
|
+
[cx - ux + nx, cy - uy + ny],
|
|
373
|
+
[cx + ux + nx, cy + uy + ny],
|
|
374
|
+
[cx + ux - nx, cy + uy - ny],
|
|
375
|
+
[cx - ux - nx, cy - uy - ny],
|
|
376
|
+
];
|
|
377
|
+
const d = q.map(([x, y], i) => `${i === 0 ? "M" : "L"} ${sx(x)} ${sy(y)}`).join(" ");
|
|
378
|
+
return `<path d="${d} Z" fill="${fill}"/>`;
|
|
379
|
+
}
|
|
283
380
|
if (seg.horizontal) {
|
|
284
381
|
return `<rect x="${sx(cx - w / 2)}" y="${sy(cy + t / 2)}" width="${w * scale}" height="${t * scale}" fill="${fill}"/>`;
|
|
285
382
|
}
|
|
@@ -315,7 +412,19 @@ function doorSwing(
|
|
|
315
412
|
let hinge: { x: number; y: number };
|
|
316
413
|
let along: { x: number; y: number };
|
|
317
414
|
let inward: { x: number; y: number };
|
|
318
|
-
if (seg.
|
|
415
|
+
if (seg.diagonal) {
|
|
416
|
+
// 斜めの線分では吊元は始端側に固定し (hingeのN/E/S/Wは軸の言葉なので使えない)、
|
|
417
|
+
// 開く側は法線のうち開く空間の重心へ向く方をとる
|
|
418
|
+
const dx = seg.x2 - seg.x1;
|
|
419
|
+
const dy = seg.y2 - seg.y1;
|
|
420
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
421
|
+
along = { x: dx / len, y: dy / len };
|
|
422
|
+
const n = { x: -along.y, y: along.x };
|
|
423
|
+
const toC = { x: c.x - cx, y: c.y - cy };
|
|
424
|
+
const sign = n.x * toC.x + n.y * toC.y >= 0 ? 1 : -1;
|
|
425
|
+
inward = { x: n.x * sign, y: n.y * sign };
|
|
426
|
+
hinge = { x: cx - along.x * (o.w / 2), y: cy - along.y * (o.w / 2) };
|
|
427
|
+
} else if (seg.horizontal) {
|
|
319
428
|
const fromEast = o.hinge === "E";
|
|
320
429
|
hinge = { x: fromEast ? cx + o.w / 2 : cx - o.w / 2, y: cy };
|
|
321
430
|
along = { x: fromEast ? -1 : 1, y: 0 };
|
package/src/poly.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// koyu — 凸片の幾何 (ADR-0027)
|
|
2
|
+
//
|
|
3
|
+
// 空間の形は**凸片の集合** (`Pt[][]`) である (ADR-0022)。矩形はその入口の綴りにすぎない。
|
|
4
|
+
// この層が存在しなかったあいだ、面積・被覆・切り分けの計算が model / graph / fabric /
|
|
5
|
+
// check / axo に散り、シューレース公式が三通り、矩形で切る処理が三通りあった。そして
|
|
6
|
+
// **「判定に使う集合」と「操作する集合」がずれる**という一つの誤りが、七箇所で別々に
|
|
7
|
+
// 現れた — 離れた翼が隅切りの向きを裏返して室が消え、上階を切ると下階の屋根が消え、
|
|
8
|
+
// 軸平行の線が「何も切っていない」と誤報された。どれも check が緑のまま起きた。
|
|
9
|
+
//
|
|
10
|
+
// ここに集めるのは、その規律である。**窓 (window) を渡さない操作を作らない** —
|
|
11
|
+
// どの範囲で測り、どの範囲を切るのかを、呼び手が必ず一緒に言う。
|
|
12
|
+
|
|
13
|
+
import type { Pt, Rect } from "./model.js";
|
|
14
|
+
|
|
15
|
+
/** 幾何の許容 mm。座標はmmの整数が基本なので、これより細かい差は同一とみなす */
|
|
16
|
+
export const EPS = 0.5;
|
|
17
|
+
/** 面積の退化の閾値 mm² — 1mm×1mm 未満の片は捨てる */
|
|
18
|
+
const AREA_EPS = 1;
|
|
19
|
+
|
|
20
|
+
// ---- 基本 ----
|
|
21
|
+
|
|
22
|
+
/** 符号つき面積 mm² (反時計回りが正)。**シューレースはここにしか無い** */
|
|
23
|
+
export function signedArea(poly: Pt[]): number {
|
|
24
|
+
let s = 0;
|
|
25
|
+
for (let i = 0; i < poly.length; i++) {
|
|
26
|
+
const a = poly[i]!;
|
|
27
|
+
const b = poly[(i + 1) % poly.length]!;
|
|
28
|
+
s += a.x * b.y - b.x * a.y;
|
|
29
|
+
}
|
|
30
|
+
return s / 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 面積 mm² */
|
|
34
|
+
export const area = (poly: Pt[]): number => Math.abs(signedArea(poly));
|
|
35
|
+
|
|
36
|
+
/** 凸片の集合の面積 mm² (片同士は重ならない前提 — check の GEO01/GEO02 が保証する) */
|
|
37
|
+
export const areaOf = (pieces: Pt[][]): number => pieces.reduce((a, p) => a + area(p), 0);
|
|
38
|
+
|
|
39
|
+
export function rectToPoly(r: Rect): Pt[] {
|
|
40
|
+
return [
|
|
41
|
+
{ x: r.x1, y: r.y1 },
|
|
42
|
+
{ x: r.x2, y: r.y1 },
|
|
43
|
+
{ x: r.x2, y: r.y2 },
|
|
44
|
+
{ x: r.x1, y: r.y2 },
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function bounds(poly: Pt[]): Rect {
|
|
49
|
+
return {
|
|
50
|
+
x1: Math.min(...poly.map((p) => p.x)),
|
|
51
|
+
x2: Math.max(...poly.map((p) => p.x)),
|
|
52
|
+
y1: Math.min(...poly.map((p) => p.y)),
|
|
53
|
+
y2: Math.max(...poly.map((p) => p.y)),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 凸片の集合の外接矩形 (空なら undefined) */
|
|
58
|
+
export function boundsOf(pieces: Pt[][]): Rect | undefined {
|
|
59
|
+
const all = pieces.flat();
|
|
60
|
+
return all.length ? bounds(all) : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---- 切る ----
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 凸多角形を半平面で切る (Sutherland–Hodgman)。
|
|
67
|
+
* 半平面は有向線分 a→b の左側 (外積>0)。**面積が退化した結果は空として返す** —
|
|
68
|
+
* 以前は 1e-9 m² を閾値にしていたので mm² では 1e-3 mm² となり、
|
|
69
|
+
* 実質どんな破片も生き残っていた。
|
|
70
|
+
*/
|
|
71
|
+
export function clipHalf(poly: Pt[], a: Pt, b: Pt, keepLeft: boolean): Pt[] {
|
|
72
|
+
const side = (p: Pt): number => {
|
|
73
|
+
const v = (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);
|
|
74
|
+
return keepLeft ? v : -v;
|
|
75
|
+
};
|
|
76
|
+
const out: Pt[] = [];
|
|
77
|
+
for (let i = 0; i < poly.length; i++) {
|
|
78
|
+
const p = poly[i]!;
|
|
79
|
+
const q = poly[(i + 1) % poly.length]!;
|
|
80
|
+
const sp = side(p);
|
|
81
|
+
const sq = side(q);
|
|
82
|
+
if (sp >= -1e-6) out.push(p);
|
|
83
|
+
if ((sp > 1e-6 && sq < -1e-6) || (sp < -1e-6 && sq > 1e-6)) {
|
|
84
|
+
const t = sp / (sp - sq);
|
|
85
|
+
out.push({ x: p.x + t * (q.x - p.x), y: p.y + t * (q.y - p.y) });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out.length >= 3 && area(out) > AREA_EPS ? out : [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 軸平行の窓の内と外へ割る (どちらも凸片のまま) */
|
|
92
|
+
export function splitByRect(pieces: Pt[][], w: Rect): { inside: Pt[][]; outside: Pt[][] } {
|
|
93
|
+
const edges: Array<[Pt, Pt]> = [
|
|
94
|
+
[{ x: w.x1, y: w.y1 }, { x: w.x2, y: w.y1 }],
|
|
95
|
+
[{ x: w.x2, y: w.y1 }, { x: w.x2, y: w.y2 }],
|
|
96
|
+
[{ x: w.x2, y: w.y2 }, { x: w.x1, y: w.y2 }],
|
|
97
|
+
[{ x: w.x1, y: w.y2 }, { x: w.x1, y: w.y1 }],
|
|
98
|
+
];
|
|
99
|
+
const outside: Pt[][] = [];
|
|
100
|
+
let inside = pieces;
|
|
101
|
+
for (const [u, v] of edges) {
|
|
102
|
+
const next: Pt[][] = [];
|
|
103
|
+
for (const p of inside) {
|
|
104
|
+
const keep = clipHalf(p, u, v, true);
|
|
105
|
+
const drop = clipHalf(p, u, v, false);
|
|
106
|
+
if (keep.length) next.push(keep);
|
|
107
|
+
if (drop.length) outside.push(drop);
|
|
108
|
+
}
|
|
109
|
+
inside = next;
|
|
110
|
+
}
|
|
111
|
+
return { inside, outside };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 軸平行の窓の内側だけ */
|
|
115
|
+
export const clipToRect = (poly: Pt[], w: Rect): Pt[] => splitByRect([poly], w).inside[0] ?? [];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 凸片から凸片群を引く (差集合)。結果も凸片の集合。
|
|
119
|
+
*
|
|
120
|
+
* 一つの凸な引き手について、その各辺の外側を残す — 凸な穴の補集合は、辺ごとの
|
|
121
|
+
* 半平面の和で正確に覆える。引き手が複数なら順に適用する。
|
|
122
|
+
* **これが軸平行の矩形しか引けなかったせいで、斜めに切られた上階の下に屋根が
|
|
123
|
+
* 架からなかった** (ADR-0024 が謳った部分被覆が、斜めでは効いていなかった)。
|
|
124
|
+
*/
|
|
125
|
+
export function subtract(piece: Pt[], covers: Pt[][]): Pt[][] {
|
|
126
|
+
let rest: Pt[][] = [piece];
|
|
127
|
+
for (const c of covers) {
|
|
128
|
+
if (c.length < 3) continue;
|
|
129
|
+
const ccw = signedArea(c) > 0 ? c : [...c].reverse();
|
|
130
|
+
const next: Pt[][] = [];
|
|
131
|
+
for (const r of rest) {
|
|
132
|
+
// r ∩ c が空なら丸ごと残す (辺ごとに削ると重複が出るため先に見る)
|
|
133
|
+
let inter: Pt[] = r;
|
|
134
|
+
for (let i = 0; i < ccw.length && inter.length; i++) {
|
|
135
|
+
inter = clipHalf(inter, ccw[i]!, ccw[(i + 1) % ccw.length]!, true);
|
|
136
|
+
}
|
|
137
|
+
if (inter.length === 0) {
|
|
138
|
+
next.push(r);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// 各辺の外側を順に取り、取った分は以降の候補から外す (重なりなく分割される)
|
|
142
|
+
let remain = r;
|
|
143
|
+
for (let i = 0; i < ccw.length && remain.length; i++) {
|
|
144
|
+
const u = ccw[i]!;
|
|
145
|
+
const v = ccw[(i + 1) % ccw.length]!;
|
|
146
|
+
const out = clipHalf(remain, u, v, false);
|
|
147
|
+
if (out.length) next.push(out);
|
|
148
|
+
remain = clipHalf(remain, u, v, true);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
rest = next;
|
|
152
|
+
}
|
|
153
|
+
return rest;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 凸片の集合の**合併**面積 mm² (重なりを二重に数えない)。
|
|
158
|
+
* 建築面積 (水平投影) のように、階をまたぐ床を重ねて数える場面のための計算。
|
|
159
|
+
* 積んだものから順に引きながら足す — 座標圧縮と違い、斜めの片にも厳密である。
|
|
160
|
+
*/
|
|
161
|
+
export function unionArea(pieces: Pt[][]): number {
|
|
162
|
+
const acc: Pt[][] = [];
|
|
163
|
+
let total = 0;
|
|
164
|
+
for (const p of pieces) {
|
|
165
|
+
if (p.length < 3) continue;
|
|
166
|
+
total += areaOf(subtract(p, acc));
|
|
167
|
+
acc.push(p);
|
|
168
|
+
}
|
|
169
|
+
return total;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 凸片の集合から凸片群を引く */
|
|
173
|
+
export const subtractAll = (pieces: Pt[][], covers: Pt[][]): Pt[][] =>
|
|
174
|
+
pieces.flatMap((p) => subtract(p, covers));
|
|
175
|
+
|
|
176
|
+
// ---- 窓 (どの範囲で測り、どの範囲を切るか) ----
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 描かれた線の及ぶ窓 (ADR-0022)。
|
|
180
|
+
*
|
|
181
|
+
* **線に沿っては線自身の区間、線を横切っては相手を含む範囲。**
|
|
182
|
+
* この非対称が要である — 無限直線として扱うと離れた翼を巻き込み、
|
|
183
|
+
* 線分の外接矩形として扱うと軸平行の線で退化して何も切れない。
|
|
184
|
+
* どちらの誤りも実際に起きた (室が消える / LIN03 が誤報する)。
|
|
185
|
+
*
|
|
186
|
+
* `across` に相手の範囲を渡すと二空間の分け直しの窓 (沿っては積・横切っては和) になり、
|
|
187
|
+
* 省くと外皮を切る窓 (沿っては線の区間・横切っては自分の全体) になる。
|
|
188
|
+
*/
|
|
189
|
+
export function lineWindow(a: Pt, b: Pt, self: Rect, across?: Rect): Rect {
|
|
190
|
+
const vertical = Math.abs(b.y - a.y) >= Math.abs(b.x - a.x);
|
|
191
|
+
const lo = { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) };
|
|
192
|
+
const hi = { x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) };
|
|
193
|
+
const span = (s: number, t: number, o1?: number, o2?: number): [number, number] =>
|
|
194
|
+
o1 === undefined || o2 === undefined
|
|
195
|
+
? [Math.min(s, t), Math.max(s, t)]
|
|
196
|
+
: [Math.min(s, o1), Math.max(t, o2)];
|
|
197
|
+
if (vertical) {
|
|
198
|
+
// 沿う = y、横切る = x
|
|
199
|
+
const [y1, y2] = across
|
|
200
|
+
? [Math.max(self.y1, across.y1), Math.min(self.y2, across.y2)]
|
|
201
|
+
: [lo.y, hi.y];
|
|
202
|
+
const [x1, x2] = span(self.x1, self.x2, across?.x1, across?.x2);
|
|
203
|
+
return { x1, x2, y1, y2 };
|
|
204
|
+
}
|
|
205
|
+
const [x1, x2] = across
|
|
206
|
+
? [Math.max(self.x1, across.x1), Math.min(self.x2, across.x2)]
|
|
207
|
+
: [lo.x, hi.x];
|
|
208
|
+
const [y1, y2] = span(self.y1, self.y2, across?.y1, across?.y2);
|
|
209
|
+
return { x1, x2, y1, y2 };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** 窓が実体を持つか */
|
|
213
|
+
export const validWindow = (w: Rect): boolean => w.x2 - w.x1 > EPS && w.y2 - w.y1 > EPS;
|
|
214
|
+
|
|
215
|
+
/** 窓に触れる凸片だけを選ぶ。線が届かない翼を判定から外すための門 */
|
|
216
|
+
export function touching(pieces: Pt[][], w: Rect): Pt[][] {
|
|
217
|
+
return pieces.filter((p) => {
|
|
218
|
+
const r = bounds(p);
|
|
219
|
+
return r.x2 > w.x1 - EPS && r.x1 < w.x2 + EPS && r.y2 > w.y1 - EPS && r.y1 < w.y2 + EPS;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 線が触れる凸片が、線のどちら側に偏っているか (正=左 / 負=右 / 0=偏りなし)。
|
|
225
|
+
*
|
|
226
|
+
* **母集団は「線が触れる凸片」であり、それを丸ごと測る。**二つの誤りの間を通る:
|
|
227
|
+
* 全ての凸片を測ると、線が届かない離れた翼が符号を支配して室が消える。
|
|
228
|
+
* 窓の中だけを測ると、窓の外にある同じ片の大部分という判断材料を捨てて、
|
|
229
|
+
* 隅から隅への線が「二等分」に見えてしまう。切るのは窓の中だけ、決めるのは片の全体。
|
|
230
|
+
*/
|
|
231
|
+
export function sideOfTouching(pieces: Pt[][], w: Rect, a: Pt, b: Pt): number {
|
|
232
|
+
let left = 0;
|
|
233
|
+
let right = 0;
|
|
234
|
+
for (const p of touching(pieces, w)) {
|
|
235
|
+
left += area(clipHalf(p, a, b, true));
|
|
236
|
+
right += area(clipHalf(p, a, b, false));
|
|
237
|
+
}
|
|
238
|
+
const d = left - right;
|
|
239
|
+
return Math.abs(d) < AREA_EPS ? 0 : d > 0 ? 1 : -1;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** 窓の中で線が実際に切っているか (両側に面積が残るか) */
|
|
243
|
+
export function cutsInWindow(pieces: Pt[][], w: Rect, a: Pt, b: Pt): boolean {
|
|
244
|
+
for (const p of splitByRect(touching(pieces, w), w).inside) {
|
|
245
|
+
if (clipHalf(p, a, b, true).length > 0 && clipHalf(p, a, b, false).length > 0) return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ---- 包含 ----
|
|
251
|
+
|
|
252
|
+
/** 点が多角形の辺の上にあるか */
|
|
253
|
+
export function onEdge(p: Pt, poly: Pt[], eps = 1): boolean {
|
|
254
|
+
for (let i = 0; i < poly.length; i++) {
|
|
255
|
+
const a = poly[i]!;
|
|
256
|
+
const b = poly[(i + 1) % poly.length]!;
|
|
257
|
+
const dx = b.x - a.x;
|
|
258
|
+
const dy = b.y - a.y;
|
|
259
|
+
const len2 = dx * dx + dy * dy;
|
|
260
|
+
const t = len2 === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2));
|
|
261
|
+
const qx = a.x + t * dx;
|
|
262
|
+
const qy = a.y + t * dy;
|
|
263
|
+
if ((p.x - qx) ** 2 + (p.y - qy) ** 2 <= eps * eps) return true;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** 点が多角形の内側にあるか (境界上は内側扱い) */
|
|
269
|
+
export function pointIn(p: Pt, poly: Pt[], eps = 1): boolean {
|
|
270
|
+
if (onEdge(p, poly, eps)) return true;
|
|
271
|
+
let inside = false;
|
|
272
|
+
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
273
|
+
const a = poly[i]!;
|
|
274
|
+
const b = poly[j]!;
|
|
275
|
+
if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) {
|
|
276
|
+
inside = !inside;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return inside;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** 二つの凸片の集合が平面上で重なるか */
|
|
283
|
+
export function overlaps(A: Pt[][], B: Pt[][]): boolean {
|
|
284
|
+
for (const a of A) {
|
|
285
|
+
for (const b of B) {
|
|
286
|
+
let inter: Pt[] = a;
|
|
287
|
+
const ccw = signedArea(b) > 0 ? b : [...b].reverse();
|
|
288
|
+
for (let i = 0; i < ccw.length && inter.length; i++) {
|
|
289
|
+
inter = clipHalf(inter, ccw[i]!, ccw[(i + 1) % ccw.length]!, true);
|
|
290
|
+
}
|
|
291
|
+
if (inter.length > 0) return true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
package/src/site.ts
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
// 敷地 = site:1 属性を持つゾーン。地上の外部空間 (庭・アプローチ) はL1上の実在の空間として
|
|
4
4
|
// 建物の周りをタイルし、道路・隣地は /out を割った複数のexterior空間 (道路は road:幅員)。
|
|
5
5
|
|
|
6
|
+
import { unionArea } from "./poly.js";
|
|
6
7
|
import { segmentLength, segmentsFor } from "./graph.js";
|
|
7
8
|
import {
|
|
8
9
|
areaM2,
|
|
10
|
+
isIndoor,
|
|
9
11
|
isSemiOutdoor,
|
|
10
12
|
polygonAreaM2,
|
|
13
|
+
regionOf,
|
|
11
14
|
unionAreaM2,
|
|
12
15
|
type Model,
|
|
13
16
|
type SitePolygon,
|
|
@@ -43,11 +46,7 @@ export function siteReport(model: Model): SiteReport {
|
|
|
43
46
|
const declared = siteZone?.attrs["area"];
|
|
44
47
|
|
|
45
48
|
const spaces = [...model.spaces.values()];
|
|
46
|
-
const indoor = spaces.filter(
|
|
47
|
-
(s) =>
|
|
48
|
-
s.rects.length > 0 && s.level && s.type !== "void" && s.type !== "exterior" &&
|
|
49
|
-
!isSemiOutdoor(model, s),
|
|
50
|
-
);
|
|
49
|
+
const indoor = spaces.filter((s) => s.level && isIndoor(model, s));
|
|
51
50
|
const siteChildren = siteZone
|
|
52
51
|
? spaces.filter((s) => s.path.startsWith(siteZone.path + "/") && s.rects.length > 0)
|
|
53
52
|
: [];
|
|
@@ -59,7 +58,8 @@ export function siteReport(model: Model): SiteReport {
|
|
|
59
58
|
...siteChildren.flatMap((s) => s.rects),
|
|
60
59
|
...indoor.flatMap((s) => s.rects),
|
|
61
60
|
]);
|
|
62
|
-
|
|
61
|
+
// 建築面積も導出された形から。割付から数えると、隅切りで落とした分まで数えてしまう
|
|
62
|
+
const footprint = Math.round((unionArea(indoor.flatMap((s) => regionOf(s))) / 1e6) * 100) / 100;
|
|
63
63
|
const totalFloor =
|
|
64
64
|
Math.round(indoor.reduce((sum, s) => sum + (areaM2(s) ?? 0), 0) * 100) / 100;
|
|
65
65
|
|