@woosh/meep-engine 2.77.0 → 2.78.1

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/build/meep.cjs CHANGED
@@ -70585,10 +70585,19 @@ class Edge {
70585
70585
  return this.first === node || this.second === node;
70586
70586
  }
70587
70587
 
70588
+ /**
70589
+ *
70590
+ * @param {N} source
70591
+ * @param {N} target
70592
+ * @returns {boolean} True iff the edge contains both source and target and allows transition from source to target
70593
+ */
70588
70594
  validateTransition(source, target) {
70589
70595
  const a = this.first;
70590
70596
  const b = this.second;
70591
- return (a === source && b === target && this.traversableForward()) || (b === source && a === target && this.traversableBackward());
70597
+
70598
+ return (a === source && b === target && this.traversableForward())
70599
+ || (b === source && a === target && this.traversableBackward())
70600
+ ;
70592
70601
  }
70593
70602
 
70594
70603
  /**
@@ -70636,16 +70645,6 @@ class Edge {
70636
70645
  || (this.second === node && this.direction === EdgeDirectionType.Backward)
70637
70646
  }
70638
70647
 
70639
- /**
70640
- * @deprecated
70641
- * @returns {number}
70642
- */
70643
- angle() {
70644
-
70645
- const delta = this.second.clone().sub(this.first);
70646
- return Math.atan2(delta.y, delta.x);
70647
- }
70648
-
70649
70648
  /**
70650
70649
  *
70651
70650
  * @returns {N[]}
@@ -70654,15 +70653,6 @@ class Edge {
70654
70653
  return [this.first, this.second];
70655
70654
  }
70656
70655
 
70657
-
70658
- /**
70659
- * @deprecated
70660
- * @returns {number}
70661
- */
70662
- get length() {
70663
-
70664
- return this.first.distanceTo(this.second);
70665
- }
70666
70656
  }
70667
70657
 
70668
70658
  /**
@@ -70693,10 +70683,19 @@ class NodeContainer {
70693
70683
  /**
70694
70684
  *
70695
70685
  * @type {Map<N,number>}
70686
+ * Maps neighbour node to number of edges to that node from this one
70696
70687
  * @private
70697
70688
  */
70698
70689
  __neighbors = new Map();
70699
70690
 
70691
+ /**
70692
+ * NOTE: this method allocates memory internally
70693
+ * @returns {N[]}
70694
+ */
70695
+ get neighbours() {
70696
+ return Array.from(this.__neighbors.keys());
70697
+ }
70698
+
70700
70699
  /**
70701
70700
  *
70702
70701
  * @return {number}
@@ -70714,7 +70713,7 @@ class NodeContainer {
70714
70713
  }
70715
70714
 
70716
70715
  /**
70717
- *
70716
+ * NOTE: this method allocates memory internally
70718
70717
  * @returns {N[]}
70719
70718
  */
70720
70719
  get inNodes() {
@@ -70722,7 +70721,7 @@ class NodeContainer {
70722
70721
  }
70723
70722
 
70724
70723
  /**
70725
- *
70724
+ * NOTE: this method allocates memory internally
70726
70725
  * @returns {N[]}
70727
70726
  */
70728
70727
  get outNodes() {
@@ -70730,6 +70729,10 @@ class NodeContainer {
70730
70729
  }
70731
70730
 
70732
70731
 
70732
+ /**
70733
+ * NOTE: this method allocates memory internally
70734
+ * @returns {Edge<N>[]}
70735
+ */
70733
70736
  get outEdges() {
70734
70737
  /**
70735
70738
  *
@@ -70742,6 +70745,10 @@ class NodeContainer {
70742
70745
  return result;
70743
70746
  }
70744
70747
 
70748
+ /**
70749
+ * NOTE: this method allocates memory internally
70750
+ * @returns {Edge<N>[]}
70751
+ */
70745
70752
  get inEdges() {
70746
70753
  /**
70747
70754
  *
@@ -71070,6 +71077,7 @@ class Graph {
71070
71077
  /**
71071
71078
  *
71072
71079
  * @param {N} node
71080
+ * @returns {boolean}
71073
71081
  */
71074
71082
  removeNode(node) {
71075
71083
 
@@ -71143,7 +71151,7 @@ class Graph {
71143
71151
  }
71144
71152
 
71145
71153
  /**
71146
- *
71154
+ * Node degree is the number of attached edges
71147
71155
  * @param {N} node
71148
71156
  * @return {number}
71149
71157
  */
@@ -71157,6 +71165,14 @@ class Graph {
71157
71165
  return container.getEdgeCount();
71158
71166
  }
71159
71167
 
71168
+ /**
71169
+ *
71170
+ * @returns {N[]}
71171
+ */
71172
+ get nodes() {
71173
+ return Array.from(this.getNodes());
71174
+ }
71175
+
71160
71176
  /**
71161
71177
  * Do not modify this set directly
71162
71178
  * @return {Iterable<N>}
@@ -71177,13 +71193,18 @@ class Graph {
71177
71193
  *
71178
71194
  * @param {N} source
71179
71195
  * @param {N} target
71180
- * @param {EdgeDirectionType} [type] Undirected by default
71196
+ * @param {EdgeDirectionType} [direction] Undirected by default
71181
71197
  * @returns {Edge<N>}
71182
71198
  */
71183
- createEdge(source, target, type = EdgeDirectionType.Undirected) {
71199
+ createEdge(
71200
+ source,
71201
+ target,
71202
+ direction = EdgeDirectionType.Undirected
71203
+ ) {
71204
+
71184
71205
  const edge = new Edge(source, target);
71185
71206
 
71186
- edge.direction = type;
71207
+ edge.direction = direction;
71187
71208
 
71188
71209
  this.addEdge(edge);
71189
71210
 
@@ -71191,9 +71212,10 @@ class Graph {
71191
71212
  }
71192
71213
 
71193
71214
  /**
71194
- *
71215
+ * Both nodes that the edge is attached to must be present
71195
71216
  * @param {Edge<N>} edge
71196
- * @returns {boolean}
71217
+ * @returns {boolean} true if edge was added, false if edge was already present
71218
+ * @throws if one or both nodes are not contained in the graph
71197
71219
  */
71198
71220
  addEdge(edge) {
71199
71221
  if (this.hasEdge(edge)) {
@@ -71362,6 +71384,21 @@ class Graph {
71362
71384
  return edge_count;
71363
71385
  }
71364
71386
 
71387
+ /**
71388
+ *
71389
+ * @param {N} node
71390
+ * @returns {N[]}
71391
+ */
71392
+ getNeighbours(node) {
71393
+ const container = this.__nodes.get(node);
71394
+
71395
+ if (container === undefined) {
71396
+ return [];
71397
+ }
71398
+
71399
+ return container.neighbours;
71400
+ }
71401
+
71365
71402
  /**
71366
71403
  *
71367
71404
  * @param {N} node
@@ -71380,10 +71417,10 @@ class Graph {
71380
71417
  }
71381
71418
 
71382
71419
  /**
71383
- *
71420
+ * Find a path through the graph
71384
71421
  * @param {N} start
71385
71422
  * @param {N} goal
71386
- * @returns {null|N[]}
71423
+ * @returns {null|N[]} null if no path exists
71387
71424
  */
71388
71425
  findPath(start, goal) {
71389
71426
  const start_node_container = this.__nodes.get(start);
@@ -71423,6 +71460,7 @@ class Graph {
71423
71460
  const b = edge.second;
71424
71461
 
71425
71462
  let other = null;
71463
+
71426
71464
  if (a === current_node && (edge.direction === EdgeDirectionType.Forward || edge.direction === EdgeDirectionType.Undirected)) {
71427
71465
  other = b;
71428
71466
  } else if (b === current_node && (edge.direction === EdgeDirectionType.Backward || edge.direction === EdgeDirectionType.Undirected)) {
@@ -71451,6 +71489,9 @@ class Graph {
71451
71489
  return null;
71452
71490
  }
71453
71491
 
71492
+ /**
71493
+ * Remove all data from the graph, resetting it to empty state
71494
+ */
71454
71495
  clear() {
71455
71496
  this.__nodes.clear();
71456
71497
  this.__edges.clear();