@kensnzk/koyu 0.25.0 → 0.27.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.md +5 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/diagnose.d.ts +1 -0
- package/dist/core/diagnose.d.ts.map +1 -1
- package/dist/core/diagnose.js +40 -4
- package/dist/core/diagnose.js.map +1 -1
- package/dist/core/graph.d.ts +7 -1
- package/dist/core/graph.d.ts.map +1 -1
- package/dist/core/graph.js +125 -13
- package/dist/core/graph.js.map +1 -1
- package/dist/core/model.d.ts +16 -1
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +20 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/section.d.ts +27 -2
- package/dist/core/section.d.ts.map +1 -1
- package/dist/core/section.js +63 -11
- package/dist/core/section.js.map +1 -1
- package/dist/draw/index.d.ts +1 -1
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js +1 -1
- package/dist/draw/index.js.map +1 -1
- package/dist/draw/marks.d.ts +3 -1
- package/dist/draw/marks.d.ts.map +1 -1
- package/dist/draw/marks.js +4 -1
- package/dist/draw/marks.js.map +1 -1
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +5 -3
- package/dist/draw/plan.js.map +1 -1
- package/dist/draw/section.d.ts +20 -2
- package/dist/draw/section.d.ts.map +1 -1
- package/dist/draw/section.js +43 -10
- package/dist/draw/section.js.map +1 -1
- package/dist/draw/sheet.d.ts +15 -0
- package/dist/draw/sheet.d.ts.map +1 -1
- package/dist/draw/sheet.js +15 -0
- package/dist/draw/sheet.js.map +1 -1
- package/dist/form.d.ts +1 -1
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js.map +1 -1
- package/dist/model.d.ts +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +1 -1
- package/dist/model.js.map +1 -1
- package/dist/validate/builtin/index.d.ts +8 -3
- package/dist/validate/builtin/index.d.ts.map +1 -1
- package/dist/validate/builtin/index.js +8 -7
- package/dist/validate/builtin/index.js.map +1 -1
- package/examples/basement/main.muro +1 -1
- package/examples/complex/main.muro +1 -1
- package/examples/house/main.muro +1 -1
- package/examples/house.muro +1 -1
- package/examples/mansion.muro +1 -1
- package/examples/office.muro +1 -1
- package/examples/steps/06-finished.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/twin/main.muro +1 -1
- package/examples/two-rooms.canonical.json +1 -1
- package/examples/two-rooms.muro +1 -1
- package/package.json +4 -3
- package/src/cli.ts +1 -1
- package/src/core/diagnose.ts +43 -3
- package/src/core/graph.ts +147 -11
- package/src/core/model.ts +21 -1
- package/src/core/section.ts +107 -8
- package/src/draw/index.ts +8 -1
- package/src/draw/marks.ts +7 -2
- package/src/draw/plan.ts +5 -3
- package/src/draw/section.ts +78 -14
- package/src/draw/sheet.ts +15 -0
- package/src/form.ts +3 -0
- package/src/model.ts +1 -0
- package/src/validate/builtin/index.ts +8 -7
- package/dist/validate/builtin/envelope.d.ts +0 -30
- package/dist/validate/builtin/envelope.d.ts.map +0 -1
- package/dist/validate/builtin/envelope.js +0 -169
- package/dist/validate/builtin/envelope.js.map +0 -1
- package/src/validate/builtin/envelope.ts +0 -227
package/src/core/graph.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
canonicalBoundaryOrder,
|
|
9
9
|
canonicalizeDrawn,
|
|
10
10
|
compareCanonical,
|
|
11
|
+
EXTERIOR,
|
|
12
|
+
isOutside,
|
|
11
13
|
rectToPoly,
|
|
12
14
|
srcRef,
|
|
13
15
|
} from "./model.js";
|
|
@@ -191,6 +193,76 @@ export function deriveDefaultBoundaries(model: Model): void {
|
|
|
191
193
|
declared.add(key);
|
|
192
194
|
}
|
|
193
195
|
}
|
|
196
|
+
deriveExteriorBoundaries(model);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The spaces whose free perimeter becomes a wall.
|
|
201
|
+
*
|
|
202
|
+
* **Not every space is enclosed, and the excluded ones are excluded because being open is what
|
|
203
|
+
* they are** — an `outside:1` space is the outside, a semi-outdoor space (ADR-0007) is one whose
|
|
204
|
+
* openness was declared with `open` or `air:1`, and the tiles under a `site:1` zone are paving.
|
|
205
|
+
* Putting a wall around any of those would be inventing a building nobody wrote.
|
|
206
|
+
*
|
|
207
|
+
* A void is *not* excluded. A void has a region and sits on a level, and where one reaches the
|
|
208
|
+
* edge of the building the outer wall passes it exactly as it passes a room.
|
|
209
|
+
*
|
|
210
|
+
* **`isSemiOutdoor` cannot see a derived wall, so this cannot chase its own tail.** It reads
|
|
211
|
+
* only `open` and `air:1` boundaries, and every boundary derived here is a plain `wall` — so
|
|
212
|
+
* running the derivation can never change which spaces are in this population, which is what
|
|
213
|
+
* makes `deriveDefaultBoundaries` idempotent.
|
|
214
|
+
*/
|
|
215
|
+
function facesTheOutside(s: Space, siteZones: readonly string[], index: GapIndex): boolean {
|
|
216
|
+
if (s.rects.length === 0 || s.level === undefined) return false;
|
|
217
|
+
if (isOutside(s) || index.semiOutdoor.has(s.path)) return false;
|
|
218
|
+
return !siteZones.some((prefix) => s.path.startsWith(prefix));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 外部との既定境界の導出 (ADR-0065) — 「屋外に面していれば、宣言しない限り壁」。
|
|
223
|
+
*
|
|
224
|
+
* ADR-0014 は接する空間の組に既定の壁を導いたが、領域を持たない相手 (外部) との組は除いた。
|
|
225
|
+
* 名指し (道路側か隣地側か庭か) が情報だからである。代償は ADR-0025 が数えた通りで、
|
|
226
|
+
* **外部への境界の書き忘れは黙って壁の不在になる** — 416空間の建物で34箇所、目で見つけたのは2箇所。
|
|
227
|
+
*
|
|
228
|
+
* 名指しは旧規則で得られていたわけではない。要求されていただけで、忘れたときに手に入るのは
|
|
229
|
+
* 名前ではなく穴だった。**既定を壁にしても名指しは失われない** — 宣言はそのまま勝つ。
|
|
230
|
+
* 失われるのは穴のほうである。書き忘れは BND08 が言葉にする。
|
|
231
|
+
*
|
|
232
|
+
* 抑制は**組ではなく区間で効く。**外部は組ではない — 「他の何にも面していない残り」だからで、
|
|
233
|
+
* 抑制すべき相手が居ない。`envelopeGaps` が宣言された境界の実現する区間を引いた残りが、
|
|
234
|
+
* そのまま導出される壁になる。だから `boundary /L1/a /road edge:S` と書いた空間の
|
|
235
|
+
* 北・東・西にも壁が立つ (1.3 までは何も立たなかった)。
|
|
236
|
+
*/
|
|
237
|
+
function deriveExteriorBoundaries(model: Model): void {
|
|
238
|
+
const siteZones = [...model.zones.values()]
|
|
239
|
+
.filter((z) => z.attrs["site"] === 1)
|
|
240
|
+
.map((z) => `${z.path}/`);
|
|
241
|
+
// 冪等 — 二度目の呼び出しで同じ壁を重ねない。`envelopeGaps` は導出された境界を数えないので、
|
|
242
|
+
// これが無いと一度導いた壁の区間がまた「面していない残り」として返ってくる
|
|
243
|
+
const already = new Set(
|
|
244
|
+
model.boundaries.filter((b) => b.b === EXTERIOR).map((b) => b.a),
|
|
245
|
+
);
|
|
246
|
+
const index = indexFor(model);
|
|
247
|
+
// **宣言順で走る。**導出された境界は正準JSONに出ないので書かれた向きを持たず、
|
|
248
|
+
// 並べ直しは `canonicalBoundaryOrder` が受け持つ (ADR-0041)
|
|
249
|
+
for (const s of model.spaces.values()) {
|
|
250
|
+
if (already.has(s.path)) continue;
|
|
251
|
+
if (!facesTheOutside(s, siteZones, index)) continue;
|
|
252
|
+
if (gapsOf(model, s, index).length === 0) continue;
|
|
253
|
+
model.boundaries.push({
|
|
254
|
+
// a は領域を持つ側である。`edgeOfA` は室から見た面になり、`edge:` を書いた宣言と
|
|
255
|
+
// 同じ向きで読める
|
|
256
|
+
a: s.path,
|
|
257
|
+
b: EXTERIOR,
|
|
258
|
+
kind: "wall",
|
|
259
|
+
derived: true,
|
|
260
|
+
attrs: {},
|
|
261
|
+
openings: [],
|
|
262
|
+
segs: [],
|
|
263
|
+
line: 0,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
194
266
|
}
|
|
195
267
|
|
|
196
268
|
/**
|
|
@@ -305,6 +377,10 @@ export function drawnCut(
|
|
|
305
377
|
/** 境界の壁芯線分を導く。壁の位置は空間の割付から生成される — 壁を置く操作は存在しない */
|
|
306
378
|
export function segmentsFor(model: Model, b: Boundary): Segment[] {
|
|
307
379
|
const sa = model.spaces.get(b.a);
|
|
380
|
+
// 外部との既定境界 (ADR-0065)。相手は空間ではないので `model.spaces` を引いても居ない。
|
|
381
|
+
// **実現するのは「他の何にも面していない残り」そのもの** — 宣言された境界が覆う区間は
|
|
382
|
+
// その宣言のものであり、ここには残らない。だから抑制は組ではなく区間で効く
|
|
383
|
+
if (b.b === EXTERIOR) return sa ? envelopeGaps(model, sa) : [];
|
|
308
384
|
const sb = model.spaces.get(b.b);
|
|
309
385
|
if (!sa || !sb) return [];
|
|
310
386
|
|
|
@@ -351,17 +427,68 @@ export function segmentsFor(model: Model, b: Boundary): Segment[] {
|
|
|
351
427
|
* 外部への境界の書き忘れは黙って壁の不在になる。これを言葉にするための導出。
|
|
352
428
|
*/
|
|
353
429
|
export function envelopeGaps(model: Model, s: Space): Segment[] {
|
|
430
|
+
return gapsOf(model, s, indexFor(model));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The lookups `gapsOf` and the exterior derivation would otherwise rebuild per space.
|
|
435
|
+
*
|
|
436
|
+
* **Asking about one space is cheap; asking about all of them was not.** Both a walk of
|
|
437
|
+
* `model.spaces` and a walk of `model.boundaries` sat inside a loop over every space, and on a
|
|
438
|
+
* 1,808-space building that took composition from 165ms to 745ms — nearly all of it spent
|
|
439
|
+
* establishing that there was nothing to derive.
|
|
440
|
+
*/
|
|
441
|
+
interface GapIndex {
|
|
442
|
+
/** the pieces of every space of a level, by level */
|
|
443
|
+
readonly byLevel: Map<string, Array<{ space: Space; pieces: Pt[][] }>>;
|
|
444
|
+
/** the written, horizontal boundaries that name a space, by path */
|
|
445
|
+
readonly byPath: Map<string, Boundary[]>;
|
|
446
|
+
/** the paths derived as semi-outdoor (ADR-0007) — an `open` or `air:1` boundary to the outside */
|
|
447
|
+
readonly semiOutdoor: ReadonlySet<string>;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function indexFor(model: Model): GapIndex {
|
|
451
|
+
const byLevel = new Map<string, Array<{ space: Space; pieces: Pt[][] }>>();
|
|
452
|
+
for (const o of model.spaces.values()) {
|
|
453
|
+
if (o.level === undefined) continue;
|
|
454
|
+
const row = byLevel.get(o.level) ?? [];
|
|
455
|
+
row.push({ space: o, pieces: piecesOf(o) });
|
|
456
|
+
byLevel.set(o.level, row);
|
|
457
|
+
}
|
|
458
|
+
const byPath = new Map<string, Boundary[]>();
|
|
459
|
+
const semiOutdoor = new Set<string>();
|
|
460
|
+
for (const b of model.boundaries) {
|
|
461
|
+
if (!b.derived && b.kind !== "stair" && b.kind !== "shaft" && b.kind !== "void") {
|
|
462
|
+
for (const path of b.a === b.b ? [b.a] : [b.a, b.b]) {
|
|
463
|
+
const row = byPath.get(path) ?? [];
|
|
464
|
+
row.push(b);
|
|
465
|
+
byPath.set(path, row);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// the same predicate as `isSemiOutdoor`, read once over the boundaries instead of once
|
|
469
|
+
// over the boundaries per space
|
|
470
|
+
if (b.kind !== "open" && !b.air) continue;
|
|
471
|
+
for (const [self, other] of [[b.a, b.b], [b.b, b.a]] as const) {
|
|
472
|
+
const mine = model.spaces.get(self);
|
|
473
|
+
const theirs = model.spaces.get(other);
|
|
474
|
+
if (mine && mine.rects.length > 0 && theirs && isOutside(theirs)) semiOutdoor.add(self);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return { byLevel, byPath, semiOutdoor };
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function gapsOf(model: Model, s: Space, index: GapIndex): Segment[] {
|
|
354
481
|
if (s.rects.length === 0 || !s.level) return [];
|
|
355
482
|
const others: Pt[][] = [];
|
|
356
|
-
for (const o of
|
|
357
|
-
if (o === s
|
|
358
|
-
others.push(...
|
|
483
|
+
for (const o of index.byLevel.get(s.level) ?? []) {
|
|
484
|
+
if (o.space === s) continue;
|
|
485
|
+
others.push(...o.pieces);
|
|
359
486
|
}
|
|
360
487
|
let gaps = pieceOutline(piecesOf(s), others);
|
|
361
|
-
// 宣言された境界 (外部・斜めを含む)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
488
|
+
// 宣言された境界 (外部・斜めを含む) が覆う区間を引く。
|
|
489
|
+
// **導出された境界は引かない。**外部との既定境界はこの関数の答えそのものなので、数えれば
|
|
490
|
+
// 自分を呼び戻す。接する空間同士の既定壁は共有辺であり、上の `others` が既に引いている
|
|
491
|
+
for (const b of index.byPath.get(s.path) ?? []) {
|
|
365
492
|
for (const seg of segmentsFor(model, b)) {
|
|
366
493
|
gaps = gaps.flatMap((g) => subtractOverlap(g, seg));
|
|
367
494
|
}
|
|
@@ -673,7 +800,13 @@ export function doorsBetween(model: Model, from: string, to: string): Route | un
|
|
|
673
800
|
}
|
|
674
801
|
|
|
675
802
|
export interface NeighborInfo {
|
|
676
|
-
|
|
803
|
+
/** 相手の綴り。空間ならその path、外部との既定境界なら [[EXTERIOR]] */
|
|
804
|
+
path: string;
|
|
805
|
+
/**
|
|
806
|
+
* 相手の空間。**外部との既定境界 (ADR-0065) では無い** — 外部は空間ではないからである。
|
|
807
|
+
* `path` は必ずあり、`space` は名指された相手が居るときだけある
|
|
808
|
+
*/
|
|
809
|
+
space?: Space;
|
|
677
810
|
boundary: Boundary;
|
|
678
811
|
passable: boolean;
|
|
679
812
|
doors: number;
|
|
@@ -683,11 +816,14 @@ export function neighbors(model: Model, path: string): NeighborInfo[] {
|
|
|
683
816
|
const out: NeighborInfo[] = [];
|
|
684
817
|
for (const b of model.boundaries) {
|
|
685
818
|
const other = b.a === path ? b.b : b.b === path ? b.a : undefined;
|
|
686
|
-
if (
|
|
819
|
+
if (other === undefined) continue;
|
|
687
820
|
const s = model.spaces.get(other);
|
|
688
|
-
|
|
821
|
+
// 外部との既定境界は関係として本物である — 隠すと、壁のある面を「何とも接していない」と
|
|
822
|
+
// 答えることになる。相手が空間として居ないだけで、辺は在る
|
|
823
|
+
if (!s && other !== EXTERIOR) continue;
|
|
689
824
|
out.push({
|
|
690
|
-
|
|
825
|
+
path: other,
|
|
826
|
+
...(s ? { space: s } : {}),
|
|
691
827
|
boundary: b,
|
|
692
828
|
passable: passable(b),
|
|
693
829
|
doors: b.openings.filter((o) => o.kind === "door").length,
|
package/src/core/model.ts
CHANGED
|
@@ -47,6 +47,10 @@ export const MURO_SUPPORT: readonly { muro: string; since: string; until: string
|
|
|
47
47
|
// space, so tenancy, fire compartment and department all competed for it. VER07 stops it here;
|
|
48
48
|
// the ledger row stays so that every version up to 1.2 goes on reading it (ADR-0061).
|
|
49
49
|
{ muro: "1.3", since: "0.21.0", until: null },
|
|
50
|
+
// 1.4 inverts the exterior default. Up to 1.3 a face looking at nothing got no wall unless a
|
|
51
|
+
// boundary to a region-less space was written, so a forgotten line was a silent hole; from 1.4
|
|
52
|
+
// that face is a wall, and what is declared is which outside it looks at (ADR-0065).
|
|
53
|
+
{ muro: "1.4", since: "0.26.0", until: null },
|
|
50
54
|
];
|
|
51
55
|
|
|
52
56
|
/** The word a version line is written with from 1.2 on. */
|
|
@@ -73,7 +77,7 @@ export const LAST_KOYU_SPELLED_VERSION = "1.1";
|
|
|
73
77
|
* `since` column is written in this vocabulary, and every surface that answers "which muro
|
|
74
78
|
* does this build speak" needs both halves at once.
|
|
75
79
|
*/
|
|
76
|
-
export const KOYU_VERSION = "0.
|
|
80
|
+
export const KOYU_VERSION = "0.27.0";
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* Whether `a` names a later language version than `b`.
|
|
@@ -791,6 +795,22 @@ export function columnsFor(model: Model, level: string): Column[] {
|
|
|
791
795
|
return out;
|
|
792
796
|
}
|
|
793
797
|
|
|
798
|
+
/**
|
|
799
|
+
* The counterpart of a derived exterior wall — the outside a face looks at when nothing was
|
|
800
|
+
* written about it.
|
|
801
|
+
*
|
|
802
|
+
* **It is deliberately not a member of `model.spaces`.** Every space path begins with `/`
|
|
803
|
+
* (`parseSpace` refuses one that does not), so this spelling can never collide with a space
|
|
804
|
+
* anyone wrote; and a materialised exterior would leak into the canonical form, the area
|
|
805
|
+
* tallies, the drawings and every listing that walks `model.spaces`, each of which would then
|
|
806
|
+
* need an exclusion nobody can be trusted to remember.
|
|
807
|
+
*
|
|
808
|
+
* An `outside:1` space is not replaced by it. Declaring one **names** a part of the outside —
|
|
809
|
+
* the road, the neighbour, the garden — and a boundary to it wins over the default wherever it
|
|
810
|
+
* reaches. This constant is what stands where no name was given.
|
|
811
|
+
*/
|
|
812
|
+
export const EXTERIOR = "outside";
|
|
813
|
+
|
|
794
814
|
/**
|
|
795
815
|
* 建物の外部か。**空間の型ではなく `outside:1` の宣言で決まる。**
|
|
796
816
|
*
|
package/src/core/section.ts
CHANGED
|
@@ -56,6 +56,26 @@ export interface SectionSpec {
|
|
|
56
56
|
look: Edge;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** A directed cutting line in plan. `u` starts at `(x1,y1)` and increases toward `(x2,y2)`. */
|
|
60
|
+
export interface SectionLine {
|
|
61
|
+
x1: number;
|
|
62
|
+
y1: number;
|
|
63
|
+
x2: number;
|
|
64
|
+
y2: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A vertical plane named by a directed line rather than a grid-parallel coordinate.
|
|
69
|
+
*
|
|
70
|
+
* The viewer looks toward the line's left side, so the line direction is left-to-right on the
|
|
71
|
+
* sheet. The two endpoints name the frame; the cutting plane itself is infinite.
|
|
72
|
+
*/
|
|
73
|
+
export interface LineSectionSpec {
|
|
74
|
+
cut: SectionLine;
|
|
75
|
+
/** a caller-owned name for the cut, when there is one */
|
|
76
|
+
atRef?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
export interface SectionEntity {
|
|
60
80
|
class: SectionClass;
|
|
61
81
|
of: SectionSubject;
|
|
@@ -81,6 +101,13 @@ export interface FormSection {
|
|
|
81
101
|
entities: SectionEntity[];
|
|
82
102
|
}
|
|
83
103
|
|
|
104
|
+
/** A section made by a directed line. Its entities have the same meaning as an axis section. */
|
|
105
|
+
export interface LineFormSection {
|
|
106
|
+
cut: SectionLine;
|
|
107
|
+
atRef?: string;
|
|
108
|
+
entities: SectionEntity[];
|
|
109
|
+
}
|
|
110
|
+
|
|
84
111
|
/** The direction of view as a unit vector in plan. */
|
|
85
112
|
function look(edge: Edge): Pt {
|
|
86
113
|
return edge === "N"
|
|
@@ -160,6 +187,36 @@ function cutOf(body: FormBody, axis: SectionAxis, at: number, u: (p: Pt) => numb
|
|
|
160
187
|
];
|
|
161
188
|
}
|
|
162
189
|
|
|
190
|
+
/** The polygon a body leaves on a directed line, in that line's `(u,z)` frame. */
|
|
191
|
+
function lineCutOf(
|
|
192
|
+
body: FormBody,
|
|
193
|
+
u: (p: Pt) => number,
|
|
194
|
+
behind: (p: Pt) => number,
|
|
195
|
+
): SectionPt[] | undefined {
|
|
196
|
+
// `crossing` already owns the tolerance and the rules for a convex ring grazing a plane. Put
|
|
197
|
+
// the body into the line's orthonormal frame and ask the same axis question there, so an
|
|
198
|
+
// oblique cut cannot acquire a second intersection rule.
|
|
199
|
+
const local = body.poly.map((p) => ({ x: behind(p), y: u(p) }));
|
|
200
|
+
const met = crossing(local, "X", 0);
|
|
201
|
+
if (!met) return undefined;
|
|
202
|
+
const n = body.poly.length;
|
|
203
|
+
const at01 = (v: number[], c: { edge: number; t: number }): number =>
|
|
204
|
+
v[c.edge]! + c.t * (v[(c.edge + 1) % n]! - v[c.edge]!);
|
|
205
|
+
const ends = met.map((c) => ({
|
|
206
|
+
u: local[c.edge]!.y + c.t * (local[(c.edge + 1) % n]!.y - local[c.edge]!.y),
|
|
207
|
+
z0: at01(body.bottom, c),
|
|
208
|
+
z1: at01(body.top, c),
|
|
209
|
+
}));
|
|
210
|
+
const [a, b] = ends[0]!.u <= ends[1]!.u ? [ends[0]!, ends[1]!] : [ends[1]!, ends[0]!];
|
|
211
|
+
if (b.u - a.u <= EPS) return undefined;
|
|
212
|
+
return [
|
|
213
|
+
{ u: a.u, z: a.z0 },
|
|
214
|
+
{ u: b.u, z: b.z0 },
|
|
215
|
+
{ u: b.u, z: b.z1 },
|
|
216
|
+
{ u: a.u, z: a.z1 },
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
|
|
163
220
|
/**
|
|
164
221
|
* The shape a body throws onto the plane, seen head-on.
|
|
165
222
|
*
|
|
@@ -202,12 +259,44 @@ function shadowOf(body: FormBody, u: (p: Pt) => number): SectionPt[] | undefined
|
|
|
202
259
|
return ring.length >= 3 ? ring.map((p) => ({ u: p.x, z: p.y })) : undefined;
|
|
203
260
|
}
|
|
204
261
|
|
|
205
|
-
|
|
262
|
+
interface SectionFrame {
|
|
263
|
+
u: (p: Pt) => number;
|
|
264
|
+
/** How far behind the plane a point stands. Positive is away from the viewer. */
|
|
265
|
+
behind: (p: Pt) => number;
|
|
266
|
+
cut: (body: FormBody) => SectionPt[] | undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function axisFrame(spec: SectionSpec): SectionFrame {
|
|
206
270
|
const d = look(spec.look);
|
|
207
271
|
const r = rightOf(d);
|
|
208
272
|
const u = (p: Pt): number => p.x * r.x + p.y * r.y;
|
|
209
|
-
/** How far behind the plane a point stands. Positive is away from the viewer. */
|
|
210
273
|
const behind = (p: Pt): number => (spec.axis === "X" ? (p.x - spec.at) * d.x : (p.y - spec.at) * d.y);
|
|
274
|
+
return { u, behind, cut: (body) => cutOf(body, spec.axis, spec.at, u) };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function lineFrame(spec: LineSectionSpec): SectionFrame {
|
|
278
|
+
const { x1, y1, x2, y2 } = spec.cut;
|
|
279
|
+
const dx = x2 - x1;
|
|
280
|
+
const dy = y2 - y1;
|
|
281
|
+
const length = Math.hypot(dx, dy);
|
|
282
|
+
if (length <= EPS) throw new Error("A section line needs two distinct points");
|
|
283
|
+
// q is right on the sheet. d points away from the viewer, toward the line's left side.
|
|
284
|
+
const q = { x: dx / length, y: dy / length };
|
|
285
|
+
const d = { x: -q.y, y: q.x };
|
|
286
|
+
const relative = (p: Pt): Pt => ({ x: p.x - x1, y: p.y - y1 });
|
|
287
|
+
const u = (p: Pt): number => {
|
|
288
|
+
const v = relative(p);
|
|
289
|
+
return v.x * q.x + v.y * q.y;
|
|
290
|
+
};
|
|
291
|
+
const behind = (p: Pt): number => {
|
|
292
|
+
const v = relative(p);
|
|
293
|
+
return v.x * d.x + v.y * d.y;
|
|
294
|
+
};
|
|
295
|
+
return { u, behind, cut: (body) => lineCutOf(body, u, behind) };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function entitiesOf(bodies: FormBody[], frame: SectionFrame): SectionEntity[] {
|
|
299
|
+
const { u, behind } = frame;
|
|
211
300
|
|
|
212
301
|
const out: SectionEntity[] = [];
|
|
213
302
|
for (const body of bodies) {
|
|
@@ -226,7 +315,7 @@ function entitiesOf(bodies: FormBody[], spec: SectionSpec): SectionEntity[] {
|
|
|
226
315
|
const wholly = { behind: lo >= -EPS && hi > EPS, front: hi <= EPS && lo < -EPS };
|
|
227
316
|
if (!wholly.behind && !wholly.front) {
|
|
228
317
|
// It reaches both sides: the plane crossed it.
|
|
229
|
-
const polygon =
|
|
318
|
+
const polygon = frame.cut(body);
|
|
230
319
|
if (polygon) {
|
|
231
320
|
out.push({ class: "cut", of: body.of, ref: body.ref, ...(body.kind ? { kind: body.kind } : {}), polygon, depth: 0 });
|
|
232
321
|
}
|
|
@@ -256,10 +345,20 @@ function entitiesOf(bodies: FormBody[], spec: SectionSpec): SectionEntity[] {
|
|
|
256
345
|
/**
|
|
257
346
|
* The section a vertical plane makes of a `Form`.
|
|
258
347
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
348
|
+
* An axis spec names a coordinate and a facing. A line spec names the same frame by two directed
|
|
349
|
+
* plan points, with positive `u` running from the first to the second.
|
|
261
350
|
*/
|
|
262
|
-
export function sectionForm(form: Form, spec: SectionSpec): FormSection
|
|
351
|
+
export function sectionForm(form: Form, spec: SectionSpec): FormSection;
|
|
352
|
+
export function sectionForm(form: Form, spec: LineSectionSpec): LineFormSection;
|
|
353
|
+
export function sectionForm(form: Form, spec: SectionSpec | LineSectionSpec): FormSection | LineFormSection {
|
|
354
|
+
if ("cut" in spec) {
|
|
355
|
+
const frame = lineFrame(spec);
|
|
356
|
+
return {
|
|
357
|
+
cut: spec.cut,
|
|
358
|
+
...(spec.atRef !== undefined ? { atRef: spec.atRef } : {}),
|
|
359
|
+
entities: entitiesOf(cuttableBodies(form), frame),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
263
362
|
if (axisOf(spec.look) !== spec.axis) {
|
|
264
363
|
throw new Error(
|
|
265
364
|
`Looking ${spec.look} runs along the ${spec.axis} plane rather than across it (an X plane is looked at from E or W, a Y plane from N or S)`,
|
|
@@ -270,7 +369,7 @@ export function sectionForm(form: Form, spec: SectionSpec): FormSection {
|
|
|
270
369
|
at: spec.at,
|
|
271
370
|
...(spec.atRef !== undefined ? { atRef: spec.atRef } : {}),
|
|
272
371
|
look: spec.look,
|
|
273
|
-
entities: entitiesOf(cuttableBodies(form), spec),
|
|
372
|
+
entities: entitiesOf(cuttableBodies(form), axisFrame(spec)),
|
|
274
373
|
};
|
|
275
374
|
}
|
|
276
375
|
|
|
@@ -302,7 +401,7 @@ export function elevationForm(form: Form, face: Edge): FormSection {
|
|
|
302
401
|
}
|
|
303
402
|
}
|
|
304
403
|
const spec: SectionSpec = { axis, at, look: from };
|
|
305
|
-
return { axis, at, look: from, entities: entitiesOf(bodies, spec) };
|
|
404
|
+
return { axis, at, look: from, entities: entitiesOf(bodies, axisFrame(spec)) };
|
|
306
405
|
}
|
|
307
406
|
|
|
308
407
|
/** The area of a section polygon, mm². Used by the tests that hold the cut against the Form. */
|
package/src/draw/index.ts
CHANGED
|
@@ -31,5 +31,12 @@ export {
|
|
|
31
31
|
type SceneRole,
|
|
32
32
|
type SceneSubject,
|
|
33
33
|
} from "./scene.js";
|
|
34
|
-
export {
|
|
34
|
+
export {
|
|
35
|
+
svgSection,
|
|
36
|
+
svgElevation,
|
|
37
|
+
type ElevationOptions,
|
|
38
|
+
type LineSectionOptions,
|
|
39
|
+
type SectionGuide,
|
|
40
|
+
type SectionOptions,
|
|
41
|
+
} from "./section.js";
|
|
35
42
|
export { writtenOf, type Written } from "./written.js";
|
package/src/draw/marks.ts
CHANGED
|
@@ -29,8 +29,10 @@ import type { RunDevice, Seg2 } from "../core/vertical.js";
|
|
|
29
29
|
export type MarkRole =
|
|
30
30
|
/** a space's face, cut by the plane */
|
|
31
31
|
| "space"
|
|
32
|
-
/** the same, where the space is
|
|
32
|
+
/** the same, where the space is semi-outdoor — roofed, not enclosed */
|
|
33
33
|
| "space-semi-outdoor"
|
|
34
|
+
/** the same, where the space is declared `outside:1` — ground, not floor */
|
|
35
|
+
| "space-outdoor"
|
|
34
36
|
/** a void's face — no floor, so no room */
|
|
35
37
|
| "space-void"
|
|
36
38
|
/** the void's two bounding-box diagonals (a drafting convention, not a shape of the building) */
|
|
@@ -182,7 +184,10 @@ export function planMarks(form: Form, level: string, opts?: MarkOptions): Mark[]
|
|
|
182
184
|
continue;
|
|
183
185
|
}
|
|
184
186
|
marks.push({
|
|
185
|
-
|
|
187
|
+
// **Outside is asked first.** A space declared `outside:1` that also carries an `open` or
|
|
188
|
+
// `air:1` boundary to another outside space derives as semi-outdoor too, and of the two
|
|
189
|
+
// facts the declared one is the one that decides what the space is
|
|
190
|
+
role: s?.outside ? "space-outdoor" : s?.semiOutdoor ? "space-semi-outdoor" : "space",
|
|
186
191
|
of: "space",
|
|
187
192
|
ref: e.ref,
|
|
188
193
|
class: "cut",
|
package/src/draw/plan.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { derive } from "../core/derive.js";
|
|
|
13
13
|
import { displayName, polyBounds, type Model, type Pt } from "../core/model.js";
|
|
14
14
|
import { slopeText } from "../core/vertical.js";
|
|
15
15
|
import { planMarks, type Mark } from "./marks.js";
|
|
16
|
-
import { esc, Extent, FAINT, GRID, INK, openSheet, PAPER, ROOM } from "./sheet.js";
|
|
16
|
+
import { esc, Extent, FAINT, GRID, INK, openSheet, OUTDOOR, PAPER, ROOM, SEMI_OUTDOOR } from "./sheet.js";
|
|
17
17
|
import { writtenOf } from "./written.js";
|
|
18
18
|
|
|
19
19
|
export interface PlanOptions {
|
|
@@ -77,11 +77,12 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// 空間の面 — 切断面が気積を切った姿。同色・輪郭なしなのでL字も切られた形も一体に見える。
|
|
80
|
-
//
|
|
80
|
+
// **暖色が屋内、寒色が屋外**である。宣言された屋外 (outside:1)・半屋外・屋内の三段で、
|
|
81
|
+
// 前庭と玄関ホールが同じ一枚のクリームに見えていた状態を分ける
|
|
81
82
|
for (const s of rooms) {
|
|
82
83
|
const isVoid = s.void;
|
|
83
84
|
for (const poly of s.outline) {
|
|
84
|
-
parts.push(fill(poly, isVoid ? PAPER : s.semiOutdoor ?
|
|
85
|
+
parts.push(fill(poly, isVoid ? PAPER : s.outside ? OUTDOOR : s.semiOutdoor ? SEMI_OUTDOOR : ROOM));
|
|
85
86
|
if (isVoid) {
|
|
86
87
|
// 吹抜け: 破線の対角線 (作図慣習)
|
|
87
88
|
const r = polyBounds(poly);
|
|
@@ -140,6 +141,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
|
|
|
140
141
|
// 分節には Form しか持たない座と向きが要るため。上部吹抜けは空間ラベルより後ろに置く
|
|
141
142
|
case "space":
|
|
142
143
|
case "space-semi-outdoor":
|
|
144
|
+
case "space-outdoor":
|
|
143
145
|
case "space-void":
|
|
144
146
|
case "void-hatch":
|
|
145
147
|
case "void-above":
|
package/src/draw/section.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
elevationForm,
|
|
19
19
|
sectionForm,
|
|
20
20
|
type FormSection,
|
|
21
|
+
type LineFormSection,
|
|
22
|
+
type SectionLine,
|
|
21
23
|
type SectionAxis,
|
|
22
24
|
type SectionEntity,
|
|
23
25
|
type SectionPt,
|
|
@@ -35,6 +37,26 @@ export interface SectionOptions {
|
|
|
35
37
|
look?: Edge;
|
|
36
38
|
/** px per mm (default 0.05, the same as a plan, so the two can be laid side by side) */
|
|
37
39
|
scale?: number;
|
|
40
|
+
/** caller-supplied reference geometry in the section's `(u,z)` frame */
|
|
41
|
+
guides?: SectionGuide[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A section whose plane follows a directed line in plan. */
|
|
45
|
+
export interface LineSectionOptions {
|
|
46
|
+
cut: SectionLine;
|
|
47
|
+
/** a caller-owned name for the cut */
|
|
48
|
+
atRef?: string;
|
|
49
|
+
/** px per mm */
|
|
50
|
+
scale?: number;
|
|
51
|
+
/** caller-supplied reference geometry in the section's `(u,z)` frame */
|
|
52
|
+
guides?: SectionGuide[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A reference polyline drawn over a section without becoming part of the building Form. */
|
|
56
|
+
export interface SectionGuide {
|
|
57
|
+
points: SectionPt[];
|
|
58
|
+
label?: string;
|
|
59
|
+
showVertices?: boolean;
|
|
38
60
|
}
|
|
39
61
|
|
|
40
62
|
export interface ElevationOptions {
|
|
@@ -51,9 +73,17 @@ const GLASS = "#b9c3c0";
|
|
|
51
73
|
/** Annotation. */
|
|
52
74
|
const LABEL = "#8a8171";
|
|
53
75
|
|
|
54
|
-
export function svgSection(model: Model, opts: SectionOptions): string {
|
|
55
|
-
const look = opts.look ?? defaultLook(opts.axis);
|
|
76
|
+
export function svgSection(model: Model, opts: SectionOptions | LineSectionOptions): string {
|
|
56
77
|
const form = derive(model);
|
|
78
|
+
if ("cut" in opts) {
|
|
79
|
+
const section = sectionForm(form, {
|
|
80
|
+
cut: opts.cut,
|
|
81
|
+
...(opts.atRef !== undefined ? { atRef: opts.atRef } : {}),
|
|
82
|
+
});
|
|
83
|
+
const where = opts.atRef ?? `(${opts.cut.x1}, ${opts.cut.y1})–(${opts.cut.x2}, ${opts.cut.y2})`;
|
|
84
|
+
return sheet(model, form, section, opts.scale, `${model.name ?? "Untitled"} — section along ${where}`, opts.guides);
|
|
85
|
+
}
|
|
86
|
+
const look = opts.look ?? defaultLook(opts.axis);
|
|
57
87
|
const section = sectionForm(form, {
|
|
58
88
|
axis: opts.axis,
|
|
59
89
|
at: opts.at,
|
|
@@ -61,7 +91,14 @@ export function svgSection(model: Model, opts: SectionOptions): string {
|
|
|
61
91
|
look,
|
|
62
92
|
});
|
|
63
93
|
const where = opts.atRef ?? `${opts.axis} ${opts.at}`;
|
|
64
|
-
return sheet(
|
|
94
|
+
return sheet(
|
|
95
|
+
model,
|
|
96
|
+
form,
|
|
97
|
+
section,
|
|
98
|
+
opts.scale,
|
|
99
|
+
`${model.name ?? "Untitled"} — section at ${where} looking ${look}`,
|
|
100
|
+
opts.guides,
|
|
101
|
+
);
|
|
65
102
|
}
|
|
66
103
|
|
|
67
104
|
export function svgElevation(model: Model, opts: ElevationOptions): string {
|
|
@@ -82,9 +119,10 @@ export function svgElevation(model: Model, opts: ElevationOptions): string {
|
|
|
82
119
|
function sheet(
|
|
83
120
|
model: Model,
|
|
84
121
|
form: Form,
|
|
85
|
-
section: FormSection,
|
|
122
|
+
section: FormSection | LineFormSection,
|
|
86
123
|
scale: number | undefined,
|
|
87
124
|
heading: string,
|
|
125
|
+
guides: SectionGuide[] = [],
|
|
88
126
|
): string {
|
|
89
127
|
const s = scale ?? 0.05;
|
|
90
128
|
|
|
@@ -92,6 +130,9 @@ function sheet(
|
|
|
92
130
|
// limit on how many arguments a call may take.
|
|
93
131
|
const ext = new Extent();
|
|
94
132
|
for (const e of section.entities) for (const p of e.polygon) ext.see(p.u, p.z);
|
|
133
|
+
for (const guide of guides) {
|
|
134
|
+
for (const p of guide.points) if (Number.isFinite(p.u) && Number.isFinite(p.z)) ext.see(p.u, p.z);
|
|
135
|
+
}
|
|
95
136
|
if (ext.empty) throw new Error("There is nothing to draw");
|
|
96
137
|
const minU = ext.min0;
|
|
97
138
|
const maxU = ext.max0;
|
|
@@ -165,16 +206,18 @@ function sheet(
|
|
|
165
206
|
// ---- the grid, along the sheet ----
|
|
166
207
|
// The axis the plane is named on gets no bubbles — every one of its lines would land on the same
|
|
167
208
|
// point. The other axis is what runs across the sheet, so that is the one that marks it.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
209
|
+
if ("axis" in section) {
|
|
210
|
+
const across = section.axis === "X" ? model.grid.Y : model.grid.X;
|
|
211
|
+
const sign = section.look === "W" || section.look === "N" ? 1 : -1;
|
|
212
|
+
for (const [i, c] of across.coords.entries()) {
|
|
213
|
+
const u = c * sign;
|
|
214
|
+
if (u < minU - 1 || u > maxU + 1) continue;
|
|
215
|
+
parts.push(
|
|
216
|
+
`<line x1="${sx(u)}" y1="${MT - 26}" x2="${sx(u)}" y2="${H - MB + 26}" stroke="${GRID}" stroke-width="0.8" stroke-dasharray="7 3 1.5 3"/>`,
|
|
217
|
+
`<circle cx="${sx(u)}" cy="${MT - 40}" r="11" fill="none" stroke="${GRID}" stroke-width="1"/>`,
|
|
218
|
+
`<text x="${sx(u)}" y="${MT - 36}" text-anchor="middle" font-size="10" fill="${GRID}">${across.names[i]!}</text>`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
178
221
|
}
|
|
179
222
|
|
|
180
223
|
// ---- what the plane cut ----
|
|
@@ -193,6 +236,27 @@ function sheet(
|
|
|
193
236
|
);
|
|
194
237
|
}
|
|
195
238
|
|
|
239
|
+
// ---- caller-supplied reference geometry ----
|
|
240
|
+
// These lines explain the section but are not part of the building. Their coordinates use the
|
|
241
|
+
// section's own frame, so a caller never has to reproduce the world-to-sheet mapping.
|
|
242
|
+
for (const guide of guides) {
|
|
243
|
+
const points = guide.points.filter((p) => Number.isFinite(p.u) && Number.isFinite(p.z));
|
|
244
|
+
if (points.length >= 2) {
|
|
245
|
+
parts.push(
|
|
246
|
+
`<polyline points="${points.map((p) => `${sx(p.u)},${sy(p.z)}`).join(" ")}" fill="none" stroke="#A84940" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>`,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
if (guide.showVertices) {
|
|
250
|
+
for (const p of points) {
|
|
251
|
+
parts.push(`<circle cx="${sx(p.u)}" cy="${sy(p.z)}" r="2.8" fill="#A84940"/>`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const last = points[points.length - 1];
|
|
255
|
+
if (last && guide.label) {
|
|
256
|
+
parts.push(`<text x="${sx(last.u) + 7}" y="${sy(last.z) - 7}" font-size="10" fill="#A84940">${esc(guide.label)}</text>`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
196
260
|
// ---- the rooms, named ----
|
|
197
261
|
for (const e of section.entities) {
|
|
198
262
|
if (e.class !== "cut" || e.of !== "space") continue;
|
package/src/draw/sheet.ts
CHANGED
|
@@ -21,6 +21,21 @@ export const INK = "#1f1f1f";
|
|
|
21
21
|
export const PAPER = "#faf8f4";
|
|
22
22
|
/** The air of a room, cut open. */
|
|
23
23
|
export const ROOM = "#f1ebdd";
|
|
24
|
+
/**
|
|
25
|
+
* A space that is roofed but not enclosed — a balcony, a piloti, an external walkway.
|
|
26
|
+
*
|
|
27
|
+
* **Warm is inside and cool is outside**, and this is the step between them: paler than a room,
|
|
28
|
+
* because there is less of a room here, and already tinted away from the warm of one.
|
|
29
|
+
*/
|
|
30
|
+
export const SEMI_OUTDOOR = "#eef1e9";
|
|
31
|
+
/**
|
|
32
|
+
* A space declared `outside:1` that has a region — a courtyard, a plaza, the paving of a site.
|
|
33
|
+
*
|
|
34
|
+
* It used to be painted as a room, which said the opposite of what it is: on a large plan the
|
|
35
|
+
* forecourt and the entrance hall were one continuous field of the same cream. Cool and a shade
|
|
36
|
+
* deeper reads as ground rather than floor without naming a material.
|
|
37
|
+
*/
|
|
38
|
+
export const OUTDOOR = "#dfe6da";
|
|
24
39
|
/** Given lines — the grid, and the level datums that are the grid of a section. */
|
|
25
40
|
export const GRID = "#b5aa94";
|
|
26
41
|
/** A line that is present but not the subject. */
|