@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.
Files changed (79) hide show
  1. package/README.md +5 -0
  2. package/dist/cli.js +1 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/core/diagnose.d.ts +1 -0
  5. package/dist/core/diagnose.d.ts.map +1 -1
  6. package/dist/core/diagnose.js +40 -4
  7. package/dist/core/diagnose.js.map +1 -1
  8. package/dist/core/graph.d.ts +7 -1
  9. package/dist/core/graph.d.ts.map +1 -1
  10. package/dist/core/graph.js +125 -13
  11. package/dist/core/graph.js.map +1 -1
  12. package/dist/core/model.d.ts +16 -1
  13. package/dist/core/model.d.ts.map +1 -1
  14. package/dist/core/model.js +20 -1
  15. package/dist/core/model.js.map +1 -1
  16. package/dist/core/section.d.ts +27 -2
  17. package/dist/core/section.d.ts.map +1 -1
  18. package/dist/core/section.js +63 -11
  19. package/dist/core/section.js.map +1 -1
  20. package/dist/draw/index.d.ts +1 -1
  21. package/dist/draw/index.d.ts.map +1 -1
  22. package/dist/draw/index.js +1 -1
  23. package/dist/draw/index.js.map +1 -1
  24. package/dist/draw/marks.d.ts +3 -1
  25. package/dist/draw/marks.d.ts.map +1 -1
  26. package/dist/draw/marks.js +4 -1
  27. package/dist/draw/marks.js.map +1 -1
  28. package/dist/draw/plan.d.ts.map +1 -1
  29. package/dist/draw/plan.js +5 -3
  30. package/dist/draw/plan.js.map +1 -1
  31. package/dist/draw/section.d.ts +20 -2
  32. package/dist/draw/section.d.ts.map +1 -1
  33. package/dist/draw/section.js +43 -10
  34. package/dist/draw/section.js.map +1 -1
  35. package/dist/draw/sheet.d.ts +15 -0
  36. package/dist/draw/sheet.d.ts.map +1 -1
  37. package/dist/draw/sheet.js +15 -0
  38. package/dist/draw/sheet.js.map +1 -1
  39. package/dist/form.d.ts +1 -1
  40. package/dist/form.d.ts.map +1 -1
  41. package/dist/form.js.map +1 -1
  42. package/dist/model.d.ts +1 -1
  43. package/dist/model.d.ts.map +1 -1
  44. package/dist/model.js +1 -1
  45. package/dist/model.js.map +1 -1
  46. package/dist/validate/builtin/index.d.ts +8 -3
  47. package/dist/validate/builtin/index.d.ts.map +1 -1
  48. package/dist/validate/builtin/index.js +8 -7
  49. package/dist/validate/builtin/index.js.map +1 -1
  50. package/examples/basement/main.muro +1 -1
  51. package/examples/complex/main.muro +1 -1
  52. package/examples/house/main.muro +1 -1
  53. package/examples/house.muro +1 -1
  54. package/examples/mansion.muro +1 -1
  55. package/examples/office.muro +1 -1
  56. package/examples/steps/06-finished.muro +1 -1
  57. package/examples/tower/main.muro +1 -1
  58. package/examples/twin/main.muro +1 -1
  59. package/examples/two-rooms.canonical.json +1 -1
  60. package/examples/two-rooms.muro +1 -1
  61. package/package.json +4 -3
  62. package/src/cli.ts +1 -1
  63. package/src/core/diagnose.ts +43 -3
  64. package/src/core/graph.ts +147 -11
  65. package/src/core/model.ts +21 -1
  66. package/src/core/section.ts +107 -8
  67. package/src/draw/index.ts +8 -1
  68. package/src/draw/marks.ts +7 -2
  69. package/src/draw/plan.ts +5 -3
  70. package/src/draw/section.ts +78 -14
  71. package/src/draw/sheet.ts +15 -0
  72. package/src/form.ts +3 -0
  73. package/src/model.ts +1 -0
  74. package/src/validate/builtin/index.ts +8 -7
  75. package/dist/validate/builtin/envelope.d.ts +0 -30
  76. package/dist/validate/builtin/envelope.d.ts.map +0 -1
  77. package/dist/validate/builtin/envelope.js +0 -169
  78. package/dist/validate/builtin/envelope.js.map +0 -1
  79. package/src/validate/builtin/envelope.ts +0 -227
package/src/form.ts CHANGED
@@ -46,9 +46,12 @@ export {
46
46
  sectionArea,
47
47
  sectionForm,
48
48
  type FormSection,
49
+ type LineFormSection,
50
+ type LineSectionSpec,
49
51
  type SectionAxis,
50
52
  type SectionClass,
51
53
  type SectionEntity,
54
+ type SectionLine,
52
55
  type SectionPt,
53
56
  type SectionSpec,
54
57
  type SectionSubject,
package/src/model.ts CHANGED
@@ -31,6 +31,7 @@ export {
31
31
  DEFAULT_LANGUAGE_VERSION,
32
32
  displayName,
33
33
  effectiveAttr,
34
+ EXTERIOR,
34
35
  heff,
35
36
  isCoveredAbove,
36
37
  isIndoor,
@@ -42,7 +42,6 @@ import {
42
42
  DOOR_COLUMN_COLLISIONS_ANALYSIS,
43
43
  DOOR_COLUMN_COLLISIONS_ANALYSIS_ID,
44
44
  } from "./door-column-collisions.js";
45
- import { ENVELOPE_ANALYSIS, ENVELOPE_ANALYSIS_ID, ENVELOPE_GAP_RULE } from "./envelope.js";
46
45
  import {
47
46
  SITE_ANALYSIS,
48
47
  SITE_ANALYSIS_ID,
@@ -62,7 +61,6 @@ import {
62
61
  export * from "./access.js";
63
62
  export * from "./daylight.js";
64
63
  export * from "./door-column-collisions.js";
65
- export * from "./envelope.js";
66
64
  export * from "./site.js";
67
65
  export * from "./vertical-runs.js";
68
66
 
@@ -77,14 +75,13 @@ export const SCHEMATIC_PROFILE_ID: ProfileRef = freezeBuiltin({
77
75
  });
78
76
 
79
77
  /**
80
- * The six analyses, in the order they are declared in the catalog.
78
+ * The five analyses, in the order they are declared in the catalog.
81
79
  *
82
80
  * Each computes facts once and says nothing about pass or fail — no rule identity, no level,
83
81
  * no compliance summary. CLI, MCP and eval read these rather than recomputing a ratio,
84
82
  * an area tolerance, a frontage, a route or a slope of their own.
85
83
  */
86
84
  export const SCHEMATIC_ANALYSES: readonly AnalysisDefinition<JsonValue>[] = freezeBuiltin([
87
- ENVELOPE_ANALYSIS,
88
85
  DAYLIGHT_ANALYSIS,
89
86
  VERTICAL_RUNS_ANALYSIS,
90
87
  ACCESS_ANALYSIS,
@@ -93,7 +90,6 @@ export const SCHEMATIC_ANALYSES: readonly AnalysisDefinition<JsonValue>[] = free
93
90
  ] as unknown as AnalysisDefinition<JsonValue>[]);
94
91
 
95
92
  export const SCHEMATIC_ANALYSIS_IDS: readonly AnalysisRef[] = freezeBuiltin([
96
- ENVELOPE_ANALYSIS_ID,
97
93
  DAYLIGHT_ANALYSIS_ID,
98
94
  VERTICAL_RUNS_ANALYSIS_ID,
99
95
  ACCESS_ANALYSIS_ID,
@@ -102,14 +98,19 @@ export const SCHEMATIC_ANALYSIS_IDS: readonly AnalysisRef[] = freezeBuiltin([
102
98
  ] as unknown as AnalysisRef[]);
103
99
 
104
100
  /**
105
- * The sixteen rules, in the order of the legacy ledger.
101
+ * The fifteen rules, in the order of the legacy ledger.
106
102
  *
107
103
  * The one place the order is not a copy is the old `run.slope`, which splits in place into the
108
104
  * ramp rule and then the escalator rule: a declared limit and a customary band have different
109
105
  * grounds and have to be revisable one without the other.
106
+ *
107
+ * `koyu.schematic.envelope.gap` used to open the list and is gone. It said "this perimeter faces
108
+ * nothing" — a state muro 1.4 cannot reach, because an unfaced perimeter is a wall (ADR-0065).
109
+ * What is left of the question is that nobody said *which* outside the face looks at, and that is
110
+ * a fact about a missing declaration rather than a judgement about a building, so it belongs to
111
+ * `check` and is [[BND08]].
110
112
  */
111
113
  export const SCHEMATIC_RULES: readonly Rule[] = freezeBuiltin([
112
- ENVELOPE_GAP_RULE,
113
114
  DAYLIGHT_RATIO_RULE,
114
115
  DAYLIGHT_UNKNOWN_RULE,
115
116
  STAIR_PROPORTION_RULE,
@@ -1,30 +0,0 @@
1
- import type { AnalysisDefinition, AnalysisRef } from "../../analysis/contracts.js";
2
- import type { Rule } from "../contracts.js";
3
- export type EnvelopeRunFact = {
4
- readonly edge: string;
5
- readonly lengthMm: number;
6
- readonly segment: {
7
- readonly x1: number;
8
- readonly y1: number;
9
- readonly x2: number;
10
- readonly y2: number;
11
- };
12
- };
13
- export type EnvelopeSpaceFact = {
14
- readonly ref: string;
15
- readonly levelRef: string;
16
- readonly uncoveredLengthMm: number;
17
- readonly runs: readonly EnvelopeRunFact[];
18
- };
19
- export type EnvelopeAnalysisValue = {
20
- readonly startedLevels: readonly string[];
21
- readonly spaces: readonly EnvelopeSpaceFact[];
22
- };
23
- export declare const ENVELOPE_ANALYSIS_ID: AnalysisRef<EnvelopeAnalysisValue>;
24
- export declare const ENVELOPE_GAP_RULE_ID: {
25
- readonly id: "koyu.schematic.envelope.gap";
26
- readonly revision: "1";
27
- };
28
- export declare const ENVELOPE_ANALYSIS: AnalysisDefinition<EnvelopeAnalysisValue>;
29
- export declare const ENVELOPE_GAP_RULE: Rule;
30
- //# sourceMappingURL=envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/validate/builtin/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,WAAW,EAIZ,MAAM,6BAA6B,CAAC;AASrC,OAAO,KAAK,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAGzE,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,eAAe,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC/C,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,qBAAqB,CAGlE,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;CAGtB,CAAC;AAIZ,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,qBAAqB,CAoCtE,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,IAoC9B,CAAC"}
@@ -1,169 +0,0 @@
1
- import { envelopeGaps, segmentLength } from "../../core/graph.js";
2
- import { canonicalSpaceOrder, isOutside, isSemiOutdoor, } from "../../core/model.js";
3
- import { freezeBuiltin } from "./freeze.js";
4
- export const ENVELOPE_ANALYSIS_ID = freezeBuiltin({
5
- id: "koyu.analysis.envelope",
6
- revision: "1",
7
- });
8
- export const ENVELOPE_GAP_RULE_ID = freezeBuiltin({
9
- id: "koyu.schematic.envelope.gap",
10
- revision: "1",
11
- });
12
- const VERTICAL_BOUNDARIES = new Set(["stair", "shaft", "void"]);
13
- export const ENVELOPE_ANALYSIS = freezeBuiltin({
14
- ...ENVELOPE_ANALYSIS_ID,
15
- title: "Envelope observations",
16
- model: "consistent",
17
- dependencies: [],
18
- context: [],
19
- run: ({ model }) => {
20
- const coreModel = model;
21
- const startedLevels = new Set();
22
- for (const boundary of model.boundaries) {
23
- if (boundary.derived || VERTICAL_BOUNDARIES.has(boundary.kind))
24
- continue;
25
- const a = model.spaces.get(boundary.a);
26
- const b = model.spaces.get(boundary.b);
27
- if (!a || !b)
28
- continue;
29
- const outer = a.rects.length === 0 ? b : b.rects.length === 0 ? a : undefined;
30
- if (outer?.level)
31
- startedLevels.add(outer.level);
32
- }
33
- const siteZones = [...model.zones.values()]
34
- .filter((zone) => zone.attrs["site"] === 1)
35
- .map((zone) => zone.path)
36
- .sort(compareText);
37
- const spaces = canonicalSpaceOrder(coreModel)
38
- .filter((space) => envelopePopulation(coreModel, space, startedLevels, siteZones))
39
- .map((space) => envelopeFact(coreModel, space));
40
- const evidence = spaces.map((space) => envelopeEvidence(space, coreModel.spaces.get(space.ref)));
41
- return {
42
- state: "complete",
43
- value: {
44
- startedLevels: [...startedLevels].sort(compareText),
45
- spaces,
46
- },
47
- evidence,
48
- };
49
- },
50
- });
51
- export const ENVELOPE_GAP_RULE = freezeBuiltin({
52
- ...ENVELOPE_GAP_RULE_ID,
53
- title: "Envelope perimeter gap",
54
- level: "caution",
55
- model: "consistent",
56
- analyses: [{ analysis: ENVELOPE_ANALYSIS_ID, accept: "complete" }],
57
- context: [],
58
- authority: [],
59
- evaluate: ({ get }) => {
60
- const artifact = get(ENVELOPE_ANALYSIS_ID);
61
- if (artifact.state !== "complete")
62
- return analysisIndeterminate(artifact);
63
- if (artifact.value.spaces.length === 0) {
64
- return {
65
- applicability: "not-applicable",
66
- reason: "No enclosed-space population exists on a level whose envelope has been started",
67
- evidence: [],
68
- };
69
- }
70
- const evidenceById = new Map(artifact.evidence.map((item) => [item.id, item]));
71
- const outcomes = artifact.value.spaces.map((space) => {
72
- const evidence = evidenceById.get(envelopeEvidenceId(space.ref));
73
- if (!evidence)
74
- throw new Error(`missing envelope evidence for ${space.ref}`);
75
- const status = space.runs.length > 0 ? "fail" : "pass";
76
- return {
77
- id: space.ref,
78
- status,
79
- subjects: [spaceSubject(space.ref)],
80
- message: status === "fail"
81
- ? `Perimeter not faced by any envelope: ${space.ref} — ${describeRuns(space.runs)} (${Math.round(space.uncoveredLengthMm)}mm over ${space.runs.length} run(s)). Write a boundary to the exterior`
82
- : `${space.ref} has no uncovered envelope run`,
83
- evidence: [evidence],
84
- };
85
- });
86
- return { applicability: "applicable", outcomes: outcomes };
87
- },
88
- });
89
- function envelopePopulation(model, space, startedLevels, siteZones) {
90
- if (space.rects.length === 0 || !space.level || !startedLevels.has(space.level))
91
- return false;
92
- if (isOutside(space) || isSemiOutdoor(model, space))
93
- return false;
94
- return !siteZones.some((zone) => space.path.startsWith(`${zone}/`));
95
- }
96
- function envelopeFact(model, space) {
97
- const runs = envelopeGaps(model, space)
98
- .map((segment) => ({
99
- edge: segment.edgeOfA ?? (segment.horizontal ? "N/S" : "E/W"),
100
- lengthMm: segmentLength(segment),
101
- segment: {
102
- x1: segment.x1,
103
- y1: segment.y1,
104
- x2: segment.x2,
105
- y2: segment.y2,
106
- },
107
- }))
108
- .sort(compareRuns);
109
- return {
110
- ref: space.path,
111
- levelRef: space.level,
112
- uncoveredLengthMm: runs.reduce((sum, run) => sum + run.lengthMm, 0),
113
- runs,
114
- };
115
- }
116
- function envelopeEvidence(space, source) {
117
- const subject = spaceSubject(space.ref);
118
- return {
119
- id: envelopeEvidenceId(space.ref),
120
- kind: "fact",
121
- name: "uncoveredEnvelopeRuns",
122
- value: {
123
- length: { value: space.uncoveredLengthMm, unit: "mm" },
124
- runs: space.runs,
125
- },
126
- subjects: [subject],
127
- sources: [modelSource(subject, source)],
128
- producedBy: ENVELOPE_ANALYSIS_ID,
129
- };
130
- }
131
- function modelSource(subject, source) {
132
- return {
133
- kind: "model",
134
- subject,
135
- location: {
136
- ...(source.file !== undefined ? { file: source.file } : {}),
137
- line: source.line,
138
- },
139
- };
140
- }
141
- function spaceSubject(ref) {
142
- return { kind: "space", ref };
143
- }
144
- function envelopeEvidenceId(ref) {
145
- return `envelope:${ref}`;
146
- }
147
- function analysisIndeterminate(artifact) {
148
- return {
149
- applicability: "indeterminate",
150
- reason: "Envelope observations are incomplete",
151
- missing: artifact.missing,
152
- evidence: artifact.state === "partial" ? artifact.evidence : [],
153
- };
154
- }
155
- /** `S 3600mm / N 3600mm / W 4500mm` — which way each uncovered run faces, and how long it is. */
156
- function describeRuns(runs) {
157
- return runs.map((run) => `${run.edge} ${Math.round(run.lengthMm)}mm`).join(" / ");
158
- }
159
- function compareText(a, b) {
160
- return a < b ? -1 : a > b ? 1 : 0;
161
- }
162
- function compareRuns(a, b) {
163
- return compareText(a.edge, b.edge)
164
- || a.segment.x1 - b.segment.x1
165
- || a.segment.y1 - b.segment.y1
166
- || a.segment.x2 - b.segment.x2
167
- || a.segment.y2 - b.segment.y2;
168
- }
169
- //# sourceMappingURL=envelope.js.map
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C,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,WAAW,CAAC,CAAkB,EAAE,CAAkB;IACzD,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;WAC7B,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE;WAC3B,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE;WAC3B,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE;WAC3B,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;AACnC,CAAC"}
@@ -1,227 +0,0 @@
1
- import type {
2
- AnalysisDefinition,
3
- AnalysisArtifact,
4
- AnalysisRef,
5
- Evidence,
6
- SourceRef,
7
- SubjectRef,
8
- } from "../../analysis/contracts.js";
9
- import { envelopeGaps, segmentLength } from "../../core/graph.js";
10
- import {
11
- canonicalSpaceOrder,
12
- isOutside,
13
- isSemiOutdoor,
14
- type Model,
15
- type Space,
16
- } from "../../core/model.js";
17
- import type { Rule, RuleEvaluation, RuleOutcome } from "../contracts.js";
18
- import { freezeBuiltin } from "./freeze.js";
19
-
20
- export type EnvelopeRunFact = {
21
- readonly edge: string;
22
- readonly lengthMm: number;
23
- readonly segment: {
24
- readonly x1: number;
25
- readonly y1: number;
26
- readonly x2: number;
27
- readonly y2: number;
28
- };
29
- };
30
-
31
- export type EnvelopeSpaceFact = {
32
- readonly ref: string;
33
- readonly levelRef: string;
34
- readonly uncoveredLengthMm: number;
35
- readonly runs: readonly EnvelopeRunFact[];
36
- };
37
-
38
- export type EnvelopeAnalysisValue = {
39
- readonly startedLevels: readonly string[];
40
- readonly spaces: readonly EnvelopeSpaceFact[];
41
- };
42
-
43
- export const ENVELOPE_ANALYSIS_ID: AnalysisRef<EnvelopeAnalysisValue> = freezeBuiltin({
44
- id: "koyu.analysis.envelope",
45
- revision: "1",
46
- });
47
-
48
- export const ENVELOPE_GAP_RULE_ID = freezeBuiltin({
49
- id: "koyu.schematic.envelope.gap",
50
- revision: "1",
51
- } as const);
52
-
53
- const VERTICAL_BOUNDARIES = new Set(["stair", "shaft", "void"]);
54
-
55
- export const ENVELOPE_ANALYSIS: AnalysisDefinition<EnvelopeAnalysisValue> = freezeBuiltin<AnalysisDefinition<EnvelopeAnalysisValue>>({
56
- ...ENVELOPE_ANALYSIS_ID,
57
- title: "Envelope observations",
58
- model: "consistent",
59
- dependencies: [],
60
- context: [],
61
- run: ({ model }): AnalysisArtifact<EnvelopeAnalysisValue> => {
62
- const coreModel = model as unknown as Model;
63
- const startedLevels = new Set<string>();
64
- for (const boundary of model.boundaries) {
65
- if (boundary.derived || VERTICAL_BOUNDARIES.has(boundary.kind)) continue;
66
- const a = model.spaces.get(boundary.a);
67
- const b = model.spaces.get(boundary.b);
68
- if (!a || !b) continue;
69
- const outer = a.rects.length === 0 ? b : b.rects.length === 0 ? a : undefined;
70
- if (outer?.level) startedLevels.add(outer.level);
71
- }
72
-
73
- const siteZones = [...model.zones.values()]
74
- .filter((zone) => zone.attrs["site"] === 1)
75
- .map((zone) => zone.path)
76
- .sort(compareText);
77
- const spaces = canonicalSpaceOrder(coreModel)
78
- .filter((space) => envelopePopulation(coreModel, space, startedLevels, siteZones))
79
- .map((space) => envelopeFact(coreModel, space));
80
- const evidence = spaces.map((space) => envelopeEvidence(space, coreModel.spaces.get(space.ref)!));
81
-
82
- return {
83
- state: "complete",
84
- value: {
85
- startedLevels: [...startedLevels].sort(compareText),
86
- spaces,
87
- },
88
- evidence,
89
- };
90
- },
91
- });
92
-
93
- export const ENVELOPE_GAP_RULE: Rule = freezeBuiltin<Rule>({
94
- ...ENVELOPE_GAP_RULE_ID,
95
- title: "Envelope perimeter gap",
96
- level: "caution",
97
- model: "consistent",
98
- analyses: [{ analysis: ENVELOPE_ANALYSIS_ID, accept: "complete" }],
99
- context: [],
100
- authority: [],
101
- evaluate: ({ get }): RuleEvaluation => {
102
- const artifact = get(ENVELOPE_ANALYSIS_ID);
103
- if (artifact.state !== "complete") return analysisIndeterminate(artifact);
104
- if (artifact.value.spaces.length === 0) {
105
- return {
106
- applicability: "not-applicable",
107
- reason: "No enclosed-space population exists on a level whose envelope has been started",
108
- evidence: [],
109
- };
110
- }
111
-
112
- const evidenceById = new Map(artifact.evidence.map((item) => [item.id, item]));
113
- const outcomes = artifact.value.spaces.map((space): RuleOutcome => {
114
- const evidence = evidenceById.get(envelopeEvidenceId(space.ref));
115
- if (!evidence) throw new Error(`missing envelope evidence for ${space.ref}`);
116
- const status = space.runs.length > 0 ? "fail" : "pass";
117
- return {
118
- id: space.ref,
119
- status,
120
- subjects: [spaceSubject(space.ref)],
121
- message: status === "fail"
122
- ? `Perimeter not faced by any envelope: ${space.ref} — ${describeRuns(space.runs)} (${Math.round(space.uncoveredLengthMm)}mm over ${space.runs.length} run(s)). Write a boundary to the exterior`
123
- : `${space.ref} has no uncovered envelope run`,
124
- evidence: [evidence],
125
- };
126
- });
127
- return { applicability: "applicable", outcomes: outcomes as [RuleOutcome, ...RuleOutcome[]] };
128
- },
129
- });
130
-
131
- function envelopePopulation(
132
- model: Parameters<typeof isSemiOutdoor>[0],
133
- space: Space,
134
- startedLevels: ReadonlySet<string>,
135
- siteZones: readonly string[],
136
- ): boolean {
137
- if (space.rects.length === 0 || !space.level || !startedLevels.has(space.level)) return false;
138
- if (isOutside(space) || isSemiOutdoor(model, space)) return false;
139
- return !siteZones.some((zone) => space.path.startsWith(`${zone}/`));
140
- }
141
-
142
- function envelopeFact(
143
- model: Parameters<typeof envelopeGaps>[0],
144
- space: Space,
145
- ): EnvelopeSpaceFact {
146
- const runs = envelopeGaps(model, space)
147
- .map((segment): EnvelopeRunFact => ({
148
- edge: segment.edgeOfA ?? (segment.horizontal ? "N/S" : "E/W"),
149
- lengthMm: segmentLength(segment),
150
- segment: {
151
- x1: segment.x1,
152
- y1: segment.y1,
153
- x2: segment.x2,
154
- y2: segment.y2,
155
- },
156
- }))
157
- .sort(compareRuns);
158
- return {
159
- ref: space.path,
160
- levelRef: space.level!,
161
- uncoveredLengthMm: runs.reduce((sum, run) => sum + run.lengthMm, 0),
162
- runs,
163
- };
164
- }
165
-
166
- function envelopeEvidence(space: EnvelopeSpaceFact, source: Space): Evidence {
167
- const subject = spaceSubject(space.ref);
168
- return {
169
- id: envelopeEvidenceId(space.ref),
170
- kind: "fact",
171
- name: "uncoveredEnvelopeRuns",
172
- value: {
173
- length: { value: space.uncoveredLengthMm, unit: "mm" },
174
- runs: space.runs,
175
- },
176
- subjects: [subject],
177
- sources: [modelSource(subject, source)],
178
- producedBy: ENVELOPE_ANALYSIS_ID,
179
- };
180
- }
181
-
182
- function modelSource(subject: SubjectRef, source: Space): SourceRef {
183
- return {
184
- kind: "model",
185
- subject,
186
- location: {
187
- ...(source.file !== undefined ? { file: source.file } : {}),
188
- line: source.line,
189
- },
190
- };
191
- }
192
-
193
- function spaceSubject(ref: string): SubjectRef {
194
- return { kind: "space", ref };
195
- }
196
-
197
- function envelopeEvidenceId(ref: string): string {
198
- return `envelope:${ref}`;
199
- }
200
-
201
- function analysisIndeterminate(
202
- artifact: Exclude<AnalysisArtifact<EnvelopeAnalysisValue>, { state: "complete" }>,
203
- ): Extract<RuleEvaluation, { applicability: "indeterminate" }> {
204
- return {
205
- applicability: "indeterminate",
206
- reason: "Envelope observations are incomplete",
207
- missing: artifact.missing,
208
- evidence: artifact.state === "partial" ? artifact.evidence : [],
209
- };
210
- }
211
-
212
- /** `S 3600mm / N 3600mm / W 4500mm` — which way each uncovered run faces, and how long it is. */
213
- function describeRuns(runs: readonly EnvelopeRunFact[]): string {
214
- return runs.map((run) => `${run.edge} ${Math.round(run.lengthMm)}mm`).join(" / ");
215
- }
216
-
217
- function compareText(a: string, b: string): number {
218
- return a < b ? -1 : a > b ? 1 : 0;
219
- }
220
-
221
- function compareRuns(a: EnvelopeRunFact, b: EnvelopeRunFact): number {
222
- return compareText(a.edge, b.edge)
223
- || a.segment.x1 - b.segment.x1
224
- || a.segment.y1 - b.segment.y1
225
- || a.segment.x2 - b.segment.x2
226
- || a.segment.y2 - b.segment.y2;
227
- }