@woosh/meep-engine 2.50.2 → 2.51.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 (147) hide show
  1. package/README.md +4 -1
  2. package/editor/actions/concrete/WriteGridValueAction.js +13 -18
  3. package/editor/ecs/component/editors/Sampler2DEditor.js +2 -2
  4. package/editor/process/SymbolicDisplayProcess.js +1 -1
  5. package/editor/process/symbolic/buildThreeJSHelperEntity.js +1 -1
  6. package/editor/process/symbolic/makeCameraSymbolicDisplay.js +1 -1
  7. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  8. package/editor/process/symbolic/makeLightSymbolicDisplay.js +1 -1
  9. package/editor/process/symbolic/makePathSymbolicDisplay.js +1 -1
  10. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +1 -1
  11. package/editor/view/ecs/components/GridObstacleController.js +2 -2
  12. package/editor/view/ecs/components/TerrainController.js +2 -2
  13. package/package.json +1 -1
  14. package/samples/terrain/editor.js +2 -2
  15. package/src/core/UUID.spec.js +8 -0
  16. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.d.ts +4 -0
  17. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +57 -55
  18. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +54 -0
  19. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +3 -3
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +60 -0
  21. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +2 -2
  22. package/src/core/cache/Cache.d.ts +4 -0
  23. package/src/core/cache/Cache.js +32 -18
  24. package/src/core/cache/Cache.spec.js +33 -0
  25. package/src/core/cache/CacheElement.js +1 -0
  26. package/src/core/cache/FrequencySketch.js +26 -23
  27. package/src/core/cache/FrequencySketch.spec.js +5 -0
  28. package/src/core/cache/LoadingCache.d.ts +2 -0
  29. package/src/core/cache/LoadingCache.js +16 -7
  30. package/src/core/cache/LoadingCache.spec.js +24 -0
  31. package/src/core/collection/HashMap.d.ts +2 -0
  32. package/src/core/collection/HashMap.spec.js +51 -2
  33. package/src/core/collection/list/List.d.ts +13 -1
  34. package/src/core/collection/list/List.js +702 -684
  35. package/src/core/collection/list/List.spec.js +93 -0
  36. package/src/core/collection/map/AsyncLoadingCache.js +1 -0
  37. package/src/core/fsm/simple/SimpleStateMachine.js +23 -22
  38. package/src/core/function/extractFunctionBody.spec.js +15 -0
  39. package/src/core/geom/2d/convex-hull/convex_hull_monotone_2d.js +69 -33
  40. package/src/core/geom/2d/convex-hull/convex_hull_monotone_2d.spec.js +33 -0
  41. package/src/core/geom/2d/convex-hull/orientation3.js +55 -10
  42. package/src/core/geom/2d/quad-tree/PointQuadTree.js +10 -0
  43. package/src/core/geom/3d/aabb/aabb3_array_combine.js +3 -3
  44. package/src/core/graph/{convertGraphToDotString.js → convert_graph_to_dot_string.js} +1 -1
  45. package/src/core/graph/convert_graph_to_dot_string.spec.js +28 -0
  46. package/src/core/math/noise/sdnoise.js +5 -7
  47. package/src/core/math/noise/sdnoise.spec.js +87 -0
  48. package/src/core/process/matcher/Matchers.js +1 -1
  49. package/src/engine/asset/loaders/image/png/PNG.spec.js +5 -0
  50. package/src/engine/asset/loaders/image/png/PNGReader.spec.js +5 -0
  51. package/src/engine/asset/loaders/image/png/crc.spec.js +15 -0
  52. package/src/engine/{Platform.js → browserInfo.js} +1 -5
  53. package/src/engine/ecs/EntityBlueprint.js +4 -0
  54. package/src/engine/ecs/EntityBuilder.js +48 -49
  55. package/src/engine/ecs/EntityBuilderFlags.js +2 -2
  56. package/src/engine/ecs/fow/FogOfWar.js +48 -54
  57. package/src/engine/ecs/guid/GUID.js +1 -0
  58. package/src/engine/ecs/{systems → renderable}/RenderSystem.d.ts +1 -1
  59. package/src/engine/ecs/{systems → renderable}/RenderSystem.js +10 -38
  60. package/src/engine/ecs/renderable/Renderable.d.ts +25 -0
  61. package/src/engine/ecs/{components → renderable}/Renderable.js +18 -83
  62. package/src/engine/ecs/renderable/Renderable.spec.js +10 -0
  63. package/src/engine/ecs/speaker/VoiceSystem.js +15 -9
  64. package/src/engine/ecs/systems/MeshColliderSystem.js +1 -1
  65. package/src/engine/ecs/systems/RangedAttackSystem.js +1 -1
  66. package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +1 -1
  67. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +2 -2
  68. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +3 -3
  69. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +2 -2
  70. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +2 -2
  71. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
  72. package/src/engine/graphics/copy_transform_to_threejs_object.js +12 -0
  73. package/src/engine/graphics/debug/VisualSymbolLine.js +1 -1
  74. package/src/engine/graphics/ecs/decal/DecalSystem.js +1 -1
  75. package/src/engine/graphics/ecs/highlight/renderer/makeGaussianBlurShader.js +1 -4
  76. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts +1 -1
  77. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +2 -2
  78. package/src/engine/graphics/ecs/mesh/applyTransformToThreeObject.js +2 -5
  79. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +2 -2
  80. package/src/engine/graphics/geometry/optimization/merge/prototypeGeometryMerge.js +1 -1
  81. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  82. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  83. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
  84. package/src/engine/graphics/shaders/SoftOutlineShader.js +2 -4
  85. package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +24 -0
  86. package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +46 -0
  87. package/src/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
  88. package/src/engine/graphics/texture/sampler/bicubic.spec.js +13 -0
  89. package/src/engine/graphics/texture/sampler/differenceSampler.js +1 -1
  90. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +5 -1
  91. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.spec.js +183 -0
  92. package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +20 -0
  93. package/src/engine/graphics/texture/sampler/filter/mitchell.js +0 -21
  94. package/src/engine/graphics/texture/sampler/filter/mitchell_v1.js +21 -0
  95. package/src/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +17 -16
  96. package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +11 -9
  97. package/src/engine/graphics/texture/sampler/{scaleSampler2D.js → resize/sampler2d_scale.js} +8 -8
  98. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale.spec.js +73 -0
  99. package/src/engine/graphics/texture/sampler/{sampler2_d_scale_down_lanczos.js → resize/sampler2d_scale_down_lanczos.js} +3 -24
  100. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +29 -0
  101. package/src/engine/graphics/texture/sampler/{sampler2d_scale_down_linear.js → resize/sampler2d_scale_down_linear.js} +5 -5
  102. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.spec.js +44 -0
  103. package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.js → sampler2d_scale_down_mipmap.js} +2 -2
  104. package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.spec.js → sampler2d_scale_down_mipmap.spec.js} +2 -2
  105. package/src/engine/graphics/texture/sampler/{genericResampleSampler2D.js → resize/sampler2d_scale_generic.js} +16 -12
  106. package/src/engine/graphics/texture/sampler/{upsampleSampler2D.js → resize/sampler2d_scale_up_linear.js} +5 -2
  107. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_up_linear.spec.js +14 -0
  108. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +4 -2
  109. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.spec.js +15 -0
  110. package/src/engine/graphics/texture/sampler/util/drawSamplerHTML.js +2 -2
  111. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +66 -0
  112. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.spec.js +108 -0
  113. package/src/engine/graphics/trail/TemporalPath.js +83 -78
  114. package/src/engine/graphics/trail/TemporalPath.spec.js +5 -0
  115. package/src/engine/graphics/trail/x/RibbonX.spec.js +5 -0
  116. package/src/engine/input/devices/InputDeviceSwitch.spec.js +5 -0
  117. package/src/engine/input/ecs/{InputBinding.js → components/InputBinding.js} +1 -1
  118. package/src/engine/input/ecs/components/InputController.js +2 -2
  119. package/src/engine/input/ecs/ism/InputBinding.js +2 -2
  120. package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
  121. package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +1 -1
  122. package/src/engine/intelligence/behavior/behavior_to_dot.spec.js +25 -0
  123. package/src/engine/intelligence/behavior/util/DelayBehavior.js +6 -4
  124. package/src/engine/intelligence/blackboard/Blackboard.d.ts +2 -0
  125. package/src/engine/intelligence/blackboard/Blackboard.js +36 -2
  126. package/src/engine/intelligence/blackboard/Blackboard.spec.js +49 -0
  127. package/src/engine/intelligence/blackboard/BlackboardSerializationAdapter.spec.js +2 -0
  128. package/src/engine/navigation/grid/{AStar.js → find_path_on_grid_astar.js} +21 -18
  129. package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +7 -0
  130. package/src/engine/sound/ecs/SoundListenerSystem.js +1 -1
  131. package/src/generation/markers/debug/visualizeMarkers.js +1 -1
  132. package/src/engine/MeepSettings.js +0 -9
  133. package/src/engine/User.js +0 -28
  134. package/src/engine/UserController.js +0 -273
  135. package/src/engine/ecs/components/AABB.js +0 -33
  136. package/src/engine/ecs/components/AABBCollider.js +0 -15
  137. package/src/engine/ecs/components/Renderable.d.ts +0 -14
  138. package/src/engine/ecs/grid/Sampler2DDecoder.js +0 -57
  139. package/src/engine/ecs/grid/makeTerrainGeometry.js +0 -110
  140. package/src/engine/ecs/systems/AABBColliderSystem.js +0 -61
  141. package/src/engine/ecs/systems/AABBSystem.js +0 -89
  142. package/src/engine/graphics/texture/sampler/sampler2d_make_array_filler_function.js +0 -65
  143. package/src/engine/graphics/texture/sampler/sampler2d_scale_down_linear.spec.js +0 -17
  144. package/src/engine/graphics/trail/x/simulator/RibbonState.js +0 -10
  145. package/src/engine/grid/Grid.js +0 -131
  146. package/src/engine/navigation/grid/GridField.js +0 -328
  147. /package/src/engine/ecs/{components → renderable}/RenderableFlags.js +0 -0
@@ -107,3 +107,96 @@ test("add increases length", () => {
107
107
 
108
108
  expect(list.length).toBe(2);
109
109
  });
110
+
111
+
112
+ test("removeIf", () => {
113
+ const list = new List([1, 3, 1]);
114
+
115
+ list.removeIf(a => a === 1);
116
+
117
+ expect(list.length).toEqual(1);
118
+ expect(list.get(0)).toBe(3);
119
+ });
120
+
121
+ test("removeOneIf", () => {
122
+ const list = new List([1, 3, 1]);
123
+
124
+ list.removeOneIf(a => a === 1);
125
+
126
+ expect(list.length).toEqual(2);
127
+ expect(list.get(0)).toBe(3);
128
+ expect(list.get(1)).toBe(1);
129
+ });
130
+
131
+ test("find", () => {
132
+ const list = new List([1, 3, 1]);
133
+
134
+ const a = list.find(a => a === 3);
135
+
136
+ expect(a).toEqual(3);
137
+
138
+ const b = list.find(a => a === 5);
139
+
140
+ expect(b).toBeUndefined();
141
+ });
142
+
143
+ test("reset", () => {
144
+ const list = new List([1, 3, 1]);
145
+
146
+ list.reset();
147
+
148
+ expect(list.length).toEqual(0);
149
+
150
+ list.reset(); // test idempotence
151
+
152
+ expect(list.length).toEqual(0);
153
+
154
+ // check event handlers
155
+ const remove_callback = jest.fn();
156
+
157
+ list.on.removed.add(remove_callback);
158
+
159
+ list.add(3);
160
+
161
+ list.reset();
162
+
163
+ expect(list.length).toEqual(0);
164
+
165
+ expect(remove_callback).toHaveBeenCalledTimes(1);
166
+ expect(remove_callback).toHaveBeenLastCalledWith(3, 0);
167
+ });
168
+
169
+ test("insert", () => {
170
+
171
+ const list = new List();
172
+
173
+ const add_callback = jest.fn();
174
+ list.on.added.add(add_callback);
175
+
176
+ list.insert(0, "x");
177
+
178
+ expect(list.length).toEqual(1);
179
+ expect(list.get(0)).toBe("x");
180
+ expect(add_callback).toHaveBeenLastCalledWith("x", 0);
181
+
182
+ list.insert(0, 'y');
183
+
184
+ expect(list.length).toEqual(2);
185
+ expect(list.get(0)).toBe("y");
186
+ expect(list.get(1)).toBe("x");
187
+ expect(add_callback).toHaveBeenLastCalledWith("y", 0);
188
+
189
+ list.insert(2, "z");
190
+
191
+ expect(list.length).toEqual(3);
192
+ expect(list.get(0)).toBe("y");
193
+ expect(list.get(1)).toBe("x");
194
+ expect(list.get(2)).toBe("z");
195
+ expect(add_callback).toHaveBeenLastCalledWith("z", 2);
196
+ });
197
+
198
+ test("map", () => {
199
+ const list = new List([1, 2, 3]);
200
+
201
+ expect(list.map(a => a * 7)).toEqual([7, 14, 21]);
202
+ });
@@ -2,6 +2,7 @@ import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
3
  /**
4
4
  * Cache wrapper that loads data when it's not found in the cache
5
+ * @deprecated prefer to use {@link LoadingCache} instead
5
6
  */
6
7
  export class AsyncLoadingCache extends AbstractAsyncMap {
7
8
  /**
@@ -4,6 +4,28 @@ import { noop } from "../../function/Functions.js";
4
4
  import { SimpleStateMachineDescription } from "./SimpleStateMachineDescription.js";
5
5
 
6
6
  export class SimpleStateMachine {
7
+
8
+ /**
9
+ *
10
+ * @type {number}
11
+ * @private
12
+ */
13
+ __state = -1;
14
+
15
+ /**
16
+ *
17
+ * @type {Array}
18
+ * @private
19
+ */
20
+ __eventHandlersStateEntry = [];
21
+
22
+ /**
23
+ *
24
+ * @type {Array}
25
+ * @private
26
+ */
27
+ __eventHandlersStateExit = [];
28
+
7
29
  /**
8
30
  *
9
31
  * @param {SimpleStateMachineDescription} description
@@ -16,27 +38,6 @@ export class SimpleStateMachine {
16
38
  * @type {SimpleStateMachineDescription}
17
39
  */
18
40
  this.description = description;
19
-
20
- /**
21
- *
22
- * @type {number}
23
- * @private
24
- */
25
- this.__state = -1;
26
-
27
- /**
28
- *
29
- * @type {Array}
30
- * @private
31
- */
32
- this.__eventHandlersStateEntry = [];
33
-
34
- /**
35
- *
36
- * @type {Array}
37
- * @private
38
- */
39
- this.__eventHandlersStateExit = [];
40
41
  }
41
42
 
42
43
  /**
@@ -212,7 +213,7 @@ export class SimpleStateMachine {
212
213
  const targetNodes = description.getOutgoingStates(this.__state);
213
214
 
214
215
  if (targetNodes.length !== 1) {
215
- //no selector, and number of targets is ambiguous
216
+ //no selector and number of targets is ambiguous
216
217
  return false;
217
218
  }
218
219
 
@@ -0,0 +1,15 @@
1
+ import { extractFunctionBody } from "./extractFunctionBody.js";
2
+
3
+ test("sanity", () => {
4
+
5
+ const a = function x(a, b, c) {
6
+ };
7
+
8
+ expect(extractFunctionBody(a)).toBe("");
9
+
10
+ const b = function x(a, b, c) {
11
+ return a + b + c;
12
+ };
13
+
14
+ expect(extractFunctionBody(b)).toBe("return a + b + c;");
15
+ });
@@ -1,82 +1,118 @@
1
- import { orientation3_v2 } from "./orientation3_v2.js";
1
+ import { assert } from "../../../assert.js";
2
+ import { orientation3_array } from "./orientation3_array.js";
2
3
 
3
4
  /**
4
5
  * Ported from https://github.com/mikolalysenko/monotone-convex-hull-2d
5
- * @param {number[][]} points
6
- * @returns {number}
6
+ * @param {number[]|Float32Array|Float64Array} points
7
+ * @param {number} [point_count]
8
+ * @returns {number[]}
7
9
  */
8
- export function convex_hull_monotone_2d(points) {
9
- var n = points.length
10
+ export function convex_hull_monotone_2d(points, point_count = points.length * 0.5) {
11
+ assert.isNumber(point_count, 'point_count');
12
+ assert.isNonNegativeInteger(point_count, 'point_count');
10
13
 
11
- if (n < 3) {
12
- var result = new Array(n)
13
- for (var i = 0; i < n; ++i) {
14
- result[i] = i
15
- }
14
+ if (point_count < 3) {
15
+
16
+ if (
17
+ point_count === 2
18
+ && points[0] === points[2]
19
+ && points[1] === points[3]
20
+ ) {
16
21
 
17
- if (n === 2 &&
18
- points[0][0] === points[1][0] &&
19
- points[0][1] === points[1][1]) {
20
22
  return [0]
23
+
24
+ }
25
+
26
+ const result = new Array(point_count)
27
+
28
+ for (let i = 0; i < point_count; ++i) {
29
+ result[i] = i
21
30
  }
22
31
 
23
32
  return result
24
33
  }
25
34
 
26
35
  //Sort point indices along x-axis
27
- var sorted = new Array(n)
28
- for (var i = 0; i < n; ++i) {
36
+ const sorted = new Array(point_count)
37
+
38
+ for (let i = 0; i < point_count; ++i) {
29
39
  sorted[i] = i
30
40
  }
41
+
31
42
  sorted.sort(function (a, b) {
32
- var d = points[a][0] - points[b][0]
43
+ const a2 = a * 2;
44
+ const b2 = b * 2;
45
+
46
+ var d = points[a2] - points[b2]
47
+
33
48
  if (d) {
34
49
  return d
35
50
  }
36
- return points[a][1] - points[b][1]
51
+
52
+ return points[a2 + 1] - points[b2 + 1]
37
53
  })
38
54
 
39
55
  //Construct upper and lower hulls
40
- var lower = [sorted[0], sorted[1]]
41
- var upper = [sorted[0], sorted[1]]
56
+ const lower = [sorted[0], sorted[1]]
57
+ const upper = [sorted[0], sorted[1]]
42
58
 
43
- for (var i = 2; i < n; ++i) {
44
- var idx = sorted[i]
45
- var p = points[idx]
59
+ for (let i = 2; i < point_count; ++i) {
60
+ const idx = sorted[i]
46
61
 
47
62
  //Insert into lower list
48
- var m = lower.length
49
- while (m > 1 && orientation3_v2(
50
- points[lower[m - 2]],
51
- points[lower[m - 1]],
52
- p) <= 0) {
63
+ let m = lower.length
64
+
65
+ while (
66
+ m > 1
67
+ && orientation3_array(
68
+ points,
69
+ lower[m - 2],
70
+ lower[m - 1],
71
+ idx) <= 0
72
+ ) {
73
+
53
74
  m -= 1
54
75
  lower.pop()
76
+
55
77
  }
78
+
56
79
  lower.push(idx)
57
80
 
58
81
  //Insert into upper list
59
82
  m = upper.length
60
- while (m > 1 && orientation3_v2(
61
- points[upper[m - 2]],
62
- points[upper[m - 1]],
63
- p) >= 0) {
83
+
84
+ while (
85
+ m > 1
86
+ && orientation3_array(
87
+ points,
88
+ upper[m - 2],
89
+ upper[m - 1],
90
+ idx) >= 0
91
+ ) {
92
+
64
93
  m -= 1
65
94
  upper.pop()
95
+
66
96
  }
97
+
67
98
  upper.push(idx)
99
+
68
100
  }
69
101
 
70
102
  //Merge lists together
71
- var result = new Array(upper.length + lower.length - 2)
72
- var ptr = 0
103
+ const result = new Array(upper.length + lower.length - 2)
104
+
105
+ let ptr = 0
106
+
73
107
  for (var i = 0, nl = lower.length; i < nl; ++i) {
74
108
  result[ptr++] = lower[i]
75
109
  }
110
+
76
111
  for (var j = upper.length - 2; j > 0; --j) {
77
112
  result[ptr++] = upper[j]
78
113
  }
79
114
 
115
+
80
116
  //Return result
81
117
  return result
82
118
  }
@@ -0,0 +1,33 @@
1
+ import { convex_hull_monotone_2d } from "./convex_hull_monotone_2d.js";
2
+
3
+ test("box with extra points", () => {
4
+ const hull = convex_hull_monotone_2d([
5
+ 0, 1,
6
+ -1, 0,
7
+ 1, 0,
8
+ 0, -1,
9
+ // extra points inside
10
+ 0.3, 0.3,
11
+ -0.3, -0.3,
12
+ 0.3, -0.3,
13
+ -0.3, 0.3
14
+ ]);
15
+
16
+ expect(hull.length).toBe(4);
17
+
18
+ expect(hull).toContain(0);
19
+ expect(hull).toContain(1);
20
+ expect(hull).toContain(2);
21
+ expect(hull).toContain(3);
22
+ });
23
+
24
+
25
+ test("exact triangle", () => {
26
+ const hull = convex_hull_monotone_2d([
27
+ 0, 0,
28
+ 1, 0,
29
+ 1, 1,
30
+ ]);
31
+
32
+ expect(hull.length).toBe(3);
33
+ });
@@ -4,6 +4,12 @@ const sum = linearExpansionSum;
4
4
  const prod = robustProduct;
5
5
  const sub = robustSubtract;
6
6
 
7
+ /**
8
+ *
9
+ * @param {number[]} e
10
+ * @param {number[]} f
11
+ * @return {number[]}
12
+ */
7
13
  function robustSubtract(e, f) {
8
14
  var ne = e.length;
9
15
  var nf = f.length;
@@ -141,14 +147,24 @@ function robustSubtract(e, f) {
141
147
  return g
142
148
  }
143
149
 
150
+ /**
151
+ *
152
+ * @param {number[]} a
153
+ * @param {number[]} b
154
+ * @return {number[]}
155
+ */
144
156
  function robustProduct(a, b) {
145
157
  let r = [0]
146
- if (a.length < b.length) {
147
- for (var i = 0; i < a.length; ++i) {
158
+
159
+ const a_count = a.length;
160
+ const b_count = b.length;
161
+
162
+ if (a_count < b_count) {
163
+ for (let i = 0; i < a_count; ++i) {
148
164
  r = linearExpansionSum(r, scaleLinearExpansion(b, a[i]))
149
165
  }
150
166
  } else {
151
- for (var i = 0; i < b.length; ++i) {
167
+ for (let i = 0; i < b_count; ++i) {
152
168
  r = linearExpansionSum(r, scaleLinearExpansion(a, b[i]))
153
169
  }
154
170
  }
@@ -157,6 +173,13 @@ function robustProduct(a, b) {
157
173
 
158
174
  var SPLITTER = +(Math.pow(2, 27) + 1.0)
159
175
 
176
+ /**
177
+ *
178
+ * @param {number} a
179
+ * @param {number} b
180
+ * @param {number[]} [result]
181
+ * @return {number[]}
182
+ */
160
183
  function twoProduct(a, b, result) {
161
184
  var x = a * b
162
185
 
@@ -185,6 +208,13 @@ function twoProduct(a, b, result) {
185
208
  return [y, x]
186
209
  }
187
210
 
211
+ /**
212
+ *
213
+ * @param {number[]} a
214
+ * @param {number[]} b
215
+ * @param {number[]} result
216
+ * @return {number[]}
217
+ */
188
218
  function twoSum(a, b, result) {
189
219
  var x = a + b
190
220
  var bv = x - a
@@ -199,6 +229,12 @@ function twoSum(a, b, result) {
199
229
  return [ar + br, x]
200
230
  }
201
231
 
232
+ /**
233
+ *
234
+ * @param {number[]} e
235
+ * @param {number} scale
236
+ * @return {number[]}
237
+ */
202
238
  function scaleLinearExpansion(e, scale) {
203
239
  var n = e.length
204
240
  if (n === 1) {
@@ -388,16 +424,25 @@ function linearExpansionSum(e, f) {
388
424
 
389
425
  /**
390
426
  *
391
- * @param {number[]} m0
392
- * @param {number[]} m1
393
- * @param {number[]} m2
427
+ * @param {number[][]} m0
428
+ * @param {number[][]} m1
429
+ * @param {number[][]} m2
394
430
  * @returns {number}
395
431
  */
396
432
  function orientation3Exact(m0, m1, m2) {
397
- const p = sum(sum(prod(m1[1], m2[0]), prod(-m2[1], m1[0])), sum(prod(m0[1], m1[0]), prod(-m1[1], m0[0])))
398
- const n = sum(prod(m0[1], m2[0]), prod(-m2[1], m0[0]))
399
- const d = sub(p, n)
400
- return d[d.length - 1]
433
+ const p = sum(
434
+ sum(prod(m1[1], m2[0]), prod(-m2[1], m1[0])),
435
+ sum(prod(m0[1], m1[0]), prod(-m1[1], m0[0]))
436
+ );
437
+
438
+ const n = sum(
439
+ prod(m0[1], m2[0]),
440
+ prod(-m2[1], m0[0])
441
+ );
442
+
443
+ const d = sub(p, n);
444
+
445
+ return d[d.length - 1];
401
446
  }
402
447
 
403
448
  /**
@@ -170,7 +170,17 @@ class PointQuadTree {
170
170
  this.br = undefined;
171
171
  }
172
172
 
173
+ /**
174
+ *
175
+ * @param {T} p
176
+ * @param {number} x
177
+ * @param {number} y
178
+ * @return {Element}
179
+ */
173
180
  insert(p, x, y) {
181
+ assert.isNumber(x, 'x');
182
+ assert.isNumber(y, 'y');
183
+
174
184
  const element = new Element(p, x, y);
175
185
 
176
186
  this.resizeToFit(x, y); //adjust size if needed
@@ -5,9 +5,9 @@ import { max2 } from "../../../math/max2.js";
5
5
 
6
6
  /**
7
7
  * Merge bounds of two axis-aligned bounding boxes, the result is a box that tightly bounds inputs
8
- * @param {ArrayLike<number>|number[]} result where resulting value is written to
9
- * @param {ArrayLike<number>|number[]} a
10
- * @param {ArrayLike<number>|number[]} b
8
+ * @param {ArrayLike<number>|number[]|Float32Array} result where resulting value is written to
9
+ * @param {ArrayLike<number>|number[]|Float32Array} a
10
+ * @param {ArrayLike<number>|number[]|Float32Array} b
11
11
  */
12
12
  export function aabb3_array_combine(result, a, b) {
13
13
  result[0] = min2(a[0], b[0]);
@@ -13,7 +13,7 @@ function defaultNodeToDot(node){
13
13
  * @param {function(Node):string} nodeToDot
14
14
  * @returns {string}
15
15
  */
16
- export function convertGraphToDotString({
16
+ export function convert_graph_to_dot_string({
17
17
  graph,
18
18
  nodeToDot=defaultNodeToDot
19
19
  }) {
@@ -0,0 +1,28 @@
1
+ import { convert_graph_to_dot_string } from "./convert_graph_to_dot_string.js";
2
+ import { Graph } from "./v2/Graph.js";
3
+ import { EdgeDirectionType } from "./Edge.js";
4
+
5
+ test("empty graph should produce valid string", () => {
6
+ const dot = convert_graph_to_dot_string({
7
+ graph: new Graph()
8
+ });
9
+
10
+ expect(typeof dot).toEqual("string");
11
+ expect(dot.trim().length).toBeGreaterThan(0);
12
+ });
13
+
14
+ test("graph with 2 nodes and an edge should produce valid string", () => {
15
+ const graph = new Graph();
16
+
17
+ graph.addNode(1);
18
+ graph.addNode(2);
19
+
20
+ graph.createEdge(1, 2, EdgeDirectionType.Forward);
21
+
22
+ const dot = convert_graph_to_dot_string({
23
+ graph: graph
24
+ });
25
+
26
+ expect(typeof dot).toEqual("string");
27
+ expect(dot.trim().length).toBeGreaterThan(0);
28
+ });
@@ -195,7 +195,7 @@ function grad4(result, hash) {
195
195
  * @param {number[]} derivatives
196
196
  * @returns {number}
197
197
  */
198
- function sdnoise1(derivatives, x) {
198
+ export function sdnoise1(derivatives, x) {
199
199
  const i0 = x | 0;
200
200
  const i1 = i0 + 1;
201
201
 
@@ -207,8 +207,7 @@ function sdnoise1(derivatives, x) {
207
207
  let t1, t20, t40, t21, t41, x21;
208
208
 
209
209
  const x20 = x0 * x0;
210
- const t0 = 1.0
211
- f - x20;
210
+ const t0 = 1.0 - x20;
212
211
  // if(t0 < 0.0f) t0 = 0.0f; // Never happens for 1D: x0<=1 always
213
212
  t20 = t0 * t0;
214
213
  t40 = t20 * t20;
@@ -218,8 +217,7 @@ function sdnoise1(derivatives, x) {
218
217
  n0 = t40 * gx0 * x0;
219
218
 
220
219
  x21 = x1 * x1;
221
- t1 = 1.0
222
- f - x21;
220
+ t1 = 1.0 - x21;
223
221
  // if(t1 < 0.0f) t1 = 0.0f; // Never happens for 1D: |x1|<=1 always
224
222
  t21 = t1 * t1;
225
223
  t41 = t21 * t21;
@@ -265,7 +263,7 @@ const G2 = 0.21132486540518713;
265
263
  * @param {number[]} derivatives
266
264
  * @returns {number}
267
265
  */
268
- function sdnoise2(derivatives, x, y) {
266
+ export function sdnoise2(derivatives, x, y) {
269
267
  let n0, n1, n2; /* Noise contributions from the three simplex corners */
270
268
  let gx0, gy0, gx1, gy1, gx2, gy2; /* Gradients at simplex corners */
271
269
  let t0, t1, t2, x1, x2, y1, y2;
@@ -280,7 +278,7 @@ function sdnoise2(derivatives, x, y) {
280
278
  let ii, i = xs | 0;
281
279
  let jj, j = ys | 0;
282
280
 
283
- const t = (float)(i + j) * G2;
281
+ const t = (i + j) * G2;
284
282
  const X0 = i - t; /* Unskew the cell origin back to (x,y) space */
285
283
  const Y0 = j - t;
286
284
  const x0 = x - X0; /* The x,y distances from the cell origin */
@@ -0,0 +1,87 @@
1
+ import { sdnoise1, sdnoise2, sdnoise3, sdnoise4 } from "./sdnoise.js";
2
+
3
+ describe("sdnoise1", () => {
4
+ test("sanity", () => {
5
+ const derivatives = [];
6
+
7
+ const value = sdnoise1(derivatives, 0);
8
+
9
+ expect(typeof value).toBe("number");
10
+ expect(value).not.toBeNaN();
11
+
12
+ expect(derivatives.length).toEqual(1);
13
+
14
+ expect(typeof derivatives[0]).toBe("number");
15
+ expect(derivatives[0]).not.toBeNaN();
16
+
17
+ });
18
+ });
19
+
20
+ describe("sdnoise2", () => {
21
+ test("sanity", () => {
22
+ const derivatives = [];
23
+
24
+ const value = sdnoise2(derivatives, 0, 0);
25
+
26
+ expect(typeof value).toBe("number");
27
+ expect(value).not.toBeNaN();
28
+
29
+ expect(derivatives.length).toEqual(2);
30
+
31
+ expect(typeof derivatives[0]).toBe("number");
32
+ expect(derivatives[0]).not.toBeNaN();
33
+
34
+ expect(typeof derivatives[1]).toBe("number");
35
+ expect(derivatives[1]).not.toBeNaN();
36
+
37
+ });
38
+ });
39
+
40
+ describe("sdnoise3", () => {
41
+ test("sanity", () => {
42
+ const derivatives = [];
43
+
44
+ const value = sdnoise3(derivatives, 0, 0, 0);
45
+
46
+ expect(typeof value).toBe("number");
47
+ expect(value).not.toBeNaN();
48
+
49
+ expect(derivatives.length).toEqual(3);
50
+
51
+ expect(typeof derivatives[0]).toBe("number");
52
+ expect(derivatives[0]).not.toBeNaN();
53
+
54
+ expect(typeof derivatives[1]).toBe("number");
55
+ expect(derivatives[1]).not.toBeNaN();
56
+
57
+ expect(typeof derivatives[2]).toBe("number");
58
+ expect(derivatives[2]).not.toBeNaN();
59
+
60
+ });
61
+ });
62
+
63
+ describe("sdnoise4", () => {
64
+ test("sanity", () => {
65
+ const derivatives = [];
66
+
67
+ const value = sdnoise4(derivatives, 0, 0, 0, 0);
68
+
69
+ expect(typeof value).toBe("number");
70
+ expect(value).not.toBeNaN();
71
+
72
+ expect(derivatives.length).toEqual(4);
73
+
74
+ expect(typeof derivatives[0]).toBe("number");
75
+ expect(derivatives[0]).not.toBeNaN();
76
+
77
+ expect(typeof derivatives[1]).toBe("number");
78
+ expect(derivatives[1]).not.toBeNaN();
79
+
80
+ expect(typeof derivatives[2]).toBe("number");
81
+ expect(derivatives[2]).not.toBeNaN();
82
+
83
+ expect(typeof derivatives[3]).toBe("number");
84
+ expect(derivatives[3]).not.toBeNaN();
85
+
86
+ });
87
+ });