@woosh/meep-engine 2.104.0 → 2.105.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.
@@ -32,6 +32,19 @@ test("trying to insert an element into the cache that's larger than the cache ca
32
32
  expect(cache.contains(2)).toBe(false);
33
33
  });
34
34
 
35
+ test("Recently accessed element should not be targeted for eviction where possible", () => {
36
+ const cache = new Cache();
37
+
38
+ cache.put(2, "hello");
39
+ cache.put(7, "world");
40
+
41
+ cache.get(2);
42
+
43
+ cache.evictOne();
44
+
45
+ expect(cache.has(2)).toBe(true);
46
+ });
47
+
35
48
  test("removeListener is called when element is evicted", () => {
36
49
 
37
50
  const removeListener = jest.fn();
@@ -233,3 +246,32 @@ test("silentRemove should not notify", () => {
233
246
 
234
247
  expect(mock).not.toHaveBeenCalled();
235
248
  });
249
+
250
+ test("setting maxWeight will drop data and update weight", () => {
251
+
252
+ const cache = new Cache();
253
+
254
+ cache.set("a", 1);
255
+ cache.set("b", 2);
256
+ cache.set("c", 3);
257
+
258
+ expect(cache.weight).toEqual(3);
259
+
260
+ cache.maxWeight = 1;
261
+
262
+ expect(cache.maxWeight).toEqual(1);
263
+ expect(cache.weight).toEqual(1);
264
+ });
265
+
266
+ test("setting maxWeight to 0 will empty out cache", () => {
267
+
268
+ const cache = new Cache();
269
+
270
+ cache.set("a", 1);
271
+ cache.set("b", 2);
272
+
273
+ cache.maxWeight = 0;
274
+
275
+ expect(cache.size()).toBe(0);
276
+
277
+ });
@@ -30,5 +30,6 @@ export class CacheElement<Key, Value> {
30
30
  */
31
31
  previous: CacheElement<Key_1, Value_1>;
32
32
  unlink(): void;
33
+ toString(): string;
33
34
  }
34
35
  //# sourceMappingURL=CacheElement.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CacheElement.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/CacheElement.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;IAMQ;;;OAGG;IACH,WAAe;IAEf;;;OAGG;IACH,eAAiB;IAEjB;;;OAGG;IACH,QAFU,MAAM,CAED;IAEf;;;OAGG;IACH,mCAAgB;IAEhB;;;OAGG;IACH,uCAAoB;IAGxB,eAWC;CACJ"}
1
+ {"version":3,"file":"CacheElement.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/CacheElement.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;IAMQ;;;OAGG;IACH,WAAe;IAEf;;;OAGG;IACH,eAAiB;IAEjB;;;OAGG;IACH,QAFU,MAAM,CAED;IAEf;;;OAGG;IACH,mCAAgB;IAEhB;;;OAGG;IACH,uCAAoB;IAGxB,eAWC;IAED,mBAEC;CACJ"}
@@ -52,4 +52,8 @@ export class CacheElement {
52
52
  next.previous = previous;
53
53
  }
54
54
  }
55
+
56
+ toString() {
57
+ return `CacheElement{ hasNext:${this.next !== null}, hasPrevious:${this.previous !== null}, weight:${this.weight}, key:${this.key}, value:${this.value} }`;
58
+ }
55
59
  }
@@ -9,16 +9,6 @@ declare class LineBuilder {
9
9
  * @returns {LineBuilder}
10
10
  */
11
11
  static fromText(text: string): LineBuilder;
12
- /**
13
- *
14
- * @type {Line[]}
15
- */
16
- lines: Line[];
17
- /**
18
- *
19
- * @type {number}
20
- */
21
- indentation: number;
22
12
  /**
23
13
  *
24
14
  * @type {number}
@@ -62,19 +52,6 @@ declare class LineBuilder {
62
52
  * @returns {string}
63
53
  */
64
54
  build(): string;
65
- }
66
- /**
67
- * Created by Alex on 08/06/2015.
68
- */
69
- declare class Line {
70
- /**
71
- *
72
- * @param {string} text
73
- * @param {number} indent
74
- * @constructor
75
- */
76
- constructor(text: string, indent: number);
77
- text: string;
78
- indentation: number;
55
+ #private;
79
56
  }
80
57
  //# sourceMappingURL=LineBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LineBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/codegen/LineBuilder.js"],"names":[],"mappings":";AAoBA;;GAEG;AACH;IAkII;;;;OAIG;IACH,sBAHW,MAAM,GACJ,WAAW,CAkBvB;IArJD;;;OAGG;IACH,OAFU,IAAI,EAAE,CAEL;IACX;;;OAGG;IACH,aAFU,MAAM,CAEA;IAChB;;;OAGG;IACH,cAFU,MAAM,CAEqB;IAErC;;;OAGG;IACH,oBAEC;IAED;;;;OAIG;IACH,wBAFW,MAAM,GADL,OAAO,CAiBlB;IAED;;;OAGG;IACH,UAFa,WAAW,CAKvB;IAED;;;OAGG;IACH,UAFa,WAAW,CAKvB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,WAAW,CASvB;IAED;;;OAGG;IACH,gBAFW,WAAW,QAgBrB;IAED,cAGC;IAED;;;OAGG;IACH,SAFa,MAAM,CAsBlB;CAwBJ;AA/KD;;GAEG;AAGH;IACI;;;;;OAKG;IACH,kBAJW,MAAM,UACN,MAAM,EAMhB;IAFG,aAAgB;IAChB,oBAAyB;CAEhC"}
1
+ {"version":3,"file":"LineBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/codegen/LineBuilder.js"],"names":[],"mappings":";AAoBA;;GAEG;AACH;IAoII;;;;OAIG;IACH,sBAHW,MAAM,GACJ,WAAW,CAoBvB;IA7ID;;;OAGG;IACH,cAFU,MAAM,CAEqB;IAErC;;;OAGG;IACH,oBAEC;IAED;;;;OAIG;IACH,wBAFW,MAAM,GADL,OAAO,CAiBlB;IAED;;;OAGG;IACH,UAFa,WAAW,CAKvB;IAED;;;OAGG;IACH,UAFa,WAAW,CAKvB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,WAAW,CASvB;IAED;;;OAGG;IACH,gBAFW,WAAW,QAgBrB;IAED,cAGC;IAED;;;OAGG;IACH,SAFa,MAAM,CAsBlB;;CA0BJ"}
@@ -27,12 +27,14 @@ class LineBuilder {
27
27
  *
28
28
  * @type {Line[]}
29
29
  */
30
- lines = [];
30
+ #lines = [];
31
+
31
32
  /**
32
33
  *
33
34
  * @type {number}
34
35
  */
35
- indentation = 0;
36
+ #indentation = 0;
37
+
36
38
  /**
37
39
  *
38
40
  * @type {number}
@@ -44,7 +46,7 @@ class LineBuilder {
44
46
  * @return {number}
45
47
  */
46
48
  get count() {
47
- return this.lines.length;
49
+ return this.#lines.length;
48
50
  }
49
51
 
50
52
  /**
@@ -53,7 +55,7 @@ class LineBuilder {
53
55
  * @param {string} term
54
56
  */
55
57
  containsSubstring(term) {
56
- const lines = this.lines;
58
+ const lines = this.#lines;
57
59
  const n = lines.length;
58
60
  for (let i = 0; i < n; i++) {
59
61
  const line = lines[i];
@@ -73,7 +75,7 @@ class LineBuilder {
73
75
  * @returns {LineBuilder}
74
76
  */
75
77
  indent() {
76
- this.indentation++;
78
+ this.#indentation++;
77
79
  return this;
78
80
  }
79
81
 
@@ -82,7 +84,7 @@ class LineBuilder {
82
84
  * @returns {LineBuilder}
83
85
  */
84
86
  dedent() {
85
- this.indentation--;
87
+ this.#indentation--;
86
88
  return this;
87
89
  }
88
90
 
@@ -93,9 +95,9 @@ class LineBuilder {
93
95
  */
94
96
  add(line_text) {
95
97
 
96
- const line = new Line(line_text, this.indentation);
98
+ const line = new Line(line_text, this.#indentation);
97
99
 
98
- this.lines.push(line);
100
+ this.#lines.push(line);
99
101
 
100
102
  return this;
101
103
  }
@@ -106,23 +108,23 @@ class LineBuilder {
106
108
  */
107
109
  addLines(lines) {
108
110
 
109
- const other_lines = lines.lines;
111
+ const other_lines = lines.#lines;
110
112
 
111
113
  const other_line_count = other_lines.length;
112
114
 
113
115
  for (let i = 0; i < other_line_count; i++) {
114
116
  const otherLine = other_lines[i];
115
117
 
116
- const line = new Line(otherLine.text, otherLine.indentation + this.indentation);
118
+ const line = new Line(otherLine.text, otherLine.indentation + this.#indentation);
117
119
 
118
- this.lines.push(line);
120
+ this.#lines.push(line);
119
121
  }
120
122
 
121
123
  }
122
124
 
123
125
  clear() {
124
- this.lines = [];
125
- this.indentation = 0;
126
+ this.#lines = [];
127
+ this.#indentation = 0;
126
128
  }
127
129
 
128
130
  /**
@@ -134,7 +136,7 @@ class LineBuilder {
134
136
 
135
137
  let i, j, l;
136
138
 
137
- const lines = this.lines;
139
+ const lines = this.#lines;
138
140
 
139
141
  for (i = 0, l = lines.length; i < l; i++) {
140
142
  const line = lines[i];
@@ -167,7 +169,9 @@ class LineBuilder {
167
169
 
168
170
  for (let i = 0; i < n; i++) {
169
171
 
170
- r.add(lines[i]);
172
+ const line_text = lines[i];
173
+
174
+ r.add(line_text);
171
175
 
172
176
  }
173
177
 
@@ -1 +1 @@
1
- {"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AAsHD;;;;;;;GAOG;AACH;IA2DI;;;;;;OAMG;IACH,4FALuB,MAAM,EAsC5B;IAlBG;;;;;OAKG;IACH,iCAAsC;IACtC;;;;;OAKG;IACH,qCAA8C;IAOlD,mBAEC;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IA2HD;;;;OAIG;IACH,SAHW,CAAC,SACD,CAAC,QAoEX;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CA+BvB;IAED;;;;;;;;OAQG;IACH,kBALW,CAAC,kBACQ,CAAC,KAAE,CAAC,0BAEZ,CAAC,CAcZ;IAED;;;;;OAKG;IACH,cAJW,CAAC,SACD,CAAC,GACA,CAAC,CAYZ;IAuBD;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CA+CnB;IAED;;;;;OAKG;IACH,4CAFa,OAAO,CA+BnB;IAOD;;OAEG;IACH,gBAkDC;IAmBD,2CAwBC;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,OAAO,CAInB;IAED;;OAEG;IACH,cA6BC;IA+BD;;;OAGG;IACH,UAFa,SAAS,CAAC,CAAC,CAOvB;IAED;;;OAGG;IACH,QAFa,SAAS,CAAC,CAAC,CAMvB;IAhDD,yDA2BC;;CAsBJ"}
1
+ {"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AA8FD;;;;;;;GAOG;AACH;IA+DI;;;;;;OAMG;IACH,4FALuB,MAAM,EAsC5B;IAlBG;;;;;OAKG;IACH,iCAAsC;IACtC;;;;;OAKG;IACH,qCAA8C;IAOlD,mBAEC;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAkJD;;;;OAIG;IACH,SAHW,CAAC,SACD,CAAC,QAsEX;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CA+BvB;IAED;;;;;;;;OAQG;IACH,kBALW,CAAC,kBACQ,CAAC,KAAE,CAAC,0BAEZ,CAAC,CAcZ;IAED;;;;;OAKG;IACH,cAJW,CAAC,SACD,CAAC,GACA,CAAC,CAYZ;IAuBD;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CA+CnB;IAED;;;;;OAKG;IACH,4CAFa,OAAO,CA+BnB;IAOD;;OAEG;IACH,gBAkDC;IAmBD,2CAwBC;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,OAAO,CAInB;IAED;;OAEG;IACH,cA6BC;IA+BD;;;OAGG;IACH,UAFa,SAAS,CAAC,CAAC,CAOvB;IAED;;;OAGG;IACH,QAFa,SAAS,CAAC,CAAC,CAMvB;IAhDD,yDA2BC;;CAsBJ"}
@@ -124,30 +124,6 @@ const RESERVED_HASH_SUBSTITUTE = 0;
124
124
  const UNDEFINED_BIN_INDEX = ~0;
125
125
 
126
126
 
127
- /**
128
- * @template K,V
129
- * @param {HashMapEntry<K,V>} record
130
- * @param {number} hash
131
- * @param {K} key
132
- * @param {function(a:K,b:K):boolean} equality_op
133
- */
134
- function entry_equality_check(record, hash, key, equality_op) {
135
- if (record.hash !== hash) {
136
- return false;
137
- }
138
-
139
- if (record.key === key) {
140
- return true;
141
- }
142
-
143
- const result = equality_op(record.key, key);
144
-
145
- assert.isBoolean(result, `result(a=${record.key},b=${key})`);
146
-
147
- return result;
148
- }
149
-
150
-
151
127
  const EMPTY_BINS = new Uint32Array(0);
152
128
 
153
129
  /**
@@ -215,6 +191,10 @@ export class HashMap {
215
191
  */
216
192
  #load_factor = DEFAULT_LOAD_FACTOR;
217
193
 
194
+ /**
195
+ * Used to track modifications to prevent concurrent changes during iteration
196
+ * @type {number}
197
+ */
218
198
  #version = 0;
219
199
 
220
200
  /**
@@ -339,6 +319,29 @@ export class HashMap {
339
319
  return original === RESERVED_HASH ? RESERVED_HASH_SUBSTITUTE : original;
340
320
  }
341
321
 
322
+ /**
323
+ * @param {HashMapEntry<K,V>} record
324
+ * @param {number} hash
325
+ * @param {K} key
326
+ */
327
+ #entry_equality_check(record, hash, key) {
328
+ if (record.hash !== hash) {
329
+ return false;
330
+ }
331
+
332
+ if (record.key === key) {
333
+ return true;
334
+ }
335
+
336
+ assert.equal(record.hash, this.#build_key_hash(record.key), `Key hash has diverged for key ${record.key}, likely key was mutated or hash function is unstable`);
337
+
338
+ const result = this.keyEqualityFunction(record.key, key);
339
+
340
+ assert.isBoolean(result, `result(a=${record.key},b=${key})`);
341
+
342
+ return result;
343
+ }
344
+
342
345
  /**
343
346
  *
344
347
  * @param {K} k
@@ -402,6 +405,7 @@ export class HashMap {
402
405
 
403
406
  const raw_hash = this.#build_key_hash(key);
404
407
  let bin_index = this.#compute_bin_index(raw_hash);
408
+
405
409
  assert.isFiniteNumber(bin_index, 'hash');
406
410
 
407
411
  let first_deleted_bin_index = UNDEFINED_BIN_INDEX;
@@ -415,11 +419,12 @@ export class HashMap {
415
419
  // check if it's the entry that we're looking for
416
420
  const entry = this.#entries[bin - ENTRY_BASE];
417
421
 
418
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
422
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
419
423
  // found the right entry
420
424
  entry.value = value;
421
425
  return;
422
426
  }
427
+
423
428
  } else if (bin === BIN_RESERVED_VALUE_EMPTY) {
424
429
  // bin is empty
425
430
 
@@ -484,7 +489,7 @@ export class HashMap {
484
489
  // check if the entry is what we're looking for
485
490
  const entry = this.#entries[bin - ENTRY_BASE];
486
491
 
487
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
492
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
488
493
  // found the right entry
489
494
  return entry.value;
490
495
  }
@@ -588,7 +593,7 @@ export class HashMap {
588
593
  const entry_index = bin - ENTRY_BASE;
589
594
  const entry = entries[entry_index];
590
595
 
591
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
596
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
592
597
  // found the right entry
593
598
 
594
599
  // record entry as dead
@@ -244,7 +244,7 @@ export class NodeGraph {
244
244
  * @return {NodeInstance[]}
245
245
  */
246
246
  getNodes() {
247
- return this.nodes.data.slice();
247
+ return this.nodes.asArray().slice();
248
248
  }
249
249
 
250
250
  /**
@@ -252,7 +252,7 @@ export class NodeGraph {
252
252
  * @return {Connection[]}
253
253
  */
254
254
  getConnections() {
255
- return this.connections.data.slice();
255
+ return this.connections.asArray().slice();
256
256
  }
257
257
 
258
258
  /**
@@ -397,7 +397,7 @@ class Mesh {
397
397
  const matrixWorld = skeletonBone.matrixWorld;
398
398
 
399
399
 
400
- result.threejs_setFromMatrixPosition(matrixWorld);
400
+ result.setFromMatrixPosition(matrixWorld.elements);
401
401
  }
402
402
 
403
403
  }
@@ -41,7 +41,7 @@ export class GeometrySpatialQueryAccelerator {
41
41
  * @param {number} value in bytes
42
42
  */
43
43
  set cache_size(value) {
44
- this.cache.setMaxWeight(value);
44
+ this.cache.maxWeight = value;
45
45
  }
46
46
 
47
47
  /**