@kensnzk/koyu 0.27.0 → 0.28.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/assets/plan/README.md +18 -0
- package/assets/plan/catalog.muro +87 -0
- package/assets/plan/library.muro +26 -0
- package/assets/plan/svg/bathtub.svg +9 -0
- package/assets/plan/svg/bed-double.svg +9 -0
- package/assets/plan/svg/bed-single.svg +8 -0
- package/assets/plan/svg/cabinet.svg +9 -0
- package/assets/plan/svg/chair.svg +8 -0
- package/assets/plan/svg/desk.svg +9 -0
- package/assets/plan/svg/hedge-2m.svg +7 -0
- package/assets/plan/svg/kitchen-sink.svg +10 -0
- package/assets/plan/svg/locker.svg +9 -0
- package/assets/plan/svg/office-chair.svg +25 -0
- package/assets/plan/svg/potted-plant.svg +14 -0
- package/assets/plan/svg/refrigerator.svg +10 -0
- package/assets/plan/svg/shelf.svg +9 -0
- package/assets/plan/svg/shrub-1m.svg +7 -0
- package/assets/plan/svg/sofa-2.svg +9 -0
- package/assets/plan/svg/sofa-3.svg +9 -0
- package/assets/plan/svg/table-rect.svg +7 -0
- package/assets/plan/svg/table-round.svg +7 -0
- package/assets/plan/svg/tree-3m.svg +8 -0
- package/assets/plan/svg/urinal.svg +9 -0
- package/assets/plan/svg/washing-machine-pan.svg +13 -0
- package/assets/plan/svg/washing-machine.svg +10 -0
- package/assets/plan/svg/washstand-500.svg +12 -0
- package/assets/plan/svg/washstand.svg +12 -0
- package/assets/plan/svg/wc-cabinet.svg +14 -0
- package/assets/plan/svg/wc.svg +9 -0
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/core/components.d.ts +31 -0
- package/dist/core/components.d.ts.map +1 -0
- package/dist/core/components.js +167 -0
- package/dist/core/components.js.map +1 -0
- package/dist/core/derive.d.ts +9 -1
- package/dist/core/derive.d.ts.map +1 -1
- package/dist/core/derive.js +33 -3
- package/dist/core/derive.js.map +1 -1
- package/dist/core/diagnose.d.ts +6 -0
- package/dist/core/diagnose.d.ts.map +1 -1
- package/dist/core/diagnose.js +137 -4
- package/dist/core/diagnose.js.map +1 -1
- package/dist/core/model.d.ts +5 -5
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +6 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +5 -4
- package/dist/core/parse.js.map +1 -1
- package/dist/core/vocabulary.d.ts +20 -4
- package/dist/core/vocabulary.d.ts.map +1 -1
- package/dist/core/vocabulary.js +107 -9
- package/dist/core/vocabulary.js.map +1 -1
- package/dist/draw/component-files.d.ts +8 -0
- package/dist/draw/component-files.d.ts.map +1 -0
- package/dist/draw/component-files.js +35 -0
- package/dist/draw/component-files.js.map +1 -0
- package/dist/draw/component-svg.d.ts +14 -0
- package/dist/draw/component-svg.d.ts.map +1 -0
- package/dist/draw/component-svg.js +67 -0
- package/dist/draw/component-svg.js.map +1 -0
- package/dist/draw/conventions/architectural.d.ts +32 -0
- package/dist/draw/conventions/architectural.d.ts.map +1 -0
- package/dist/draw/conventions/architectural.js +29 -0
- package/dist/draw/conventions/architectural.js.map +1 -0
- 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 +37 -12
- package/dist/draw/marks.d.ts.map +1 -1
- package/dist/draw/marks.js +508 -38
- package/dist/draw/marks.js.map +1 -1
- package/dist/draw/plan.d.ts +3 -1
- package/dist/draw/plan.d.ts.map +1 -1
- package/dist/draw/plan.js +247 -85
- package/dist/draw/plan.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/index.js +1 -1
- package/dist/mcp.js +21 -3
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -0
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +1 -0
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/builtin/index.d.ts +4 -2
- package/dist/validate/builtin/index.d.ts.map +1 -1
- package/dist/validate/builtin/index.js +9 -2
- package/dist/validate/builtin/index.js.map +1 -1
- package/dist/validate/builtin/opening-operations.d.ts +63 -0
- package/dist/validate/builtin/opening-operations.d.ts.map +1 -0
- package/dist/validate/builtin/opening-operations.js +406 -0
- package/dist/validate/builtin/opening-operations.js.map +1 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +3 -3
- package/examples/basement/main.muro +3 -3
- package/examples/complex/L1.muro +1 -1
- package/examples/complex/assets.muro +2 -2
- package/examples/complex/main.muro +1 -1
- package/examples/house/L1.muro +3 -3
- package/examples/house/L2.muro +2 -2
- package/examples/house/assets.muro +8 -8
- package/examples/house/main.muro +1 -1
- package/examples/house/site.muro +2 -2
- package/examples/house.muro +6 -6
- package/examples/mansion.muro +1 -1
- package/examples/office.muro +1 -1
- package/examples/steps/06-finished.muro +1 -1
- package/examples/tower/assets.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/twin/assets.muro +2 -2
- 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 +7 -4
- package/src/cli.ts +2 -2
- package/src/core/components.ts +224 -0
- package/src/core/derive.ts +47 -4
- package/src/core/diagnose.ts +182 -4
- package/src/core/model.ts +10 -5
- package/src/core/parse.ts +5 -4
- package/src/core/vocabulary.ts +115 -9
- package/src/draw/component-files.ts +36 -0
- package/src/draw/component-svg.ts +79 -0
- package/src/draw/conventions/architectural.ts +60 -0
- package/src/draw/index.ts +1 -1
- package/src/draw/marks.ts +564 -44
- package/src/draw/plan.ts +253 -88
- package/src/form.ts +1 -0
- package/src/index.ts +1 -1
- package/src/mcp.ts +21 -3
- package/src/parse-file.ts +1 -0
- package/src/validate/builtin/index.ts +14 -2
- package/src/validate/builtin/opening-operations.ts +519 -0
|
@@ -42,6 +42,12 @@ import {
|
|
|
42
42
|
DOOR_COLUMN_COLLISIONS_ANALYSIS,
|
|
43
43
|
DOOR_COLUMN_COLLISIONS_ANALYSIS_ID,
|
|
44
44
|
} from "./door-column-collisions.js";
|
|
45
|
+
import {
|
|
46
|
+
OPENING_OPERATIONS_ANALYSIS,
|
|
47
|
+
OPENING_OPERATIONS_ANALYSIS_ID,
|
|
48
|
+
SLIDING_STORAGE_LEAVES_SPACE_RULE,
|
|
49
|
+
SLIDING_STORAGE_OVERLAPS_OPENING_RULE,
|
|
50
|
+
} from "./opening-operations.js";
|
|
45
51
|
import {
|
|
46
52
|
SITE_ANALYSIS,
|
|
47
53
|
SITE_ANALYSIS_ID,
|
|
@@ -61,6 +67,7 @@ import {
|
|
|
61
67
|
export * from "./access.js";
|
|
62
68
|
export * from "./daylight.js";
|
|
63
69
|
export * from "./door-column-collisions.js";
|
|
70
|
+
export * from "./opening-operations.js";
|
|
64
71
|
export * from "./site.js";
|
|
65
72
|
export * from "./vertical-runs.js";
|
|
66
73
|
|
|
@@ -75,7 +82,7 @@ export const SCHEMATIC_PROFILE_ID: ProfileRef = freezeBuiltin({
|
|
|
75
82
|
});
|
|
76
83
|
|
|
77
84
|
/**
|
|
78
|
-
* The
|
|
85
|
+
* The analyses, in the order they are declared in the catalog.
|
|
79
86
|
*
|
|
80
87
|
* Each computes facts once and says nothing about pass or fail — no rule identity, no level,
|
|
81
88
|
* no compliance summary. CLI, MCP and eval read these rather than recomputing a ratio,
|
|
@@ -86,6 +93,7 @@ export const SCHEMATIC_ANALYSES: readonly AnalysisDefinition<JsonValue>[] = free
|
|
|
86
93
|
VERTICAL_RUNS_ANALYSIS,
|
|
87
94
|
ACCESS_ANALYSIS,
|
|
88
95
|
DOOR_COLUMN_COLLISIONS_ANALYSIS,
|
|
96
|
+
OPENING_OPERATIONS_ANALYSIS,
|
|
89
97
|
SITE_ANALYSIS,
|
|
90
98
|
] as unknown as AnalysisDefinition<JsonValue>[]);
|
|
91
99
|
|
|
@@ -94,11 +102,13 @@ export const SCHEMATIC_ANALYSIS_IDS: readonly AnalysisRef[] = freezeBuiltin([
|
|
|
94
102
|
VERTICAL_RUNS_ANALYSIS_ID,
|
|
95
103
|
ACCESS_ANALYSIS_ID,
|
|
96
104
|
DOOR_COLUMN_COLLISIONS_ANALYSIS_ID,
|
|
105
|
+
OPENING_OPERATIONS_ANALYSIS_ID,
|
|
97
106
|
SITE_ANALYSIS_ID,
|
|
98
107
|
] as unknown as AnalysisRef[]);
|
|
99
108
|
|
|
100
109
|
/**
|
|
101
|
-
* The
|
|
110
|
+
* The legacy rules in their original order, followed by opening-operation checks introduced by
|
|
111
|
+
* the current pack, then the remaining legacy site rules.
|
|
102
112
|
*
|
|
103
113
|
* The one place the order is not a copy is the old `run.slope`, which splits in place into the
|
|
104
114
|
* ramp rule and then the escalator rule: a declared limit and a customary band have different
|
|
@@ -123,6 +133,8 @@ export const SCHEMATIC_RULES: readonly Rule[] = freezeBuiltin([
|
|
|
123
133
|
ACCESS_PARKING_RULE,
|
|
124
134
|
ACCESS_BACKOFHOUSE_RULE,
|
|
125
135
|
COLUMN_BLOCKS_DOOR_RULE,
|
|
136
|
+
SLIDING_STORAGE_LEAVES_SPACE_RULE,
|
|
137
|
+
SLIDING_STORAGE_OVERLAPS_OPENING_RULE,
|
|
126
138
|
SITE_ESCAPE_RULE,
|
|
127
139
|
SITE_AREA_RULE,
|
|
128
140
|
SITE_FRONTAGE_RULE,
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnalysisArtifact,
|
|
3
|
+
AnalysisDefinition,
|
|
4
|
+
AnalysisRef,
|
|
5
|
+
Evidence,
|
|
6
|
+
SourceRef,
|
|
7
|
+
SubjectRef,
|
|
8
|
+
} from "../../analysis/contracts.js";
|
|
9
|
+
import { codePointCompare } from "../../analysis/json.js";
|
|
10
|
+
import { derive, type FormOpening } from "../../core/derive.js";
|
|
11
|
+
import {
|
|
12
|
+
canonicalBoundaryOrder,
|
|
13
|
+
canonicalOpeningOrder,
|
|
14
|
+
canonicalSpaceOrder,
|
|
15
|
+
regionOf,
|
|
16
|
+
type Model,
|
|
17
|
+
type Pt,
|
|
18
|
+
type Space,
|
|
19
|
+
} from "../../core/model.js";
|
|
20
|
+
import { pointIn } from "../../core/poly.js";
|
|
21
|
+
import { EPS, PARALLEL_EPS, PROBE } from "../../core/tolerance.js";
|
|
22
|
+
import type { Rule, RuleEvaluation, RuleOutcome } from "../contracts.js";
|
|
23
|
+
import { freezeBuiltin } from "./freeze.js";
|
|
24
|
+
|
|
25
|
+
export const SLIDING_STORAGE_LEAVES_SPACE_RULE_ID = freezeBuiltin({
|
|
26
|
+
id: "koyu.schematic.opening.storage-leaves-space",
|
|
27
|
+
revision: "1",
|
|
28
|
+
} as const);
|
|
29
|
+
|
|
30
|
+
export const SLIDING_STORAGE_OVERLAPS_OPENING_RULE_ID = freezeBuiltin({
|
|
31
|
+
id: "koyu.schematic.opening.storage-overlaps-opening",
|
|
32
|
+
revision: "1",
|
|
33
|
+
} as const);
|
|
34
|
+
|
|
35
|
+
export type OperationPoint = {
|
|
36
|
+
readonly x: number;
|
|
37
|
+
readonly y: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type OperationSegment = {
|
|
41
|
+
readonly x1: number;
|
|
42
|
+
readonly y1: number;
|
|
43
|
+
readonly x2: number;
|
|
44
|
+
readonly y2: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type CrossedSpaceObservation = {
|
|
48
|
+
readonly ref: string;
|
|
49
|
+
readonly lengthMm: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type SlidingStorageLeafObservation = {
|
|
53
|
+
readonly leaf: number;
|
|
54
|
+
readonly widthMm: number;
|
|
55
|
+
/** The leaf's fully open position, on the intended room side of the wall face. */
|
|
56
|
+
readonly parked: OperationSegment;
|
|
57
|
+
/** The same parked interval on the wall axis, before the room-side probe is applied. */
|
|
58
|
+
readonly wallAxis: OperationSegment;
|
|
59
|
+
/** How much of `parked` does not lie in the intended room. */
|
|
60
|
+
readonly outsideTargetMm: number;
|
|
61
|
+
/** Other modelled spaces occupied by the parked leaf, in canonical path order. */
|
|
62
|
+
readonly crossedSpaces: readonly CrossedSpaceObservation[];
|
|
63
|
+
/** Other apertures covered by this parked leaf, with vertical overlap already required. */
|
|
64
|
+
readonly overlappedOpenings: readonly {
|
|
65
|
+
readonly ref: string;
|
|
66
|
+
readonly lengthMm: number;
|
|
67
|
+
}[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type SlidingStorageObservation = {
|
|
71
|
+
readonly ref: string;
|
|
72
|
+
readonly boundaryRef: string;
|
|
73
|
+
readonly level: string;
|
|
74
|
+
readonly kind: "door" | "window";
|
|
75
|
+
readonly style:
|
|
76
|
+
| "sliding"
|
|
77
|
+
| "sliding-double"
|
|
78
|
+
| "sliding-bypass"
|
|
79
|
+
| "auto"
|
|
80
|
+
| "auto-single"
|
|
81
|
+
| "auto-double"
|
|
82
|
+
| "gate-sliding";
|
|
83
|
+
readonly z0: number;
|
|
84
|
+
readonly z1: number;
|
|
85
|
+
readonly aperture: OperationSegment;
|
|
86
|
+
readonly intoSpace: string | null;
|
|
87
|
+
readonly state: "complete" | "indeterminate";
|
|
88
|
+
readonly reason: "opening-side-unresolved" | null;
|
|
89
|
+
readonly storage: readonly SlidingStorageLeafObservation[];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type OpeningOperationsAnalysisValue = {
|
|
93
|
+
readonly openings: readonly SlidingStorageObservation[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const OPENING_OPERATIONS_ANALYSIS_ID: AnalysisRef<OpeningOperationsAnalysisValue> = freezeBuiltin({
|
|
97
|
+
id: "koyu.analysis.opening-operations",
|
|
98
|
+
revision: "1",
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const OPENING_OPERATIONS_ANALYSIS: AnalysisDefinition<OpeningOperationsAnalysisValue> = freezeBuiltin<AnalysisDefinition<OpeningOperationsAnalysisValue>>({
|
|
102
|
+
...OPENING_OPERATIONS_ANALYSIS_ID,
|
|
103
|
+
title: "Opening operation geometry observations",
|
|
104
|
+
model: "consistent",
|
|
105
|
+
dependencies: [],
|
|
106
|
+
context: [],
|
|
107
|
+
run: ({ model }): AnalysisArtifact<OpeningOperationsAnalysisValue> => {
|
|
108
|
+
const coreModel = model as unknown as Model;
|
|
109
|
+
const form = derive(coreModel);
|
|
110
|
+
const spaces = canonicalSpaceOrder(coreModel);
|
|
111
|
+
const openings: SlidingStorageObservation[] = [];
|
|
112
|
+
const evidence: Evidence[] = [];
|
|
113
|
+
|
|
114
|
+
for (const opening of form.openings) {
|
|
115
|
+
const style = slidingStyle(opening.style);
|
|
116
|
+
if (!style) continue;
|
|
117
|
+
const observation = storageObservation(opening, style, spaces, form.openings);
|
|
118
|
+
openings.push(observation);
|
|
119
|
+
evidence.push(storageEvidence(observation, opening, coreModel));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
openings.sort((a, b) => codePointCompare(a.ref, b.ref));
|
|
123
|
+
evidence.sort((a, b) => codePointCompare(a.id, b.id));
|
|
124
|
+
return { state: "complete", value: { openings }, evidence };
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const SLIDING_STORAGE_LEAVES_SPACE_RULE: Rule = freezeBuiltin<Rule>({
|
|
129
|
+
...SLIDING_STORAGE_LEAVES_SPACE_RULE_ID,
|
|
130
|
+
title: "Sliding leaf storage stays in its intended space",
|
|
131
|
+
level: "violation",
|
|
132
|
+
model: "consistent",
|
|
133
|
+
analyses: [{ analysis: OPENING_OPERATIONS_ANALYSIS_ID, accept: "complete" }],
|
|
134
|
+
context: [],
|
|
135
|
+
authority: [],
|
|
136
|
+
evaluate: ({ get }) => evaluateSlidingStorage(get(OPENING_OPERATIONS_ANALYSIS_ID)),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const SLIDING_STORAGE_OVERLAPS_OPENING_RULE: Rule = freezeBuiltin<Rule>({
|
|
140
|
+
...SLIDING_STORAGE_OVERLAPS_OPENING_RULE_ID,
|
|
141
|
+
title: "Sliding leaf storage does not cover another opening",
|
|
142
|
+
level: "violation",
|
|
143
|
+
model: "consistent",
|
|
144
|
+
analyses: [{ analysis: OPENING_OPERATIONS_ANALYSIS_ID, accept: "complete" }],
|
|
145
|
+
context: [],
|
|
146
|
+
authority: [],
|
|
147
|
+
evaluate: ({ get }) => evaluateStorageOpeningOverlap(get(OPENING_OPERATIONS_ANALYSIS_ID)),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
function evaluateSlidingStorage(
|
|
151
|
+
artifact: AnalysisArtifact<OpeningOperationsAnalysisValue>,
|
|
152
|
+
): RuleEvaluation {
|
|
153
|
+
if (artifact.state !== "complete") {
|
|
154
|
+
return {
|
|
155
|
+
applicability: "indeterminate",
|
|
156
|
+
reason: "Opening operation geometry observations are incomplete",
|
|
157
|
+
missing: artifact.missing,
|
|
158
|
+
evidence: artifact.state === "partial" ? artifact.evidence : [],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (artifact.value.openings.length === 0) {
|
|
162
|
+
return { applicability: "not-applicable", reason: "No placeable sliding opening is present", evidence: [] };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const evidenceById = new Map(artifact.evidence.map((item) => [item.id, item]));
|
|
166
|
+
const outcomes = artifact.value.openings.map((opening): RuleOutcome => {
|
|
167
|
+
const evidence = evidenceById.get(storageEvidenceId(opening.ref));
|
|
168
|
+
if (!evidence) throw new Error(`missing opening-operation evidence for ${opening.ref}`);
|
|
169
|
+
const subjects = storageSubjects(opening);
|
|
170
|
+
if (opening.state === "indeterminate") {
|
|
171
|
+
return {
|
|
172
|
+
id: opening.ref,
|
|
173
|
+
status: "indeterminate",
|
|
174
|
+
subjects,
|
|
175
|
+
message: `${opening.ref} has no resolved room side for its sliding-leaf storage`,
|
|
176
|
+
evidence: [evidence],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (opening.storage.length === 0) {
|
|
180
|
+
return {
|
|
181
|
+
id: opening.ref,
|
|
182
|
+
status: "pass",
|
|
183
|
+
subjects,
|
|
184
|
+
message: `${opening.ref} needs no sliding-leaf storage beyond its aperture`,
|
|
185
|
+
evidence: [evidence],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const outside = opening.storage.reduce((sum, leaf) => sum + leaf.outsideTargetMm, 0);
|
|
189
|
+
const failed = outside > EPS;
|
|
190
|
+
return {
|
|
191
|
+
id: opening.ref,
|
|
192
|
+
status: failed ? "fail" : "pass",
|
|
193
|
+
subjects,
|
|
194
|
+
message: failed
|
|
195
|
+
? `${opening.ref} has ${roundMm(outside)} mm of sliding-leaf storage outside ${opening.intoSpace}`
|
|
196
|
+
: `${opening.ref} keeps its sliding-leaf storage inside ${opening.intoSpace}`,
|
|
197
|
+
evidence: [evidence],
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
return { applicability: "applicable", outcomes: outcomes as [RuleOutcome, ...RuleOutcome[]] };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function evaluateStorageOpeningOverlap(
|
|
204
|
+
artifact: AnalysisArtifact<OpeningOperationsAnalysisValue>,
|
|
205
|
+
): RuleEvaluation {
|
|
206
|
+
if (artifact.state !== "complete") {
|
|
207
|
+
return {
|
|
208
|
+
applicability: "indeterminate",
|
|
209
|
+
reason: "Opening operation geometry observations are incomplete",
|
|
210
|
+
missing: artifact.missing,
|
|
211
|
+
evidence: artifact.state === "partial" ? artifact.evidence : [],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (artifact.value.openings.length === 0) {
|
|
215
|
+
return { applicability: "not-applicable", reason: "No placeable sliding opening is present", evidence: [] };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const evidenceById = new Map(artifact.evidence.map((item) => [item.id, item]));
|
|
219
|
+
const outcomes = artifact.value.openings.map((opening): RuleOutcome => {
|
|
220
|
+
const evidence = evidenceById.get(storageEvidenceId(opening.ref));
|
|
221
|
+
if (!evidence) throw new Error(`missing opening-operation evidence for ${opening.ref}`);
|
|
222
|
+
const subjects = storageSubjects(opening);
|
|
223
|
+
if (opening.state === "indeterminate") {
|
|
224
|
+
return {
|
|
225
|
+
id: opening.ref,
|
|
226
|
+
status: "indeterminate",
|
|
227
|
+
subjects,
|
|
228
|
+
message: `${opening.ref} has unresolved sliding-leaf storage geometry`,
|
|
229
|
+
evidence: [evidence],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const overlaps = opening.storage.flatMap((leaf) => leaf.overlappedOpenings);
|
|
233
|
+
const first = overlaps[0];
|
|
234
|
+
return {
|
|
235
|
+
id: opening.ref,
|
|
236
|
+
status: first ? "fail" : "pass",
|
|
237
|
+
subjects,
|
|
238
|
+
message: first
|
|
239
|
+
? `${opening.ref} stores a sliding leaf across ${first.ref} for ${roundMm(first.lengthMm)} mm`
|
|
240
|
+
: `${opening.ref} stores no sliding leaf across another opening`,
|
|
241
|
+
evidence: [evidence],
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
return { applicability: "applicable", outcomes: outcomes as [RuleOutcome, ...RuleOutcome[]] };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type SlidingStyle = SlidingStorageObservation["style"];
|
|
248
|
+
type SlideKind = "single" | "double" | "bypass";
|
|
249
|
+
|
|
250
|
+
function slidingStyle(style: string | undefined): SlidingStyle | undefined {
|
|
251
|
+
switch (style) {
|
|
252
|
+
case "sliding":
|
|
253
|
+
case "sliding-double":
|
|
254
|
+
case "sliding-bypass":
|
|
255
|
+
case "auto":
|
|
256
|
+
case "auto-single":
|
|
257
|
+
case "auto-double":
|
|
258
|
+
case "gate-sliding":
|
|
259
|
+
return style;
|
|
260
|
+
default:
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function slideKind(style: SlidingStyle): SlideKind {
|
|
266
|
+
if (
|
|
267
|
+
style === "sliding-bypass"
|
|
268
|
+
|| style === "auto"
|
|
269
|
+
|| style === "auto-single"
|
|
270
|
+
|| style === "auto-double"
|
|
271
|
+
) return "bypass";
|
|
272
|
+
if (style === "sliding-double") return "double";
|
|
273
|
+
return "single";
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function storageObservation(
|
|
277
|
+
opening: FormOpening,
|
|
278
|
+
style: SlidingStyle,
|
|
279
|
+
spaces: readonly Space[],
|
|
280
|
+
allOpenings: readonly FormOpening[],
|
|
281
|
+
): SlidingStorageObservation {
|
|
282
|
+
const aperture = segment(opening.swing?.hinge ?? apertureStart(opening), opening.swing?.jamb ?? apertureEnd(opening));
|
|
283
|
+
const base = {
|
|
284
|
+
ref: opening.ref,
|
|
285
|
+
boundaryRef: opening.ref.slice(0, opening.ref.lastIndexOf("/")),
|
|
286
|
+
level: opening.level ?? "",
|
|
287
|
+
kind: opening.kind,
|
|
288
|
+
style,
|
|
289
|
+
z0: opening.z0,
|
|
290
|
+
z1: opening.z1,
|
|
291
|
+
aperture,
|
|
292
|
+
} as const;
|
|
293
|
+
const kind = slideKind(style);
|
|
294
|
+
if (kind === "bypass") {
|
|
295
|
+
return {
|
|
296
|
+
...base,
|
|
297
|
+
intoSpace: opening.swing?.into ?? null,
|
|
298
|
+
state: "complete",
|
|
299
|
+
reason: null,
|
|
300
|
+
storage: [],
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (!opening.swing || !opening.level) {
|
|
304
|
+
return {
|
|
305
|
+
...base,
|
|
306
|
+
intoSpace: opening.swing?.into ?? null,
|
|
307
|
+
state: "indeterminate",
|
|
308
|
+
reason: "opening-side-unresolved",
|
|
309
|
+
storage: [],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const target = spaces.find((space) => space.path === opening.swing!.into);
|
|
314
|
+
if (!target) {
|
|
315
|
+
return {
|
|
316
|
+
...base,
|
|
317
|
+
intoSpace: opening.swing.into,
|
|
318
|
+
state: "indeterminate",
|
|
319
|
+
reason: "opening-side-unresolved",
|
|
320
|
+
storage: [],
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const along = unit(opening.swing.hinge, opening.swing.jamb);
|
|
325
|
+
const inward = unit(opening.swing.hinge, opening.swing.leaf);
|
|
326
|
+
const faceOffset = opening.t / 2 + PROBE;
|
|
327
|
+
const parkedAxis = kind === "double"
|
|
328
|
+
? [
|
|
329
|
+
{ widthMm: opening.w / 2, from: move(opening.swing.hinge, along, -opening.w / 2), to: opening.swing.hinge },
|
|
330
|
+
{ widthMm: opening.w / 2, from: opening.swing.jamb, to: move(opening.swing.jamb, along, opening.w / 2) },
|
|
331
|
+
]
|
|
332
|
+
: [{ widthMm: opening.w, from: move(opening.swing.hinge, along, -opening.w), to: opening.swing.hinge }];
|
|
333
|
+
const levelSpaces = spaces.filter((space) => space.level === opening.level);
|
|
334
|
+
const storage = parkedAxis.map((leaf, index): SlidingStorageLeafObservation => {
|
|
335
|
+
const axis = segment(leaf.from, leaf.to);
|
|
336
|
+
const line = segment(move(leaf.from, inward, faceOffset), move(leaf.to, inward, faceOffset));
|
|
337
|
+
const targetLength = coveredLength(line, regionOf(target));
|
|
338
|
+
const crossedSpaces = levelSpaces
|
|
339
|
+
.filter((space) => space.path !== target.path)
|
|
340
|
+
.map((space): CrossedSpaceObservation => ({
|
|
341
|
+
ref: space.path,
|
|
342
|
+
lengthMm: roundMm(coveredLength(line, regionOf(space))),
|
|
343
|
+
}))
|
|
344
|
+
.filter((space) => space.lengthMm > EPS);
|
|
345
|
+
return {
|
|
346
|
+
leaf: index,
|
|
347
|
+
widthMm: leaf.widthMm,
|
|
348
|
+
parked: line,
|
|
349
|
+
wallAxis: axis,
|
|
350
|
+
outsideTargetMm: roundMm(Math.max(0, leaf.widthMm - targetLength)),
|
|
351
|
+
crossedSpaces,
|
|
352
|
+
overlappedOpenings: allOpenings
|
|
353
|
+
.filter((candidate) => candidate.ref !== opening.ref && verticalOverlap(opening, candidate) > EPS)
|
|
354
|
+
.map((candidate) => ({
|
|
355
|
+
ref: candidate.ref,
|
|
356
|
+
lengthMm: roundMm(collinearOverlap(axis, apertureSegment(candidate))),
|
|
357
|
+
}))
|
|
358
|
+
.filter((candidate) => candidate.lengthMm > EPS)
|
|
359
|
+
.sort((a, b) => codePointCompare(a.ref, b.ref)),
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
...base,
|
|
365
|
+
intoSpace: target.path,
|
|
366
|
+
state: "complete",
|
|
367
|
+
reason: null,
|
|
368
|
+
storage,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function apertureSegment(opening: FormOpening): OperationSegment {
|
|
373
|
+
return segment(opening.swing?.hinge ?? apertureStart(opening), opening.swing?.jamb ?? apertureEnd(opening));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function verticalOverlap(a: FormOpening, b: FormOpening): number {
|
|
377
|
+
return Math.max(0, Math.min(a.z1, b.z1) - Math.max(a.z0, b.z0));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function collinearOverlap(a: OperationSegment, b: OperationSegment): number {
|
|
381
|
+
const from = { x: a.x1, y: a.y1 };
|
|
382
|
+
const to = { x: a.x2, y: a.y2 };
|
|
383
|
+
const direction = unit(from, to);
|
|
384
|
+
const length = Math.hypot(to.x - from.x, to.y - from.y);
|
|
385
|
+
if (length <= EPS) return 0;
|
|
386
|
+
const normal = { x: -direction.y, y: direction.x };
|
|
387
|
+
const b1 = { x: b.x1, y: b.y1 };
|
|
388
|
+
const b2 = { x: b.x2, y: b.y2 };
|
|
389
|
+
const distance1 = Math.abs((b1.x - from.x) * normal.x + (b1.y - from.y) * normal.y);
|
|
390
|
+
const distance2 = Math.abs((b2.x - from.x) * normal.x + (b2.y - from.y) * normal.y);
|
|
391
|
+
if (distance1 > EPS || distance2 > EPS) return 0;
|
|
392
|
+
const project = (point: Pt): number => (point.x - from.x) * direction.x + (point.y - from.y) * direction.y;
|
|
393
|
+
const bStart = Math.min(project(b1), project(b2));
|
|
394
|
+
const bEnd = Math.max(project(b1), project(b2));
|
|
395
|
+
return Math.max(0, Math.min(length, bEnd) - Math.max(0, bStart));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function coveredLength(line: OperationSegment, pieces: readonly Pt[][]): number {
|
|
399
|
+
const from = { x: line.x1, y: line.y1 };
|
|
400
|
+
const to = { x: line.x2, y: line.y2 };
|
|
401
|
+
const length = Math.hypot(to.x - from.x, to.y - from.y);
|
|
402
|
+
if (length <= EPS) return 0;
|
|
403
|
+
const cuts = [0, 1];
|
|
404
|
+
for (const piece of pieces) {
|
|
405
|
+
for (let i = 0; i < piece.length; i++) {
|
|
406
|
+
addIntersectionParameters(cuts, from, to, piece[i]!, piece[(i + 1) % piece.length]!);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
cuts.sort((a, b) => a - b);
|
|
410
|
+
const unique = cuts.filter((value, index) => index === 0 || Math.abs(value - cuts[index - 1]!) * length > EPS);
|
|
411
|
+
let inside = 0;
|
|
412
|
+
for (let i = 0; i + 1 < unique.length; i++) {
|
|
413
|
+
const a = unique[i]!;
|
|
414
|
+
const b = unique[i + 1]!;
|
|
415
|
+
if ((b - a) * length <= EPS) continue;
|
|
416
|
+
const at = (a + b) / 2;
|
|
417
|
+
const point = { x: from.x + (to.x - from.x) * at, y: from.y + (to.y - from.y) * at };
|
|
418
|
+
if (pieces.some((piece) => pointIn(point, piece))) inside += (b - a) * length;
|
|
419
|
+
}
|
|
420
|
+
return inside;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function addIntersectionParameters(cuts: number[], p: Pt, q: Pt, a: Pt, b: Pt): void {
|
|
424
|
+
const rx = q.x - p.x;
|
|
425
|
+
const ry = q.y - p.y;
|
|
426
|
+
const sx = b.x - a.x;
|
|
427
|
+
const sy = b.y - a.y;
|
|
428
|
+
const cross = rx * sy - ry * sx;
|
|
429
|
+
const apx = a.x - p.x;
|
|
430
|
+
const apy = a.y - p.y;
|
|
431
|
+
if (Math.abs(cross) <= PARALLEL_EPS) {
|
|
432
|
+
if (Math.abs(apx * ry - apy * rx) > PARALLEL_EPS) return;
|
|
433
|
+
const length2 = rx * rx + ry * ry;
|
|
434
|
+
if (length2 === 0) return;
|
|
435
|
+
for (const edgePoint of [a, b]) {
|
|
436
|
+
const at = ((edgePoint.x - p.x) * rx + (edgePoint.y - p.y) * ry) / length2;
|
|
437
|
+
if (at > 0 && at < 1) cuts.push(at);
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const t = (apx * sy - apy * sx) / cross;
|
|
442
|
+
const u = (apx * ry - apy * rx) / cross;
|
|
443
|
+
if (t >= 0 && t <= 1 && u >= 0 && u <= 1) cuts.push(Math.max(0, Math.min(1, t)));
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function apertureStart(opening: FormOpening): Pt {
|
|
447
|
+
const along = unit({ x: opening.segment.x1, y: opening.segment.y1 }, { x: opening.segment.x2, y: opening.segment.y2 });
|
|
448
|
+
return move({ x: opening.cx, y: opening.cy }, along, -opening.w / 2);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function apertureEnd(opening: FormOpening): Pt {
|
|
452
|
+
const along = unit({ x: opening.segment.x1, y: opening.segment.y1 }, { x: opening.segment.x2, y: opening.segment.y2 });
|
|
453
|
+
return move({ x: opening.cx, y: opening.cy }, along, opening.w / 2);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function unit(from: Pt, to: Pt): Pt {
|
|
457
|
+
const length = Math.hypot(to.x - from.x, to.y - from.y) || 1;
|
|
458
|
+
return { x: (to.x - from.x) / length, y: (to.y - from.y) / length };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function move(point: Pt, direction: Pt, distance: number): Pt {
|
|
462
|
+
return { x: point.x + direction.x * distance, y: point.y + direction.y * distance };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function segment(from: Pt, to: Pt): OperationSegment {
|
|
466
|
+
return { x1: from.x, y1: from.y, x2: to.x, y2: to.y };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function roundMm(value: number): number {
|
|
470
|
+
return Math.round(value * 1000) / 1000;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function storageEvidence(
|
|
474
|
+
observation: SlidingStorageObservation,
|
|
475
|
+
formOpening: FormOpening,
|
|
476
|
+
model: Model,
|
|
477
|
+
): Evidence {
|
|
478
|
+
const boundary = canonicalBoundaryOrder(model)[formOpening.boundary]!;
|
|
479
|
+
const opening = canonicalOpeningOrder(boundary)[formOpening.index]!;
|
|
480
|
+
return {
|
|
481
|
+
id: storageEvidenceId(observation.ref),
|
|
482
|
+
kind: "fact",
|
|
483
|
+
name: "openingOperationGeometry",
|
|
484
|
+
value: observation,
|
|
485
|
+
subjects: storageSubjects(observation),
|
|
486
|
+
sources: [modelSource(openingSubject(observation.ref), opening.line, boundary.file)],
|
|
487
|
+
producedBy: OPENING_OPERATIONS_ANALYSIS_ID,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function storageSubjects(observation: SlidingStorageObservation): [SubjectRef, ...SubjectRef[]] {
|
|
492
|
+
const refs: SubjectRef[] = [openingSubject(observation.ref)];
|
|
493
|
+
if (observation.intoSpace) refs.push(spaceSubject(observation.intoSpace));
|
|
494
|
+
const crossed = new Set(observation.storage.flatMap((leaf) => leaf.crossedSpaces.map((space) => space.ref)));
|
|
495
|
+
for (const ref of [...crossed].sort(codePointCompare)) refs.push(spaceSubject(ref));
|
|
496
|
+
const openings = new Set(observation.storage.flatMap((leaf) => leaf.overlappedOpenings.map((item) => item.ref)));
|
|
497
|
+
for (const ref of [...openings].sort(codePointCompare)) refs.push(openingSubject(ref));
|
|
498
|
+
return refs as [SubjectRef, ...SubjectRef[]];
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function modelSource(subject: SubjectRef, line: number, file?: string): SourceRef {
|
|
502
|
+
return {
|
|
503
|
+
kind: "model",
|
|
504
|
+
subject,
|
|
505
|
+
location: { ...(file !== undefined ? { file } : {}), line },
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function openingSubject(ref: string): SubjectRef {
|
|
510
|
+
return { kind: "opening", ref };
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function spaceSubject(ref: string): SubjectRef {
|
|
514
|
+
return { kind: "space", ref };
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function storageEvidenceId(ref: string): string {
|
|
518
|
+
return `opening-operation:${ref}`;
|
|
519
|
+
}
|