@sentropic/diagram-canvas 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/dist/camera.d.ts +28 -9
- package/dist/camera.js +34 -13
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/layout/cache.js +12 -2
- package/dist/layout/channels.d.ts +10 -0
- package/dist/layout/channels.js +13 -0
- package/dist/layout/conventions.d.ts +117 -0
- package/dist/layout/conventions.js +185 -0
- package/dist/layout/dock.d.ts +2 -0
- package/dist/layout/dock.js +5 -1
- package/dist/layout/fingerprint.d.ts +4 -2
- package/dist/layout/fingerprint.js +26 -2
- package/dist/layout/hints.d.ts +1 -1
- package/dist/layout/hints.js +10 -3
- package/dist/layout/index.d.ts +5 -3
- package/dist/layout/index.js +5 -3
- package/dist/layout/labels.d.ts +2 -0
- package/dist/layout/labels.js +2 -0
- package/dist/layout/measure.d.ts +6 -0
- package/dist/layout/measure.js +28 -0
- package/dist/layout/measured.js +1051 -100
- package/dist/layout/route.d.ts +27 -1
- package/dist/layout/route.js +640 -32
- package/dist/layout/routeSpacing.d.ts +84 -0
- package/dist/layout/routeSpacing.js +472 -0
- package/dist/layout/spacing.generated.d.ts +10 -1
- package/dist/layout/spacing.generated.js +10 -1
- package/dist/layout/types.d.ts +33 -2
- package/dist/layout/types.js +2 -0
- package/dist/presentation/connectorPath.d.ts +32 -0
- package/dist/presentation/connectorPath.js +213 -0
- package/dist/presentation/connectorStyle.d.ts +70 -0
- package/dist/presentation/connectorStyle.js +99 -0
- package/dist/presentation/diagramCardModel.d.ts +1 -1
- package/dist/presentation/diagramCardModel.js +1 -1
- package/dist/presentation/diagramSceneModel.d.ts +58 -7
- package/dist/presentation/diagramSceneModel.js +225 -35
- package/dist/presentation/diagramSceneTypes.d.ts +9 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.js +4 -0
- package/dist/presentation/linkLegend.d.ts +132 -0
- package/dist/presentation/linkLegend.js +231 -0
- package/dist/presentation/renderSceneSvg.d.ts +3 -1
- package/dist/presentation/renderSceneSvg.js +81 -11
- package/dist/presentation/sceneLabelClearance.d.ts +1 -1
- package/dist/presentation/sceneLabelClearance.js +19 -3
- package/dist/r7Mode.d.ts +13 -0
- package/dist/r7Mode.js +67 -0
- package/dist/visibility.d.ts +1 -1
- package/dist/visibility.js +3 -2
- package/package.json +2 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in geometric check for minimum route spacing (DE-2, OWNER-ADDENDA ask 2).
|
|
3
|
+
*
|
|
4
|
+
* Audits orthogonal routes against token-governed spacing invariants:
|
|
5
|
+
* - No overlapping segments between distinct routes (`segment-overlap`)
|
|
6
|
+
* - Parallel segments separated by at least `routeSpacing` (`parallel-segment-spacing`)
|
|
7
|
+
* - Neighbouring elbows separated by at least `routeSpacing` (`elbow-spacing`)
|
|
8
|
+
* - Distinct dock ports on an entity separated by at least `routeSpacing` (`port-spacing`)
|
|
9
|
+
* - Arrowheads separated by at least `routeSpacing` (`arrowhead-spacing`)
|
|
10
|
+
* - Link segments kept at least `borderClearance` from non-endpoint box borders (`link-to-border`)
|
|
11
|
+
* - Longitudinal channel track demand checked against finite channel capacity (`channel-capacity-exceeded`)
|
|
12
|
+
*
|
|
13
|
+
* Pure geometry: zero DOM, zero external dependencies.
|
|
14
|
+
*/
|
|
15
|
+
import type { CanonicalArrowheadKind } from "@sentropic/diagram-core";
|
|
16
|
+
import type { Rect, Vec2 } from "../transform.js";
|
|
17
|
+
import { type LayoutChannel } from "./channels.js";
|
|
18
|
+
/** Default minimum spacing between parallel route segments, elbows, ports and arrowheads (world units). */
|
|
19
|
+
export declare const DEFAULT_ROUTE_SPACING: 24;
|
|
20
|
+
/** Default minimum clearance from routed link segments to non-endpoint borders (world units). */
|
|
21
|
+
export declare const DEFAULT_ROUTE_BORDER_CLEARANCE: 15;
|
|
22
|
+
export type RouteSpacingConflictKind = "segment-overlap" | "parallel-segment-spacing" | "elbow-spacing" | "port-spacing" | "arrowhead-spacing" | "link-to-border" | "channel-capacity-exceeded";
|
|
23
|
+
export interface RouteSpacingConflict {
|
|
24
|
+
readonly kind: RouteSpacingConflictKind;
|
|
25
|
+
readonly routes: readonly string[];
|
|
26
|
+
readonly entity?: string;
|
|
27
|
+
readonly channelId?: string;
|
|
28
|
+
readonly actual: number;
|
|
29
|
+
readonly required: number;
|
|
30
|
+
readonly message: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ChannelCapacitySummary {
|
|
33
|
+
readonly capacity: number;
|
|
34
|
+
readonly demand: number;
|
|
35
|
+
readonly gap: number;
|
|
36
|
+
}
|
|
37
|
+
export interface RouteSpacingReport {
|
|
38
|
+
readonly conflictCount: number;
|
|
39
|
+
readonly conflicts: readonly RouteSpacingConflict[];
|
|
40
|
+
readonly routeSpacing: number;
|
|
41
|
+
readonly borderClearance: number;
|
|
42
|
+
readonly channelCapacity: Readonly<Record<string, ChannelCapacitySummary>>;
|
|
43
|
+
}
|
|
44
|
+
export interface CheckedRoute {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly source: string;
|
|
47
|
+
readonly target: string;
|
|
48
|
+
readonly points: readonly Vec2[];
|
|
49
|
+
readonly sourcePort?: string;
|
|
50
|
+
readonly targetPort?: string;
|
|
51
|
+
readonly arrowhead?: CanonicalArrowheadKind;
|
|
52
|
+
/** True when the route also carries a start-end arrowhead (e.g. bidirectional numbered flow bundle). */
|
|
53
|
+
readonly startArrowhead?: boolean;
|
|
54
|
+
readonly passable?: ReadonlySet<string>;
|
|
55
|
+
}
|
|
56
|
+
export interface SpacingBarrier {
|
|
57
|
+
readonly rect: Rect;
|
|
58
|
+
/** Optional owner entity id whose first/last dock stub may touch this barrier's outer edge. */
|
|
59
|
+
readonly entity?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface CheckRouteSpacingInput {
|
|
62
|
+
readonly rects: ReadonlyMap<string, Rect>;
|
|
63
|
+
readonly routes: readonly CheckedRoute[];
|
|
64
|
+
readonly routeSpacing?: number;
|
|
65
|
+
readonly borderClearance?: number;
|
|
66
|
+
readonly channels?: readonly LayoutChannel[];
|
|
67
|
+
/** Impassable interior barriers (e.g. expanded zone title bands) audited for link-to-border clearance. */
|
|
68
|
+
readonly barriers?: readonly (Rect | SpacingBarrier)[];
|
|
69
|
+
}
|
|
70
|
+
/** Exact Euclidean distance between an axis-aligned segment and a closed rectangle (0 if intersecting). */
|
|
71
|
+
export declare function segmentToRectDistance(a: Vec2, b: Vec2, rect: Rect): number;
|
|
72
|
+
/**
|
|
73
|
+
* Euclidean distance from an orthogonal segment to the parallel border edges of
|
|
74
|
+
* a passable expanded ancestor zone. Perpendicular wall crossings are allowed;
|
|
75
|
+
* running parallel inside or outside a zone wall closer than `borderClearance` is caught.
|
|
76
|
+
*/
|
|
77
|
+
export declare function segmentToPassableBorderDistance(a: Vec2, b: Vec2, rect: Rect): number;
|
|
78
|
+
/**
|
|
79
|
+
* Audit every route against the minimum route spacing and link-to-border
|
|
80
|
+
* tokens, plus longitudinal channel capacity. Returns every conflict and the
|
|
81
|
+
* exact `conflictCount`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function checkRouteSpacing(input: CheckRouteSpacingInput): RouteSpacingReport;
|
|
84
|
+
//# sourceMappingURL=routeSpacing.d.ts.map
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { channelCapacity } from "./channels.js";
|
|
2
|
+
import { DIAGRAM_SCENE_SPACING as spacing } from "./spacing.generated.js";
|
|
3
|
+
/** Default minimum spacing between parallel route segments, elbows, ports and arrowheads (world units). */
|
|
4
|
+
export const DEFAULT_ROUTE_SPACING = spacing.routeSpacing;
|
|
5
|
+
/** Default minimum clearance from routed link segments to non-endpoint borders (world units). */
|
|
6
|
+
export const DEFAULT_ROUTE_BORDER_CLEARANCE = spacing.routeBorderClearance;
|
|
7
|
+
const EPS = 1e-4;
|
|
8
|
+
function segmentsOf(points) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (let i = 0; i + 1 < points.length; i += 1) {
|
|
11
|
+
const a = points[i];
|
|
12
|
+
const b = points[i + 1];
|
|
13
|
+
if (Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS)
|
|
14
|
+
continue;
|
|
15
|
+
if (Math.abs(a.y - b.y) <= EPS) {
|
|
16
|
+
out.push({
|
|
17
|
+
horizontal: true,
|
|
18
|
+
coord: (a.y + b.y) / 2,
|
|
19
|
+
lo: Math.min(a.x, b.x),
|
|
20
|
+
hi: Math.max(a.x, b.x),
|
|
21
|
+
index: i,
|
|
22
|
+
a,
|
|
23
|
+
b,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (Math.abs(a.x - b.x) <= EPS) {
|
|
27
|
+
out.push({
|
|
28
|
+
horizontal: false,
|
|
29
|
+
coord: (a.x + b.x) / 2,
|
|
30
|
+
lo: Math.min(a.y, b.y),
|
|
31
|
+
hi: Math.max(a.y, b.y),
|
|
32
|
+
index: i,
|
|
33
|
+
a,
|
|
34
|
+
b,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** Exact Euclidean distance between an axis-aligned segment and a closed rectangle (0 if intersecting). */
|
|
41
|
+
export function segmentToRectDistance(a, b, rect) {
|
|
42
|
+
const minX = Math.min(a.x, b.x);
|
|
43
|
+
const maxX = Math.max(a.x, b.x);
|
|
44
|
+
const minY = Math.min(a.y, b.y);
|
|
45
|
+
const maxY = Math.max(a.y, b.y);
|
|
46
|
+
const rRight = rect.x + rect.width;
|
|
47
|
+
const rBottom = rect.y + rect.height;
|
|
48
|
+
const dx = maxX < rect.x ? rect.x - maxX : minX > rRight ? minX - rRight : 0;
|
|
49
|
+
const dy = maxY < rect.y ? rect.y - maxY : minY > rBottom ? minY - rBottom : 0;
|
|
50
|
+
return Math.hypot(dx, dy);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Euclidean distance from an orthogonal segment to the parallel border edges of
|
|
54
|
+
* a passable expanded ancestor zone. Perpendicular wall crossings are allowed;
|
|
55
|
+
* running parallel inside or outside a zone wall closer than `borderClearance` is caught.
|
|
56
|
+
*/
|
|
57
|
+
export function segmentToPassableBorderDistance(a, b, rect) {
|
|
58
|
+
const rRight = rect.x + rect.width;
|
|
59
|
+
const rBottom = rect.y + rect.height;
|
|
60
|
+
if (Math.abs(a.y - b.y) <= EPS && Math.abs(a.x - b.x) > EPS) {
|
|
61
|
+
const lo = Math.min(a.x, b.x);
|
|
62
|
+
const hi = Math.max(a.x, b.x);
|
|
63
|
+
const y = (a.y + b.y) / 2;
|
|
64
|
+
const dx = hi < rect.x ? rect.x - hi : lo > rRight ? lo - rRight : 0;
|
|
65
|
+
return Math.min(Math.hypot(dx, Math.abs(y - rect.y)), Math.hypot(dx, Math.abs(y - rBottom)));
|
|
66
|
+
}
|
|
67
|
+
if (Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) > EPS) {
|
|
68
|
+
const lo = Math.min(a.y, b.y);
|
|
69
|
+
const hi = Math.max(a.y, b.y);
|
|
70
|
+
const x = (a.x + b.x) / 2;
|
|
71
|
+
const dy = hi < rect.y ? rect.y - hi : lo > rBottom ? lo - rBottom : 0;
|
|
72
|
+
return Math.min(Math.hypot(Math.abs(x - rect.x), dy), Math.hypot(Math.abs(x - rRight), dy));
|
|
73
|
+
}
|
|
74
|
+
return Number.POSITIVE_INFINITY;
|
|
75
|
+
}
|
|
76
|
+
function samePoint(left, right) {
|
|
77
|
+
return Math.hypot(left.x - right.x, left.y - right.y) <= EPS;
|
|
78
|
+
}
|
|
79
|
+
function sharedPortStub(left, leftSegIndex, leftLastIndex, right, rightSegIndex, rightLastIndex) {
|
|
80
|
+
if (leftSegIndex === 0 &&
|
|
81
|
+
rightSegIndex === 0 &&
|
|
82
|
+
left.source === right.source &&
|
|
83
|
+
left.sourcePort !== undefined &&
|
|
84
|
+
left.sourcePort === right.sourcePort &&
|
|
85
|
+
samePoint(left.points[0], right.points[0])) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (leftSegIndex === leftLastIndex &&
|
|
89
|
+
rightSegIndex === rightLastIndex &&
|
|
90
|
+
left.target === right.target &&
|
|
91
|
+
left.targetPort !== undefined &&
|
|
92
|
+
left.targetPort === right.targetPort &&
|
|
93
|
+
samePoint(left.points.at(-1), right.points.at(-1))) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (leftSegIndex === 0 &&
|
|
97
|
+
rightSegIndex === rightLastIndex &&
|
|
98
|
+
left.source === right.target &&
|
|
99
|
+
left.sourcePort !== undefined &&
|
|
100
|
+
left.sourcePort === right.targetPort &&
|
|
101
|
+
samePoint(left.points[0], right.points.at(-1))) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (leftSegIndex === leftLastIndex &&
|
|
105
|
+
rightSegIndex === 0 &&
|
|
106
|
+
left.target === right.source &&
|
|
107
|
+
left.targetPort !== undefined &&
|
|
108
|
+
left.targetPort === right.sourcePort &&
|
|
109
|
+
samePoint(left.points.at(-1), right.points[0])) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Audit every route against the minimum route spacing and link-to-border
|
|
116
|
+
* tokens, plus longitudinal channel capacity. Returns every conflict and the
|
|
117
|
+
* exact `conflictCount`.
|
|
118
|
+
*/
|
|
119
|
+
export function checkRouteSpacing(input) {
|
|
120
|
+
const routeSpacing = input.routeSpacing ?? DEFAULT_ROUTE_SPACING;
|
|
121
|
+
const borderClearance = input.borderClearance ?? DEFAULT_ROUTE_BORDER_CLEARANCE;
|
|
122
|
+
const conflicts = [];
|
|
123
|
+
const parsed = input.routes.map((route) => ({
|
|
124
|
+
route,
|
|
125
|
+
segments: segmentsOf(route.points),
|
|
126
|
+
elbows: route.points.length > 2 ? route.points.slice(1, -1) : [],
|
|
127
|
+
}));
|
|
128
|
+
// 1 & 2. Segment overlaps and parallel segment spacing (cross-route and self-hairpins).
|
|
129
|
+
for (let i = 0; i < parsed.length; i += 1) {
|
|
130
|
+
const left = parsed[i];
|
|
131
|
+
const leftLast = Math.max(0, left.route.points.length - 2);
|
|
132
|
+
// Self-parallel hairpin check (non-adjacent segments on the same route).
|
|
133
|
+
for (let s1 = 0; s1 < left.segments.length; s1 += 1) {
|
|
134
|
+
const segA = left.segments[s1];
|
|
135
|
+
for (let s2 = s1 + 2; s2 < left.segments.length; s2 += 1) {
|
|
136
|
+
const segB = left.segments[s2];
|
|
137
|
+
if (segA.horizontal !== segB.horizontal)
|
|
138
|
+
continue;
|
|
139
|
+
const overlap = Math.min(segA.hi, segB.hi) - Math.max(segA.lo, segB.lo);
|
|
140
|
+
if (overlap <= EPS)
|
|
141
|
+
continue;
|
|
142
|
+
const sep = Math.abs(segA.coord - segB.coord);
|
|
143
|
+
if (sep <= EPS) {
|
|
144
|
+
conflicts.push({
|
|
145
|
+
kind: "segment-overlap",
|
|
146
|
+
routes: [left.route.id],
|
|
147
|
+
actual: 0,
|
|
148
|
+
required: routeSpacing,
|
|
149
|
+
message: `route ${left.route.id} folds back onto itself with overlapping segments`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else if (sep < routeSpacing - EPS) {
|
|
153
|
+
conflicts.push({
|
|
154
|
+
kind: "parallel-segment-spacing",
|
|
155
|
+
routes: [left.route.id],
|
|
156
|
+
actual: Math.round(sep * 1000) / 1000,
|
|
157
|
+
required: routeSpacing,
|
|
158
|
+
message: `parallel segments of ${left.route.id} are ${sep.toFixed(1)} apart (< ${routeSpacing})`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (let j = i + 1; j < parsed.length; j += 1) {
|
|
164
|
+
const right = parsed[j];
|
|
165
|
+
const rightLast = Math.max(0, right.route.points.length - 2);
|
|
166
|
+
let reportedOverlap = false;
|
|
167
|
+
let minParallelGap = Number.POSITIVE_INFINITY;
|
|
168
|
+
for (const segA of left.segments) {
|
|
169
|
+
for (const segB of right.segments) {
|
|
170
|
+
if (segA.horizontal !== segB.horizontal)
|
|
171
|
+
continue;
|
|
172
|
+
const overlap = Math.min(segA.hi, segB.hi) - Math.max(segA.lo, segB.lo);
|
|
173
|
+
if (overlap <= EPS)
|
|
174
|
+
continue;
|
|
175
|
+
const sep = Math.abs(segA.coord - segB.coord);
|
|
176
|
+
// A shared port can have a short escape stub. Long overlaps and
|
|
177
|
+
// coincident straight routes remain conflicts.
|
|
178
|
+
if (overlap <= routeSpacing + borderClearance + EPS &&
|
|
179
|
+
(leftLast > 0 || rightLast > 0) &&
|
|
180
|
+
sharedPortStub(left.route, segA.index, leftLast, right.route, segB.index, rightLast))
|
|
181
|
+
continue;
|
|
182
|
+
if (sep <= EPS) {
|
|
183
|
+
reportedOverlap = true;
|
|
184
|
+
}
|
|
185
|
+
else if (sep < routeSpacing - EPS && sep < minParallelGap) {
|
|
186
|
+
minParallelGap = sep;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (reportedOverlap) {
|
|
191
|
+
conflicts.push({
|
|
192
|
+
kind: "segment-overlap",
|
|
193
|
+
routes: [left.route.id, right.route.id],
|
|
194
|
+
actual: 0,
|
|
195
|
+
required: routeSpacing,
|
|
196
|
+
message: `routes ${left.route.id} and ${right.route.id} share an overlapping segment`,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else if (minParallelGap < routeSpacing - EPS) {
|
|
200
|
+
conflicts.push({
|
|
201
|
+
kind: "parallel-segment-spacing",
|
|
202
|
+
routes: [left.route.id, right.route.id],
|
|
203
|
+
actual: Math.round(minParallelGap * 1000) / 1000,
|
|
204
|
+
required: routeSpacing,
|
|
205
|
+
message: `parallel segments of ${left.route.id} and ${right.route.id} are ${minParallelGap.toFixed(1)} apart (< ${routeSpacing})`,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// 3. Neighbouring elbows between distinct routes.
|
|
209
|
+
let minElbowDist = Number.POSITIVE_INFINITY;
|
|
210
|
+
for (const e1 of left.elbows) {
|
|
211
|
+
for (const e2 of right.elbows) {
|
|
212
|
+
const dist = Math.hypot(e1.x - e2.x, e1.y - e2.y);
|
|
213
|
+
if (dist < minElbowDist)
|
|
214
|
+
minElbowDist = dist;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (minElbowDist < routeSpacing - EPS) {
|
|
218
|
+
conflicts.push({
|
|
219
|
+
kind: "elbow-spacing",
|
|
220
|
+
routes: [left.route.id, right.route.id],
|
|
221
|
+
actual: Math.round(minElbowDist * 1000) / 1000,
|
|
222
|
+
required: routeSpacing,
|
|
223
|
+
message: `neighbouring elbows of ${left.route.id} and ${right.route.id} are ${minElbowDist.toFixed(1)} apart (< ${routeSpacing})`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const docksByEntity = new Map();
|
|
229
|
+
const arrowheads = [];
|
|
230
|
+
for (const { route } of parsed) {
|
|
231
|
+
if (route.points.length < 2)
|
|
232
|
+
continue;
|
|
233
|
+
const start = route.points[0];
|
|
234
|
+
const end = route.points[route.points.length - 1];
|
|
235
|
+
const hasStartArrow = route.startArrowhead === true;
|
|
236
|
+
const hasEndArrow = route.arrowhead !== "none";
|
|
237
|
+
const pushDock = (entry) => {
|
|
238
|
+
const list = docksByEntity.get(entry.entity) ?? [];
|
|
239
|
+
list.push(entry);
|
|
240
|
+
docksByEntity.set(entry.entity, list);
|
|
241
|
+
};
|
|
242
|
+
const startEntry = {
|
|
243
|
+
routeId: route.id,
|
|
244
|
+
entity: route.source,
|
|
245
|
+
point: start,
|
|
246
|
+
port: route.sourcePort,
|
|
247
|
+
isArrowhead: hasStartArrow,
|
|
248
|
+
};
|
|
249
|
+
const endEntry = {
|
|
250
|
+
routeId: route.id,
|
|
251
|
+
entity: route.target,
|
|
252
|
+
point: end,
|
|
253
|
+
port: route.targetPort,
|
|
254
|
+
isArrowhead: hasEndArrow,
|
|
255
|
+
};
|
|
256
|
+
pushDock(startEntry);
|
|
257
|
+
pushDock(endEntry);
|
|
258
|
+
if (hasStartArrow)
|
|
259
|
+
arrowheads.push(startEntry);
|
|
260
|
+
if (hasEndArrow)
|
|
261
|
+
arrowheads.push(endEntry);
|
|
262
|
+
}
|
|
263
|
+
for (const [entity, docks] of docksByEntity) {
|
|
264
|
+
for (let i = 0; i < docks.length; i += 1) {
|
|
265
|
+
const a = docks[i];
|
|
266
|
+
for (let j = i + 1; j < docks.length; j += 1) {
|
|
267
|
+
const b = docks[j];
|
|
268
|
+
if (a.port !== undefined && a.port === b.port && samePoint(a.point, b.point))
|
|
269
|
+
continue;
|
|
270
|
+
// Pairs of arrowhead tips on the same entity are counted once below as `arrowhead-spacing`.
|
|
271
|
+
if (a.isArrowhead && b.isArrowhead)
|
|
272
|
+
continue;
|
|
273
|
+
const dist = Math.hypot(a.point.x - b.point.x, a.point.y - b.point.y);
|
|
274
|
+
if (dist < routeSpacing - EPS) {
|
|
275
|
+
conflicts.push({
|
|
276
|
+
kind: "port-spacing",
|
|
277
|
+
routes: a.routeId === b.routeId ? [a.routeId] : [a.routeId, b.routeId],
|
|
278
|
+
entity,
|
|
279
|
+
actual: Math.round(dist * 1000) / 1000,
|
|
280
|
+
required: routeSpacing,
|
|
281
|
+
message: `ports on ${entity} for ${a.routeId} and ${b.routeId} are ${dist.toFixed(1)} apart (< ${routeSpacing})`,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// 5. Arrowhead spacing across all directed tips (including backward flowArrow start tips).
|
|
288
|
+
for (let i = 0; i < arrowheads.length; i += 1) {
|
|
289
|
+
const a = arrowheads[i];
|
|
290
|
+
for (let j = i + 1; j < arrowheads.length; j += 1) {
|
|
291
|
+
const b = arrowheads[j];
|
|
292
|
+
if (a.entity === b.entity && a.port !== undefined && a.port === b.port && samePoint(a.point, b.point))
|
|
293
|
+
continue;
|
|
294
|
+
const dist = Math.hypot(a.point.x - b.point.x, a.point.y - b.point.y);
|
|
295
|
+
if (dist < routeSpacing - EPS) {
|
|
296
|
+
conflicts.push({
|
|
297
|
+
kind: "arrowhead-spacing",
|
|
298
|
+
routes: a.routeId === b.routeId ? [a.routeId] : [a.routeId, b.routeId],
|
|
299
|
+
...(a.entity === b.entity ? { entity: a.entity } : {}),
|
|
300
|
+
actual: Math.round(dist * 1000) / 1000,
|
|
301
|
+
required: routeSpacing,
|
|
302
|
+
message: `arrowheads of ${a.routeId} and ${b.routeId} are ${dist.toFixed(1)} apart (< ${routeSpacing})`,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// 6. Link-to-border clearance against all entity boxes (including parallel walls of passable ancestor zones) and title barriers.
|
|
308
|
+
for (const { route, segments } of parsed) {
|
|
309
|
+
const lastIdx = Math.max(0, route.points.length - 2);
|
|
310
|
+
for (const [entity, rect] of input.rects) {
|
|
311
|
+
const isPassable = route.passable?.has(entity) === true;
|
|
312
|
+
let minDist = Number.POSITIVE_INFINITY;
|
|
313
|
+
for (const seg of segments) {
|
|
314
|
+
if (entity === route.source && seg.index === 0)
|
|
315
|
+
continue;
|
|
316
|
+
if (entity === route.target && seg.index === lastIdx)
|
|
317
|
+
continue;
|
|
318
|
+
const dist = isPassable
|
|
319
|
+
? segmentToPassableBorderDistance(seg.a, seg.b, rect)
|
|
320
|
+
: segmentToRectDistance(seg.a, seg.b, rect);
|
|
321
|
+
if (dist < minDist)
|
|
322
|
+
minDist = dist;
|
|
323
|
+
}
|
|
324
|
+
if (minDist < borderClearance - EPS) {
|
|
325
|
+
conflicts.push({
|
|
326
|
+
kind: "link-to-border",
|
|
327
|
+
routes: [route.id],
|
|
328
|
+
entity,
|
|
329
|
+
actual: Math.round(minDist * 1000) / 1000,
|
|
330
|
+
required: borderClearance,
|
|
331
|
+
message: `route ${route.id} clears ${entity} by ${minDist.toFixed(1)} (< ${borderClearance})`,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (let bIdx = 0; bIdx < (input.barriers?.length ?? 0); bIdx += 1) {
|
|
336
|
+
const rawBarrier = input.barriers[bIdx];
|
|
337
|
+
const barrier = "rect" in rawBarrier ? rawBarrier.rect : rawBarrier;
|
|
338
|
+
const barrierEntity = "rect" in rawBarrier ? rawBarrier.entity : undefined;
|
|
339
|
+
let minDist = Number.POSITIVE_INFINITY;
|
|
340
|
+
for (const seg of segments) {
|
|
341
|
+
if (barrierEntity !== undefined) {
|
|
342
|
+
if (barrierEntity === route.source && seg.index === 0)
|
|
343
|
+
continue;
|
|
344
|
+
if (barrierEntity === route.target && seg.index === lastIdx)
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const dist = segmentToRectDistance(seg.a, seg.b, barrier);
|
|
348
|
+
if (dist < minDist)
|
|
349
|
+
minDist = dist;
|
|
350
|
+
}
|
|
351
|
+
if (minDist < borderClearance - EPS) {
|
|
352
|
+
conflicts.push({
|
|
353
|
+
kind: "link-to-border",
|
|
354
|
+
routes: [route.id],
|
|
355
|
+
entity: barrierEntity ?? `barrier:${String(bIdx)}`,
|
|
356
|
+
actual: Math.round(minDist * 1000) / 1000,
|
|
357
|
+
required: borderClearance,
|
|
358
|
+
message: `route ${route.id} clears title barrier ${bIdx} by ${minDist.toFixed(1)} (< ${borderClearance})`,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// 7. Finite longitudinal channel capacity report.
|
|
364
|
+
const channelSummary = {};
|
|
365
|
+
const rectList = [...input.rects.values()];
|
|
366
|
+
for (const channel of input.channels ?? []) {
|
|
367
|
+
const cap = channelCapacity(channel.gap, routeSpacing, borderClearance);
|
|
368
|
+
// Longitudinal routes run along the channel strip (vertical segments in a horizontal-gap channel,
|
|
369
|
+
// horizontal segments in a vertical-gap channel). Compute max concurrent demand along the
|
|
370
|
+
// physically bounded intervals of each strip (where boxes border both sides of the gap; an
|
|
371
|
+
// empty quadrant beside a partial shelf is open space, not a `gap`-wide gutter).
|
|
372
|
+
const wantHorizontal = channel.axis === "vertical";
|
|
373
|
+
const events = [];
|
|
374
|
+
const longitudinalRoutes = new Set();
|
|
375
|
+
const boundedSpansOf = (strip) => {
|
|
376
|
+
const crossLo = wantHorizontal ? strip.y : strip.x;
|
|
377
|
+
const crossHi = wantHorizontal ? strip.y + strip.height : strip.x + strip.width;
|
|
378
|
+
const stripLo = wantHorizontal ? strip.x : strip.y;
|
|
379
|
+
const stripHi = wantHorizontal ? strip.x + strip.width : strip.y + strip.height;
|
|
380
|
+
const sideA = [];
|
|
381
|
+
const sideB = [];
|
|
382
|
+
for (const r of rectList) {
|
|
383
|
+
const rCrossLo = wantHorizontal ? r.y : r.x;
|
|
384
|
+
const rCrossHi = wantHorizontal ? r.y + r.height : r.x + r.width;
|
|
385
|
+
const rLongLo = wantHorizontal ? r.x : r.y;
|
|
386
|
+
const rLongHi = wantHorizontal ? r.x + r.width : r.y + r.height;
|
|
387
|
+
const lo = Math.max(stripLo, rLongLo);
|
|
388
|
+
const hi = Math.min(stripHi, rLongHi);
|
|
389
|
+
if (hi - lo <= EPS)
|
|
390
|
+
continue;
|
|
391
|
+
if (Math.abs(rCrossHi - crossLo) <= 1)
|
|
392
|
+
sideA.push([lo, hi]);
|
|
393
|
+
if (Math.abs(rCrossLo - crossHi) <= 1)
|
|
394
|
+
sideB.push([lo, hi]);
|
|
395
|
+
}
|
|
396
|
+
if (sideA.length === 0 || sideB.length === 0)
|
|
397
|
+
return [[stripLo, stripHi]];
|
|
398
|
+
const raw = [];
|
|
399
|
+
for (const [a0, a1] of sideA) {
|
|
400
|
+
for (const [b0, b1] of sideB) {
|
|
401
|
+
const lo = Math.max(a0, b0);
|
|
402
|
+
const hi = Math.min(a1, b1);
|
|
403
|
+
if (hi - lo > EPS)
|
|
404
|
+
raw.push([lo, hi]);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (raw.length === 0)
|
|
408
|
+
return [[stripLo, stripHi]];
|
|
409
|
+
raw.sort((u, v) => u[0] - v[0] || u[1] - v[1]);
|
|
410
|
+
const merged = [raw[0]];
|
|
411
|
+
for (let k = 1; k < raw.length; k += 1) {
|
|
412
|
+
const prev = merged[merged.length - 1];
|
|
413
|
+
const curr = raw[k];
|
|
414
|
+
if (curr[0] <= prev[1] + EPS)
|
|
415
|
+
prev[1] = Math.max(prev[1], curr[1]);
|
|
416
|
+
else
|
|
417
|
+
merged.push([curr[0], curr[1]]);
|
|
418
|
+
}
|
|
419
|
+
return merged;
|
|
420
|
+
};
|
|
421
|
+
for (const strip of channel.strips) {
|
|
422
|
+
const spans = boundedSpansOf(strip);
|
|
423
|
+
for (const { route, segments } of parsed) {
|
|
424
|
+
for (const seg of segments) {
|
|
425
|
+
if (seg.horizontal !== wantHorizontal)
|
|
426
|
+
continue;
|
|
427
|
+
const insideCross = wantHorizontal
|
|
428
|
+
? seg.coord >= strip.y - EPS && seg.coord <= strip.y + strip.height + EPS
|
|
429
|
+
: seg.coord >= strip.x - EPS && seg.coord <= strip.x + strip.width + EPS;
|
|
430
|
+
if (!insideCross)
|
|
431
|
+
continue;
|
|
432
|
+
for (const [spanLo, spanHi] of spans) {
|
|
433
|
+
const lo = Math.max(seg.lo, spanLo);
|
|
434
|
+
const hi = Math.min(seg.hi, spanHi);
|
|
435
|
+
if (hi - lo <= EPS)
|
|
436
|
+
continue;
|
|
437
|
+
longitudinalRoutes.add(route.id);
|
|
438
|
+
events.push({ pos: lo, delta: 1, routeId: route.id });
|
|
439
|
+
events.push({ pos: hi, delta: -1, routeId: route.id });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
events.sort((a, b) => a.pos - b.pos || a.delta - b.delta);
|
|
445
|
+
let active = 0;
|
|
446
|
+
let peak = 0;
|
|
447
|
+
for (const event of events) {
|
|
448
|
+
active += event.delta;
|
|
449
|
+
if (active > peak)
|
|
450
|
+
peak = active;
|
|
451
|
+
}
|
|
452
|
+
channelSummary[channel.id] = { capacity: cap, demand: peak, gap: channel.gap };
|
|
453
|
+
if (peak > cap) {
|
|
454
|
+
conflicts.push({
|
|
455
|
+
kind: "channel-capacity-exceeded",
|
|
456
|
+
routes: [...longitudinalRoutes].sort(),
|
|
457
|
+
channelId: channel.id,
|
|
458
|
+
actual: peak,
|
|
459
|
+
required: cap,
|
|
460
|
+
message: `channel ${channel.id} (gap ${channel.gap}) carries ${peak} parallel tracks, exceeding capacity ${cap}`,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
conflictCount: conflicts.length,
|
|
466
|
+
conflicts,
|
|
467
|
+
routeSpacing,
|
|
468
|
+
borderClearance,
|
|
469
|
+
channelCapacity: channelSummary,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
//# sourceMappingURL=routeSpacing.js.map
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* World units. Owner A9 is resolved: V1 (72 vertical / 96 horizontal); canvas defaults are generated.
|
|
3
|
+
* `zoneGutter` (96) is the single fixed gutter token between sibling zones on both axes (DE-2 ask 3);
|
|
4
|
+
* routing adapts inside the fixed gutter instead of widening it.
|
|
5
|
+
* `routeSpacing` (24) is the minimum spacing between parallel route segments, neighbouring elbows,
|
|
6
|
+
* ports and arrowheads; `routeBorderClearance` (15) is the minimum link-to-border clearance (DE-2 ask 2).
|
|
7
|
+
*/
|
|
2
8
|
export declare const DIAGRAM_SCENE_SPACING: {
|
|
3
9
|
readonly gapMin: 96;
|
|
4
10
|
readonly gapMinBlock: 72;
|
|
@@ -9,5 +15,8 @@ export declare const DIAGRAM_SCENE_SPACING: {
|
|
|
9
15
|
readonly labelBand: 30;
|
|
10
16
|
readonly gapMax: 240;
|
|
11
17
|
readonly containerPadding: 16;
|
|
18
|
+
readonly zoneGutter: 96;
|
|
19
|
+
readonly routeSpacing: 24;
|
|
20
|
+
readonly routeBorderClearance: 15;
|
|
12
21
|
};
|
|
13
22
|
//# sourceMappingURL=spacing.generated.d.ts.map
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// Generated by scripts/sync-diagram-spacing.mjs. Edit tokens/src/diagramSpacing.ts.
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* World units. Owner A9 is resolved: V1 (72 vertical / 96 horizontal); canvas defaults are generated.
|
|
4
|
+
* `zoneGutter` (96) is the single fixed gutter token between sibling zones on both axes (DE-2 ask 3);
|
|
5
|
+
* routing adapts inside the fixed gutter instead of widening it.
|
|
6
|
+
* `routeSpacing` (24) is the minimum spacing between parallel route segments, neighbouring elbows,
|
|
7
|
+
* ports and arrowheads; `routeBorderClearance` (15) is the minimum link-to-border clearance (DE-2 ask 2).
|
|
8
|
+
*/
|
|
3
9
|
export const DIAGRAM_SCENE_SPACING = {
|
|
4
10
|
gapMin: 96, gapMinBlock: 72, gapBase: 64, gapBaseBlock: 8,
|
|
5
11
|
trackSpacing: 14, trackSpacingBlock: 7, labelBand: 30, gapMax: 240,
|
|
6
12
|
containerPadding: 16,
|
|
13
|
+
zoneGutter: 96,
|
|
14
|
+
routeSpacing: 24,
|
|
15
|
+
routeBorderClearance: 15,
|
|
7
16
|
};
|
|
8
17
|
//# sourceMappingURL=spacing.generated.js.map
|