@kensnzk/koyu 0.15.0 → 0.17.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 +14 -10
- package/README.md +16 -13
- package/dist/cli.js +162 -84
- package/dist/cli.js.map +1 -1
- package/dist/core/derive.d.ts +264 -0
- package/dist/core/derive.d.ts.map +1 -0
- package/dist/core/derive.js +576 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{check.d.ts → core/diagnose.d.ts} +15 -15
- package/dist/core/diagnose.d.ts.map +1 -0
- package/dist/{check.js → core/diagnose.js} +269 -223
- package/dist/core/diagnose.js.map +1 -0
- package/dist/{diff.d.ts → core/diff.d.ts} +3 -2
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/{diff.js → core/diff.js} +89 -43
- package/dist/core/diff.js.map +1 -0
- package/dist/{fabric.d.ts → core/fabric.d.ts} +5 -3
- package/dist/core/fabric.d.ts.map +1 -0
- package/dist/{fabric.js → core/fabric.js} +12 -11
- package/dist/core/fabric.js.map +1 -0
- package/dist/{graph.d.ts → core/graph.d.ts} +2 -4
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/{graph.js → core/graph.js} +53 -54
- package/dist/core/graph.js.map +1 -0
- package/dist/core/light.d.ts +24 -0
- package/dist/core/light.d.ts.map +1 -0
- package/dist/{light.js → core/light.js} +17 -12
- package/dist/core/light.js.map +1 -0
- package/dist/{model.d.ts → core/model.d.ts} +178 -18
- package/dist/core/model.d.ts.map +1 -0
- package/dist/{model.js → core/model.js} +307 -68
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/{parse.js → core/parse.js} +546 -133
- package/dist/core/parse.js.map +1 -0
- package/dist/{poly.d.ts → core/poly.d.ts} +3 -6
- package/dist/core/poly.d.ts.map +1 -0
- package/dist/{poly.js → core/poly.js} +8 -13
- package/dist/core/poly.js.map +1 -0
- package/dist/core/site.d.ts.map +1 -0
- package/dist/{site.js → core/site.js} +2 -2
- package/dist/core/site.js.map +1 -0
- package/dist/core/tolerance.d.ts +26 -0
- package/dist/core/tolerance.d.ts.map +1 -0
- package/dist/core/tolerance.js +48 -0
- package/dist/core/tolerance.js.map +1 -0
- package/dist/{vertical.d.ts → core/vertical.d.ts} +48 -12
- package/dist/core/vertical.d.ts.map +1 -0
- package/dist/{vertical.js → core/vertical.js} +53 -105
- package/dist/core/vertical.js.map +1 -0
- package/dist/core/vocabulary.d.ts +40 -0
- package/dist/core/vocabulary.d.ts.map +1 -0
- package/dist/core/vocabulary.js +176 -0
- package/dist/core/vocabulary.js.map +1 -0
- package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
- package/dist/draw/axo.d.ts.map +1 -0
- package/dist/{axo.js → draw/axo.js} +53 -81
- package/dist/draw/axo.js.map +1 -0
- package/dist/draw/index.d.ts +3 -0
- package/dist/draw/index.d.ts.map +1 -0
- package/dist/draw/index.js +11 -0
- package/dist/draw/index.js.map +1 -0
- package/dist/draw/plan.d.ts +10 -0
- package/dist/draw/plan.d.ts.map +1 -0
- package/dist/draw/plan.js +284 -0
- package/dist/draw/plan.js.map +1 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +112 -50
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -1
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +19 -4
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/access.d.ts +6 -0
- package/dist/validate/access.d.ts.map +1 -0
- package/dist/validate/access.js +248 -0
- package/dist/validate/access.js.map +1 -0
- package/dist/validate/envelope.d.ts +4 -0
- package/dist/validate/envelope.d.ts.map +1 -0
- package/dist/validate/envelope.js +55 -0
- package/dist/validate/envelope.js.map +1 -0
- package/dist/validate/index.d.ts +60 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +77 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/light.d.ts +6 -0
- package/dist/validate/light.d.ts.map +1 -0
- package/dist/validate/light.js +28 -0
- package/dist/validate/light.js.map +1 -0
- package/dist/validate/runs.d.ts +16 -0
- package/dist/validate/runs.d.ts.map +1 -0
- package/dist/validate/runs.js +60 -0
- package/dist/validate/runs.js.map +1 -0
- package/dist/validate/site.d.ts +6 -0
- package/dist/validate/site.d.ts.map +1 -0
- package/dist/validate/site.js +63 -0
- package/dist/validate/site.js.map +1 -0
- package/editors/vscode/.vscodeignore +2 -0
- package/editors/vscode/README.md +28 -0
- package/editors/vscode/extension.js +150 -0
- package/editors/vscode/language-configuration.json +19 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
- package/examples/basement/main.muro +3 -3
- package/examples/complex/main.muro +1 -1
- package/examples/complex/podium.muro +1 -1
- package/examples/complex/site.muro +6 -6
- package/examples/house/L2.muro +1 -1
- package/examples/house/main.muro +2 -2
- package/examples/house/site.muro +4 -4
- package/examples/house.muro +7 -7
- package/examples/mansion.muro +3 -3
- package/examples/office.muro +4 -4
- package/examples/steps/01-one-room.muro +1 -1
- package/examples/steps/02-two-rooms.muro +1 -1
- package/examples/steps/03-door.muro +1 -1
- package/examples/steps/04-exterior.muro +2 -2
- package/examples/steps/05-two-storeys.muro +2 -2
- package/examples/steps/06-finished.muro +3 -3
- package/examples/tower/L2.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/tower/site.muro +4 -4
- package/examples/twin/main.muro +2 -2
- package/examples/twin/podium.muro +4 -4
- package/examples/twin/site.muro +8 -8
- package/examples/two-rooms.canonical.json +6 -4
- package/examples/two-rooms.muro +3 -3
- package/package.json +18 -3
- package/src/cli.ts +173 -83
- package/src/core/derive.ts +869 -0
- package/src/{check.ts → core/diagnose.ts} +313 -235
- package/src/{diff.ts → core/diff.ts} +91 -43
- package/src/{fabric.ts → core/fabric.ts} +22 -12
- package/src/{graph.ts → core/graph.ts} +64 -63
- package/src/core/light.ts +69 -0
- package/src/{model.ts → core/model.ts} +361 -74
- package/src/{parse.ts → core/parse.ts} +618 -135
- package/src/{poly.ts → core/poly.ts} +8 -16
- package/src/{site.ts → core/site.ts} +2 -2
- package/src/core/tolerance.ts +55 -0
- package/src/{vertical.ts → core/vertical.ts} +73 -116
- package/src/core/vocabulary.ts +210 -0
- package/src/{axo.ts → draw/axo.ts} +51 -94
- package/src/draw/index.ts +11 -0
- package/src/draw/plan.ts +344 -0
- package/src/index.ts +201 -34
- package/src/mcp.ts +119 -50
- package/src/parse-file.ts +19 -5
- package/src/validate/access.ts +291 -0
- package/src/validate/envelope.ts +59 -0
- package/src/validate/index.ts +107 -0
- package/src/validate/light.ts +43 -0
- package/src/validate/runs.ts +87 -0
- package/src/validate/site.ts +84 -0
- package/dist/axo.d.ts.map +0 -1
- package/dist/axo.js.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fabric.d.ts.map +0 -1
- package/dist/fabric.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/light.d.ts +0 -15
- package/dist/light.d.ts.map +0 -1
- package/dist/light.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js.map +0 -1
- package/dist/plan.d.ts +0 -10
- package/dist/plan.d.ts.map +0 -1
- package/dist/plan.js +0 -354
- package/dist/plan.js.map +0 -1
- package/dist/poly.d.ts.map +0 -1
- package/dist/poly.js.map +0 -1
- package/dist/site.d.ts.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/vertical.d.ts.map +0 -1
- package/dist/vertical.js.map +0 -1
- package/src/light.ts +0 -63
- package/src/plan.ts +0 -472
- /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
- /package/dist/{site.d.ts → core/site.d.ts} +0 -0
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
canonicalOpeningEntry,
|
|
12
12
|
canonicalSegEntry,
|
|
13
13
|
canonicalSpaceEntry,
|
|
14
|
+
openingIdentity,
|
|
14
15
|
polygonAreaM2,
|
|
15
16
|
type Attrs,
|
|
16
17
|
type AttrValue,
|
|
@@ -56,7 +57,8 @@ export interface GridChange {
|
|
|
56
57
|
|
|
57
58
|
export interface SpaceItem {
|
|
58
59
|
path: string;
|
|
59
|
-
|
|
60
|
+
/** 書かれていれば。型は任意である */
|
|
61
|
+
type?: string;
|
|
60
62
|
areaM2?: number;
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -185,7 +187,7 @@ function fmtGrids(s: Space): string {
|
|
|
185
187
|
return s.grids.map((g) => `${g.xa}..${g.xb} ${g.ya}..${g.yb}`).join(" + ");
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
const fmtArea = (v: number | undefined): string | undefined => (v === undefined ? undefined : `${v.toFixed(2)}
|
|
190
|
+
const fmtArea = (v: number | undefined): string | undefined => (v === undefined ? undefined : `${v.toFixed(2)} m2`);
|
|
189
191
|
|
|
190
192
|
function spaceFields(sa: Space, sb: Space): FieldChange[] {
|
|
191
193
|
const fields: FieldChange[] = [];
|
|
@@ -194,12 +196,12 @@ function spaceFields(sa: Space, sb: Space): FieldChange[] {
|
|
|
194
196
|
const ea = canonicalSpaceEntry(sa);
|
|
195
197
|
const eb = canonicalSpaceEntry(sb);
|
|
196
198
|
if (JSON.stringify(ea["at"] ?? null) !== JSON.stringify(eb["at"] ?? null)) {
|
|
197
|
-
fields.push(fieldChange("
|
|
199
|
+
fields.push(fieldChange("region", fmtGrids(sa), fmtGrids(sb)));
|
|
198
200
|
}
|
|
199
201
|
// 面積は導出値の差分として別掲する — 領域が同じでもグリッド座標の移動で変わる (原因はgrid差分が先頭で言う)
|
|
200
202
|
const arA = areaM2(sa);
|
|
201
203
|
const arB = areaM2(sb);
|
|
202
|
-
if (arA !== arB) fields.push(fieldChange("
|
|
204
|
+
if (arA !== arB) fields.push(fieldChange("area", fmtArea(arA), fmtArea(arB)));
|
|
203
205
|
fields.push(...attrFields(sa.attrs, sb.attrs));
|
|
204
206
|
// 数えない分節 (area) — 正準順の直列で多重集合として比べる
|
|
205
207
|
fields.push(
|
|
@@ -263,10 +265,25 @@ function comparable(b: Boundary, tok: (p: string) => string): string {
|
|
|
263
265
|
return JSON.stringify(e);
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
/**
|
|
269
|
+
* 開口の対のキー。**名があれば名が優先である** (ADR-0039) —
|
|
270
|
+
* 開口の同一性は「含む対象 + その中で一意な名」から導かれるので (docs/reference/scope.md)、
|
|
271
|
+
* 名の付いた扉を動かせば「同じ扉の at が変わった」であって「消えて生えた」ではない。
|
|
272
|
+
* 名が無ければ位置で対応づける他にない: (kind, edge??"", atRef??at)。
|
|
273
|
+
* 名のある開口と無い開口は別のキー空間に落ちるので、名を後から書き足した編集は追加/削除に見える —
|
|
274
|
+
* 名を書く行為そのものが同一性の宣言なので、それでよい
|
|
275
|
+
*/
|
|
276
|
+
const openingKey = (model: Model) => (o: Opening): string => {
|
|
277
|
+
const name = openingIdentity(model, o);
|
|
278
|
+
// 名は、位置のキー (door… / window…) と混ざらないトークン空間に置く
|
|
279
|
+
if (name !== undefined) return `\u0000name:${name}`;
|
|
280
|
+
return `${o.kind}#${o.edge ?? ""}#${String(o.atRef ?? o.at)}`;
|
|
281
|
+
};
|
|
282
|
+
const openingLabel = (model: Model) => (o: Opening): string => {
|
|
283
|
+
const name = openingIdentity(model, o);
|
|
284
|
+
if (name !== undefined) return `${o.kind} ${name}`;
|
|
285
|
+
return `${o.kind}${o.edge ? ` edge:${o.edge}` : ""} at:${String(o.atRef ?? o.at)}`;
|
|
286
|
+
};
|
|
270
287
|
|
|
271
288
|
function describeOpening(o: Opening): string {
|
|
272
289
|
const parts = [
|
|
@@ -280,9 +297,17 @@ function describeOpening(o: Opening): string {
|
|
|
280
297
|
return parts.join(" ");
|
|
281
298
|
}
|
|
282
299
|
|
|
283
|
-
/** seg
|
|
284
|
-
const segKey = (g: Seg): string =>
|
|
285
|
-
const
|
|
300
|
+
/** segの対のキー — 開口と同じ規律。名があれば名、無ければ (edge??"", atRef??at, w) */
|
|
301
|
+
const segKey = (g: Seg): string => {
|
|
302
|
+
const name = g.attrs["name"];
|
|
303
|
+
if (name !== undefined && name !== "") return `\u0000name:${String(name)}`;
|
|
304
|
+
return `${g.edge ?? ""}#${String(g.atRef ?? g.at)}#${g.w}`;
|
|
305
|
+
};
|
|
306
|
+
const segLabel = (g: Seg): string => {
|
|
307
|
+
const name = g.attrs["name"];
|
|
308
|
+
if (name !== undefined && name !== "") return `seg ${String(name)}`;
|
|
309
|
+
return `seg${g.edge ? ` edge:${g.edge}` : ""} at:${String(g.atRef ?? g.at)} w:${g.w}`;
|
|
310
|
+
};
|
|
286
311
|
|
|
287
312
|
interface Keyed<T> {
|
|
288
313
|
x: T;
|
|
@@ -334,12 +359,17 @@ function pairUp<T>(as: Keyed<T>[], bs: Keyed<T>[]) {
|
|
|
334
359
|
const keyed = <T>(xs: T[], key: (x: T) => string, serial: (x: T) => string): Keyed<T>[] =>
|
|
335
360
|
xs.map((x) => ({ x, key: key(x), serial: serial(x) }));
|
|
336
361
|
|
|
337
|
-
function openingFields(oa: Opening, ob: Opening): FieldChange[] {
|
|
338
|
-
const label = openingLabel(ob);
|
|
362
|
+
function openingFields(mb: Model, oa: Opening, ob: Opening): FieldChange[] {
|
|
363
|
+
const label = openingLabel(mb)(ob);
|
|
339
364
|
const out: FieldChange[] = [];
|
|
340
365
|
const sub = (f: string, va: AttrValue | undefined, vb: AttrValue | undefined) => {
|
|
341
366
|
if (va !== vb) out.push(fieldChange(`${label} ${f}`, str(va), str(vb)));
|
|
342
367
|
};
|
|
368
|
+
// 名で対応づいた対は、種別も辺も位置もキーに入っていない — フィールドの変化として言う。
|
|
369
|
+
// 位置で対応づいた対ではこの三つは定義上一致するので、何も出ない (ADR-0039)
|
|
370
|
+
sub("kind", oa.kind, ob.kind);
|
|
371
|
+
sub("edge", oa.edge, ob.edge);
|
|
372
|
+
sub("at", String(oa.atRef ?? oa.at), String(ob.atRef ?? ob.at));
|
|
343
373
|
sub("ref", oa.ref, ob.ref);
|
|
344
374
|
sub("w", oa.w, ob.w);
|
|
345
375
|
sub("h", oa.h, ob.h);
|
|
@@ -356,13 +386,20 @@ function lineLabel(d: DrawnLine | undefined): string | undefined {
|
|
|
356
386
|
return forward ? `${d.aRef}..${d.bRef}` : `${d.bRef}..${d.aRef}`;
|
|
357
387
|
}
|
|
358
388
|
|
|
359
|
-
function boundaryFields(
|
|
389
|
+
function boundaryFields(
|
|
390
|
+
ma: Model,
|
|
391
|
+
mb: Model,
|
|
392
|
+
ba: Boundary,
|
|
393
|
+
bb: Boundary,
|
|
394
|
+
tokA: (p: string) => string,
|
|
395
|
+
tokB: (p: string) => string,
|
|
396
|
+
): FieldChange[] {
|
|
360
397
|
const out: FieldChange[] = [];
|
|
361
398
|
if (ba.kind !== bb.kind) out.push(fieldChange("kind", ba.kind, bb.kind));
|
|
362
399
|
if (ba.t !== bb.t) out.push(fieldChange("t", str(ba.t), str(bb.t)));
|
|
363
400
|
if ((ba.air ?? false) !== (bb.air ?? false)) out.push(fieldChange("air", ba.air ? "1" : undefined, bb.air ? "1" : undefined));
|
|
364
401
|
if ((orientationMatters(ba) || orientationMatters(bb)) && tokA(ba.a) !== tokB(bb.a)) {
|
|
365
|
-
out.push(fieldChange("
|
|
402
|
+
out.push(fieldChange("orientation (a side)", ba.a, bb.a));
|
|
366
403
|
}
|
|
367
404
|
// 描かれた線 (ADR-0022) — 境界の実現そのものなので、動かせば建物の形が変わる。
|
|
368
405
|
// 面積の変化として空間側に間接的に出ることはあるが、それは導出値であって原因ではない。
|
|
@@ -371,16 +408,24 @@ function boundaryFields(ba: Boundary, bb: Boundary, tokA: (p: string) => string,
|
|
|
371
408
|
out.push(fieldChange("line", lineLabel(ba.drawn), lineLabel(bb.drawn)));
|
|
372
409
|
}
|
|
373
410
|
out.push(...attrFields(ba.attrs, bb.attrs));
|
|
374
|
-
// 開口 — (kind, edge, at) で対にし、対はフィールド差分、残りは追加/削除
|
|
411
|
+
// 開口 — 名 (あれば)、無ければ (kind, edge, at) で対にし、対はフィールド差分、残りは追加/削除
|
|
375
412
|
const oSerial = (o: Opening): string => JSON.stringify(canonicalOpeningEntry(o));
|
|
376
|
-
const ops = pairUp(keyed(ba.openings, openingKey, oSerial), keyed(bb.openings, openingKey, oSerial));
|
|
377
|
-
for (const [oa, ob] of ops.pairs) out.push(...openingFields(oa, ob));
|
|
378
|
-
for (const o of ops.added) out.push(fieldChange(openingLabel(o), undefined, describeOpening(o)));
|
|
379
|
-
for (const o of ops.removed) out.push(fieldChange(openingLabel(o), describeOpening(o), undefined));
|
|
380
|
-
// seg — (edge, at, w)
|
|
413
|
+
const ops = pairUp(keyed(ba.openings, openingKey(ma), oSerial), keyed(bb.openings, openingKey(mb), oSerial));
|
|
414
|
+
for (const [oa, ob] of ops.pairs) out.push(...openingFields(mb, oa, ob));
|
|
415
|
+
for (const o of ops.added) out.push(fieldChange(openingLabel(mb)(o), undefined, describeOpening(o)));
|
|
416
|
+
for (const o of ops.removed) out.push(fieldChange(openingLabel(ma)(o), describeOpening(o), undefined));
|
|
417
|
+
// seg — 名 (あれば)、無ければ (edge, at, w) で対にする
|
|
381
418
|
const gSerial = (g: Seg): string => JSON.stringify(canonicalSegEntry(g));
|
|
382
419
|
const sgs = pairUp(keyed(ba.segs, segKey, gSerial), keyed(bb.segs, segKey, gSerial));
|
|
383
|
-
for (const [ga, gb] of sgs.pairs)
|
|
420
|
+
for (const [ga, gb] of sgs.pairs) {
|
|
421
|
+
const lab = segLabel(gb);
|
|
422
|
+
// 名で対応づいた対は、辺も位置も幅もキーに入っていない (ADR-0039)
|
|
423
|
+
if ((ga.edge ?? "") !== (gb.edge ?? "")) out.push(fieldChange(`${lab} edge`, ga.edge, gb.edge));
|
|
424
|
+
const [pa, pb] = [String(ga.atRef ?? ga.at), String(gb.atRef ?? gb.at)];
|
|
425
|
+
if (pa !== pb) out.push(fieldChange(`${lab} at`, pa, pb));
|
|
426
|
+
if (ga.w !== gb.w) out.push(fieldChange(`${lab} w`, String(ga.w), String(gb.w)));
|
|
427
|
+
out.push(...attrFields(ga.attrs, gb.attrs, `${lab} `));
|
|
428
|
+
}
|
|
384
429
|
for (const g of sgs.added) {
|
|
385
430
|
out.push(fieldChange(segLabel(g), undefined, Object.entries(g.attrs).map(([k, v]) => `${k}:${v}`).join(" ")));
|
|
386
431
|
}
|
|
@@ -487,12 +532,12 @@ export function semanticDiff(a: Model, b: Model): ModelDiff {
|
|
|
487
532
|
// 何も伝えない。形が変わって頂点数も面積も同じなら、そう言う
|
|
488
533
|
const fields: FieldChange[] = [];
|
|
489
534
|
if (pa.points.length !== pb.points.length) {
|
|
490
|
-
fields.push(fieldChange("
|
|
535
|
+
fields.push(fieldChange("vertices", String(pa.points.length), String(pb.points.length)));
|
|
491
536
|
}
|
|
492
537
|
const ar = round2(polygonAreaM2(pa.points));
|
|
493
538
|
const br = round2(polygonAreaM2(pb.points));
|
|
494
|
-
if (ar !== br) fields.push(fieldChange("
|
|
495
|
-
if (fields.length === 0) fields.push(fieldChange("
|
|
539
|
+
if (ar !== br) fields.push(fieldChange("area", fmtArea(ar), fmtArea(br)));
|
|
540
|
+
if (fields.length === 0) fields.push(fieldChange("shape", "same vertex count and same area", "the vertices sit elsewhere"));
|
|
496
541
|
d.polygons.changed.push({ path, fields });
|
|
497
542
|
}
|
|
498
543
|
}
|
|
@@ -502,7 +547,7 @@ export function semanticDiff(a: Model, b: Model): ModelDiff {
|
|
|
502
547
|
{
|
|
503
548
|
const label = (c: ColumnDecl): string =>
|
|
504
549
|
[
|
|
505
|
-
`${c.size}
|
|
550
|
+
`${c.size} square`,
|
|
506
551
|
...(c.depth !== undefined ? [`d:${c.depth}`] : []),
|
|
507
552
|
c.levels.length > 2 ? `${c.levels[0]}..${c.levels[c.levels.length - 1]}` : c.levels.join(","),
|
|
508
553
|
...(c.xNames ? [`x:${c.xNames.join(",")}`] : []),
|
|
@@ -521,7 +566,7 @@ export function semanticDiff(a: Model, b: Model): ModelDiff {
|
|
|
521
566
|
for (const [lab, at] of ra) {
|
|
522
567
|
const to = rb.get(lab);
|
|
523
568
|
if (to !== undefined && to !== at) {
|
|
524
|
-
d.columns.changed.push({ path: lab, fields: [fieldChange("
|
|
569
|
+
d.columns.changed.push({ path: lab, fields: [fieldChange("rank", String(at), String(to))] });
|
|
525
570
|
}
|
|
526
571
|
}
|
|
527
572
|
}
|
|
@@ -543,7 +588,7 @@ export function semanticDiff(a: Model, b: Model): ModelDiff {
|
|
|
543
588
|
d.spaces.renamed = sm.renamed.sort((x, y) => (key(x.to) < key(y.to) ? -1 : 1));
|
|
544
589
|
const spaceItem = (s: Space): SpaceItem => {
|
|
545
590
|
const ar = areaM2(s);
|
|
546
|
-
return { path: s.path, type: s.type, ...(ar !== undefined ? { areaM2: ar } : {}) };
|
|
591
|
+
return { path: s.path, ...(s.type !== undefined ? { type: s.type } : {}), ...(ar !== undefined ? { areaM2: ar } : {}) };
|
|
547
592
|
};
|
|
548
593
|
d.spaces.added = sm.added.map(spaceItem).sort((x, y) => (key(x.path) < key(y.path) ? -1 : 1));
|
|
549
594
|
d.spaces.removed = sm.removed.map(spaceItem).sort((x, y) => (key(x.path) < key(y.path) ? -1 : 1));
|
|
@@ -582,7 +627,7 @@ export function semanticDiff(a: Model, b: Model): ModelDiff {
|
|
|
582
627
|
return kx < ky ? -1 : 1;
|
|
583
628
|
};
|
|
584
629
|
for (const [ba, bb] of bm.pairs) {
|
|
585
|
-
const fields = boundaryFields(ba, bb, tokA, tokB);
|
|
630
|
+
const fields = boundaryFields(a, b, ba, bb, tokA, tokB);
|
|
586
631
|
if (fields.length) {
|
|
587
632
|
d.boundaries.changed.push({
|
|
588
633
|
between: [bb.a, bb.b].sort() as [string, string],
|
|
@@ -633,7 +678,7 @@ const fmtFields = (fields: FieldChange[]): string => fields.map(fmtField).join("
|
|
|
633
678
|
const betweenLabel = (x: { between: [string, string]; edge?: Edge }): string =>
|
|
634
679
|
`${x.between[0]} | ${x.between[1]}${x.edge ? ` edge:${x.edge}` : ""}`;
|
|
635
680
|
|
|
636
|
-
/**
|
|
681
|
+
/** 差分行 (英語・空なら差分なし)。並びはsemanticDiffが決めた正準順のまま */
|
|
637
682
|
export function renderDiff(d: ModelDiff): string[] {
|
|
638
683
|
const out: string[] = [];
|
|
639
684
|
for (const g of d.grid) {
|
|
@@ -652,25 +697,28 @@ export function renderDiff(d: ModelDiff): string[] {
|
|
|
652
697
|
for (const p of d.polygons.added) out.push(`+ polygon ${p}`);
|
|
653
698
|
for (const p of d.polygons.removed) out.push(`− polygon ${p}`);
|
|
654
699
|
for (const c of d.polygons.changed) out.push(`± polygon ${c.path}: ${fmtFields(c.fields)}`);
|
|
655
|
-
for (const r of d.zones.renamed) out.push(
|
|
656
|
-
for (const p of d.zones.added) out.push(`+
|
|
657
|
-
for (const p of d.zones.removed) out.push(`−
|
|
658
|
-
for (const c of d.zones.changed) out.push(`±
|
|
659
|
-
for (const r of d.spaces.renamed) out.push(
|
|
700
|
+
for (const r of d.zones.renamed) out.push(`renamed zone ${r.from} → ${r.to} (uid:${r.uid})`);
|
|
701
|
+
for (const p of d.zones.added) out.push(`+ zone ${p}`);
|
|
702
|
+
for (const p of d.zones.removed) out.push(`− zone ${p}`);
|
|
703
|
+
for (const c of d.zones.changed) out.push(`± zone ${c.path}: ${fmtFields(c.fields)}`);
|
|
704
|
+
for (const r of d.spaces.renamed) out.push(`renamed ${r.from} → ${r.to} (uid:${r.uid})`);
|
|
705
|
+
// 型は任意なので、書かれていない空間もある。`${undefined}` が "undefined" と刷られると
|
|
706
|
+
// 型がそう綴られたように読めるので、集計の見出しと同じ形で言う (cli.ts と同じ構え)
|
|
707
|
+
const label = (t?: string) => t ?? "(untyped)";
|
|
660
708
|
for (const s of d.spaces.added) {
|
|
661
|
-
out.push(`+
|
|
709
|
+
out.push(`+ space ${s.path} (${label(s.type)}${s.areaM2 !== undefined ? ` ${s.areaM2.toFixed(2)} m2` : ""})`);
|
|
662
710
|
}
|
|
663
711
|
for (const s of d.spaces.removed) {
|
|
664
|
-
out.push(`−
|
|
712
|
+
out.push(`− space ${s.path} (${label(s.type)}${s.areaM2 !== undefined ? ` ${s.areaM2.toFixed(2)} m2` : ""})`);
|
|
665
713
|
}
|
|
666
714
|
for (const c of d.spaces.changed) out.push(`± ${c.path}: ${fmtFields(c.fields)}`);
|
|
667
715
|
for (const x of d.boundaries.added) {
|
|
668
|
-
out.push(`+
|
|
716
|
+
out.push(`+ boundary ${betweenLabel(x)} (${x.kind}${x.t !== undefined ? ` t:${x.t}` : ""})`);
|
|
669
717
|
}
|
|
670
|
-
for (const x of d.boundaries.removed) out.push(`−
|
|
671
|
-
for (const c of d.boundaries.changed) out.push(`±
|
|
672
|
-
for (const c of d.columns.added) out.push(`+
|
|
673
|
-
for (const c of d.columns.removed) out.push(`−
|
|
674
|
-
for (const c of d.columns.changed) out.push(`±
|
|
718
|
+
for (const x of d.boundaries.removed) out.push(`− boundary ${betweenLabel(x)}`);
|
|
719
|
+
for (const c of d.boundaries.changed) out.push(`± boundary ${betweenLabel(c)}: ${fmtFields(c.fields)}`);
|
|
720
|
+
for (const c of d.columns.added) out.push(`+ column ${c.label}`);
|
|
721
|
+
for (const c of d.columns.removed) out.push(`− column ${c.label}`);
|
|
722
|
+
for (const c of d.columns.changed) out.push(`± column ${c.path}: ${fmtFields(c.fields)}`);
|
|
675
723
|
return out;
|
|
676
724
|
}
|
|
@@ -6,18 +6,26 @@
|
|
|
6
6
|
// 壁が境界から現れ、柱が通りの交点から現れるのと同じ構えで、面もまた宣言から現れる —
|
|
7
7
|
// 床を置く操作も、天井を張る操作も、屋根を架ける操作も存在しない。
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
canonicalSpaceOrder,
|
|
11
|
+
heff,
|
|
12
|
+
isSemiOutdoor,
|
|
13
|
+
levelsSorted,
|
|
14
|
+
regionOf,
|
|
15
|
+
type Model,
|
|
16
|
+
type Pt,
|
|
17
|
+
type Space,
|
|
18
|
+
isOutside,
|
|
19
|
+
isVoid as isVoidSpace
|
|
20
|
+
} from "./model.js";
|
|
10
21
|
import { areaOf, rectToPoly, subtract } from "./poly.js";
|
|
22
|
+
import { AREA_EPS } from "./tolerance.js";
|
|
11
23
|
import { runDecls } from "./vertical.js";
|
|
12
24
|
|
|
13
25
|
/** 天井面の見付け厚 mm (仕上げの面としての厚み) */
|
|
14
|
-
const CEILING_T = 30;
|
|
26
|
+
export const CEILING_T = 30;
|
|
15
27
|
/** 上に何も無いときの屋根版の厚さ mm (上階レベルの slab が無い場合の既定) */
|
|
16
|
-
const ROOF_T = 200;
|
|
17
|
-
|
|
18
|
-
/** 空間の導出された領域。parse の出口で必ず埋まる (ADR-0022) — 割付への退避は持たない */
|
|
19
|
-
export const regionOf = (s: Space): Pt[][] =>
|
|
20
|
-
s.pieces.length > 0 ? s.pieces : s.rects.map(rectToPoly);
|
|
28
|
+
export const ROOF_T = 200;
|
|
21
29
|
|
|
22
30
|
export type SlabKind = "floor" | "ceiling" | "roof";
|
|
23
31
|
|
|
@@ -48,7 +56,9 @@ export function slabs(model: Model): Slab[] {
|
|
|
48
56
|
const levels = levelsSorted(model);
|
|
49
57
|
const out: Slab[] = [];
|
|
50
58
|
const byLevel = new Map<string, Space[]>();
|
|
51
|
-
|
|
59
|
+
// Canonical order — the canonical form discards declaration order, so a surface that reads
|
|
60
|
+
// it makes the shape a function of it (promise 1)
|
|
61
|
+
for (const s of canonicalSpaceOrder(model)) {
|
|
52
62
|
if (s.rects.length === 0 || !s.level) continue;
|
|
53
63
|
const arr = byLevel.get(s.level) ?? [];
|
|
54
64
|
arr.push(s);
|
|
@@ -59,8 +69,8 @@ export function slabs(model: Model): Slab[] {
|
|
|
59
69
|
const upper = levels[li + 1];
|
|
60
70
|
for (const s of byLevel.get(level.name) ?? []) {
|
|
61
71
|
const pieces = regionOf(s);
|
|
62
|
-
const isVoid = s
|
|
63
|
-
const isExterior = s
|
|
72
|
+
const isVoid = isVoidSpace(s);
|
|
73
|
+
const isExterior = isOutside(s);
|
|
64
74
|
const semi = isSemiOutdoor(model, s);
|
|
65
75
|
const isRun = runDecls(s).length > 0;
|
|
66
76
|
|
|
@@ -105,7 +115,7 @@ export function slabs(model: Model): Slab[] {
|
|
|
105
115
|
const covers: Pt[][] = [];
|
|
106
116
|
for (const up of levels.slice(li + 1)) {
|
|
107
117
|
for (const o of byLevel.get(up.name) ?? []) {
|
|
108
|
-
if (o
|
|
118
|
+
if (isOutside(o)) continue;
|
|
109
119
|
covers.push(...regionOf(o));
|
|
110
120
|
}
|
|
111
121
|
}
|
|
@@ -113,7 +123,7 @@ export function slabs(model: Model): Slab[] {
|
|
|
113
123
|
const t = upper?.slab ?? ROOF_T;
|
|
114
124
|
for (const outline of pieces) {
|
|
115
125
|
for (const tile of subtract(outline, covers)) {
|
|
116
|
-
if (areaOf([tile]) <
|
|
126
|
+
if (areaOf([tile]) < AREA_EPS) continue;
|
|
117
127
|
out.push({ kind: "roof", space: s.path, level: level.name, outline: tile, z0: top - t, z1: top });
|
|
118
128
|
}
|
|
119
129
|
}
|
|
@@ -4,8 +4,15 @@
|
|
|
4
4
|
// 空間の領域は矩形の合併 (L字など)。壁は合併の外周と共有辺から導出される。
|
|
5
5
|
|
|
6
6
|
import type { Boundary, Edge, Model, Opening, Pt, Rect, Space } from "./model.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
canonicalBoundaryOrder,
|
|
9
|
+
canonicalizeDrawn,
|
|
10
|
+
compareCanonical,
|
|
11
|
+
rectToPoly,
|
|
12
|
+
srcRef,
|
|
13
|
+
} from "./model.js";
|
|
8
14
|
import * as poly from "./poly.js";
|
|
15
|
+
import { EPS, PARALLEL_EPS, PROBE, SPAN_EPS } from "./tolerance.js";
|
|
9
16
|
|
|
10
17
|
/** 壁芯線分 (mm)。水平なら y1===y2、垂直なら x1===x2。
|
|
11
18
|
* 描かれた線 (ADR-0022) は斜めになりうる — その場合 diagonal が立つ */
|
|
@@ -21,35 +28,6 @@ export interface Segment {
|
|
|
21
28
|
edgeOfA?: Edge;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
const EPS = 0.5;
|
|
25
|
-
|
|
26
|
-
/** 二つの矩形が共有する辺の線分 (触れていなければ undefined) */
|
|
27
|
-
export function sharedSegment(a: Rect, b: Rect): Segment | undefined {
|
|
28
|
-
for (const [x, ea] of [
|
|
29
|
-
[a.x2, "E"],
|
|
30
|
-
[a.x1, "W"],
|
|
31
|
-
] as const) {
|
|
32
|
-
const bx = ea === "E" ? b.x1 : b.x2;
|
|
33
|
-
if (Math.abs(x - bx) < EPS) {
|
|
34
|
-
const y1 = Math.max(a.y1, b.y1);
|
|
35
|
-
const y2 = Math.min(a.y2, b.y2);
|
|
36
|
-
if (y2 - y1 > EPS) return { x1: x, y1, x2: x, y2, horizontal: false, edgeOfA: ea };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
for (const [y, ea] of [
|
|
40
|
-
[a.y2, "N"],
|
|
41
|
-
[a.y1, "S"],
|
|
42
|
-
] as const) {
|
|
43
|
-
const by = ea === "N" ? b.y1 : b.y2;
|
|
44
|
-
if (Math.abs(y - by) < EPS) {
|
|
45
|
-
const x1 = Math.max(a.x1, b.x1);
|
|
46
|
-
const x2 = Math.min(a.x2, b.x2);
|
|
47
|
-
if (x2 - x1 > EPS) return { x1, y1: y, x2, y2: y, horizontal: true, edgeOfA: ea };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
31
|
/**
|
|
54
32
|
* 凸片の軸平行な辺 (向きから N/E/S/W を読む)。頂点列は反時計回りなので、
|
|
55
33
|
* +x へ進む辺が南、+y が東、-x が北、-y が西の面になる。
|
|
@@ -118,8 +96,8 @@ function pieceOutline(pieces: Pt[][], others: Pt[][]): Segment[] {
|
|
|
118
96
|
}
|
|
119
97
|
|
|
120
98
|
/**
|
|
121
|
-
* 二つの領域 (凸片の集合)
|
|
122
|
-
*
|
|
99
|
+
* 二つの領域 (凸片の集合) が共有する軸平行な辺。矩形どうしの共有辺ではなく凸片で見るので、
|
|
100
|
+
* 描かれた線で切られた形にも正しい。
|
|
123
101
|
* 斜めの辺は返さない — それは描かれた線であり、自分の境界が実現を持っている
|
|
124
102
|
*/
|
|
125
103
|
function sharedFromPieces(A: Pt[][], B: Pt[][]): Segment[] {
|
|
@@ -176,7 +154,7 @@ export function mergeCollinear(segs: Segment[]): Segment[] {
|
|
|
176
154
|
* 既定境界の導出 (ADR-0014) — 垂直の「既定は床」と対称の、水平の「既定は壁」。
|
|
177
155
|
* 同一レベル (未特定同士を含む) で平面が接する領域つき空間の組に、宣言境界がその組に
|
|
178
156
|
* 一つも無ければ kind:wall の既定境界を導く。宣言は例外 (open・手すり) と属性のためにある。
|
|
179
|
-
* 領域を持たない空間 (
|
|
157
|
+
* 領域を持たない空間 (`outside:1` の外部など) との境界は導かない — 相手の名指しが情報のため宣言する。
|
|
180
158
|
* 合成・スパン展開の完了後に呼ぶ (parse / parseWith の出口)。冪等。
|
|
181
159
|
*/
|
|
182
160
|
export function deriveDefaultBoundaries(model: Model): void {
|
|
@@ -192,9 +170,17 @@ export function deriveDefaultBoundaries(model: Model): void {
|
|
|
192
170
|
if (declared.has(key)) continue;
|
|
193
171
|
// 接触は**導出された形**で見る — 線で接触が消えた組に既定の壁を作らない
|
|
194
172
|
if (sharedFromPieces(piecesOf(a), piecesOf(b)).length === 0) continue;
|
|
173
|
+
// The a/b orientation is decided in **canonical order**. On a declared boundary, `a` is
|
|
174
|
+
// the side as written and the canonical form preserves it as the `a` key, so the shape
|
|
175
|
+
// may read it. A derived boundary never appears in the canonical form, so it has no
|
|
176
|
+
// written orientation; taking the declaration order of the spaces would let discarded
|
|
177
|
+
// information change the shape — the relation identity (`a|b@i`) and the `edgeOfA`
|
|
178
|
+
// bearing would flip with it, against promise 1
|
|
179
|
+
const [pa, pb] =
|
|
180
|
+
compareCanonical(a.path, b.path) <= 0 ? [a.path, b.path] : [b.path, a.path];
|
|
195
181
|
model.boundaries.push({
|
|
196
|
-
a:
|
|
197
|
-
b:
|
|
182
|
+
a: pa,
|
|
183
|
+
b: pb,
|
|
198
184
|
kind: "wall",
|
|
199
185
|
derived: true,
|
|
200
186
|
attrs: {},
|
|
@@ -220,15 +206,33 @@ export function deriveDefaultBoundaries(model: Model): void {
|
|
|
220
206
|
*/
|
|
221
207
|
export function derivePieces(model: Model): void {
|
|
222
208
|
for (const s of model.spaces.values()) s.pieces = s.rects.map(rectToPoly);
|
|
223
|
-
// 線は宣言順に効く。derivePieces は parse の出口で一度だけ呼ぶ (冪等ではない)
|
|
224
209
|
|
|
225
|
-
|
|
210
|
+
// **線の向きを正準に揃えてから切る。**線分は向きを持たないので、正準JSONは端点の対を
|
|
211
|
+
// 解決座標の昇順に並べ替える。モデルの側が書き順のままだと、開口の `at:` の起点が
|
|
212
|
+
// 書き順で決まり、**正準JSONがバイト同一のまま扉が別の位置に出る** (ADR-0041)
|
|
213
|
+
for (const b of model.boundaries) if (b.drawn) canonicalizeDrawn(b.drawn);
|
|
214
|
+
|
|
215
|
+
// **正準の境界順で切る。**線の切り分けは直前の切り分けの結果を読むので順序が効くが、
|
|
216
|
+
// 正準JSONは境界の宣言順を捨てる。宣言順で切ると、同じ正準JSONから違う面積が出る
|
|
217
|
+
// (実測: 交差する二本の線で /L1/a が 27.00㎡ ↔ 22.50㎡)。並びは toCanonical と同じ規則
|
|
218
|
+
for (const b of canonicalBoundaryOrder(model)) {
|
|
226
219
|
if (!b.drawn) continue;
|
|
227
220
|
const sa = model.spaces.get(b.a);
|
|
228
221
|
const sb = model.spaces.get(b.b);
|
|
229
222
|
if (!sa || !sb) continue;
|
|
230
223
|
const cut = drawnCut(sa, sb, b.drawn.a, b.drawn.b);
|
|
231
|
-
if (!cut)
|
|
224
|
+
if (!cut) {
|
|
225
|
+
b.drawn.effect = "undetermined";
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
// **何を切ったかは、切るその場で記録する。**後から計算し直すと、既に切られた形を
|
|
229
|
+
// 相手に窓を組み立てることになる (ADR-0041)
|
|
230
|
+
const targets = cut.solo ? [cut.solo] : [sa, sb];
|
|
231
|
+
b.drawn.effect = targets.some((s) =>
|
|
232
|
+
poly.cutsInWindow(s.pieces, cut.window, b.drawn!.a, b.drawn!.b),
|
|
233
|
+
)
|
|
234
|
+
? "cut"
|
|
235
|
+
: "nothing";
|
|
232
236
|
|
|
233
237
|
if (cut.solo) {
|
|
234
238
|
// 外皮を切る線 — 持つ側だけが窓の中で自分の側へ切り落とされる。相手は面積を得ない
|
|
@@ -258,7 +262,7 @@ export function derivePieces(model: Model): void {
|
|
|
258
262
|
}
|
|
259
263
|
|
|
260
264
|
/**
|
|
261
|
-
* 描かれた線の切り方を一度に決める — 窓・残す側・片側かどうか (ADR-0022 /
|
|
265
|
+
* 描かれた線の切り方を一度に決める — 窓・残す側・片側かどうか (ADR-0022 / docs/reference/form/index.md-1.3)。
|
|
262
266
|
*
|
|
263
267
|
* **窓と側は必ず一緒に決める。**別々に決めていたために、側は空間の全割付を無限直線で
|
|
264
268
|
* 測るのに切るのは線の近傍だけ、という母集団のずれが生まれ、線から遠い翼が符号を
|
|
@@ -282,7 +286,10 @@ export function drawnCut(
|
|
|
282
286
|
if (!poly.validWindow(w)) return undefined;
|
|
283
287
|
const side = poly.sideOfTouching(solo.pieces, w, a, b);
|
|
284
288
|
if (side === 0) return undefined; // 窓の中でちょうど二等分 — 残す側が決まらない (LIN01)
|
|
285
|
-
|
|
289
|
+
// **残す側は、領域を持つ側そのものが決める。**a/b の向きで符号を返していたので、
|
|
290
|
+
// `boundary /out /L1/room` と書くと残す側が反転していた (実測 26㎡ ↔ 34㎡、check は緑)。
|
|
291
|
+
// a/b の向きが意味を持つのは `edge` と `swing` だけで、形はそれに従わない (ADR-0041)
|
|
292
|
+
return { window: w, sideA: side, solo };
|
|
286
293
|
}
|
|
287
294
|
const w = poly.lineWindow(a, b, ba, bb);
|
|
288
295
|
if (!poly.validWindow(w)) return undefined;
|
|
@@ -295,11 +302,6 @@ export function drawnCut(
|
|
|
295
302
|
return { window: w, sideA: ia };
|
|
296
303
|
}
|
|
297
304
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
305
|
/** 境界の壁芯線分を導く。壁の位置は空間の割付から生成される — 壁を置く操作は存在しない */
|
|
304
306
|
export function segmentsFor(model: Model, b: Boundary): Segment[] {
|
|
305
307
|
const sa = model.spaces.get(b.a);
|
|
@@ -364,7 +366,7 @@ export function envelopeGaps(model: Model, s: Space): Segment[] {
|
|
|
364
366
|
gaps = gaps.flatMap((g) => subtractOverlap(g, seg));
|
|
365
367
|
}
|
|
366
368
|
}
|
|
367
|
-
return gaps.filter((g) => segmentLength(g) >
|
|
369
|
+
return gaps.filter((g) => segmentLength(g) > SPAN_EPS);
|
|
368
370
|
}
|
|
369
371
|
|
|
370
372
|
/** 軸平行の線分から、同一直線上で重なる区間を引く */
|
|
@@ -394,9 +396,6 @@ function piecesOf(s: Space): Pt[][] {
|
|
|
394
396
|
return s.pieces.length > 0 ? s.pieces : s.rects.map(rectToPoly);
|
|
395
397
|
}
|
|
396
398
|
|
|
397
|
-
/** 線の左右へ少し離れた点。どちらの空間に属するかを見るための探り */
|
|
398
|
-
const PROBE = 5;
|
|
399
|
-
|
|
400
399
|
/**
|
|
401
400
|
* 描かれた線のうち、この二空間が実際に向かい合っている区間だけを返す (ADR-0022)。
|
|
402
401
|
*
|
|
@@ -419,7 +418,7 @@ function drawnShare(model: Model, sa: Space, sb: Space, p: Pt, q: Pt): Segment[]
|
|
|
419
418
|
for (const poly of [...A, ...B]) {
|
|
420
419
|
for (let i = 0; i < poly.length; i++) {
|
|
421
420
|
const t = lineHit(p, q, poly[i]!, poly[(i + 1) % poly.length]!);
|
|
422
|
-
if (t !== undefined && t >
|
|
421
|
+
if (t !== undefined && t > PARALLEL_EPS && t < 1 - PARALLEL_EPS) cuts.add(t);
|
|
423
422
|
}
|
|
424
423
|
}
|
|
425
424
|
const ts = [...cuts].sort((x, y) => x - y);
|
|
@@ -455,8 +454,8 @@ function drawnShare(model: Model, sa: Space, sb: Space, p: Pt, q: Pt): Segment[]
|
|
|
455
454
|
last.y2 = end.y;
|
|
456
455
|
continue;
|
|
457
456
|
}
|
|
458
|
-
const horizontal = Math.abs(dy) <
|
|
459
|
-
const vertical = Math.abs(dx) <
|
|
457
|
+
const horizontal = Math.abs(dy) < EPS;
|
|
458
|
+
const vertical = Math.abs(dx) < EPS;
|
|
460
459
|
out.push({
|
|
461
460
|
x1: start.x,
|
|
462
461
|
y1: start.y,
|
|
@@ -476,10 +475,10 @@ function lineHit(p: Pt, q: Pt, u: Pt, v: Pt): number | undefined {
|
|
|
476
475
|
const sx = v.x - u.x;
|
|
477
476
|
const sy = v.y - u.y;
|
|
478
477
|
const d = rx * sy - ry * sx;
|
|
479
|
-
if (Math.abs(d) <
|
|
478
|
+
if (Math.abs(d) < PARALLEL_EPS) return undefined;
|
|
480
479
|
const t = ((u.x - p.x) * sy - (u.y - p.y) * sx) / d;
|
|
481
480
|
const w = ((u.x - p.x) * ry - (u.y - p.y) * rx) / d;
|
|
482
|
-
return w >= -
|
|
481
|
+
return w >= -PARALLEL_EPS && w <= 1 + PARALLEL_EPS ? t : undefined;
|
|
483
482
|
}
|
|
484
483
|
|
|
485
484
|
export function segmentLength(s: Segment): number {
|
|
@@ -559,15 +558,15 @@ export function placeBand(
|
|
|
559
558
|
let segs = segmentsFor(model, b);
|
|
560
559
|
if (band.edge) segs = segs.filter((s) => s.edgeOfA === band.edge);
|
|
561
560
|
if (segs.length === 0) {
|
|
562
|
-
return fail("04",
|
|
561
|
+
return fail("04", `No boundary segment can hold the ${label} (${b.a} | ${b.b})`);
|
|
563
562
|
}
|
|
564
563
|
if (segs.length > 1) {
|
|
565
|
-
return fail("05",
|
|
564
|
+
return fail("05", `There is more than one boundary segment; pick an edge with edge:N/E/S/W (${b.a} | ${b.b})`);
|
|
566
565
|
}
|
|
567
566
|
const seg = segs[0]!;
|
|
568
567
|
const len = segmentLength(seg);
|
|
569
568
|
if (band.w > len) {
|
|
570
|
-
return fail("06",
|
|
569
|
+
return fail("06", `The ${label} width ${band.w} exceeds the boundary segment length ${len}`);
|
|
571
570
|
}
|
|
572
571
|
const half = band.w / 2;
|
|
573
572
|
let pos: number;
|
|
@@ -576,7 +575,7 @@ export function placeBand(
|
|
|
576
575
|
if (seg.diagonal) {
|
|
577
576
|
return fail(
|
|
578
577
|
"07",
|
|
579
|
-
|
|
578
|
+
`The ${label} position ${band.atRef} cannot be used on a diagonal segment (write it as a ratio, at:0..1)`,
|
|
580
579
|
);
|
|
581
580
|
}
|
|
582
581
|
// 明示位置: 通り参照で置かれたものはクランプしない — はみ出しは言葉のエラーになる
|
|
@@ -584,9 +583,11 @@ export function placeBand(
|
|
|
584
583
|
if (!axisOk) {
|
|
585
584
|
return fail(
|
|
586
585
|
"07",
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
586
|
+
// **期待する軸を言う。**書かれた軸を言うと「X1+200 は Y系で書かれています」のような
|
|
587
|
+
// 偽の文になる (この枝は軸が食い違ったときにだけ通るので、書かれた軸は期待と逆である)
|
|
588
|
+
`The ${label} position ${band.atRef} is on the wrong axis: ${
|
|
589
|
+
seg.horizontal ? "a horizontal segment takes an X" : "a vertical segment takes a Y"
|
|
590
|
+
} grid line`,
|
|
590
591
|
);
|
|
591
592
|
}
|
|
592
593
|
const start = seg.horizontal ? seg.x1 : seg.y1;
|
|
@@ -594,9 +595,9 @@ export function placeBand(
|
|
|
594
595
|
if (pos < half - EPS || pos > len - half + EPS) {
|
|
595
596
|
return fail(
|
|
596
597
|
"08",
|
|
597
|
-
|
|
598
|
+
`At ${band.atRef} the ${label} (width ${band.w}) runs off the boundary segment (segment ${Math.round(
|
|
598
599
|
start,
|
|
599
|
-
)}
|
|
600
|
+
)}-${Math.round(start + len)}mm, center allowed ${Math.round(start + half)}-${Math.round(
|
|
600
601
|
start + len - half,
|
|
601
602
|
)}mm)`,
|
|
602
603
|
);
|