@woosh/meep-engine 2.76.4 → 2.77.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 (26) hide show
  1. package/build/meep.cjs +197 -616
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +197 -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/Graph.js +1 -0
  9. package/src/core/graph/SquareMatrix.js +4 -2
  10. package/src/core/graph/WeightedEdge.js +5 -9
  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/v2/Graph.js +16 -9
  17. package/src/core/graph/v2/NodeContainer.js +120 -22
  18. package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +8 -6
  19. package/src/engine/graphics/particles/node-based/codegen/modules/FunctionModuleRegistry.js +1 -1
  20. package/src/engine/navigation/grid/find_path_on_grid_astar.js +25 -22
  21. package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +2 -2
  22. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +17 -33
  23. package/src/core/graph/GraphUtils.js +0 -284
  24. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +0 -464
  25. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizer.js +0 -622
  26. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +0 -383
@@ -70614,6 +70614,26 @@ class Edge {
70614
70614
  return (this.direction & EdgeDirectionType.Backward) !== 0;
70615
70615
  }
70616
70616
 
70617
+ /**
70618
+ * Checks direction of the edge, if the edge is directed towards supplied node - returns true, false otherwise
70619
+ * @param {N} node
70620
+ * @returns {boolean}
70621
+ */
70622
+ isDirectedTowards(node) {
70623
+ return (this.first === node && this.direction === EdgeDirectionType.Backward)
70624
+ || (this.second === node && this.direction === EdgeDirectionType.Forward);
70625
+ }
70626
+
70627
+ /**
70628
+ * Checks direction of the edge, if the edge is directed away from the supplied node - returns true, false otherwise
70629
+ * @param {N} node
70630
+ * @returns {boolean}
70631
+ */
70632
+ isDirectedAwayFrom(node) {
70633
+ return (this.first === node && this.direction === EdgeDirectionType.Forward)
70634
+ || (this.second === node && this.direction === EdgeDirectionType.Backward)
70635
+ }
70636
+
70617
70637
  /**
70618
70638
  * @deprecated
70619
70639
  * @returns {number}
@@ -70649,46 +70669,142 @@ class Edge {
70649
70669
  */
70650
70670
  Edge.prototype.isEdge = true;
70651
70671
 
70672
+ /**
70673
+ * Supplementary structure to `Graph`, holds edges and neighbour nodes for fast access
70674
+ * Used internally by `Graph`
70675
+ * @template N
70676
+ */
70652
70677
  class NodeContainer {
70653
70678
  /**
70654
- * @template N
70679
+ * Node being described
70680
+ * @type {N}
70655
70681
  */
70656
- constructor() {
70657
- /**
70658
- *
70659
- * @type {N}
70660
- */
70661
- this.node = null;
70682
+ node = null;
70662
70683
 
70684
+ /**
70685
+ * Attached edges
70686
+ * @type {Edge<N>[]}
70687
+ * @private
70688
+ */
70689
+ __edges = [];
70690
+
70691
+ /**
70692
+ *
70693
+ * @type {Map<N,number>}
70694
+ * @private
70695
+ */
70696
+ __neighbors = new Map();
70697
+
70698
+ /**
70699
+ *
70700
+ * @return {number}
70701
+ */
70702
+ getEdgeCount() {
70703
+ return this.__edges.length;
70704
+ }
70705
+
70706
+ /**
70707
+ * Do not modify the returned value
70708
+ * @return {Edge<N>[]}
70709
+ */
70710
+ getEdges() {
70711
+ return this.__edges;
70712
+ }
70713
+
70714
+ /**
70715
+ *
70716
+ * @returns {N[]}
70717
+ */
70718
+ get inNodes() {
70719
+ return this.inEdges.map(e => e.other(this.node));
70720
+ }
70721
+
70722
+ /**
70723
+ *
70724
+ * @returns {N[]}
70725
+ */
70726
+ get outNodes() {
70727
+ return this.outEdges.map(e => e.other(this.node));
70728
+ }
70729
+
70730
+
70731
+ get outEdges() {
70663
70732
  /**
70664
70733
  *
70665
70734
  * @type {Edge<N>[]}
70666
- * @private
70667
70735
  */
70668
- this.__edges = [];
70736
+ const result = [];
70737
+
70738
+ this.getOutgoingEdges(result);
70739
+
70740
+ return result;
70741
+ }
70669
70742
 
70743
+ get inEdges() {
70670
70744
  /**
70671
70745
  *
70672
- * @type {Map<N,number>}
70673
- * @private
70746
+ * @type {Edge<N>[]}
70674
70747
  */
70675
- this.__neighbors = new Map();
70748
+ const result = [];
70749
+
70750
+ this.getIncomingEdges(result);
70751
+
70752
+ return result;
70676
70753
  }
70677
70754
 
70755
+
70678
70756
  /**
70679
70757
  *
70680
- * @return {number}
70758
+ * @param {Edge<N>[]} result
70759
+ * @returns {number}
70681
70760
  */
70682
- getEdgeCount() {
70683
- return this.__edges.length;
70761
+ getIncomingEdges(result) {
70762
+ const edges = this.__edges;
70763
+
70764
+ const edge_count = edges.length;
70765
+
70766
+ let result_count = 0;
70767
+
70768
+ for (let i = 0; i < edge_count; i++) {
70769
+ const edge = edges[i];
70770
+
70771
+ if (edge.isDirectedTowards(this.node)) {
70772
+
70773
+ result.push(edge);
70774
+ result_count++;
70775
+
70776
+ }
70777
+
70778
+ }
70779
+
70780
+ return result_count;
70684
70781
  }
70685
70782
 
70686
70783
  /**
70687
- * Do not modify the returned value
70688
- * @return {Edge<N>[]}
70784
+ *
70785
+ * @param {Edge<N>[]} result
70786
+ * @returns {number}
70689
70787
  */
70690
- getEdges() {
70691
- return this.__edges;
70788
+ getOutgoingEdges(result) {
70789
+ const edges = this.__edges;
70790
+
70791
+ const edge_count = edges.length;
70792
+
70793
+ let result_count = 0;
70794
+
70795
+ for (let i = 0; i < edge_count; i++) {
70796
+ const edge = edges[i];
70797
+
70798
+ if (edge.isDirectedAwayFrom(this.node)) {
70799
+
70800
+ result.push(edge);
70801
+ result_count++;
70802
+
70803
+ }
70804
+
70805
+ }
70806
+
70807
+ return result_count;
70692
70808
  }
70693
70809
 
70694
70810
  /**
@@ -70701,12 +70817,14 @@ class NodeContainer {
70701
70817
  const edges = this.__edges;
70702
70818
  const edge_count = edges.length;
70703
70819
 
70820
+ const current_node = this.node;
70821
+
70704
70822
  for (let i = 0; i < edge_count; i++) {
70705
70823
  const edge = edges[i];
70706
70824
 
70707
70825
  if (
70708
- (edge.first === this.node && edge.direction === EdgeDirectionType.Forward)
70709
- || (edge.second === this.node && edge.direction === EdgeDirectionType.Backward)
70826
+ (edge.first === current_node && edge.direction === EdgeDirectionType.Forward)
70827
+ || (edge.second === current_node && edge.direction === EdgeDirectionType.Backward)
70710
70828
 
70711
70829
  ) {
70712
70830
  r++;
@@ -70730,7 +70848,7 @@ class NodeContainer {
70730
70848
 
70731
70849
  /**
70732
70850
  *
70733
- * @param {function(Edge)} visitor
70851
+ * @param {function(Edge<N>)} visitor
70734
70852
  * @param {*} [thisArg]
70735
70853
  * @returns {number}
70736
70854
  */
@@ -70862,17 +70980,20 @@ class NodeContainer {
70862
70980
  }
70863
70981
 
70864
70982
  /**
70983
+ * Reconstruct path from search metadata
70865
70984
  * @template T
70866
70985
  * @param {NodeContainer<T>} goal_node_container
70867
- * @param {Map<NodeContainer<T>,NodeContainer<T>>} cameFrom
70868
- * @returns {T[]}
70986
+ * @param {Map<NodeContainer<T>,NodeContainer<T>>} came_from
70987
+ * @returns {T[]} Nodes comprising the path from start to goal
70869
70988
  */
70870
- function construct_path(goal_node_container, cameFrom) {
70989
+ function construct_path(goal_node_container, came_from) {
70871
70990
  const result = [];
70991
+
70872
70992
  let c = goal_node_container;
70993
+
70873
70994
  do {
70874
70995
  result.unshift(c.node);
70875
- c = cameFrom.get(c);
70996
+ c = came_from.get(c);
70876
70997
  } while (c !== undefined);
70877
70998
 
70878
70999
  return result;
@@ -70881,21 +71002,26 @@ function construct_path(goal_node_container, cameFrom) {
70881
71002
  /**
70882
71003
  * @template N
70883
71004
  */
70884
- let Graph$1 = class Graph {
71005
+ class Graph {
70885
71006
 
70886
71007
  /**
70887
71008
  *
70888
71009
  * @type {Map<N, NodeContainer<N>>}
71010
+ * @readonly
70889
71011
  * @private
70890
71012
  */
70891
71013
  __nodes = new Map();
70892
71014
  /**
70893
71015
  *
70894
71016
  * @type {Set<Edge<N>>}
71017
+ * @readonly
70895
71018
  * @private
70896
71019
  */
70897
71020
  __edges = new Set();
70898
71021
 
71022
+ /**
71023
+ * @readonly
71024
+ */
70899
71025
  on = {
70900
71026
  /**
70901
71027
  * @type {Signal<N,this>}
@@ -71049,10 +71175,10 @@ let Graph$1 = class Graph {
71049
71175
  *
71050
71176
  * @param {N} source
71051
71177
  * @param {N} target
71052
- * @param {EdgeDirectionType} type
71178
+ * @param {EdgeDirectionType} [type] Undirected by default
71053
71179
  * @returns {Edge<N>}
71054
71180
  */
71055
- createEdge(source, target, type) {
71181
+ createEdge(source, target, type = EdgeDirectionType.Undirected) {
71056
71182
  const edge = new Edge(source, target);
71057
71183
 
71058
71184
  edge.direction = type;
@@ -71228,8 +71354,7 @@ let Graph$1 = class Graph {
71228
71354
  const edge_count = edges.length;
71229
71355
 
71230
71356
  for (let i = 0; i < edge_count; i++) {
71231
- const edge = edges[i];
71232
- result[i] = edge;
71357
+ result[i] = edges[i];
71233
71358
  }
71234
71359
 
71235
71360
  return edge_count;
@@ -71350,7 +71475,7 @@ let Graph$1 = class Graph {
71350
71475
 
71351
71476
  return r;
71352
71477
  }
71353
- };
71478
+ }
71354
71479
 
71355
71480
  /**
71356
71481
  *
@@ -71359,7 +71484,7 @@ let Graph$1 = class Graph {
71359
71484
  * @return {Graph}
71360
71485
  */
71361
71486
  function computeSystemComponentDependencyGraph(system_count, systems) {
71362
- const dependency_graph = new Graph$1();
71487
+ const dependency_graph = new Graph();
71363
71488
 
71364
71489
  for (let i = 0; i < system_count; i++) {
71365
71490
  const system = systems[i];
@@ -86095,564 +86220,6 @@ class PeriodicConsolePrinter {
86095
86220
  }
86096
86221
  }
86097
86222
 
86098
- /**
86099
- * Created by Alex on 29/01/14.
86100
- */
86101
-
86102
-
86103
- /**
86104
- * @callback Graph~visitor
86105
- * @param {*} node
86106
- * @param {Edge} edge
86107
- * @returns {boolean|undefined} if false is returned, traversal should stop
86108
- */
86109
-
86110
- /**
86111
- * @template N
86112
- */
86113
- class Graph {
86114
- /**
86115
- * @template N
86116
- * @constructor
86117
- */
86118
- constructor() {
86119
- /**
86120
- * @private
86121
- * @type {N[]}
86122
- */
86123
- this.__nodes = [];
86124
-
86125
- /**
86126
- * Accelerated data structure for faster lookups
86127
- * @type {Set<any>}
86128
- * @private
86129
- */
86130
- this.__nodes_set = new Set();
86131
-
86132
- /**
86133
- * @private
86134
- * @type {Edge<N>[]}
86135
- */
86136
- this.__edges = [];
86137
- this.onChange = new Signal();
86138
- }
86139
-
86140
- /**
86141
- *
86142
- * @returns {N[]}
86143
- */
86144
- get nodes() {
86145
- return this.__nodes;
86146
- }
86147
-
86148
- /**
86149
- *
86150
- * @returns {Edge<N>[]}
86151
- */
86152
- get edges() {
86153
- return this.__edges;
86154
- }
86155
-
86156
- /**
86157
- * Converts this graph into a shallow copy of supplied graph
86158
- * @param {Graph<N>} other
86159
- */
86160
- copy(other) {
86161
- this.clear();
86162
-
86163
- this.__nodes = other.__nodes.slice();
86164
- this.__edges = other.__edges.slice();
86165
-
86166
- this.__nodes_set = new Set(this.__nodes);
86167
- }
86168
-
86169
- /**
86170
- *
86171
- * @param {N} start
86172
- * @param {N} goal
86173
- * @returns {Array<N>|null} nodes from start to goal in the shortest path including both start and goal.
86174
- */
86175
- findPath(start, goal) {
86176
- const open = new Set();
86177
- open.add(start);
86178
-
86179
- const closed = new Set();
86180
-
86181
- const cameFrom = new Map();
86182
-
86183
- function constructPath() {
86184
- const result = [];
86185
- let c = goal;
86186
- do {
86187
- result.unshift(c);
86188
- c = cameFrom.get(c);
86189
- } while (c !== undefined);
86190
-
86191
- return result;
86192
- }
86193
-
86194
- const graph = this;
86195
-
86196
- function expandNode(current) {
86197
- graph.traverseSuccessors(current, function (node, edge) {
86198
- if (closed.has(node)) {
86199
- return;
86200
- }
86201
- if (open.has(node)) {
86202
- return;
86203
- }
86204
- open.add(node);
86205
- cameFrom.set(node, current);
86206
- });
86207
- }
86208
-
86209
- while (open.size > 0) {
86210
- const current = open.values().next().value;
86211
- if (current === goal) {
86212
- //reached the goal
86213
- return constructPath();
86214
- }
86215
- open.delete(current);
86216
- closed.add(current);
86217
-
86218
- //expand node
86219
- expandNode(current);
86220
- }
86221
-
86222
- //no path found
86223
- return null;
86224
- }
86225
-
86226
- /**
86227
- * Returns true if there is an edge between two given nodes on this graph
86228
- * @param {N} node1
86229
- * @param {N} node2
86230
- * @returns {boolean}
86231
- */
86232
- isEdgeBetween(node1, node2) {
86233
- if (!this.containsNode(node1) || !this.containsNode(node2)) {
86234
- return false; // one or both nodes are not part of the graph
86235
- }
86236
- const connectingEdge = this.findConnectingEdge(node1, node2);
86237
- return connectingEdge !== null;
86238
- }
86239
-
86240
- /**
86241
- * Strictly traversable edge exists from source to target
86242
- * @param {N} source
86243
- * @param {N} target
86244
- * @returns {boolean}
86245
- */
86246
- edgeExists(source, target) {
86247
- if (!this.containsNode(source) || !this.containsNode(target)) {
86248
- return false; // one or both nodes are not part of the graph
86249
- }
86250
-
86251
- return this.traversePredecessors(source, function (destination) {
86252
- if (destination === target) {
86253
- //terminate traversal, this will make "traversePredecessors" return true also
86254
- return false;
86255
- }
86256
- });
86257
- }
86258
-
86259
- /**
86260
- *
86261
- * @param {function(node:N):boolean} visitor
86262
- * @param {*} [thisArg]
86263
- */
86264
- traverseNodes(visitor, thisArg) {
86265
- const nodes = this.__nodes;
86266
- const l = nodes.length;
86267
- for (let i = 0; i < l; i++) {
86268
- const node = nodes[i];
86269
- if (visitor.call(thisArg, node) === false) {
86270
- return;
86271
- }
86272
- }
86273
- }
86274
-
86275
- /**
86276
- *
86277
- * @param {N} node
86278
- * @param {function(node:N, edge:Edge<N>):(boolean|void)} visitor
86279
- */
86280
- traverseSuccessors(node, visitor) {
86281
- const edges = this.__edges;
86282
- let i = 0;
86283
- const l = edges.length;
86284
-
86285
- for (; i < l; i++) {
86286
- const edge = edges[i];
86287
- const first = edge.first;
86288
- const second = edge.second;
86289
-
86290
- if (first === node && edge.traversableForward()) {
86291
- if (visitor(second, edge) === false) {
86292
- //terminate traversal if visitor returns false
86293
- return;
86294
- }
86295
- } else if (second === node && edge.traversableBackward()) {
86296
- if (visitor(first, edge) === false) {
86297
- //terminate traversal if visitor returns false
86298
- return;
86299
- }
86300
- }
86301
- }
86302
-
86303
- }
86304
-
86305
- /**
86306
- *
86307
- * @param {function(edge:Edge<N>):boolean} visitor
86308
- */
86309
- traverseEdges(visitor) {
86310
- const edges = this.__edges;
86311
- let i = 0;
86312
- const l = edges.length;
86313
- for (; i < l; i++) {
86314
- const edge = edges[i];
86315
- if (visitor(edge) === false) {
86316
- //terminate traversal if visitor returns false
86317
- return;
86318
- }
86319
- }
86320
- }
86321
-
86322
- /**
86323
- *
86324
- * @param {N} node
86325
- * @param {function(N,Edge<N>)} visitor
86326
- */
86327
- traversePredecessors(node, visitor) {
86328
- const edges = this.__edges;
86329
- let i = 0;
86330
- const l = edges.length;
86331
- for (; i < l; i++) {
86332
- const edge = edges[i];
86333
- const first = edge.first;
86334
- const second = edge.second;
86335
-
86336
- if (second === node && edge.traversableForward()) {
86337
- if (visitor(first, edge) === false) {
86338
- //terminate traversal if visitor returns false
86339
- return true;
86340
- }
86341
- } else if (first === node && edge.traversableBackward()) {
86342
- if (visitor(second, edge) === false) {
86343
- //terminate traversal if visitor returns false
86344
- return true;
86345
- }
86346
- }
86347
- }
86348
- return false;
86349
- }
86350
-
86351
- /**
86352
- *
86353
- * @param {N} node
86354
- * @param {function(N,Edge):(boolean|void)} visitor
86355
- */
86356
- traverseAttachedEdges(node, visitor) {
86357
- const edges = this.__edges;
86358
- let i = 0;
86359
- const l = edges.length;
86360
- for (; i < l; i++) {
86361
- const edge = edges[i];
86362
- const first = edge.first;
86363
- const second = edge.second;
86364
-
86365
- if (first === node) {
86366
- if (visitor(second, edge) === false) {
86367
- //terminate traversal if visitor returns false
86368
- return;
86369
- }
86370
- } else if (second === node) {
86371
- if (visitor(first, edge) === false) {
86372
- //terminate traversal if visitor returns false
86373
- return;
86374
- }
86375
- }
86376
- }
86377
- }
86378
-
86379
- /**
86380
- *
86381
- * @param {N} source
86382
- * @param {N} target
86383
- * @return {Edge<N>|null}
86384
- */
86385
- findTraversableEdge(source, target) {
86386
-
86387
- const edges = this.__edges;
86388
-
86389
- const numEdges = edges.length;
86390
-
86391
- for (let i = 0; i < numEdges; i++) {
86392
-
86393
- /**
86394
- *
86395
- * @type {Edge<N>}
86396
- */
86397
- const edge = edges[i];
86398
-
86399
- if (
86400
- (edge.first === source && edge.second === target && edge.direction !== EdgeDirectionType.Backward)
86401
- || (edge.second === source && edge.first === target && edge.direction !== EdgeDirectionType.Forward)
86402
- ) {
86403
- return edge;
86404
- }
86405
- }
86406
-
86407
- return null;
86408
- }
86409
-
86410
- /**
86411
- *
86412
- * @param {N} node1
86413
- * @param {N} node2
86414
- * @returns {Edge<N>|null}
86415
- */
86416
- findConnectingEdge(node1, node2) {
86417
- const edges = this.__edges;
86418
-
86419
- const numEdges = edges.length;
86420
-
86421
- for (let i = 0; i < numEdges; i++) {
86422
-
86423
- const edge = edges[i];
86424
-
86425
- if (edge.contains(node1) && edge.contains(node2)) {
86426
- return edge;
86427
- }
86428
-
86429
- }
86430
-
86431
- return null;
86432
- }
86433
-
86434
- /**
86435
- *
86436
- * @param {N} source
86437
- * @param {N} target
86438
- * @param {function(Edge<N>):boolean} visitor
86439
- */
86440
- findTraversableEdges(source, target, visitor) {
86441
- const edges = this.__edges;
86442
- for (let i = 0; i < edges.length; i++) {
86443
- const edge = edges[i];
86444
- if (edge.validateTransition(source, target)) {
86445
-
86446
- if (visitor(edge) === false) {
86447
- return;
86448
- }
86449
- }
86450
- }
86451
- }
86452
-
86453
- /**
86454
- *
86455
- * @param {N} node
86456
- * @returns {Edge<N>[]}
86457
- */
86458
- getAttachedEdges(node) {
86459
- let i = 0;
86460
-
86461
- const result = [];
86462
-
86463
- const edges = this.__edges;
86464
- const l = edges.length;
86465
-
86466
- for (; i < l; i++) {
86467
- const edge = edges[i];
86468
-
86469
- if (edge.contains(node)) {
86470
- result.push(edge);
86471
- }
86472
- }
86473
-
86474
- return result;
86475
- }
86476
-
86477
- /**
86478
- *
86479
- * @param {N} node
86480
- * @returns {N[]}
86481
- */
86482
- getNeighbours(node) {
86483
- const result = [];
86484
-
86485
- const edges = this.edges;
86486
- const nEdges = edges.length;
86487
-
86488
- for (let i = 0; i < nEdges; i++) {
86489
- const edge = edges[i];
86490
-
86491
- const first = edge.first;
86492
- const second = edge.second;
86493
-
86494
- if (first === node && (edge.direction === EdgeDirectionType.Forward || edge.direction === EdgeDirectionType.Undirected)) {
86495
- if (result.indexOf(second) === -1) {
86496
- result.push(second);
86497
- }
86498
- } else if (second === node && (edge.direction === EdgeDirectionType.Backward || edge.direction === EdgeDirectionType.Undirected)) {
86499
- if (result.indexOf(first) === -1) {
86500
- result.push(first);
86501
- }
86502
- }
86503
-
86504
- }
86505
-
86506
- return result;
86507
- }
86508
-
86509
- /**
86510
- *
86511
- * @param {N} node
86512
- * @returns {boolean}
86513
- */
86514
- containsNode(node) {
86515
- return this.__nodes_set.has(node);
86516
- }
86517
-
86518
- /**
86519
- * @deprecated
86520
- * @returns {number}
86521
- */
86522
- length() {
86523
- const edges = this.__edges;
86524
- let result = 0;
86525
- for (let i = 0; i < edges.length; i++) {
86526
- const edge = edges[i];
86527
- result += edge.length;
86528
- }
86529
- return result;
86530
- }
86531
-
86532
- /**
86533
- *
86534
- * @param {N} node
86535
- */
86536
- addNode(node) {
86537
-
86538
- this.__nodes_set.add(node);
86539
-
86540
- this.__nodes.push(node);
86541
- }
86542
-
86543
- /**
86544
- *
86545
- * @param {N} node
86546
- * @returns {boolean}
86547
- */
86548
- removeNode(node) {
86549
- if (!this.containsNode(node)) {
86550
- return false;
86551
- }
86552
-
86553
- const i = this.__nodes.indexOf(node);
86554
-
86555
- if (i === -1) {
86556
- // this should never happen
86557
- return false;
86558
- } else {
86559
- //remove attached connections
86560
- const attachedEdges = this.getAttachedEdges(node);
86561
-
86562
- const n = attachedEdges.length;
86563
-
86564
- for (let j = 0; j < n; j++) {
86565
- const edge = attachedEdges[j];
86566
-
86567
- this.removeEdge(edge);
86568
- }
86569
-
86570
- this.__nodes.splice(i, 1);
86571
- this.__nodes_set.delete(node);
86572
-
86573
- return true;
86574
- }
86575
- }
86576
-
86577
- /**
86578
- * Whether or not the graph contains given node
86579
- * NOTE: same as {@link #containsNode}
86580
- * @param {N} node
86581
- * @returns {boolean}
86582
- */
86583
- hasNode(node) {
86584
- return this.containsNode(node);
86585
- }
86586
-
86587
- /**
86588
- *
86589
- * @param {Edge<N>} edge
86590
- */
86591
- addEdge(edge) {
86592
- //assert.ok(this.containsNode(edge.first), `Node Edge.first(=${edge.first}) is not present in the graph`);
86593
- //assert.ok(this.containsNode(edge.second), `Node Edge.second(=${edge.second}) is not present in the graph`);
86594
-
86595
- this.__edges.push(edge);
86596
- this.onChange.send1(edge);
86597
- }
86598
-
86599
- /**
86600
- *
86601
- * @param {N} source
86602
- * @param {N} target
86603
- * @param {EdgeDirectionType} [direction]
86604
- * @returns {Edge<N>}
86605
- */
86606
- createEdge(source, target, direction = EdgeDirectionType.Undirected) {
86607
- const edge = new Edge(source, target);
86608
-
86609
- edge.direction = direction;
86610
-
86611
- this.addEdge(edge);
86612
-
86613
- return edge;
86614
- }
86615
-
86616
- /**
86617
- *
86618
- * @param {Edge<N>} edge
86619
- * @returns {boolean}
86620
- */
86621
- removeEdge(edge) {
86622
- const edges = this.__edges;
86623
- const indexOf = edges.indexOf(edge);
86624
- if (indexOf >= 0) {
86625
- edges.splice(indexOf, 1);
86626
- this.onChange.send1(edge);
86627
-
86628
- return true;
86629
- } else {
86630
-
86631
- return false;
86632
- }
86633
- }
86634
-
86635
- clear() {
86636
- this.__edges = [];
86637
- this.__nodes = [];
86638
- this.__nodes_set.clear();
86639
-
86640
- this.onChange.send0();
86641
- }
86642
-
86643
- /**
86644
- *
86645
- * @returns {Graph<N>}
86646
- */
86647
- clone() {
86648
- const graph = new Graph();
86649
-
86650
- graph.copy(this);
86651
-
86652
- return graph;
86653
- }
86654
- }
86655
-
86656
86223
  /**
86657
86224
  * Contains serializers for various data types as well as data upgraders which enable support for serialization format changes
86658
86225
  */
@@ -86689,23 +86256,25 @@ class BinarySerializationRegistry {
86689
86256
  */
86690
86257
  registerAdapter(adapter, className) {
86691
86258
 
86692
- if (className === undefined) {
86259
+ let _className = className;
86260
+
86261
+ if (_className === undefined) {
86693
86262
  const klass = adapter.getClass();
86694
86263
 
86695
86264
  if (typeof klass.typeName === "string") {
86696
- className = klass.typeName;
86265
+ _className = klass.typeName;
86697
86266
  } else {
86698
86267
  throw new Error(`className not specified, could not infer class name from the class itself`);
86699
86268
  }
86700
86269
  }
86701
86270
 
86702
- if (this.serializers.has(className)) {
86271
+ if (this.serializers.has(_className)) {
86703
86272
  //a serializer already exists
86704
86273
 
86705
86274
  return false;
86706
86275
  }
86707
86276
 
86708
- this.serializers.set(className, adapter);
86277
+ this.serializers.set(_className, adapter);
86709
86278
 
86710
86279
  return true;
86711
86280
  }
@@ -116360,7 +115929,7 @@ class Uint32Heap {
116360
115929
  const size = this.__size;
116361
115930
 
116362
115931
  while (true) {
116363
- const l = ((i) << 1) + 1;
115932
+ const l = (i << 1) + 1;
116364
115933
  const r = l + 1;
116365
115934
 
116366
115935
  let smallest = i;
@@ -116482,6 +116051,15 @@ class Uint32Heap {
116482
116051
  return -1;
116483
116052
  }
116484
116053
 
116054
+ /**
116055
+ *
116056
+ * @param {number} id
116057
+ * @returns {boolean}
116058
+ */
116059
+ contains(id){
116060
+ return this.find_index_by_id(id) !== -1;
116061
+ }
116062
+
116485
116063
  /**
116486
116064
  * Clear out all the data, heap will be made empty
116487
116065
  */
@@ -116647,7 +116225,7 @@ function index2point(result, index, width) {
116647
116225
  * @param {number} height
116648
116226
  * @returns {number}
116649
116227
  */
116650
- function computeNeighbors(result, index, width, height) {
116228
+ function compute_neighbors(result, index, width, height) {
116651
116229
  const x = index % width;
116652
116230
  const y = (index / width) | 0;
116653
116231
 
@@ -116657,14 +116235,17 @@ function computeNeighbors(result, index, width, height) {
116657
116235
  result[neighbour_count] = index - width;
116658
116236
  neighbour_count++;
116659
116237
  }
116238
+
116660
116239
  if (x > 0) {
116661
116240
  result[neighbour_count] = index - 1;
116662
116241
  neighbour_count++;
116663
116242
  }
116243
+
116664
116244
  if (x < width - 1) {
116665
116245
  result[neighbour_count] = index + 1;
116666
116246
  neighbour_count++;
116667
116247
  }
116248
+
116668
116249
  if (y < height - 1) {
116669
116250
  result[neighbour_count] = index + width;
116670
116251
  neighbour_count++;
@@ -116681,7 +116262,7 @@ function computeNeighbors(result, index, width, height) {
116681
116262
  * @param {number} height
116682
116263
  * @returns {number[]}
116683
116264
  */
116684
- function pathTo(node, g_score, width, height) {
116265
+ function compute_path(node, g_score, width, height) {
116685
116266
  let v_previous = new Vector2(-1, -1);
116686
116267
  let v_current = new Vector2();
116687
116268
 
@@ -116732,7 +116313,7 @@ function pathTo(node, g_score, width, height) {
116732
116313
  v_current = t;
116733
116314
 
116734
116315
  // find next point
116735
- const neighbour_count = computeNeighbors(neighbors, current, width, height);
116316
+ const neighbour_count = compute_neighbors(neighbors, current, width, height);
116736
116317
 
116737
116318
  current = -1;
116738
116319
 
@@ -116811,16 +116392,16 @@ closed.preventShrink();
116811
116392
  * @param {number} height
116812
116393
  * @param {number} start
116813
116394
  * @param {number} goal
116814
- * @param {number} crossingPenalty
116815
- * @param {number} blockValue value in the field that signifies impassible obstacle
116395
+ * @param {number} crossing_penalty
116396
+ * @param {number} block_value value in the field that signifies impassible obstacle
116816
116397
  * @returns {Array.<number>} array of indices representing path from start to end
116817
116398
  */
116818
116399
  function find_path_on_grid_astar(
116819
116400
  field,
116820
116401
  width, height,
116821
116402
  start, goal,
116822
- crossingPenalty,
116823
- blockValue
116403
+ crossing_penalty,
116404
+ block_value
116824
116405
  ) {
116825
116406
 
116826
116407
  // prepare sets
@@ -116844,15 +116425,15 @@ function find_path_on_grid_astar(
116844
116425
  const currentNode = open.pop_min();
116845
116426
 
116846
116427
  if (currentNode === goal) {
116847
- // End case -- result has been found, return the traced path.
116848
- return pathTo(currentNode, g_score, width, height);
116428
+ // End case - result has been found, return the traced path.
116429
+ return compute_path(currentNode, g_score, width, height);
116849
116430
  }
116850
116431
 
116851
116432
  // Normal case -- move currentNode from open to closed, process each of its neighbors.
116852
116433
  closed.set(currentNode, true);
116853
116434
 
116854
116435
  // Find all neighbors for the current node.
116855
- const neighbour_count = computeNeighbors(neighbors, currentNode, width, height);
116436
+ const neighbour_count = compute_neighbors(neighbors, currentNode, width, height);
116856
116437
 
116857
116438
  for (let i = 0; i < neighbour_count; ++i) {
116858
116439
  const neighbor = neighbors[i];
@@ -116864,39 +116445,39 @@ function find_path_on_grid_astar(
116864
116445
 
116865
116446
  // The g score is the shortest distance from start to current node.
116866
116447
  // We need to check if the path we have arrived at this neighbor is the shortest one we have seen yet.
116867
- const neighborValue = field[neighbor];
116448
+ const neighbor_value = field[neighbor];
116868
116449
 
116869
- if (neighborValue === blockValue) {
116450
+ if (neighbor_value === block_value) {
116870
116451
  //cell is blocked, close and continue
116871
116452
  closed.set(neighbor, true);
116872
116453
  continue;
116873
116454
  }
116874
116455
 
116875
116456
  // Cost of traversing to this neighbour
116876
- const transition_cost = neighborValue * crossingPenalty + 1;
116457
+ const transition_cost = neighbor_value * crossing_penalty + 1;
116877
116458
 
116878
116459
  // updated path cost
116879
- const gScore = g_score[currentNode] + transition_cost;
116460
+ const cost_so_far = g_score[currentNode] + transition_cost;
116880
116461
 
116881
116462
  const index_in_open_set = open.find_index_by_id(neighbor);
116882
116463
 
116883
116464
  const not_in_open_set = index_in_open_set === -1;
116884
116465
 
116885
- if (not_in_open_set || gScore < g_score[neighbor]) {
116466
+ if (not_in_open_set || cost_so_far < g_score[neighbor]) {
116886
116467
 
116887
116468
  // update refined score
116888
- g_score[neighbor] = gScore;
116469
+ g_score[neighbor] = cost_so_far;
116889
116470
 
116890
- const h = heuristic(neighbor, goal, width);
116471
+ const remaining_heuristic = heuristic(neighbor, goal, width);
116891
116472
 
116892
- const fScore = gScore + h;
116473
+ const refined_heuristic = cost_so_far + remaining_heuristic;
116893
116474
 
116894
116475
  if (not_in_open_set) {
116895
116476
  // Pushing to heap will put it in proper place based on the 'f' value.
116896
- open.insert(neighbor, fScore);
116477
+ open.insert(neighbor, refined_heuristic);
116897
116478
  } else {
116898
116479
  // Already seen the node, but since it has been re-scored we need to reorder it in the heap
116899
- open.__update_score_by_index(index_in_open_set, fScore);
116480
+ open.__update_score_by_index(index_in_open_set, refined_heuristic);
116900
116481
  }
116901
116482
  }
116902
116483
  }