@woosh/meep-engine 2.81.3 → 2.82.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.
Files changed (110) hide show
  1. package/build/meep.cjs +4392 -4420
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +4392 -4420
  4. package/editor/ecs/component/editors/primitive/ArrayEditor.js +2 -2
  5. package/editor/enableEditor.js +1 -1
  6. package/editor/view/EditorView.js +25 -25
  7. package/editor/view/ecs/components/particles/ParticleEmitterController.js +11 -11
  8. package/editor/view/node-graph/NodeView.js +7 -7
  9. package/package.json +1 -1
  10. package/samples/terrain/editor.js +19 -18
  11. package/src/core/cache/Cache.js +4 -2
  12. package/src/core/cache/Cache.spec.js +1 -1
  13. package/src/core/collection/array/arraySetDiff.js +8 -2
  14. package/src/core/collection/array/computeHashArray.js +5 -0
  15. package/src/core/collection/array/groupArrayBy.js +1 -1
  16. package/src/core/collection/array/weightedRandomFromArray.spec.js +3 -1
  17. package/src/core/collection/heap/FastBinaryHeap.spec.js +3 -2
  18. package/src/core/collection/list/List.js +8 -17
  19. package/src/core/collection/list/List.spec.js +55 -0
  20. package/src/core/collection/map/HashMap.spec.js +3 -1
  21. package/src/core/collection/set/HashSet.spec.js +23 -0
  22. package/src/core/collection/table/RowFirstTableSpec.js +44 -30
  23. package/src/core/events/signal/signal_aggregate_by_time_window.js +1 -1
  24. package/src/core/fsm/simple/SimpleStateMachine.js +2 -1
  25. package/src/core/function/chain.js +19 -0
  26. package/src/core/function/makeReturnValue.js +8 -0
  27. package/src/core/function/noop.js +6 -0
  28. package/src/core/function/objectsEqual.js +14 -0
  29. package/src/core/function/passThrough.js +9 -0
  30. package/src/core/function/returnEmptyArray.js +7 -0
  31. package/src/core/function/returnFalse.js +7 -0
  32. package/src/core/function/returnOne.js +7 -0
  33. package/src/core/function/returnTrue.js +7 -0
  34. package/src/core/function/returnZero.js +7 -0
  35. package/src/core/function/strictEquals.js +10 -0
  36. package/src/core/geom/3d/tetrahedra/validate_tetrahedral_mesh.js +2 -2
  37. package/src/core/geom/3d/topology/struct/prototypeBinaryTopology.js +5 -4
  38. package/src/core/lang/reactive/AbstractCachingParser.js +2 -1
  39. package/src/core/math/random/randomFloatBetween.spec.js +2 -1
  40. package/src/core/math/random/randomIntegerBetween.spec.js +2 -1
  41. package/src/core/model/node-graph/Connection.js +2 -1
  42. package/src/core/model/node-graph/node/parameter/NodeParameterDescription.js +2 -2
  43. package/src/core/model/object/ObjectPoolFactory.js +2 -1
  44. package/src/core/model/stat/Stat.js +4 -4
  45. package/src/core/process/PromiseWatcher.spec.js +1 -1
  46. package/src/core/process/task/Task.js +2 -1
  47. package/src/engine/EngineHarness.js +2 -1
  48. package/src/engine/achievements/gateway/StorageAchievementGateway.js +1 -1
  49. package/src/engine/asset/AssetManager.js +14 -14
  50. package/src/engine/asset/loaders/ArrayBufferLoader.js +1 -1
  51. package/src/engine/ecs/EntityComponentDataset.spec.js +2 -2
  52. package/src/engine/ecs/EntityManager.js +2 -1
  53. package/src/engine/ecs/EntityObserver.spec.js +4 -4
  54. package/src/engine/ecs/System.js +2 -2
  55. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
  56. package/src/engine/ecs/ik/IKProblem.js +1 -1
  57. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +2 -1
  58. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +2 -1
  59. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -1
  60. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +2 -1
  61. package/src/engine/ecs/terrain/util/obtainTerrain.js +1 -1
  62. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +3 -3
  63. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -1
  64. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +7 -7
  65. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -1
  66. package/src/engine/graphics/material/SplatMaterial.js +1 -15
  67. package/src/engine/graphics/render/layers/RenderLayer.js +1 -1
  68. package/src/engine/graphics/render/utils/ThreeBypassRenderer.js +2 -1
  69. package/src/engine/graphics/render/visibility/VisibilityFilter.js +2 -1
  70. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -1
  71. package/src/engine/graphics/texture/atlas/ManagedTextureAtlas.js +5 -5
  72. package/src/engine/graphics/texture/cubemap/load_environment_map.js +2 -2
  73. package/src/engine/graphics/texture/makeOnePixelTexture.js +5 -3
  74. package/src/engine/graphics/texture/virtual/VirtualTexturePage.js +2 -1
  75. package/src/engine/graphics/texture/whitePixelTexture.js +9 -0
  76. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.spec.js +5 -5
  77. package/src/engine/intelligence/blackboard/BlackboardDynamicStorageAdapter.js +3 -3
  78. package/src/engine/intelligence/mcts/MonteCarlo.js +3 -3
  79. package/src/engine/knowledge/database/StaticKnowledgeDataTable.js +3 -3
  80. package/src/engine/network/PriorityFetch.js +2 -2
  81. package/src/engine/options/Option.js +2 -2
  82. package/src/engine/options/Option.spec.js +1 -1
  83. package/src/engine/options/OptionGroup.js +2 -2
  84. package/src/engine/options/OptionGroup.spec.js +2 -2
  85. package/src/engine/save/Storage.js +2 -1
  86. package/src/engine/save/StorageBackedList.js +2 -1
  87. package/src/engine/save/storage/InMemoryStorage.js +2 -2
  88. package/src/engine/scene/transitionToScene.js +2 -1
  89. package/src/engine/sound/ecs/SoundListenerSystem.js +7 -7
  90. package/src/engine/sound/ecs/emitter/loadSoundTrackAsset.js +3 -3
  91. package/src/engine/ui/DraggableAspect.js +2 -2
  92. package/src/engine/ui/GUIEngine.js +17 -17
  93. package/src/engine/ui/notification/AnimatedObjectEmitter.js +3 -3
  94. package/src/engine/ui/notification/NotificationManager.js +4 -4
  95. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +9 -9
  96. package/src/generation/grid/generation/util/buildPathFromDistanceMap.js +1 -1
  97. package/src/generation/markers/actions/util/GridCellActionDebugBreak.js +1 -1
  98. package/src/view/common/LabelView.js +9 -9
  99. package/src/view/common/ListView.js +3 -2
  100. package/src/view/common/VirtualListView.js +7 -6
  101. package/src/view/common/dnd/DropTarget.js +2 -2
  102. package/src/view/elements/DropDownSelectionView.js +2 -2
  103. package/src/view/elements/image/ImageView.js +4 -4
  104. package/src/view/elements/progress/SmoothProgressBar.js +4 -4
  105. package/src/view/elements/radial/RadialMenuElementDefinition.js +1 -1
  106. package/src/view/elements/tiles2d/TileGrid.js +8 -8
  107. package/src/view/elements/video/VideoView.js +5 -5
  108. package/src/view/math/FunctionGraphView.js +1 -1
  109. package/src/view/tooltip/gml/TooltipParser.js +6 -5
  110. package/src/core/function/Functions.js +0 -103
@@ -1,9 +1,9 @@
1
- import { TypeEditor } from "../../TypeEditor.js";
2
1
  import List from "../../../../../src/core/collection/list/List.js";
2
+ import { noop } from "../../../../../src/core/function/noop.js";
3
3
  import { FieldDescriptor } from "../../FieldDescriptor.js";
4
4
  import { FieldValueAdapter } from "../../FieldValueAdapter.js";
5
+ import { TypeEditor } from "../../TypeEditor.js";
5
6
  import { ListEditor } from "../collection/ListEditor.js";
6
- import { noop } from "../../../../../src/core/function/Functions.js";
7
7
 
8
8
  export class ArrayEditor extends TypeEditor {
9
9
  inline = false;
@@ -1,5 +1,5 @@
1
+ import { noop } from "../src/core/function/noop.js";
1
2
  import Editor from "./Editor.js";
2
- import { noop } from "../src/core/function/Functions.js";
3
3
 
4
4
  /**
5
5
  *
@@ -3,38 +3,38 @@
3
3
  */
4
4
 
5
5
 
6
- import View from "../../src/view/View.js";
6
+ import { passThrough } from "../../src/core/function/passThrough.js";
7
+ import { SurfacePoint3 } from "../../src/core/geom/3d/SurfacePoint3.js";
8
+ import Vector2 from "../../src/core/geom/Vector2.js";
9
+ import Vector3 from "../../src/core/geom/Vector3.js";
10
+ import { ProcessState } from "../../src/core/process/ProcessState.js";
11
+ import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
12
+ import { Transform } from "../../src/engine/ecs/transform/Transform.js";
13
+ import Mesh from "../../src/engine/graphics/ecs/mesh/Mesh.js";
14
+ import { MeshEvents } from "../../src/engine/graphics/ecs/mesh/MeshEvents.js";
15
+ import { make_ray_from_viewport_position } from "../../src/engine/graphics/make_ray_from_viewport_position.js";
16
+ import LabelView from '../../src/view/common/LabelView.js';
17
+ import ListView from "../../src/view/common/ListView.js";
18
+ import VirtualListView from '../../src/view/common/VirtualListView.js';
7
19
  import dom from "../../src/view/DOM.js";
20
+ import BottomLeftResizeHandleView from "../../src/view/elements/BottomLeftResizeHandleView.js";
8
21
 
9
- import EntityListView from './ecs/EntityList.js';
10
- import EntityEditorView from './ecs/EntityEditor.js';
22
+ import SimpleWindow from '../../src/view/elements/SimpleWindow.js';
23
+ import View from "../../src/view/View.js";
24
+ import ComponentAddAction from "../actions/concrete/ComponentAddAction.js";
25
+ import EntityCreateAction from "../actions/concrete/EntityCreateAction.js";
26
+ import SelectionAddAction from "../actions/concrete/SelectionAddAction.js";
27
+ import SelectionClearAction from "../actions/concrete/SelectionClearAction.js";
11
28
  import ComponentControlFactory from './ecs/ComponentControlFactory.js';
12
- import VirtualListView from '../../src/view/common/VirtualListView.js';
13
- import LabelView from '../../src/view/common/LabelView.js';
14
- import ToolView from './tools/ToolView.js';
29
+ import EntityEditorView from './ecs/EntityEditor.js';
15
30
 
16
- import SimpleWindow from '../../src/view/elements/SimpleWindow.js';
17
- import ToolSettingsView from "./tools/ToolSettingsView.js";
31
+ import EntityListView from './ecs/EntityList.js';
18
32
  import GridPickCoordinateView from "./GridPickCoordinateView.js";
19
- import ListView from "../../src/view/common/ListView.js";
20
- import ProcessView from "./process/ProcessView.js";
21
33
  import MeshLibraryView from "./library/MeshLibraryView.js";
22
- import BottomLeftResizeHandleView from "../../src/view/elements/BottomLeftResizeHandleView.js";
23
- import Vector2 from "../../src/core/geom/Vector2.js";
24
- import Vector3 from "../../src/core/geom/Vector3.js";
25
- import Mesh from "../../src/engine/graphics/ecs/mesh/Mesh.js";
26
- import { Transform } from "../../src/engine/ecs/transform/Transform.js";
27
- import SelectionClearAction from "../actions/concrete/SelectionClearAction.js";
28
- import EntityCreateAction from "../actions/concrete/EntityCreateAction.js";
29
- import ComponentAddAction from "../actions/concrete/ComponentAddAction.js";
30
- import SelectionAddAction from "../actions/concrete/SelectionAddAction.js";
31
- import { passThrough } from "../../src/core/function/Functions.js";
32
- import { ProcessState } from "../../src/core/process/ProcessState.js";
33
- import { MeshEvents } from "../../src/engine/graphics/ecs/mesh/MeshEvents.js";
34
- import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
35
- import { SurfacePoint3 } from "../../src/core/geom/3d/SurfacePoint3.js";
36
- import { make_ray_from_viewport_position } from "../../src/engine/graphics/make_ray_from_viewport_position.js";
37
34
  import { makeEntityDecorators } from "./makeEntityDecorators.js";
35
+ import ProcessView from "./process/ProcessView.js";
36
+ import ToolSettingsView from "./tools/ToolSettingsView.js";
37
+ import ToolView from './tools/ToolView.js';
38
38
 
39
39
 
40
40
  class ViewManager extends View {
@@ -1,20 +1,20 @@
1
- import DatGuiController from "../DatGuiController.js";
2
- import { BlendingType } from "../../../../../src/engine/graphics/texture/sampler/BlendingType.js";
3
- import { ParticleLayer } from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js";
4
- import ParticleLayerController from "./ParticleLayerController.js";
1
+ import { noop } from "../../../../../src/core/function/noop.js";
2
+ import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
5
3
  import {
6
4
  ParticleEmitterFlag
7
5
  } from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js";
8
- import { NativeListController } from "../../../../../src/view/controller/controls/NativeListController.js";
9
- import EmptyView from "../../../../../src/view/elements/EmptyView.js";
10
- import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
11
- import { noop } from "../../../../../src/core/function/Functions.js";
12
- import {
13
- SimulationStepType
14
- } from "../../../../../src/engine/graphics/particles/particular/engine/simulator/SimulationStepType.js";
6
+ import { ParticleLayer } from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js";
15
7
  import {
16
8
  SimulationStepDefinition
17
9
  } from "../../../../../src/engine/graphics/particles/particular/engine/simulator/SimulationStepDefinition.js";
10
+ import {
11
+ SimulationStepType
12
+ } from "../../../../../src/engine/graphics/particles/particular/engine/simulator/SimulationStepType.js";
13
+ import { BlendingType } from "../../../../../src/engine/graphics/texture/sampler/BlendingType.js";
14
+ import { NativeListController } from "../../../../../src/view/controller/controls/NativeListController.js";
15
+ import EmptyView from "../../../../../src/view/elements/EmptyView.js";
16
+ import DatGuiController from "../DatGuiController.js";
17
+ import ParticleLayerController from "./ParticleLayerController.js";
18
18
 
19
19
 
20
20
  /**
@@ -1,13 +1,13 @@
1
- import View from "../../../src/view/View.js";
2
- import { PortView } from "./PortView.js";
3
- import EmptyView from "../../../src/view/elements/EmptyView.js";
4
- import LabelView from "../../../src/view/common/LabelView.js";
5
- import { DraggableAspect } from "../../../src/engine/ui/DraggableAspect.js";
1
+ import { noop } from "../../../src/core/function/noop.js";
6
2
  import Vector2 from "../../../src/core/geom/Vector2.js";
7
- import { noop } from "../../../src/core/function/Functions.js";
8
3
  import { NodeParameterDataType } from "../../../src/core/model/node-graph/node/parameter/NodeParameterDataType.js";
9
- import DatGuiController from "../ecs/components/DatGuiController.js";
10
4
  import { PortDirection } from "../../../src/core/model/node-graph/node/PortDirection.js";
5
+ import { DraggableAspect } from "../../../src/engine/ui/DraggableAspect.js";
6
+ import LabelView from "../../../src/view/common/LabelView.js";
7
+ import EmptyView from "../../../src/view/elements/EmptyView.js";
8
+ import View from "../../../src/view/View.js";
9
+ import DatGuiController from "../ecs/components/DatGuiController.js";
10
+ import { PortView } from "./PortView.js";
11
11
 
12
12
  export class NodeView extends View {
13
13
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.81.3",
8
+ "version": "2.82.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,27 +1,28 @@
1
- import { EngineHarness } from "../../src/engine/EngineHarness.js";
2
- import EmptyView from "../../src/view/elements/EmptyView.js";
3
- import { EngineConfiguration } from "../../src/engine/EngineConfiguration.js";
4
- import { ArrayBufferLoader } from "../../src/engine/asset/loaders/ArrayBufferLoader.js";
5
- import { TerrainFlags } from "../../src/engine/ecs/terrain/ecs/TerrainFlags.js";
6
- import Signal from "../../src/core/events/signal/Signal.js";
7
- import { NativeListController } from "../../src/view/controller/controls/NativeListController.js";
8
- import { TerrainLayer } from "../../src/engine/ecs/terrain/ecs/layers/TerrainLayer.js";
9
- import CheckersTextureURI from "../../src/engine/graphics/texture/CheckersTextureURI.js";
10
- import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
11
- import { Cache } from "../../src/core/cache/Cache.js";
12
- import { computeStringHash } from "../../src/core/primitives/strings/computeStringHash.js";
13
- import { noop, strictEquals } from "../../src/core/function/Functions.js";
14
- import { sampler2d_scale } from "../../src/engine/graphics/texture/sampler/resize/sampler2d_scale.js";
15
- import { Sampler2D } from "../../src/engine/graphics/texture/sampler/Sampler2D.js";
16
1
  import { BinaryDataType } from "../../src/core/binary/type/BinaryDataType.js";
17
2
  import {
18
3
  compute_typed_array_constructor_from_data_type
19
4
  } from "../../src/core/binary/type/DataType2TypedArrayConstructorMapping.js";
20
- import { copy_Sampler2D_channel_data } from "../../src/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js";
5
+ import { Cache } from "../../src/core/cache/Cache.js";
6
+ import Signal from "../../src/core/events/signal/Signal.js";
7
+ import { noop } from "../../src/core/function/noop.js";
8
+ import { strictEquals } from "../../src/core/function/strictEquals.js";
9
+ import { computeStringHash } from "../../src/core/primitives/strings/computeStringHash.js";
10
+ import { ArrayBufferLoader } from "../../src/engine/asset/loaders/ArrayBufferLoader.js";
21
11
  import { TextureAssetLoader } from "../../src/engine/asset/loaders/texture/TextureAssetLoader.js";
22
- import { CanvasView } from "../../src/view/elements/CanvasView.js";
23
- import convertSampler2D2Canvas from "../../src/engine/graphics/texture/sampler/Sampler2D2Canvas.js";
12
+ import { TerrainLayer } from "../../src/engine/ecs/terrain/ecs/layers/TerrainLayer.js";
13
+ import { TerrainFlags } from "../../src/engine/ecs/terrain/ecs/TerrainFlags.js";
14
+ import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
15
+ import { EngineConfiguration } from "../../src/engine/EngineConfiguration.js";
16
+ import { EngineHarness } from "../../src/engine/EngineHarness.js";
24
17
  import { load_and_set_cubemap_v0 } from "../../src/engine/graphics/load_and_set_cubemap_v0.js";
18
+ import CheckersTextureURI from "../../src/engine/graphics/texture/CheckersTextureURI.js";
19
+ import { copy_Sampler2D_channel_data } from "../../src/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js";
20
+ import { sampler2d_scale } from "../../src/engine/graphics/texture/sampler/resize/sampler2d_scale.js";
21
+ import { Sampler2D } from "../../src/engine/graphics/texture/sampler/Sampler2D.js";
22
+ import convertSampler2D2Canvas from "../../src/engine/graphics/texture/sampler/Sampler2D2Canvas.js";
23
+ import { NativeListController } from "../../src/view/controller/controls/NativeListController.js";
24
+ import { CanvasView } from "../../src/view/elements/CanvasView.js";
25
+ import EmptyView from "../../src/view/elements/EmptyView.js";
25
26
 
26
27
  const engineHarness = new EngineHarness();
27
28
 
@@ -1,9 +1,11 @@
1
1
  import { assert } from "../assert.js";
2
+ import { collectIteratorValueToArray } from "../collection/collectIteratorValueToArray.js";
2
3
  import { HashMap } from "../collection/map/HashMap.js";
3
4
  import Signal from "../events/signal/Signal.js";
4
- import { returnOne, returnZero, strictEquals } from "../function/Functions.js";
5
+ import { returnOne } from "../function/returnOne.js";
6
+ import { returnZero } from "../function/returnZero.js";
7
+ import { strictEquals } from "../function/strictEquals.js";
5
8
  import { CacheElement } from "./CacheElement.js";
6
- import { collectIteratorValueToArray } from "../collection/collectIteratorValueToArray.js";
7
9
 
8
10
  // TODO validate hashes of held elements to keep them up to date. Keys are assumed to be immutable, but this assumption may be broken by users
9
11
 
@@ -1,6 +1,6 @@
1
1
  import { jest } from "@jest/globals";
2
+ import { returnOne } from "../function/returnOne.js";
2
3
  import { Cache } from "./Cache.js";
3
- import { returnOne } from "../function/Functions.js";
4
4
 
5
5
  test("constructor doesn't throw", () => {
6
6
  new Cache({});
@@ -1,5 +1,7 @@
1
- import {strictEquals} from "../../function/Functions.js";
2
- import {arrayIndexByEquality} from "./arrayIndexByEquality.js";
1
+ import { assert } from "../../assert.js";
2
+
3
+ import { strictEquals } from "../../function/strictEquals.js";
4
+ import { arrayIndexByEquality } from "./arrayIndexByEquality.js";
3
5
 
4
6
  /**
5
7
  * Compute a diff between two arrays, result is a 3 way split between common items, unique items in `a` array and unique items in `b` array
@@ -10,6 +12,10 @@ import {arrayIndexByEquality} from "./arrayIndexByEquality.js";
10
12
  * @returns {{uniqueA:T[], uniqueB:T[], common:T[]}}
11
13
  */
12
14
  export function arraySetDiff(a, b, equals = strictEquals) {
15
+ assert.isArray(a, 'a');
16
+ assert.isArray(b, 'b');
17
+ assert.isFunction(equals, 'equals');
18
+
13
19
  // TODO we can do this faster if we use a comparator instead of equality and pre-sort the data
14
20
  const uniqueA = a.slice();
15
21
  const uniqueB = b.slice();
@@ -1,9 +1,14 @@
1
+ import { assert } from "../../assert.js";
2
+
1
3
  /**
2
4
  * @template T
3
5
  * @param {T[]} array
4
6
  * @param {function(T):number} elementHashFunction
7
+ * @returns {number}
5
8
  */
6
9
  export function computeHashArray(array, elementHashFunction) {
10
+ assert.isArrayLike(array, 'array');
11
+ assert.isFunction(elementHashFunction, 'elementHashFunction');
7
12
 
8
13
  const numArguments = array.length;
9
14
  let hash = numArguments;
@@ -1,4 +1,4 @@
1
- import { returnZero } from "../../function/Functions.js";
1
+ import { returnZero } from "../../function/returnZero.js";
2
2
  import { HashMap } from "../map/HashMap.js";
3
3
 
4
4
  /**
@@ -1,5 +1,7 @@
1
+ import { passThrough } from "../../function/passThrough.js";
2
+ import { returnOne } from "../../function/returnOne.js";
3
+ import { returnZero } from "../../function/returnZero.js";
1
4
  import { weightedRandomFromArray } from "./weightedRandomFromArray.js";
2
- import { passThrough, returnOne, returnZero } from "../../function/Functions.js";
3
5
 
4
6
  test("empty array", () => {
5
7
  expect(weightedRandomFromArray([], returnZero, passThrough, null, 0))
@@ -1,7 +1,8 @@
1
+ import { passThrough } from "../../function/passThrough.js";
2
+ import { returnZero } from "../../function/returnZero.js";
3
+ import { randomIntegerBetween } from "../../math/random/randomIntegerBetween.js";
1
4
  import { seededRandom } from "../../math/random/seededRandom.js";
2
5
  import BinaryHeap from "./FastBinaryHeap.js";
3
- import { passThrough, returnZero } from "../../function/Functions.js";
4
- import { randomIntegerBetween } from "../../math/random/randomIntegerBetween.js";
5
6
 
6
7
  test("constructor doesn't throw", () => {
7
8
  new BinaryHeap(returnZero);
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { assert } from "../../assert.js";
7
7
  import Signal from "../../events/signal/Signal.js";
8
+ import { objectsEqual } from "../../function/objectsEqual.js";
8
9
  import { invokeObjectEquals } from "../../model/object/invokeObjectEquals.js";
9
10
  import { arrayIndexByEquality } from "../array/arrayIndexByEquality.js";
10
11
  import { arraySetDiff } from "../array/arraySetDiff.js";
@@ -190,13 +191,13 @@ class List {
190
191
  * Replace the data, replacements is performed surgically, meaning that diff is computed and add/remove operations are performed on the set
191
192
  * This method is tailored to work well with visualisation as only elements that's missing from the new set is removed, and only elements that are new to are added
192
193
  * Conversely, relevant events are dispatched that can observe. This results in fewer changes required to the visualisation
193
- * @param {T[]} newOutput
194
+ * @param {T[]} new_data
194
195
  */
195
- patch(newOutput) {
196
+ patch(new_data) {
196
197
 
197
198
  const data = this.data;
198
199
 
199
- const diff = arraySetDiff(data, newOutput, invokeObjectEquals);
200
+ const diff = arraySetDiff(data, new_data, objectsEqual);
200
201
 
201
202
  //resolve diff
202
203
  const removals = diff.uniqueA;
@@ -213,8 +214,8 @@ class List {
213
214
 
214
215
  //sort additions by their position in the input
215
216
  additions.sort((a, b) => {
216
- const ai = this.indexOf(a);
217
- const bi = this.indexOf(b);
217
+ const ai = new_data.indexOf(a);
218
+ const bi = new_data.indexOf(b);
218
219
 
219
220
  return bi - ai;
220
221
  });
@@ -225,11 +226,11 @@ class List {
225
226
  const item = additions[i];
226
227
 
227
228
  //find where the item is in the input
228
- const inputIndex = this.indexOf(item);
229
+ const inputIndex = new_data.indexOf(item);
229
230
 
230
231
  let p = 0;
231
232
  for (let i = inputIndex - 1; i >= 0; i--) {
232
- const prev = this.get(i);
233
+ const prev = new_data[i];
233
234
 
234
235
  //look for previous item in the output
235
236
  const j = this.indexOf(prev);
@@ -949,16 +950,6 @@ class List {
949
950
  }
950
951
  }
951
952
 
952
- /**
953
- *
954
- * @param {Object} a
955
- * @param {Object} b
956
- * @returns {boolean}
957
- */
958
- function objectsEqual(a, b) {
959
- return a === b || (typeof a.equals === "function" && a.equals(b));
960
- }
961
-
962
953
  function conditionEqualsViaMethod(v) {
963
954
  return this === v || this.equals(v);
964
955
  }
@@ -94,6 +94,27 @@ test("'set' at the end of the list", () => {
94
94
  expect(addHandler).toHaveBeenLastCalledWith(42, 0);
95
95
  });
96
96
 
97
+ test("'set' replace existing value", () => {
98
+ const list = new List();
99
+
100
+ const fn = jest.fn();
101
+
102
+ list.on.removed.add(fn);
103
+
104
+ list.set(0, "a");
105
+
106
+ expect(fn).not.toHaveBeenCalled();
107
+
108
+ list.set(0, "b");
109
+
110
+ expect(list.length).toBe(1);
111
+
112
+ expect(list.get(0)).toBe("b");
113
+
114
+ expect(fn).toHaveBeenCalledTimes(1);
115
+ expect(fn).toHaveBeenCalledWith("a", 0);
116
+ });
117
+
97
118
  test("add increases length", () => {
98
119
  const list = new List();
99
120
 
@@ -200,3 +221,37 @@ test("map", () => {
200
221
 
201
222
  expect(list.map(a => a * 7)).toEqual([7, 14, 21]);
202
223
  });
224
+
225
+ test("patch", () => {
226
+
227
+ /**
228
+ *
229
+ * @type {List<number>}
230
+ */
231
+ const list = new List();
232
+
233
+ list.patch([]);
234
+
235
+ expect(list.asArray()).toEqual([]);
236
+ expect(list.length).toBe(0);
237
+
238
+ list.patch([1]);
239
+
240
+ expect(list.asArray()).toEqual([1]);
241
+ expect(list.length).toBe(1);
242
+
243
+ list.patch([1, 2]);
244
+
245
+ expect(list.asArray()).toEqual([1, 2]);
246
+ expect(list.length).toBe(2);
247
+
248
+ list.patch([3, 1, 2]);
249
+
250
+ expect(list.asArray()).toEqual([3, 1, 2]);
251
+ expect(list.length).toBe(3);
252
+
253
+ list.patch([3, 1, 2]);
254
+
255
+ expect(list.asArray()).toEqual([3, 1, 2]);
256
+ expect(list.length).toBe(3);
257
+ });
@@ -1,5 +1,7 @@
1
+ import { passThrough } from "../../function/passThrough.js";
2
+ import { returnOne } from "../../function/returnOne.js";
3
+ import { strictEquals } from "../../function/strictEquals.js";
1
4
  import { generate_next_linear_congruential_index, HashMap } from "./HashMap.js";
2
- import { passThrough, returnOne, strictEquals } from "../../function/Functions.js";
3
5
 
4
6
  /**
5
7
  *
@@ -0,0 +1,23 @@
1
+ import { strictEquals } from "../../function/strictEquals.js";
2
+ import { computeStringHash } from "../../primitives/strings/computeStringHash.js";
3
+ import { HashSet } from "./HashSet.js";
4
+
5
+ test("constructor", () => {
6
+ const set = new HashSet();
7
+ });
8
+
9
+ test("add same element twice", () => {
10
+
11
+ const set = new HashSet({
12
+ keyHashFunction: computeStringHash,
13
+ keyEqualityFunction: strictEquals
14
+ });
15
+
16
+ set.add("a");
17
+
18
+ expect(set.size).toBe(1);
19
+
20
+ set.add("a");
21
+
22
+ expect(set.size).toBe(1);
23
+ });
@@ -13,41 +13,43 @@ import { computeHashArray } from "../array/computeHashArray.js";
13
13
  import { isArrayEqualStrict } from "../array/isArrayEqualStrict.js";
14
14
 
15
15
  /**
16
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
16
17
  * @readonly
17
18
  * @enum {string}
18
19
  */
19
20
  export const DataType2DataViewReaders = {
20
- "uint8": "getUint8",
21
- "uint16": "getUint16",
22
- "uint32": "getUint32",
23
- "uint64": "getUint64",
24
-
25
- "int8": "getInt8",
26
- "int16": "getInt16",
27
- "int32": "getInt32",
28
- "int64": "getInt64",
29
-
30
- "float32": "getFloat32",
31
- "float64": "getFloat64"
21
+ [BinaryDataType.Uint8]: "getUint8",
22
+ [BinaryDataType.Uint16]: "getUint16",
23
+ [BinaryDataType.Uint32]: "getUint32",
24
+ [BinaryDataType.Uint64]: "getUint64",
25
+
26
+ [BinaryDataType.Int8]: "getInt8",
27
+ [BinaryDataType.Int16]: "getInt16",
28
+ [BinaryDataType.Int32]: "getInt32",
29
+ [BinaryDataType.Int64]: "getInt64",
30
+
31
+ [BinaryDataType.Float32]: "getFloat32",
32
+ [BinaryDataType.Float64]: "getFloat64"
32
33
  };
33
34
 
34
35
  /**
36
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
35
37
  * @readonly
36
38
  * @enum {string}
37
39
  */
38
40
  export const DataType2DataViewWriters = {
39
- "uint8": "setUint8",
40
- "uint16": "setUint16",
41
- "uint32": "setUint32",
42
- "uint64": "setUint64",
43
-
44
- "int8": "setInt8",
45
- "int16": "setInt16",
46
- "int32": "setInt32",
47
- "int64": "setInt64",
48
-
49
- "float32": "setFloat32",
50
- "float64": "setFloat64"
41
+ [BinaryDataType.Uint8]: "setUint8",
42
+ [BinaryDataType.Uint16]: "setUint16",
43
+ [BinaryDataType.Uint32]: "setUint32",
44
+ [BinaryDataType.Uint64]: "setUint64",
45
+
46
+ [BinaryDataType.Int8]: "setInt8",
47
+ [BinaryDataType.Int16]: "setInt16",
48
+ [BinaryDataType.Int32]: "setInt32",
49
+ [BinaryDataType.Int64]: "setInt64",
50
+
51
+ [BinaryDataType.Float32]: "setFloat32",
52
+ [BinaryDataType.Float64]: "setFloat64"
51
53
  };
52
54
 
53
55
  /**
@@ -67,10 +69,14 @@ function genRowReader(types, endianType = EndianType.BigEndian) {
67
69
 
68
70
  const type = types[i];
69
71
 
72
+ const reader_name = DataType2DataViewReaders[type];
73
+
74
+ assert.isString(reader_name, 'reader_name');
75
+
70
76
  const littleEndianFlag = endianType === EndianType.BigEndian ? 'false' : 'true';
71
77
 
72
78
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
73
- lines.push(`result[${i}] = dataView.${DataType2DataViewReaders[type]}(${offset} + byteOffset, ${littleEndianFlag});`);
79
+ lines.push(`result[${i}] = dataView.${reader_name}(${offset} + byteOffset, ${littleEndianFlag});`);
74
80
 
75
81
  offset += DataTypeByteSizes[type];
76
82
 
@@ -100,10 +106,14 @@ function genRowWriter(types, endianType = EndianType.BigEndian) {
100
106
  for (let i = 0; i < numTypes; i++) {
101
107
  const type = types[i];
102
108
 
109
+ const writer_name = DataType2DataViewWriters[type];
110
+
111
+ assert.isString(writer_name, 'writer_name');
112
+
103
113
  const littleEndianFlag = endianType === EndianType.BigEndian ? 'false' : 'true';
104
114
 
105
115
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
106
- lines.push(`dataView.${DataType2DataViewWriters[type]}(${offset} + byteOffset, record[${i}], ${littleEndianFlag});`);
116
+ lines.push(`dataView.${writer_name}(${offset} + byteOffset, record[${i}], ${littleEndianFlag});`);
107
117
 
108
118
  offset += DataTypeByteSizes[type];
109
119
  }
@@ -267,7 +277,7 @@ export class RowFirstTableSpec {
267
277
  }
268
278
 
269
279
  /**
270
- *
280
+ * Produces an immutable spec, either creates a new spec or retrieves a cached version
271
281
  * @param {BinaryDataType[]} types
272
282
  * @param {EndianType} [endianType]
273
283
  * @returns {RowFirstTableSpec}
@@ -276,21 +286,25 @@ export class RowFirstTableSpec {
276
286
  //compute hash
277
287
  const hash = types.join('.') + ':' + endianType;
278
288
 
279
- const cachedValue = cache.get(hash);
289
+ const cachedValue = SPEC_CACHE.get(hash);
280
290
 
281
291
  if (cachedValue !== null) {
282
292
  return cachedValue;
283
293
  }
284
294
 
285
295
  const newValue = new RowFirstTableSpec(types);
286
- cache.put(hash, newValue);
296
+ SPEC_CACHE.put(hash, newValue);
287
297
 
288
298
  return newValue;
289
299
  }
290
300
  }
291
301
 
292
302
 
293
- const cache = new Cache({
303
+ /**
304
+ * @readonly
305
+ * @type {Cache<string,RowFirstTableSpec>}
306
+ */
307
+ const SPEC_CACHE = new Cache({
294
308
  keyHashFunction: computeStringHash
295
309
  });
296
310
 
@@ -1,4 +1,4 @@
1
- import { passThrough } from "../../function/Functions.js";
1
+ import { passThrough } from "../../function/passThrough.js";
2
2
  import Signal from "./Signal.js";
3
3
 
4
4
  /**
@@ -1,6 +1,7 @@
1
1
  import { dispatchViaProxy, findSignalHandlerIndexByHandle } from "../../events/signal/Signal.js";
2
2
  import { SignalHandler } from "../../events/signal/SignalHandler.js";
3
- import { noop } from "../../function/Functions.js";
3
+
4
+ import { noop } from "../../function/noop.js";
4
5
  import { SimpleStateMachineDescription } from "./SimpleStateMachineDescription.js";
5
6
 
6
7
  export class SimpleStateMachine {
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * @param {...function} processes
4
+ * @returns {function(*): *}
5
+ */
6
+ export function chain(...processes) {
7
+ const numProcesses = processes.length;
8
+
9
+ return function chain(v) {
10
+ let result = v;
11
+
12
+ for (let i = 0; i < numProcesses; i++) {
13
+ const process = processes[i];
14
+ result = process(result);
15
+ }
16
+
17
+ return result;
18
+ }
19
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @template T
3
+ * @param {T} v
4
+ * @returns {function():T}
5
+ */
6
+ export function makeReturnValue(v) {
7
+ return () => v;
8
+ }