@woosh/meep-engine 2.76.4 → 2.78.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 (28) hide show
  1. package/build/meep.cjs +236 -616
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +236 -616
  4. package/editor/view/ecs/components/TerrainController.js +9 -16
  5. package/package.json +1 -1
  6. package/src/core/collection/heap/Uint32Heap.js +10 -1
  7. package/src/core/graph/Edge.js +20 -0
  8. package/src/core/graph/SquareMatrix.js +4 -2
  9. package/src/core/graph/WeightedEdge.js +5 -9
  10. package/src/core/graph/coloring/colorizeGraphGreedy.spec.js +1 -1
  11. package/src/core/graph/coloring/validateGraphColoring.js +1 -1
  12. package/src/core/graph/eigen/matrix_eigenvalues_in_place.js +21 -0
  13. package/src/core/graph/eigen/{eigen.spec.js → matrix_eigenvalues_in_place.spec.js} +2 -2
  14. package/src/core/graph/eigen/matrix_householder_in_place.js +92 -0
  15. package/src/core/graph/eigen/{eigen.js → matrix_qr_in_place.js} +2 -113
  16. package/src/core/graph/layout/CircleLayout.js +6 -11
  17. package/src/core/graph/v2/Graph.js +39 -9
  18. package/src/core/graph/v2/NodeContainer.js +136 -22
  19. package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +8 -6
  20. package/src/engine/graphics/particles/node-based/codegen/modules/FunctionModuleRegistry.js +1 -1
  21. package/src/engine/navigation/grid/find_path_on_grid_astar.js +25 -22
  22. package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +2 -2
  23. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +17 -33
  24. package/src/core/graph/Graph.js +0 -564
  25. package/src/core/graph/GraphUtils.js +0 -284
  26. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +0 -464
  27. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizer.js +0 -622
  28. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +0 -383
@@ -1,564 +0,0 @@
1
- /**
2
- * Created by Alex on 29/01/14.
3
- */
4
-
5
-
6
- import Signal from "../events/signal/Signal.js";
7
- import { Edge, EdgeDirectionType } from "./Edge.js";
8
-
9
- /**
10
- * @callback Graph~visitor
11
- * @param {*} node
12
- * @param {Edge} edge
13
- * @returns {boolean|undefined} if false is returned, traversal should stop
14
- */
15
-
16
- /**
17
- * @template N
18
- */
19
- export class Graph {
20
- /**
21
- * @template N
22
- * @constructor
23
- */
24
- constructor() {
25
- /**
26
- * @private
27
- * @type {N[]}
28
- */
29
- this.__nodes = [];
30
-
31
- /**
32
- * Accelerated data structure for faster lookups
33
- * @type {Set<any>}
34
- * @private
35
- */
36
- this.__nodes_set = new Set();
37
-
38
- /**
39
- * @private
40
- * @type {Edge<N>[]}
41
- */
42
- this.__edges = [];
43
- this.onChange = new Signal();
44
- }
45
-
46
- /**
47
- *
48
- * @returns {N[]}
49
- */
50
- get nodes() {
51
- return this.__nodes;
52
- }
53
-
54
- /**
55
- *
56
- * @returns {Edge<N>[]}
57
- */
58
- get edges() {
59
- return this.__edges;
60
- }
61
-
62
- /**
63
- * Converts this graph into a shallow copy of supplied graph
64
- * @param {Graph<N>} other
65
- */
66
- copy(other) {
67
- this.clear();
68
-
69
- this.__nodes = other.__nodes.slice();
70
- this.__edges = other.__edges.slice();
71
-
72
- this.__nodes_set = new Set(this.__nodes);
73
- }
74
-
75
- /**
76
- *
77
- * @param {N} start
78
- * @param {N} goal
79
- * @returns {Array<N>|null} nodes from start to goal in the shortest path including both start and goal.
80
- */
81
- findPath(start, goal) {
82
- const open = new Set();
83
- open.add(start);
84
-
85
- const closed = new Set();
86
-
87
- const cameFrom = new Map();
88
-
89
- function constructPath() {
90
- const result = [];
91
- let c = goal;
92
- do {
93
- result.unshift(c);
94
- c = cameFrom.get(c);
95
- } while (c !== undefined);
96
-
97
- return result;
98
- }
99
-
100
- const graph = this;
101
-
102
- function expandNode(current) {
103
- graph.traverseSuccessors(current, function (node, edge) {
104
- if (closed.has(node)) {
105
- return;
106
- }
107
- if (open.has(node)) {
108
- return;
109
- }
110
- open.add(node);
111
- cameFrom.set(node, current);
112
- });
113
- }
114
-
115
- while (open.size > 0) {
116
- const current = open.values().next().value;
117
- if (current === goal) {
118
- //reached the goal
119
- return constructPath();
120
- }
121
- open.delete(current);
122
- closed.add(current);
123
-
124
- //expand node
125
- expandNode(current);
126
- }
127
-
128
- //no path found
129
- return null;
130
- }
131
-
132
- /**
133
- * Returns true if there is an edge between two given nodes on this graph
134
- * @param {N} node1
135
- * @param {N} node2
136
- * @returns {boolean}
137
- */
138
- isEdgeBetween(node1, node2) {
139
- if (!this.containsNode(node1) || !this.containsNode(node2)) {
140
- return false; // one or both nodes are not part of the graph
141
- }
142
- const connectingEdge = this.findConnectingEdge(node1, node2);
143
- return connectingEdge !== null;
144
- }
145
-
146
- /**
147
- * Strictly traversable edge exists from source to target
148
- * @param {N} source
149
- * @param {N} target
150
- * @returns {boolean}
151
- */
152
- edgeExists(source, target) {
153
- if (!this.containsNode(source) || !this.containsNode(target)) {
154
- return false; // one or both nodes are not part of the graph
155
- }
156
-
157
- return this.traversePredecessors(source, function (destination) {
158
- if (destination === target) {
159
- //terminate traversal, this will make "traversePredecessors" return true also
160
- return false;
161
- }
162
- });
163
- }
164
-
165
- /**
166
- *
167
- * @param {function(node:N):boolean} visitor
168
- * @param {*} [thisArg]
169
- */
170
- traverseNodes(visitor, thisArg) {
171
- const nodes = this.__nodes;
172
- const l = nodes.length;
173
- for (let i = 0; i < l; i++) {
174
- const node = nodes[i];
175
- if (visitor.call(thisArg, node) === false) {
176
- return;
177
- }
178
- }
179
- }
180
-
181
- /**
182
- *
183
- * @param {N} node
184
- * @param {function(node:N, edge:Edge<N>):(boolean|void)} visitor
185
- */
186
- traverseSuccessors(node, visitor) {
187
- const edges = this.__edges;
188
- let i = 0;
189
- const l = edges.length;
190
-
191
- for (; i < l; i++) {
192
- const edge = edges[i];
193
- const first = edge.first;
194
- const second = edge.second;
195
-
196
- if (first === node && edge.traversableForward()) {
197
- if (visitor(second, edge) === false) {
198
- //terminate traversal if visitor returns false
199
- return;
200
- }
201
- } else if (second === node && edge.traversableBackward()) {
202
- if (visitor(first, edge) === false) {
203
- //terminate traversal if visitor returns false
204
- return;
205
- }
206
- }
207
- }
208
-
209
- }
210
-
211
- /**
212
- *
213
- * @param {function(edge:Edge<N>):boolean} visitor
214
- */
215
- traverseEdges(visitor) {
216
- const edges = this.__edges;
217
- let i = 0;
218
- const l = edges.length;
219
- for (; i < l; i++) {
220
- const edge = edges[i];
221
- if (visitor(edge) === false) {
222
- //terminate traversal if visitor returns false
223
- return;
224
- }
225
- }
226
- }
227
-
228
- /**
229
- *
230
- * @param {N} node
231
- * @param {function(N,Edge<N>)} visitor
232
- */
233
- traversePredecessors(node, visitor) {
234
- const edges = this.__edges;
235
- let i = 0;
236
- const l = edges.length;
237
- for (; i < l; i++) {
238
- const edge = edges[i];
239
- const first = edge.first;
240
- const second = edge.second;
241
-
242
- if (second === node && edge.traversableForward()) {
243
- if (visitor(first, edge) === false) {
244
- //terminate traversal if visitor returns false
245
- return true;
246
- }
247
- } else if (first === node && edge.traversableBackward()) {
248
- if (visitor(second, edge) === false) {
249
- //terminate traversal if visitor returns false
250
- return true;
251
- }
252
- }
253
- }
254
- return false;
255
- }
256
-
257
- /**
258
- *
259
- * @param {N} node
260
- * @param {function(N,Edge):(boolean|void)} visitor
261
- */
262
- traverseAttachedEdges(node, visitor) {
263
- const edges = this.__edges;
264
- let i = 0;
265
- const l = edges.length;
266
- for (; i < l; i++) {
267
- const edge = edges[i];
268
- const first = edge.first;
269
- const second = edge.second;
270
-
271
- if (first === node) {
272
- if (visitor(second, edge) === false) {
273
- //terminate traversal if visitor returns false
274
- return;
275
- }
276
- } else if (second === node) {
277
- if (visitor(first, edge) === false) {
278
- //terminate traversal if visitor returns false
279
- return;
280
- }
281
- }
282
- }
283
- }
284
-
285
- /**
286
- *
287
- * @param {N} source
288
- * @param {N} target
289
- * @return {Edge<N>|null}
290
- */
291
- findTraversableEdge(source, target) {
292
-
293
- const edges = this.__edges;
294
-
295
- const numEdges = edges.length;
296
-
297
- for (let i = 0; i < numEdges; i++) {
298
-
299
- /**
300
- *
301
- * @type {Edge<N>}
302
- */
303
- const edge = edges[i];
304
-
305
- if (
306
- (edge.first === source && edge.second === target && edge.direction !== EdgeDirectionType.Backward)
307
- || (edge.second === source && edge.first === target && edge.direction !== EdgeDirectionType.Forward)
308
- ) {
309
- return edge;
310
- }
311
- }
312
-
313
- return null;
314
- }
315
-
316
- /**
317
- *
318
- * @param {N} node1
319
- * @param {N} node2
320
- * @returns {Edge<N>|null}
321
- */
322
- findConnectingEdge(node1, node2) {
323
- const edges = this.__edges;
324
-
325
- const numEdges = edges.length;
326
-
327
- for (let i = 0; i < numEdges; i++) {
328
-
329
- const edge = edges[i];
330
-
331
- if (edge.contains(node1) && edge.contains(node2)) {
332
- return edge;
333
- }
334
-
335
- }
336
-
337
- return null;
338
- }
339
-
340
- /**
341
- *
342
- * @param {N} source
343
- * @param {N} target
344
- * @param {function(Edge<N>):boolean} visitor
345
- */
346
- findTraversableEdges(source, target, visitor) {
347
- const edges = this.__edges;
348
- for (let i = 0; i < edges.length; i++) {
349
- const edge = edges[i];
350
- if (edge.validateTransition(source, target)) {
351
-
352
- if (visitor(edge) === false) {
353
- return;
354
- }
355
- }
356
- }
357
- }
358
-
359
- /**
360
- *
361
- * @param {N} node
362
- * @returns {Edge<N>[]}
363
- */
364
- getAttachedEdges(node) {
365
- let i = 0;
366
-
367
- const result = [];
368
-
369
- const edges = this.__edges;
370
- const l = edges.length;
371
-
372
- for (; i < l; i++) {
373
- const edge = edges[i];
374
-
375
- if (edge.contains(node)) {
376
- result.push(edge);
377
- }
378
- }
379
-
380
- return result;
381
- }
382
-
383
- /**
384
- *
385
- * @param {N} node
386
- * @returns {N[]}
387
- */
388
- getNeighbours(node) {
389
- const result = [];
390
-
391
- const edges = this.edges;
392
- const nEdges = edges.length;
393
-
394
- for (let i = 0; i < nEdges; i++) {
395
- const edge = edges[i];
396
-
397
- const first = edge.first;
398
- const second = edge.second;
399
-
400
- if (first === node && (edge.direction === EdgeDirectionType.Forward || edge.direction === EdgeDirectionType.Undirected)) {
401
- if (result.indexOf(second) === -1) {
402
- result.push(second);
403
- }
404
- } else if (second === node && (edge.direction === EdgeDirectionType.Backward || edge.direction === EdgeDirectionType.Undirected)) {
405
- if (result.indexOf(first) === -1) {
406
- result.push(first);
407
- }
408
- }
409
-
410
- }
411
-
412
- return result;
413
- }
414
-
415
- /**
416
- *
417
- * @param {N} node
418
- * @returns {boolean}
419
- */
420
- containsNode(node) {
421
- return this.__nodes_set.has(node);
422
- }
423
-
424
- /**
425
- * @deprecated
426
- * @returns {number}
427
- */
428
- length() {
429
- const edges = this.__edges;
430
- let result = 0;
431
- for (let i = 0; i < edges.length; i++) {
432
- const edge = edges[i];
433
- result += edge.length;
434
- }
435
- return result;
436
- }
437
-
438
- /**
439
- *
440
- * @param {N} node
441
- */
442
- addNode(node) {
443
-
444
- this.__nodes_set.add(node);
445
-
446
- this.__nodes.push(node);
447
- }
448
-
449
- /**
450
- *
451
- * @param {N} node
452
- * @returns {boolean}
453
- */
454
- removeNode(node) {
455
- if (!this.containsNode(node)) {
456
- return false;
457
- }
458
-
459
- const i = this.__nodes.indexOf(node);
460
-
461
- if (i === -1) {
462
- // this should never happen
463
- return false;
464
- } else {
465
- //remove attached connections
466
- const attachedEdges = this.getAttachedEdges(node);
467
-
468
- const n = attachedEdges.length;
469
-
470
- for (let j = 0; j < n; j++) {
471
- const edge = attachedEdges[j];
472
-
473
- this.removeEdge(edge);
474
- }
475
-
476
- this.__nodes.splice(i, 1);
477
- this.__nodes_set.delete(node);
478
-
479
- return true;
480
- }
481
- }
482
-
483
- /**
484
- * Whether or not the graph contains given node
485
- * NOTE: same as {@link #containsNode}
486
- * @param {N} node
487
- * @returns {boolean}
488
- */
489
- hasNode(node) {
490
- return this.containsNode(node);
491
- }
492
-
493
- /**
494
- *
495
- * @param {Edge<N>} edge
496
- */
497
- addEdge(edge) {
498
- //assert.ok(this.containsNode(edge.first), `Node Edge.first(=${edge.first}) is not present in the graph`);
499
- //assert.ok(this.containsNode(edge.second), `Node Edge.second(=${edge.second}) is not present in the graph`);
500
-
501
- this.__edges.push(edge);
502
- this.onChange.send1(edge);
503
- }
504
-
505
- /**
506
- *
507
- * @param {N} source
508
- * @param {N} target
509
- * @param {EdgeDirectionType} [direction]
510
- * @returns {Edge<N>}
511
- */
512
- createEdge(source, target, direction = EdgeDirectionType.Undirected) {
513
- const edge = new Edge(source, target);
514
-
515
- edge.direction = direction;
516
-
517
- this.addEdge(edge);
518
-
519
- return edge;
520
- }
521
-
522
- /**
523
- *
524
- * @param {Edge<N>} edge
525
- * @returns {boolean}
526
- */
527
- removeEdge(edge) {
528
- const edges = this.__edges;
529
- const indexOf = edges.indexOf(edge);
530
- if (indexOf >= 0) {
531
- edges.splice(indexOf, 1);
532
- this.onChange.send1(edge);
533
-
534
- return true;
535
- } else {
536
- console.error("Edge was not found");
537
-
538
- return false;
539
- }
540
- }
541
-
542
- clear() {
543
- this.__edges = [];
544
- this.__nodes = [];
545
- this.__nodes_set.clear();
546
-
547
- this.onChange.send0();
548
- }
549
-
550
- /**
551
- *
552
- * @returns {Graph<N>}
553
- */
554
- clone() {
555
- const graph = new Graph();
556
-
557
- graph.copy(this);
558
-
559
- return graph;
560
- }
561
- }
562
-
563
-
564
- export default Graph;