@woosh/meep-engine 2.47.14 → 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,78 +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
- *
117659
- * @returns {number}
117660
- */
117661
- IdPool.prototype.get = function () {
117662
- const bitIndex = this.bitSet.nextClearBit(0);
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
+ }
117663
117664
 
117664
- this.bitSet.set(bitIndex, true);
117665
+ /**
117666
+ *
117667
+ * @returns {number}
117668
+ */
117669
+ get() {
117670
+ const id = this.peek();
117665
117671
 
117666
- return bitIndex;
117667
- };
117672
+ this.#set.set(id, true);
117668
117673
 
117669
- /**
117670
- * Attempt to request a specific ID from the pool.
117671
- * @param {number} id
117672
- * @return {boolean} true if request succeeds, false otherwise
117673
- */
117674
- IdPool.prototype.getSpecific = function (id) {
117675
- if (this.isUsed(id)) {
117676
- return false;
117674
+ return id;
117677
117675
  }
117678
117676
 
117679
- this.bitSet.set(id, true);
117680
- return true;
117681
- };
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
+ }
117682
117686
 
117683
- /**
117684
- *
117685
- * @param {number} id
117686
- * @returns {boolean}
117687
- */
117688
- IdPool.prototype.isUsed = function (id) {
117689
- return this.bitSet.get(id);
117690
- };
117687
+ this.#set.set(id, true);
117688
+ return true;
117689
+ }
117691
117690
 
117692
- /**
117693
- * Traverse all IDs currently in use
117694
- * @param {function(id:number)} visitor
117695
- */
117696
- IdPool.prototype.traverseUsed = function (visitor) {
117697
- assert.equal(typeof visitor, 'function', `visitor must be a function, instead was '${typeof visitor}'`);
117691
+ /**
117692
+ *
117693
+ * @param {number} id
117694
+ * @returns {boolean}
117695
+ */
117696
+ isUsed(id) {
117697
+ return this.#set.get(id);
117698
+ }
117698
117699
 
117699
- const bitSet = this.bitSet;
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
- for (let i = bitSet.nextSetBit(0); i !== -1; i = bitSet.nextSetBit(i + 1)) {
117702
- visitor(i);
117703
- }
117707
+ const set = this.#set;
117704
117708
 
117705
- };
117709
+ for (let i = set.nextSetBit(0); i !== -1; i = set.nextSetBit(i + 1)) {
117710
+ visitor(i);
117711
+ }
117706
117712
 
117707
- /**
117708
- *
117709
- * @param {number} id
117710
- */
117711
- IdPool.prototype.release = function (id) {
117712
- this.bitSet.clear(id);
117713
- };
117713
+ }
117714
117714
 
117715
- IdPool.prototype.reset = function () {
117716
- this.bitSet.reset();
117717
- };
117715
+ /**
117716
+ *
117717
+ * @param {number} id
117718
+ */
117719
+ release(id) {
117720
+ this.#set.clear(id);
117721
+ }
117722
+
117723
+ /**
117724
+ * Release all used IDs
117725
+ */
117726
+ reset() {
117727
+ this.#set.reset();
117728
+ }
117729
+ }
117718
117730
 
117719
117731
  class AtlasPatch {
117720
117732
  constructor() {