@statelyai/flow 0.14.0 → 0.15.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 +2 -1
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +19 -14
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/layout/dagre.d.ts +2 -1
- package/dist/esm/layout/dagre.d.ts.map +1 -0
- package/dist/esm/layout/dagre.js +2 -0
- package/dist/esm/layout/dagre.js.map +1 -0
- package/dist/esm/layout/elk.d.ts +2 -1
- package/dist/esm/layout/elk.d.ts.map +1 -0
- package/dist/esm/layout/elk.js +2 -0
- package/dist/esm/layout/elk.js.map +1 -0
- package/dist/esm/layout/stately.d.ts +2 -1
- package/dist/esm/layout/stately.d.ts.map +1 -0
- package/dist/esm/layout/stately.js +2 -0
- package/dist/esm/layout/stately.js.map +1 -0
- package/dist/esm/shared.d.ts +2 -1
- package/dist/esm/shared.d.ts.map +1 -0
- package/dist/esm/shared.js +2 -0
- package/dist/esm/shared.js.map +1 -0
- package/package.json +4 -3
- package/src/__fixtures__/nested.ts +106 -0
- package/src/appearances.test.ts +428 -0
- package/src/appearances.ts +144 -0
- package/src/authoritative-route.ts +14 -0
- package/src/changeSet.test.ts +132 -0
- package/src/changeSet.ts +337 -0
- package/src/config.ts +41 -0
- package/src/configure.test.ts +212 -0
- package/src/connection-lifetime.ts +1 -0
- package/src/connectionPreview.test.ts +102 -0
- package/src/connectionPreview.ts +82 -0
- package/src/content.ts +203 -0
- package/src/createFlow.fit-frame.test.ts +256 -0
- package/src/createFlow.modern.test.ts +743 -0
- package/src/createFlow.test.ts +632 -0
- package/src/createFlow.ts +3463 -0
- package/src/createFlow.view.test.ts +212 -0
- package/src/createFlow.viewport-controls.test.ts +221 -0
- package/src/edge-geometry.ts +318 -0
- package/src/engine.cache.test.ts +728 -0
- package/src/engine.hierarchy.test.ts +1023 -0
- package/src/engine.test.ts +1965 -0
- package/src/engine.ts +3385 -0
- package/src/entity-changes.test.ts +309 -0
- package/src/entity-changes.ts +395 -0
- package/src/examples/flow-based-math.test.ts +25 -0
- package/src/examples/flow-based-math.ts +210 -0
- package/src/external-edit.test.ts +337 -0
- package/src/external-edit.ts +358 -0
- package/src/factories.test.ts +104 -0
- package/src/factories.ts +70 -0
- package/src/geometry.ts +13 -0
- package/src/graph-index.test.ts +56 -0
- package/src/graph-index.ts +194 -0
- package/src/hierarchy.test.ts +175 -0
- package/src/hierarchy.ts +330 -0
- package/src/highlights.test.ts +130 -0
- package/src/index.ts +469 -0
- package/src/input/index.ts +615 -0
- package/src/input/input.test.ts +2577 -0
- package/src/input/keymap.ts +111 -0
- package/src/input/modes.ts +1715 -0
- package/src/input/reparent.test.ts +214 -0
- package/src/layout/dagre.ts +138 -0
- package/src/layout/elk.ts +1382 -0
- package/src/layout/index.ts +12 -0
- package/src/layout/layout.test.ts +1248 -0
- package/src/layout/shared.ts +260 -0
- package/src/layout/stately-globals.d.ts +9 -0
- package/src/layout/stately.test.ts +246 -0
- package/src/layout/stately.ts +528 -0
- package/src/layout-animation.test.ts +223 -0
- package/src/layout-contract.test.ts +414 -0
- package/src/marker.test.ts +23 -0
- package/src/marker.ts +23 -0
- package/src/measurement-anchor.test.ts +232 -0
- package/src/minimap.test.ts +96 -0
- package/src/minimap.ts +137 -0
- package/src/nested-fixture.test.ts +178 -0
- package/src/port-measurement.test.ts +27 -0
- package/src/port-measurements.test.ts +187 -0
- package/src/profile.ts +124 -0
- package/src/projections.test.ts +103 -0
- package/src/projections.ts +295 -0
- package/src/render-invalidation.test.ts +62 -0
- package/src/render-invalidation.ts +55 -0
- package/src/renderer-geometry.test.ts +356 -0
- package/src/renderer-transactions.test.ts +234 -0
- package/src/routing/avoid.ts +417 -0
- package/src/routing/index.test.ts +361 -0
- package/src/routing/index.ts +366 -0
- package/src/routing/readTracking.test.ts +103 -0
- package/src/routing/readTracking.ts +233 -0
- package/src/selection-commands.test.ts +355 -0
- package/src/serialize.test.ts +167 -0
- package/src/serialize.ts +254 -0
- package/src/shapes/index.test.ts +45 -0
- package/src/shapes/index.ts +142 -0
- package/src/snap.test.ts +123 -0
- package/src/snap.ts +395 -0
- package/src/spatial.test.ts +676 -0
- package/src/spatial.ts +457 -0
- package/src/store/index.ts +4121 -0
- package/src/store.test.ts +2903 -0
- package/src/toolbar.test.ts +31 -0
- package/src/toolbar.ts +62 -0
- package/src/types.test.ts +15 -0
- package/src/types.ts +487 -0
- package/src/validation.ts +558 -0
- package/src/view.ts +172 -0
- package/src/viewport/animate.ts +285 -0
- package/src/viewport/index.ts +296 -0
- package/src/viewport.test.ts +569 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
avoidRouter,
|
|
4
|
+
bezierRouter,
|
|
5
|
+
configureAvoidRouter,
|
|
6
|
+
configureBezierRouter,
|
|
7
|
+
configureStepRouter,
|
|
8
|
+
pathToSVG,
|
|
9
|
+
straightRouter,
|
|
10
|
+
stepRouter,
|
|
11
|
+
type EdgeRouterContext,
|
|
12
|
+
} from './index';
|
|
13
|
+
import type { Rect } from '../types';
|
|
14
|
+
import { createEdge, createGraph } from '../factories';
|
|
15
|
+
|
|
16
|
+
const edge = createEdge({ id: 'ab', sourceId: 'a', targetId: 'b' });
|
|
17
|
+
|
|
18
|
+
const ctx: EdgeRouterContext = {
|
|
19
|
+
graph: createGraph({ nodes: [], edges: [edge] }),
|
|
20
|
+
getEntityBounds: () => undefined,
|
|
21
|
+
sourceBounds: { x: 0, y: 0, width: 100, height: 40 },
|
|
22
|
+
targetBounds: { x: 300, y: 0, width: 100, height: 40 },
|
|
23
|
+
sourceDirection: 'right',
|
|
24
|
+
targetDirection: 'left',
|
|
25
|
+
obstacles: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('router configuration helpers', () => {
|
|
29
|
+
it('prefers a finite non-empty router-provided SVG path', () => {
|
|
30
|
+
const path = straightRouter(edge, ctx);
|
|
31
|
+
|
|
32
|
+
expect(
|
|
33
|
+
pathToSVG({
|
|
34
|
+
...path,
|
|
35
|
+
svgPath: ' M 100 20 Q 200 -40 300 20 ',
|
|
36
|
+
}),
|
|
37
|
+
).toBe('M 100 20 Q 200 -40 300 20');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('falls back to point geometry for empty or non-finite SVG paths', () => {
|
|
41
|
+
const path = straightRouter(edge, ctx);
|
|
42
|
+
const generated = pathToSVG(path);
|
|
43
|
+
|
|
44
|
+
expect(pathToSVG({ ...path, svgPath: ' ' })).toBe(generated);
|
|
45
|
+
expect(pathToSVG({ ...path, svgPath: 'M 0 0 L NaN 20' })).toBe(generated);
|
|
46
|
+
expect(pathToSVG({ ...path, svgPath: 'M0 0LInfinity 20' })).toBe(generated);
|
|
47
|
+
expect(pathToSVG({ ...path, svgPath: 'M 0 0 L 1e999 20' })).toBe(
|
|
48
|
+
generated,
|
|
49
|
+
);
|
|
50
|
+
expect(
|
|
51
|
+
pathToSVG({
|
|
52
|
+
...path,
|
|
53
|
+
points: [{ x: 0, y: 0 }, { x: Number.POSITIVE_INFINITY, y: 20 }],
|
|
54
|
+
svgPath: 'M 0 0 L 20 20',
|
|
55
|
+
}),
|
|
56
|
+
).toBe('');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('keeps built-in routers directly usable', () => {
|
|
60
|
+
expect(bezierRouter(edge, ctx).points).toHaveLength(4);
|
|
61
|
+
expect(stepRouter(edge, ctx).points).toHaveLength(3);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders authoritative polyline and chained spline routing exactly', () => {
|
|
65
|
+
const points = [
|
|
66
|
+
{ x: 0, y: 0 },
|
|
67
|
+
{ x: 10, y: 20 },
|
|
68
|
+
{ x: 30, y: 20 },
|
|
69
|
+
{ x: 40, y: 0 },
|
|
70
|
+
{ x: 50, y: -20 },
|
|
71
|
+
{ x: 70, y: -20 },
|
|
72
|
+
{ x: 80, y: 0 },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
expect(
|
|
76
|
+
pathToSVG({
|
|
77
|
+
points: points.slice(0, 4),
|
|
78
|
+
routing: 'polyline',
|
|
79
|
+
sourceDirection: 'right',
|
|
80
|
+
targetDirection: 'left',
|
|
81
|
+
}),
|
|
82
|
+
).toBe('M 0 0 L 10 20 L 30 20 L 40 0');
|
|
83
|
+
expect(
|
|
84
|
+
pathToSVG({
|
|
85
|
+
points,
|
|
86
|
+
routing: 'splines',
|
|
87
|
+
sourceDirection: 'right',
|
|
88
|
+
targetDirection: 'left',
|
|
89
|
+
}),
|
|
90
|
+
).toBe('M 0 0 C 10 20, 30 20, 40 0 C 50 -20, 70 -20, 80 0');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('preserves no-waypoint router output', () => {
|
|
94
|
+
expect(straightRouter(edge, ctx).points).toEqual([
|
|
95
|
+
{ x: 50, y: 20 },
|
|
96
|
+
{ x: 350, y: 20 },
|
|
97
|
+
]);
|
|
98
|
+
expect(stepRouter(edge, ctx).points).toEqual([
|
|
99
|
+
{ x: 100, y: 20 },
|
|
100
|
+
{ x: 200, y: 20 },
|
|
101
|
+
{ x: 300, y: 20 },
|
|
102
|
+
]);
|
|
103
|
+
expect(bezierRouter(edge, ctx).points).toEqual([
|
|
104
|
+
{ x: 100, y: 20 },
|
|
105
|
+
{ x: 150, y: 20 },
|
|
106
|
+
{ x: 250, y: 20 },
|
|
107
|
+
{ x: 300, y: 20 },
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('honors waypoints in built-in routers', () => {
|
|
112
|
+
const withWaypoint: EdgeRouterContext = {
|
|
113
|
+
...ctx,
|
|
114
|
+
waypoints: [{ x: 180, y: 80 }],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
expect(straightRouter(edge, withWaypoint).points).toEqual([
|
|
118
|
+
{ x: 50, y: 20 },
|
|
119
|
+
{ x: 180, y: 80 },
|
|
120
|
+
{ x: 350, y: 20 },
|
|
121
|
+
]);
|
|
122
|
+
expect(stepRouter(edge, withWaypoint).points).toEqual([
|
|
123
|
+
{ x: 100, y: 20 },
|
|
124
|
+
{ x: 140, y: 20 },
|
|
125
|
+
{ x: 180, y: 80 },
|
|
126
|
+
{ x: 240, y: 80 },
|
|
127
|
+
{ x: 300, y: 20 },
|
|
128
|
+
]);
|
|
129
|
+
expect(bezierRouter(edge, withWaypoint).points).toEqual([
|
|
130
|
+
{ x: 100, y: 20 },
|
|
131
|
+
{ x: 180, y: 80 },
|
|
132
|
+
{ x: 300, y: 20 },
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('configures bezier curvature', () => {
|
|
137
|
+
const base = bezierRouter(edge, ctx).points;
|
|
138
|
+
const curved = configureBezierRouter({ curvature: 0.5, minOffset: 0 })(
|
|
139
|
+
edge,
|
|
140
|
+
ctx,
|
|
141
|
+
).points;
|
|
142
|
+
|
|
143
|
+
expect(curved[1].x - base[1].x).toBeGreaterThan(0);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('configures step offset', () => {
|
|
147
|
+
const points = configureStepRouter({ offset: 40 })(
|
|
148
|
+
edge,
|
|
149
|
+
ctx,
|
|
150
|
+
).points;
|
|
151
|
+
|
|
152
|
+
expect(points[1]).toEqual({ x: 140, y: 20 });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('routes orthogonally around obstacle interiors', () => {
|
|
156
|
+
const obstacle = { x: 160, y: 0, width: 80, height: 40 };
|
|
157
|
+
const points = avoidRouter(
|
|
158
|
+
edge,
|
|
159
|
+
{ ...ctx, obstacles: [obstacle] },
|
|
160
|
+
).points;
|
|
161
|
+
|
|
162
|
+
expect(points.length).toBeGreaterThan(3);
|
|
163
|
+
expect(allSegmentsOrthogonal(points)).toBe(true);
|
|
164
|
+
expect(pathIntersectsAny(points, [inflateRect(obstacle, 8)])).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('treats waypoints as mandatory via-points', () => {
|
|
168
|
+
const waypoint = { x: 200, y: 100 };
|
|
169
|
+
const points = avoidRouter(
|
|
170
|
+
edge,
|
|
171
|
+
{
|
|
172
|
+
...ctx,
|
|
173
|
+
waypoints: [waypoint],
|
|
174
|
+
obstacles: [{ x: 160, y: 0, width: 80, height: 40 }],
|
|
175
|
+
},
|
|
176
|
+
).points;
|
|
177
|
+
|
|
178
|
+
expect(points).toContainEqual(waypoint);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('routes around obstacles whose margin swallows an endpoint instead of cutting through', () => {
|
|
182
|
+
// Raw obstacle sits just above/right of the source point (100, 20); the
|
|
183
|
+
// default margin (8) inflates it to cover the point. The pre-fix router saw
|
|
184
|
+
// an endpoint "inside an obstacle" and bailed to a straight fallback that
|
|
185
|
+
// drove through the real node. It must now start at the endpoint, stay
|
|
186
|
+
// orthogonal, and never cross the real obstacle interior.
|
|
187
|
+
const obstacle = { x: 104, y: 24, width: 60, height: 40 };
|
|
188
|
+
const points = avoidRouter(
|
|
189
|
+
edge,
|
|
190
|
+
{ ...ctx, obstacles: [obstacle] },
|
|
191
|
+
).points;
|
|
192
|
+
|
|
193
|
+
expect(points[0]).toEqual({ x: 100, y: 20 });
|
|
194
|
+
expect(points.at(-1)).toEqual({ x: 300, y: 20 });
|
|
195
|
+
expect(allSegmentsOrthogonal(points)).toBe(true);
|
|
196
|
+
expect(pathIntersectsAny(points, [obstacle])).toBe(false);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('avoids inflated obstacle interiors across seeded fixtures', () => {
|
|
200
|
+
const random = seededRandom(13);
|
|
201
|
+
const router = configureAvoidRouter({ margin: 6 });
|
|
202
|
+
|
|
203
|
+
for (let i = 0; i < 50; i++) {
|
|
204
|
+
const obstacles = Array.from({ length: 6 }, () => ({
|
|
205
|
+
x: 130 + Math.round(random() * 260),
|
|
206
|
+
y: -110 + Math.round(random() * 220),
|
|
207
|
+
width: 32 + Math.round(random() * 56),
|
|
208
|
+
height: 28 + Math.round(random() * 64),
|
|
209
|
+
}));
|
|
210
|
+
const result = router(
|
|
211
|
+
edge,
|
|
212
|
+
{
|
|
213
|
+
...ctx,
|
|
214
|
+
sourceBounds: { x: 0, y: i * 3, width: 100, height: 40 },
|
|
215
|
+
targetBounds: { x: 500, y: 80 - i * 2, width: 100, height: 40 },
|
|
216
|
+
sourcePoint: { x: 100, y: 20 + i * 3 },
|
|
217
|
+
targetPoint: { x: 500, y: 100 - i * 2 },
|
|
218
|
+
obstacles,
|
|
219
|
+
},
|
|
220
|
+
).points;
|
|
221
|
+
|
|
222
|
+
expect(allSegmentsOrthogonal(result)).toBe(true);
|
|
223
|
+
expect(pathIntersectsAny(result, obstacles.map((obstacle) => inflateRect(obstacle, 6)))).toBe(false);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('routes through a dense obstacle grid without cutting across nodes', () => {
|
|
228
|
+
// Mirrors the AvoidRouter DenseGraph story: an 18-node grid the edge must
|
|
229
|
+
// thread. Pre-fix, dense grids bailed to a non-avoiding fallback that cut
|
|
230
|
+
// straight through obstacle interiors.
|
|
231
|
+
const margin = 12;
|
|
232
|
+
const obstacles = Array.from({ length: 18 }, (_, index) => {
|
|
233
|
+
const column = index % 6;
|
|
234
|
+
const row = Math.floor(index / 6);
|
|
235
|
+
return {
|
|
236
|
+
x: 220 + column * 112 + (row % 2) * 32,
|
|
237
|
+
y: 110 + row * 112,
|
|
238
|
+
width: 82,
|
|
239
|
+
height: 52,
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const result = configureAvoidRouter({ margin })(
|
|
244
|
+
createEdge({ id: 'dense', sourceId: 'source', targetId: 'target' }),
|
|
245
|
+
{
|
|
246
|
+
...ctx,
|
|
247
|
+
sourceBounds: { x: 56, y: 212, width: 130, height: 60 },
|
|
248
|
+
targetBounds: { x: 940, y: 212, width: 130, height: 60 },
|
|
249
|
+
sourcePoint: { x: 186, y: 242 },
|
|
250
|
+
targetPoint: { x: 940, y: 242 },
|
|
251
|
+
waypoints: [{ x: 540, y: 56 }],
|
|
252
|
+
obstacles,
|
|
253
|
+
},
|
|
254
|
+
).points;
|
|
255
|
+
|
|
256
|
+
const inflated = obstacles.map((obstacle) => inflateRect(obstacle, margin));
|
|
257
|
+
|
|
258
|
+
// (a) every segment is orthogonal (no diagonal cutting across nodes)
|
|
259
|
+
expect(allSegmentsOrthogonal(result)).toBe(true);
|
|
260
|
+
// (b) no segment crosses any inflated-obstacle interior
|
|
261
|
+
expect(pathIntersectsAny(result, inflated)).toBe(false);
|
|
262
|
+
// (c) it actually routed around the field rather than emitting the
|
|
263
|
+
// 3-point straight/step fallback through the middle.
|
|
264
|
+
expect(result.length).toBeGreaterThan(3);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('routes a dense grid with no clear straight lane (worst case)', () => {
|
|
268
|
+
// Source and target are level with the middle of the grid, so a naive
|
|
269
|
+
// straight line runs directly through the obstacle rows. A* must weave.
|
|
270
|
+
const margin = 10;
|
|
271
|
+
const obstacles = Array.from({ length: 15 }, (_, index) => {
|
|
272
|
+
const column = index % 5;
|
|
273
|
+
const row = Math.floor(index / 5);
|
|
274
|
+
return {
|
|
275
|
+
x: 200 + column * 120,
|
|
276
|
+
y: 40 + row * 90,
|
|
277
|
+
width: 70,
|
|
278
|
+
height: 46,
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const result = configureAvoidRouter({ margin })(
|
|
283
|
+
createEdge({ id: 'dense', sourceId: 'source', targetId: 'target' }),
|
|
284
|
+
{
|
|
285
|
+
...ctx,
|
|
286
|
+
sourceDirection: 'right',
|
|
287
|
+
targetDirection: 'left',
|
|
288
|
+
sourcePoint: { x: 60, y: 130 },
|
|
289
|
+
targetPoint: { x: 900, y: 130 },
|
|
290
|
+
obstacles,
|
|
291
|
+
},
|
|
292
|
+
).points;
|
|
293
|
+
|
|
294
|
+
const inflated = obstacles.map((obstacle) => inflateRect(obstacle, margin));
|
|
295
|
+
|
|
296
|
+
expect(allSegmentsOrthogonal(result)).toBe(true);
|
|
297
|
+
expect(pathIntersectsAny(result, inflated)).toBe(false);
|
|
298
|
+
// Did not fall back to the straight 2-point / 3-point path through the grid.
|
|
299
|
+
expect(result.length).toBeGreaterThan(3);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
function allSegmentsOrthogonal(points: { x: number; y: number }[]): boolean {
|
|
304
|
+
return points.slice(1).every((point, index) => {
|
|
305
|
+
const previous = points[index];
|
|
306
|
+
return previous.x === point.x || previous.y === point.y;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function pathIntersectsAny(
|
|
311
|
+
points: { x: number; y: number }[],
|
|
312
|
+
obstacles: Rect[],
|
|
313
|
+
): boolean {
|
|
314
|
+
for (let i = 1; i < points.length; i++) {
|
|
315
|
+
if (obstacles.some((rect) => segmentIntersectsInterior(points[i - 1], points[i], rect))) {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function segmentIntersectsInterior(
|
|
323
|
+
a: { x: number; y: number },
|
|
324
|
+
b: { x: number; y: number },
|
|
325
|
+
rect: Rect,
|
|
326
|
+
): boolean {
|
|
327
|
+
if (a.y === b.y) {
|
|
328
|
+
return (
|
|
329
|
+
a.y > rect.y &&
|
|
330
|
+
a.y < rect.y + rect.height &&
|
|
331
|
+
Math.min(a.x, b.x) < rect.x + rect.width &&
|
|
332
|
+
Math.max(a.x, b.x) > rect.x
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
if (a.x === b.x) {
|
|
336
|
+
return (
|
|
337
|
+
a.x > rect.x &&
|
|
338
|
+
a.x < rect.x + rect.width &&
|
|
339
|
+
Math.min(a.y, b.y) < rect.y + rect.height &&
|
|
340
|
+
Math.max(a.y, b.y) > rect.y
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function inflateRect(rect: Rect, margin: number): Rect {
|
|
347
|
+
return {
|
|
348
|
+
x: rect.x - margin,
|
|
349
|
+
y: rect.y - margin,
|
|
350
|
+
width: rect.width + margin * 2,
|
|
351
|
+
height: rect.height + margin * 2,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function seededRandom(seed: number): () => number {
|
|
356
|
+
let value = seed;
|
|
357
|
+
return () => {
|
|
358
|
+
value = (value * 16807) % 2147483647;
|
|
359
|
+
return (value - 1) / 2147483646;
|
|
360
|
+
};
|
|
361
|
+
}
|