@woosh/meep-engine 2.94.8 → 2.95.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 +3 -3
- package/build/meep.module.js +3 -3
- package/package.json +1 -1
- package/src/core/collection/array/arrayPickBestElement.d.ts.map +1 -1
- package/src/core/collection/array/arrayPickBestElement.js +3 -3
- package/src/core/collection/array/arrayPickBestElements.d.ts +2 -2
- package/src/core/collection/array/arrayPickBestElements.d.ts.map +1 -1
- package/src/core/collection/array/arrayPickBestElements.js +3 -3
- package/src/core/collection/array/array_deduplicate.d.ts +8 -0
- package/src/core/collection/array/array_deduplicate.d.ts.map +1 -0
- package/src/core/collection/array/array_deduplicate.js +9 -0
- package/src/core/collection/array/array_deduplicate.spec.d.ts +2 -0
- package/src/core/collection/array/array_deduplicate.spec.d.ts.map +1 -0
- package/src/core/collection/array/array_deduplicate.spec.js +11 -0
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.spec.js +1 -1
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.spec.js +1 -1
- package/src/core/model/node-graph/node/NodeInstance.d.ts.map +1 -1
- package/src/core/model/node-graph/node/NodeInstance.js +45 -19
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +2 -2
package/build/meep.cjs
CHANGED
|
@@ -114510,7 +114510,7 @@ class StorageAchievementGateway extends AchievementGateway {
|
|
|
114510
114510
|
* If multiple elements with the same highest score exist, the result will be first such encountered element
|
|
114511
114511
|
* @template T
|
|
114512
114512
|
* @param {T[]} array
|
|
114513
|
-
* @param {function(T):number} scoreFunction
|
|
114513
|
+
* @param {function(el:T, index:number):number} scoreFunction
|
|
114514
114514
|
* @returns {T|undefined}
|
|
114515
114515
|
*/
|
|
114516
114516
|
function arrayPickBestElement(array, scoreFunction) {
|
|
@@ -114526,13 +114526,13 @@ function arrayPickBestElement(array, scoreFunction) {
|
|
|
114526
114526
|
|
|
114527
114527
|
bestElement = array[0];
|
|
114528
114528
|
|
|
114529
|
-
bestScore = scoreFunction(bestElement);
|
|
114529
|
+
bestScore = scoreFunction(bestElement, 0);
|
|
114530
114530
|
|
|
114531
114531
|
for (let i = 1; i < size; i++) {
|
|
114532
114532
|
const el = array[i];
|
|
114533
114533
|
|
|
114534
114534
|
// compute score
|
|
114535
|
-
const score = scoreFunction(el);
|
|
114535
|
+
const score = scoreFunction(el, i);
|
|
114536
114536
|
|
|
114537
114537
|
if (score > bestScore) {
|
|
114538
114538
|
bestScore = score;
|
package/build/meep.module.js
CHANGED
|
@@ -114508,7 +114508,7 @@ class StorageAchievementGateway extends AchievementGateway {
|
|
|
114508
114508
|
* If multiple elements with the same highest score exist, the result will be first such encountered element
|
|
114509
114509
|
* @template T
|
|
114510
114510
|
* @param {T[]} array
|
|
114511
|
-
* @param {function(T):number} scoreFunction
|
|
114511
|
+
* @param {function(el:T, index:number):number} scoreFunction
|
|
114512
114512
|
* @returns {T|undefined}
|
|
114513
114513
|
*/
|
|
114514
114514
|
function arrayPickBestElement(array, scoreFunction) {
|
|
@@ -114524,13 +114524,13 @@ function arrayPickBestElement(array, scoreFunction) {
|
|
|
114524
114524
|
|
|
114525
114525
|
bestElement = array[0];
|
|
114526
114526
|
|
|
114527
|
-
bestScore = scoreFunction(bestElement);
|
|
114527
|
+
bestScore = scoreFunction(bestElement, 0);
|
|
114528
114528
|
|
|
114529
114529
|
for (let i = 1; i < size; i++) {
|
|
114530
114530
|
const el = array[i];
|
|
114531
114531
|
|
|
114532
114532
|
// compute score
|
|
114533
|
-
const score = scoreFunction(el);
|
|
114533
|
+
const score = scoreFunction(el, i);
|
|
114534
114534
|
|
|
114535
114535
|
if (score > bestScore) {
|
|
114536
114536
|
bestScore = score;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayPickBestElement.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/arrayPickBestElement.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"arrayPickBestElement.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/arrayPickBestElement.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,2EAkCC"}
|
|
@@ -5,7 +5,7 @@ import { assert } from "../../assert.js";
|
|
|
5
5
|
* If multiple elements with the same highest score exist, the result will be first such encountered element
|
|
6
6
|
* @template T
|
|
7
7
|
* @param {T[]} array
|
|
8
|
-
* @param {function(T):number} scoreFunction
|
|
8
|
+
* @param {function(el:T, index:number):number} scoreFunction
|
|
9
9
|
* @returns {T|undefined}
|
|
10
10
|
*/
|
|
11
11
|
export function arrayPickBestElement(array, scoreFunction) {
|
|
@@ -23,7 +23,7 @@ export function arrayPickBestElement(array, scoreFunction) {
|
|
|
23
23
|
|
|
24
24
|
bestElement = array[0];
|
|
25
25
|
|
|
26
|
-
bestScore = scoreFunction(bestElement);
|
|
26
|
+
bestScore = scoreFunction(bestElement, 0);
|
|
27
27
|
|
|
28
28
|
assert.isNumber(bestScore, 'bestScore');
|
|
29
29
|
|
|
@@ -31,7 +31,7 @@ export function arrayPickBestElement(array, scoreFunction) {
|
|
|
31
31
|
const el = array[i];
|
|
32
32
|
|
|
33
33
|
// compute score
|
|
34
|
-
const score = scoreFunction(el);
|
|
34
|
+
const score = scoreFunction(el, i);
|
|
35
35
|
|
|
36
36
|
assert.isNumber(score, 'score');
|
|
37
37
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @template T
|
|
3
3
|
* @param {T[]} array
|
|
4
|
-
* @param {function(T):number} scoreFunction
|
|
4
|
+
* @param {function(el:T, index:number):number} scoreFunction
|
|
5
5
|
* @returns {T[]}
|
|
6
6
|
*/
|
|
7
|
-
export function arrayPickBestElements<T>(array: T[], scoreFunction:
|
|
7
|
+
export function arrayPickBestElements<T>(array: T[], scoreFunction: any): T[];
|
|
8
8
|
//# sourceMappingURL=arrayPickBestElements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayPickBestElements.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/arrayPickBestElements.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"arrayPickBestElements.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/arrayPickBestElements.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,8EA0CC"}
|
|
@@ -3,7 +3,7 @@ import { assert } from "../../assert.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @template T
|
|
5
5
|
* @param {T[]} array
|
|
6
|
-
* @param {function(T):number} scoreFunction
|
|
6
|
+
* @param {function(el:T, index:number):number} scoreFunction
|
|
7
7
|
* @returns {T[]}
|
|
8
8
|
*/
|
|
9
9
|
export function arrayPickBestElements(array, scoreFunction) {
|
|
@@ -22,7 +22,7 @@ export function arrayPickBestElements(array, scoreFunction) {
|
|
|
22
22
|
|
|
23
23
|
const first = array[0];
|
|
24
24
|
|
|
25
|
-
bestScore = scoreFunction(first);
|
|
25
|
+
bestScore = scoreFunction(first, 0);
|
|
26
26
|
|
|
27
27
|
assert.isNumber(bestScore, 'bestScore');
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ export function arrayPickBestElements(array, scoreFunction) {
|
|
|
32
32
|
const el = array[i];
|
|
33
33
|
|
|
34
34
|
// compute score
|
|
35
|
-
const score = scoreFunction(el);
|
|
35
|
+
const score = scoreFunction(el, i);
|
|
36
36
|
|
|
37
37
|
assert.isNumber(score, 'score');
|
|
38
38
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_deduplicate.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/array_deduplicate.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,sDAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_deduplicate.spec.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/array_deduplicate.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { array_deduplicate } from "./array_deduplicate.js";
|
|
2
|
+
|
|
3
|
+
test("basics", () => {
|
|
4
|
+
expect(array_deduplicate([])).toEqual([]);
|
|
5
|
+
expect(array_deduplicate([1])).toEqual([1]);
|
|
6
|
+
expect(array_deduplicate([1, 2])).toEqual([1, 2]);
|
|
7
|
+
expect(array_deduplicate([1, 2, 2])).toEqual([1, 2]);
|
|
8
|
+
expect(array_deduplicate([1, 2, 1])).toEqual([1, 2]);
|
|
9
|
+
expect(array_deduplicate([1, 1, 2])).toEqual([1, 2]);
|
|
10
|
+
expect(array_deduplicate([1, 2])).toEqual([1, 2]);
|
|
11
|
+
});
|
|
@@ -209,7 +209,7 @@ test("add 3 element and remove in same order, expect grid to be empty", () => {
|
|
|
209
209
|
expect(grid.is_cell_empty(1, 1)).toBe(true);
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
test("performance, insertion 1m random", () => {
|
|
212
|
+
test.skip("performance, insertion 1m random", () => {
|
|
213
213
|
const grid = new SpatialHashGrid(100, 100, 1);
|
|
214
214
|
|
|
215
215
|
const random = seededRandom(42);
|
|
@@ -3,7 +3,7 @@ import { seededRandom } from "../../../math/random/seededRandom.js";
|
|
|
3
3
|
import { shg_query_elements_circle } from "./shg_query_elements_circle.js";
|
|
4
4
|
import { SpatialHashGrid } from "./SpatialHashGrid.js";
|
|
5
5
|
|
|
6
|
-
test("performance, 10k objects, 1m queries", () => {
|
|
6
|
+
test.skip("performance, 10k objects, 1m queries", () => {
|
|
7
7
|
const OBJECT_COUNT = 30000;
|
|
8
8
|
const QUERY_COUNT = 1e6;
|
|
9
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeInstance.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeInstance.js"],"names":[],"mappings":"AAcA;IAEI
|
|
1
|
+
{"version":3,"file":"NodeInstance.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeInstance.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH;IAEI;;;;OAIG;IACH,aAFU,MAAM,CAEE;IAElB;;;OAGG;IACH,6BAAmB;IAEnB;;;OAGG;IACH,WAFU,yBAAyB,EAAE,CAEtB;IAEf;;;OAGG;IACH,gBAAgB;IAEhB;;;OAGG;IACH,qBAAmB;IAEnB;;;OAGG;IACH,aAFU,gBAAgB,CAED;IAEzB;;;;;;OAMG;IACH,wBAFU,MAAM,CAEE;IAElB;;OAEG;IACH;QACI;;;WAGG;mCADO,OAAO,MAAM,WAAO;QAG9B;;;WAGG;iCADO,OAAO,MAAM,MAAI;QAG3B;;;WAGG;mCADO,OAAO,MAAM,MAAI;QAI3B;;;;WAIG;qCADO,wCAAwC;MAGpD;IAEF;;;;;;OAMG;IACH,yBALW,MAAM,aACN,aAAa,UACb,YAAY,GACV,MAAM,CAsBlB;IAED;;;OAGG;IACH,gDAEC;IAED;;;OAGG;IACH,+CAEC;IAGD;;;OAGG;IACH,mCAEC;IAED;;;;OAIG;IACH,kCAEC;IAED;;;;OAIG;IACH,mBAHW,MAAM,oBAKhB;IAED;;;;OAIG;IACH,mBAHW,MAAM,OAKhB;IAED;;;;OAIG;IACH,yBAHW,MAAM,KAOhB;IAED;;;;OAIG;IACH,2BAHW,MAAM,oBAmChB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,OAAO,CAkBnB;IAED;;;OAGG;IACH,uCAQC;IAED,wBAIC;IAED;;;OAGG;IACH,mDAqCC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,yBAAyB,GAAC,SAAS,CAe/C;IAED,eAEC;IAED;;;;OAIG;IACH,cAHW,YAAY,GACV,OAAO,CAQnB;IAED,mBAEC;IAIL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;CAPpC;0CA3VyC,gCAAgC;iBAHzD,kCAAkC;mBAChC,kCAAkC;8BAGvB,oBAAoB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {assert} from "../../../assert.js";
|
|
2
|
-
import {isArrayEqual} from "../../../collection/array/isArrayEqual.js";
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
2
|
+
import { isArrayEqual } from "../../../collection/array/isArrayEqual.js";
|
|
3
3
|
import List from "../../../collection/list/List.js";
|
|
4
4
|
import Signal from "../../../events/signal/Signal.js";
|
|
5
|
-
import {objectDeepEquals} from "../../object/objectDeepEquals.js";
|
|
6
|
-
import {NodeInstancePortReference} from "./NodeInstancePortReference.js";
|
|
7
|
-
import {PortDirection} from "./PortDirection.js";
|
|
5
|
+
import { objectDeepEquals } from "../../object/objectDeepEquals.js";
|
|
6
|
+
import { NodeInstancePortReference } from "./NodeInstancePortReference.js";
|
|
7
|
+
import { PortDirection } from "./PortDirection.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
@@ -12,10 +12,16 @@ import {PortDirection} from "./PortDirection.js";
|
|
|
12
12
|
*/
|
|
13
13
|
let id_counter = 0;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Represents a node instance in a graph, its main purpose is to provide connection medium for the graph.
|
|
17
|
+
* A useful analogy is that of a "class" and an "object", there can be multiple instances (objects) of the same class. In this analogy `NodeInstance` is the object, and `NodeDescription` is a class.
|
|
18
|
+
* There can be multiple `NodeInstance`s referencing the same `NodeDescription`.
|
|
19
|
+
*/
|
|
15
20
|
export class NodeInstance {
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* Unique identifier
|
|
24
|
+
* @readonly
|
|
19
25
|
* @type {number}
|
|
20
26
|
*/
|
|
21
27
|
id = id_counter++;
|
|
@@ -78,6 +84,13 @@ export class NodeInstance {
|
|
|
78
84
|
* @type {Signal<string, *>}
|
|
79
85
|
*/
|
|
80
86
|
parameterRemoved: new Signal(),
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* fires: (newDescription:NodeDescription, oldDescription:NodeDescription|null)
|
|
90
|
+
* @readonly
|
|
91
|
+
* @type {Signal<NodeDescription, NodeDescription>}
|
|
92
|
+
*/
|
|
93
|
+
descriptionChanged: new Signal()
|
|
81
94
|
};
|
|
82
95
|
|
|
83
96
|
/**
|
|
@@ -256,32 +269,45 @@ export class NodeInstance {
|
|
|
256
269
|
|
|
257
270
|
/**
|
|
258
271
|
*
|
|
259
|
-
* @param {NodeDescription}
|
|
272
|
+
* @param {NodeDescription} description
|
|
260
273
|
*/
|
|
261
|
-
setDescription(
|
|
262
|
-
|
|
274
|
+
setDescription(description) {
|
|
275
|
+
assert.defined(description, 'description');
|
|
276
|
+
assert.isObject(description, 'description');
|
|
277
|
+
assert.equal(description.isNodeDescription, true, 'description.isNodeDescription !== true');
|
|
263
278
|
|
|
264
|
-
|
|
279
|
+
if (!this.connections.isEmpty()) {
|
|
280
|
+
throw new Error("Node is has connections, can only change description for unconnected nodes");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const old_description = this.description;
|
|
284
|
+
|
|
285
|
+
this.description = description;
|
|
286
|
+
|
|
287
|
+
description.configureNode(this);
|
|
265
288
|
|
|
266
289
|
//generate endpoints
|
|
267
|
-
this.endpoints =
|
|
268
|
-
|
|
290
|
+
this.endpoints = description.getPorts()
|
|
291
|
+
.map((port, port_index) => {
|
|
292
|
+
const endpoint = new NodeInstancePortReference();
|
|
269
293
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
294
|
+
endpoint.id = port_index;
|
|
295
|
+
endpoint.port = port;
|
|
296
|
+
endpoint.instance = this;
|
|
273
297
|
|
|
274
|
-
|
|
275
|
-
|
|
298
|
+
return endpoint;
|
|
299
|
+
});
|
|
276
300
|
|
|
277
301
|
//clear parameters
|
|
278
302
|
this.clearParameters();
|
|
279
303
|
|
|
280
304
|
// TODO address parameters in NodeDescription as well
|
|
281
305
|
//populate parameter defaults
|
|
282
|
-
|
|
306
|
+
description.parameters.forEach(pd => {
|
|
283
307
|
this.parameters[pd.id] = pd.defaultValue;
|
|
284
308
|
});
|
|
309
|
+
|
|
310
|
+
this.on.descriptionChanged.send2(description, old_description);
|
|
285
311
|
}
|
|
286
312
|
|
|
287
313
|
/**
|
|
@@ -322,7 +348,7 @@ export class NodeInstance {
|
|
|
322
348
|
}
|
|
323
349
|
|
|
324
350
|
toString() {
|
|
325
|
-
return `NodeInstance{ id = ${this.id}, description = ${this.description
|
|
351
|
+
return `NodeInstance{ id = ${this.id}, description = ${this.description?.id} }`
|
|
326
352
|
}
|
|
327
353
|
}
|
|
328
354
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { randomIntegerBetween } from "../../../../core/math/random/randomIntegerBetween.js";
|
|
1
2
|
import { seededRandom } from "../../../../core/math/random/seededRandom.js";
|
|
2
3
|
import { HarmonicDiffusionGrid } from "./HarmonicDiffusionGrid.js";
|
|
3
|
-
import { randomIntegerBetween } from "../../../../core/math/random/randomIntegerBetween.js";
|
|
4
4
|
|
|
5
5
|
test("constructor doesn't throw", () => {
|
|
6
6
|
new HarmonicDiffusionGrid([], 0, 0);
|
|
@@ -77,7 +77,7 @@ test("20 step 4x1, corners assigned", () => {
|
|
|
77
77
|
expect(grid.data[3]).toBe(-7);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
test("performance 512x512", () => {
|
|
80
|
+
test.skip("performance 512x512", () => {
|
|
81
81
|
const w = 139;
|
|
82
82
|
const h = 139;
|
|
83
83
|
|