@woosh/meep-engine 2.47.15 → 2.47.16

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
@@ -117643,87 +117643,90 @@ class MaxRectanglesPacker {
117643
117643
  */
117644
117644
 
117645
117645
  /**
117646
- *
117647
- * @constructor
117646
+ * Pool of unsigned integer IDs, useful when you don't want to just keep incrementing ID counter and want to re-use IDs after they are no longer needed
117647
+ * Main use case is when your IDs are array indices, having compact IDs lets you use fixed size array even as objects are added and removed as you're able to reuse slots in an efficient manner
117648
117648
  */
117649
- function IdPool() {
117649
+ class IdPool {
117650
117650
  /**
117651
117651
  * @private
117652
117652
  * @type {BitSet}
117653
117653
  */
117654
- this.bitSet = new BitSet();
117655
- }
117654
+ #set = new BitSet();
117656
117655
 
117657
- /**
117658
- * Looks up next available ID without reserving it
117659
- * If you want to also reserve the ID - use {@link get} instead
117660
- * @returns {number}
117661
- */
117662
- IdPool.prototype.peek = function () {
117663
- return this.bitSet.nextClearBit(0);
117664
- };
117656
+ /**
117657
+ * Looks up next available ID without reserving it
117658
+ * If you want to also reserve the ID - use {@link get} instead
117659
+ * @returns {number}
117660
+ */
117661
+ peek() {
117662
+ return this.#set.nextClearBit(0);
117663
+ }
117665
117664
 
117666
- /**
117667
- *
117668
- * @returns {number}
117669
- */
117670
- IdPool.prototype.get = function () {
117671
- const bitIndex = this.peek();
117665
+ /**
117666
+ *
117667
+ * @returns {number}
117668
+ */
117669
+ get() {
117670
+ const id = this.peek();
117672
117671
 
117673
- this.bitSet.set(bitIndex, true);
117672
+ this.#set.set(id, true);
117674
117673
 
117675
- return bitIndex;
117676
- };
117674
+ return id;
117675
+ }
117677
117676
 
117678
- /**
117679
- * Attempt to request a specific ID from the pool.
117680
- * @param {number} id
117681
- * @return {boolean} true if request succeeds, false otherwise
117682
- */
117683
- IdPool.prototype.getSpecific = function (id) {
117684
- if (this.isUsed(id)) {
117685
- return false;
117677
+ /**
117678
+ * Attempt to request a specific ID from the pool.
117679
+ * @param {number} id
117680
+ * @return {boolean} true if request succeeds, false otherwise
117681
+ */
117682
+ getSpecific(id) {
117683
+ if (this.isUsed(id)) {
117684
+ return false;
117685
+ }
117686
+
117687
+ this.#set.set(id, true);
117688
+ return true;
117686
117689
  }
117687
117690
 
117688
- this.bitSet.set(id, true);
117689
- return true;
117690
- };
117691
+ /**
117692
+ *
117693
+ * @param {number} id
117694
+ * @returns {boolean}
117695
+ */
117696
+ isUsed(id) {
117697
+ return this.#set.get(id);
117698
+ }
117691
117699
 
117692
- /**
117693
- *
117694
- * @param {number} id
117695
- * @returns {boolean}
117696
- */
117697
- IdPool.prototype.isUsed = function (id) {
117698
- return this.bitSet.get(id);
117699
- };
117700
+ /**
117701
+ * Traverse all IDs currently in use
117702
+ * @param {function(id:number)} visitor
117703
+ */
117704
+ traverseUsed(visitor) {
117705
+ assert.isFunction(visitor, "visitor");
117700
117706
 
117701
- /**
117702
- * Traverse all IDs currently in use
117703
- * @param {function(id:number)} visitor
117704
- */
117705
- IdPool.prototype.traverseUsed = function (visitor) {
117706
- assert.equal(typeof visitor, 'function', `visitor must be a function, instead was '${typeof visitor}'`);
117707
+ const set = this.#set;
117707
117708
 
117708
- const bitSet = this.bitSet;
117709
+ for (let i = set.nextSetBit(0); i !== -1; i = set.nextSetBit(i + 1)) {
117710
+ visitor(i);
117711
+ }
117709
117712
 
117710
- for (let i = bitSet.nextSetBit(0); i !== -1; i = bitSet.nextSetBit(i + 1)) {
117711
- visitor(i);
117712
117713
  }
117713
117714
 
117714
- };
117715
-
117716
- /**
117717
- *
117718
- * @param {number} id
117719
- */
117720
- IdPool.prototype.release = function (id) {
117721
- this.bitSet.clear(id);
117722
- };
117715
+ /**
117716
+ *
117717
+ * @param {number} id
117718
+ */
117719
+ release(id) {
117720
+ this.#set.clear(id);
117721
+ }
117723
117722
 
117724
- IdPool.prototype.reset = function () {
117725
- this.bitSet.reset();
117726
- };
117723
+ /**
117724
+ * Release all used IDs
117725
+ */
117726
+ reset() {
117727
+ this.#set.reset();
117728
+ }
117729
+ }
117727
117730
 
117728
117731
  class AtlasPatch {
117729
117732
  constructor() {