@woosh/meep-engine 2.50.3 → 2.52.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 (207) hide show
  1. package/editor/actions/concrete/WriteGridValueAction.js +13 -18
  2. package/editor/ecs/component/editors/Sampler2DEditor.js +2 -2
  3. package/editor/process/SymbolicDisplayProcess.js +1 -1
  4. package/editor/process/symbolic/buildThreeJSHelperEntity.js +1 -1
  5. package/editor/process/symbolic/makeCameraSymbolicDisplay.js +1 -1
  6. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  7. package/editor/process/symbolic/makeLightSymbolicDisplay.js +1 -1
  8. package/editor/process/symbolic/makePathSymbolicDisplay.js +1 -1
  9. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +1 -1
  10. package/editor/view/ecs/components/GridObstacleController.js +2 -2
  11. package/editor/view/ecs/components/TerrainController.js +2 -2
  12. package/package.json +1 -1
  13. package/samples/terrain/editor.js +2 -2
  14. package/src/core/NumberFormat.js +0 -71
  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 +58 -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/bvh3/query/BVHQueryAny.js +16 -0
  22. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +5 -5
  23. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -3
  24. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +22 -0
  25. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +2 -2
  26. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +64 -0
  27. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -3
  28. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +2 -2
  29. package/src/core/cache/Cache.js +3 -5
  30. package/src/core/cache/CacheElement.js +1 -0
  31. package/src/core/geom/2d/quad-tree/PointQuadTree.js +10 -0
  32. package/src/core/geom/3d/aabb/aabb3_array_combine.js +3 -3
  33. package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +41 -0
  34. package/src/core/geom/3d/topology/struct/TopoMesh.js +3 -2
  35. package/src/core/geom/3d/topology/struct/prototypeBinaryTopology.js +4 -4
  36. package/src/core/geom/Vector2.d.ts +9 -0
  37. package/src/core/geom/Vector2.js +8 -22
  38. package/src/core/geom/Vector2.spec.js +153 -0
  39. package/src/core/graph/{convertGraphToDotString.js → convert_graph_to_dot_string.js} +1 -1
  40. package/src/core/graph/convert_graph_to_dot_string.spec.js +28 -0
  41. package/src/core/math/noise/sdnoise.js +5 -7
  42. package/src/core/math/noise/sdnoise.spec.js +87 -0
  43. package/src/core/model/ModuleRegistry.js +2 -4
  44. package/src/core/model/ModuleRegistry.spec.js +31 -0
  45. package/src/core/model/reactive/js/compileReactiveToJS.spec.js +14 -0
  46. package/src/core/model/reactive/model/logic/ReactiveAnd.spec.js +31 -1
  47. package/src/core/model/reactive/model/logic/ReactiveOr.spec.js +53 -0
  48. package/src/core/model/stat/LinearModifier.js +2 -2
  49. package/src/core/model/stat/LinearModifier.spec.js +62 -0
  50. package/src/core/model/stat/Stat.js +12 -0
  51. package/src/core/model/stat/Stat.spec.js +36 -0
  52. package/src/core/primitives/array/computeStridedIntegerArrayHash.spec.js +28 -0
  53. package/src/core/primitives/numbers/number_format_by_thousands.js +14 -0
  54. package/src/core/primitives/numbers/number_pretty_print.js +49 -0
  55. package/src/core/primitives/strings/computeStringHash.spec.js +12 -5
  56. package/src/core/process/BaseProcess.js +8 -8
  57. package/src/engine/Clock.js +30 -29
  58. package/src/engine/Clock.spec.js +26 -0
  59. package/src/engine/{Platform.js → browserInfo.js} +1 -5
  60. package/src/engine/ecs/EntityBuilder.js +3 -1
  61. package/src/engine/ecs/EntityBuilder.spec.js +21 -0
  62. package/src/engine/ecs/fow/FogOfWar.js +48 -54
  63. package/src/engine/ecs/gui/GUIElement.js +1 -1
  64. package/src/engine/ecs/gui/position/ViewportPosition.js +3 -3
  65. package/src/engine/ecs/{systems → renderable}/RenderSystem.d.ts +1 -1
  66. package/src/engine/ecs/{systems → renderable}/RenderSystem.js +10 -38
  67. package/src/engine/ecs/renderable/Renderable.d.ts +25 -0
  68. package/src/engine/ecs/{components → renderable}/Renderable.js +18 -83
  69. package/src/engine/ecs/renderable/Renderable.spec.js +10 -0
  70. package/src/engine/ecs/speaker/VoiceSystem.js +15 -9
  71. package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +1 -1
  72. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +3 -3
  73. package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +3 -3
  74. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +2 -2
  75. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +2 -2
  76. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
  77. package/src/engine/ecs/transform/Transform.js +1 -0
  78. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  79. package/src/engine/graphics/copy_transform_to_threejs_object.js +12 -0
  80. package/src/engine/graphics/debug/VisualSymbolLine.js +1 -1
  81. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.spec.js +5 -0
  82. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +24 -25
  83. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.spec.js +5 -0
  84. package/src/engine/graphics/ecs/decal/DecalSystem.js +3 -21
  85. package/src/engine/graphics/ecs/decal/v2/Decal.js +32 -32
  86. package/src/engine/graphics/ecs/decal/v2/Decal.spec.js +5 -0
  87. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +4 -2
  88. package/src/engine/graphics/ecs/highlight/renderer/makeGaussianBlurShader.js +1 -4
  89. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts +1 -1
  90. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +2 -2
  91. package/src/engine/graphics/ecs/mesh/applyTransformToThreeObject.js +2 -5
  92. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +4 -33
  93. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +8 -4
  94. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.spec.js +5 -0
  95. package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +0 -12
  96. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +2 -2
  97. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  98. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -4
  99. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +0 -2
  100. package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +1 -1
  101. package/src/engine/graphics/geometry/optimization/merge/prototypeGeometryMerge.js +1 -1
  102. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -3
  103. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  104. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -5
  105. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
  106. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -6
  107. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -1
  108. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +6 -1
  109. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +4 -4
  110. package/src/engine/graphics/shaders/SoftOutlineShader.js +2 -4
  111. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  112. package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +24 -0
  113. package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +46 -0
  114. package/src/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
  115. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  116. package/src/engine/graphics/texture/sampler/bicubic.spec.js +13 -0
  117. package/src/engine/graphics/texture/sampler/differenceSampler.js +1 -1
  118. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +5 -1
  119. package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.spec.js +183 -0
  120. package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +20 -0
  121. package/src/engine/graphics/texture/sampler/filter/mitchell.js +0 -21
  122. package/src/engine/graphics/texture/sampler/filter/mitchell_v1.js +21 -0
  123. package/src/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +17 -16
  124. package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +11 -9
  125. package/src/engine/graphics/texture/sampler/{scaleSampler2D.js → resize/sampler2d_scale.js} +8 -8
  126. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale.spec.js +73 -0
  127. package/src/engine/graphics/texture/sampler/{sampler2_d_scale_down_lanczos.js → resize/sampler2d_scale_down_lanczos.js} +3 -24
  128. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +29 -0
  129. package/src/engine/graphics/texture/sampler/{sampler2d_scale_down_linear.js → resize/sampler2d_scale_down_linear.js} +5 -5
  130. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.spec.js +44 -0
  131. package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.js → sampler2d_scale_down_mipmap.js} +2 -2
  132. package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.spec.js → sampler2d_scale_down_mipmap.spec.js} +2 -2
  133. package/src/engine/graphics/texture/sampler/{genericResampleSampler2D.js → resize/sampler2d_scale_generic.js} +16 -12
  134. package/src/engine/graphics/texture/sampler/{upsampleSampler2D.js → resize/sampler2d_scale_up_linear.js} +5 -2
  135. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_up_linear.spec.js +14 -0
  136. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +4 -2
  137. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.spec.js +15 -0
  138. package/src/engine/graphics/texture/sampler/util/drawSamplerHTML.js +2 -2
  139. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +46 -0
  140. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.spec.js +108 -0
  141. package/src/engine/graphics/trail/TemporalPath.js +83 -78
  142. package/src/engine/graphics/trail/TemporalPath.spec.js +5 -0
  143. package/src/engine/graphics/trail/x/RibbonX.spec.js +5 -0
  144. package/src/engine/grid/components/GridObstacle.js +45 -25
  145. package/src/engine/grid/components/GridObstacle.spec.js +130 -1
  146. package/src/engine/grid/components/GridPosition.js +5 -17
  147. package/src/engine/grid/components/GridPosition2Transform.js +1 -70
  148. package/src/engine/grid/components/GridPosition2TransformSerializationAdapter.js +70 -0
  149. package/src/engine/input/devices/InputDeviceSwitch.spec.js +5 -0
  150. package/src/engine/input/ecs/{InputBinding.js → components/InputBinding.js} +1 -1
  151. package/src/engine/input/ecs/components/InputController.js +2 -2
  152. package/src/engine/input/ecs/ism/InputBinding.js +2 -2
  153. package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
  154. package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +1 -1
  155. package/src/engine/intelligence/behavior/behavior_to_dot.spec.js +25 -0
  156. package/src/engine/intelligence/behavior/util/DelayBehavior.js +6 -4
  157. package/src/engine/intelligence/blackboard/Blackboard.d.ts +2 -0
  158. package/src/engine/intelligence/blackboard/Blackboard.js +36 -2
  159. package/src/engine/intelligence/blackboard/Blackboard.spec.js +49 -0
  160. package/src/engine/intelligence/blackboard/BlackboardSerializationAdapter.spec.js +2 -0
  161. package/src/engine/navigation/grid/{AStar.js → find_path_on_grid_astar.js} +21 -18
  162. package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +7 -0
  163. package/src/engine/plugin/EnginePlugin.js +12 -14
  164. package/src/engine/plugin/EnginePlugin.spec.js +5 -0
  165. package/src/engine/plugin/EnginePluginManager.js +18 -22
  166. package/src/engine/scene/transitionToScene.js +12 -1
  167. package/src/engine/simulation/Ticker.js +1 -1
  168. package/src/engine/sound/ecs/SoundListenerSystem.js +1 -1
  169. package/src/generation/markers/debug/visualizeMarkers.js +1 -1
  170. package/src/generation/theme/TerrainLayerDescription.js +1 -1
  171. package/src/view/common/LabelView.js +3 -3
  172. package/src/engine/MeepSettings.js +0 -9
  173. package/src/engine/User.js +0 -28
  174. package/src/engine/UserController.js +0 -273
  175. package/src/engine/ecs/components/AABB.js +0 -33
  176. package/src/engine/ecs/components/AABBCollider.js +0 -15
  177. package/src/engine/ecs/components/AimController.js +0 -18
  178. package/src/engine/ecs/components/Attacker.js +0 -13
  179. package/src/engine/ecs/components/MeshCollider.js +0 -15
  180. package/src/engine/ecs/components/RangedAttack.js +0 -12
  181. package/src/engine/ecs/components/Renderable.d.ts +0 -14
  182. package/src/engine/ecs/components/TargetAI.js +0 -11
  183. package/src/engine/ecs/components/ViewportMeshProjection.js +0 -18
  184. package/src/engine/ecs/grid/Sampler2DDecoder.js +0 -57
  185. package/src/engine/ecs/grid/makeTerrainGeometry.js +0 -110
  186. package/src/engine/ecs/systems/AABBColliderSystem.js +0 -61
  187. package/src/engine/ecs/systems/AABBSystem.js +0 -89
  188. package/src/engine/ecs/systems/AimControllerSystem.js +0 -63
  189. package/src/engine/ecs/systems/AttackerSystem.js +0 -67
  190. package/src/engine/ecs/systems/MeshColliderSystem.js +0 -47
  191. package/src/engine/ecs/systems/MonsterAISystem.js +0 -163
  192. package/src/engine/ecs/systems/MortalitySystem.js +0 -46
  193. package/src/engine/ecs/systems/RangedAttackSystem.js +0 -132
  194. package/src/engine/ecs/systems/SerializationMetadataSystem.js +0 -10
  195. package/src/engine/ecs/systems/TargetAISystem.js +0 -107
  196. package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +0 -68
  197. package/src/engine/graphics/particles/ParticleEmitterLibrary.js +0 -87
  198. package/src/engine/graphics/texture/sampler/sampler2d_make_array_filler_function.js +0 -65
  199. package/src/engine/graphics/texture/sampler/sampler2d_scale_down_linear.spec.js +0 -17
  200. package/src/engine/graphics/trail/x/simulator/RibbonState.js +0 -10
  201. package/src/engine/grid/Grid.js +0 -131
  202. package/src/engine/grid/components/ViewportGridProjection.js +0 -20
  203. package/src/engine/grid/systems/GridObstacleSystem.js +0 -58
  204. package/src/engine/grid/systems/ViewportGridProjectionSystem.js +0 -105
  205. package/src/engine/navigation/grid/GridField.js +0 -328
  206. /package/src/{engine → core/primitives/array}/computeStridedIntegerArrayHash.js +0 -0
  207. /package/src/engine/ecs/{components → renderable}/RenderableFlags.js +0 -0
@@ -1,328 +0,0 @@
1
- import Vector2 from '../../../core/geom/Vector2.js';
2
- import { clamp } from "../../../core/math/clamp.js";
3
- import BinaryHeap from '../../../core/collection/heap/BinaryHeap.js';
4
- import { assert } from "../../../core/assert.js";
5
- import { gridAStarSearch } from "./AStar.js";
6
-
7
- const blockValue = 255;
8
-
9
- /**
10
- * A kind of 2D data texture
11
- * @deprecated prefer using {@link Sampler2D} instead, as it's more versatile and has wider feature set
12
- *
13
- * @param {Number} width
14
- * @param {Number} height
15
- * @constructor
16
- *
17
- * @property {Number} width
18
- * @property {Number} height
19
- * @property {Uint8Array} data
20
- */
21
- function GridField(width, height) {
22
- this.width = width;
23
- this.height = height;
24
- this.data = null;
25
-
26
- if (height !== 0 && height !== 0) {
27
- const byteSize = height * width;
28
- this.data = new Uint8Array(byteSize);
29
- }
30
-
31
- const self = this;
32
-
33
- Object.defineProperties(this, {
34
- raw: {
35
- set: function (val) {
36
- console.warn("Deprecated, use .data accessor instead");
37
- self.data = val;
38
- },
39
- get: function () {
40
- console.warn("Deprecated, use .data accessor instead");
41
- return self.data;
42
- }
43
- }
44
- });
45
- }
46
-
47
- /**
48
- *
49
- * @param {Number} value
50
- */
51
- GridField.prototype.fill = function (value) {
52
- this.data.fill(value);
53
- };
54
-
55
- /**
56
- *
57
- * @param {Number} x0
58
- * @param {Number} y0
59
- * @param {Number} x1
60
- * @param {Number} y1
61
- * @param {function(x:Number,y:Number,value:Number)} callback
62
- */
63
- GridField.prototype.rectTraverse = function (x0, y0, x1, y1, callback) {
64
- const width = this.width;
65
- const height = this.height;
66
-
67
- let x, y;
68
-
69
- x0 = clamp(x0, 0, width - 1);
70
- y0 = clamp(y0, 0, height - 1);
71
- x1 = clamp(x1, x0, width - 1);
72
- y1 = clamp(y1, y0, height - 1);
73
-
74
- for (x = x0; x <= x1; x++) {
75
- for (y = y0; y <= y1; y++) {
76
- const index = this.point2index(x, y);
77
- const value = this.data[index];
78
- callback(x, y, value);
79
- }
80
- }
81
- };
82
-
83
- /**
84
- *
85
- * @param {Number} x0
86
- * @param {Number} y0
87
- * @param {Number} x1
88
- * @param {Number} y1
89
- * @param {Number} value
90
- */
91
- GridField.prototype.rectSet = function (x0, y0, x1, y1, value) {
92
- let x, y;
93
- for (x = x0; x <= x1; x++) {
94
- for (y = y0; y <= y1; y++) {
95
- this.pointSet(x, y, value);
96
- }
97
- }
98
- };
99
-
100
- /**
101
- *
102
- * @param {Vector2} pos
103
- */
104
- GridField.prototype.snapToNearestFreeCell = function (pos) {
105
- const self = this;
106
- const p = new Vector2().copy(pos).floor();
107
- const target = p.clone();
108
- const closed = [];
109
-
110
- function score(index) {
111
- self.index2point(index, p);
112
- return p.distanceSqrTo(target);
113
- }
114
-
115
- const open = new BinaryHeap(score);
116
- let current = this.point2index(p.x, p.y);
117
- open.push(current);
118
- const neighbors = [];
119
- while (open.size() > 0) {
120
- current = open.pop();
121
- closed[current] = true;
122
- if (this.data[current] !== blockValue) {
123
- break;
124
- }
125
- //add neighbours
126
- neighbors.length = 0; //reset
127
- this.calcNeighbors(current, neighbors);
128
- const numNeighbors = neighbors.length;
129
- for (let i = 0; i < numNeighbors; i++) {
130
- const n = neighbors[i];
131
- if (closed[n] !== void 0) {
132
- continue;
133
- }
134
- open.push(n);
135
- }
136
- }
137
- this.index2point(current, pos);
138
- };
139
-
140
- /**
141
- *
142
- * @param {Number} index
143
- * @param {function(index:Number, x:Number, y:Number)} visitor
144
- */
145
- GridField.prototype.traverseNeighbors = function traverseNeighbors(index, visitor) {
146
- const width = this.width;
147
- const height = this.height;
148
-
149
- const x = index % width;
150
- const y = (index / width) | 0;
151
-
152
- if (x > 0) {
153
- visitor(index - 1, x, y);
154
- }
155
- if (x < width - 1) {
156
- visitor(index + 1, x, y);
157
- }
158
- if (y > 0) {
159
- visitor(index - width, x, y);
160
- }
161
- if (y < height - 1) {
162
- visitor(index + width, x, y);
163
- }
164
- };
165
-
166
- /**
167
- *
168
- * @param {Number} x
169
- * @param {Number} y
170
- * @returns {Number}
171
- */
172
- GridField.prototype.read = function (x, y) {
173
- const index = this.point2index(x, y);
174
- return this.data[index];
175
- };
176
-
177
- /**
178
- *
179
- * @param {Number} x
180
- * @param {Number} y
181
- * @param {Number} value
182
- */
183
- GridField.prototype.pointAdd = function (x, y, value) {
184
- const index = this.point2index(x, y);
185
- this.data[index] += value;
186
- };
187
-
188
- /**
189
- *
190
- * @param {Number} x
191
- * @param {Number} y
192
- * @param {Number} value
193
- */
194
- GridField.prototype.pointSet = function (x, y, value) {
195
- const index = this.point2index(x, y);
196
- this.data[index] = value;
197
- };
198
-
199
-
200
- /**
201
- *
202
- * @param {Number} x
203
- * @param {Number} y
204
- * @returns {Number}
205
- */
206
- GridField.prototype.point2index = function (x, y) {
207
- return x + y * this.width;
208
- };
209
-
210
- /**
211
- * Paints with additive brush
212
- * @param {Array.<Number>} bendPointIndexList
213
- * @param {Number} value
214
- */
215
- GridField.prototype.pathAdd = function pathAdd(bendPointIndexList, value) {
216
- const indices = bendPointIndexList;
217
- const length = indices.length;
218
-
219
- //
220
- if (length > 0) {
221
- const pCurrent = new Vector2();
222
- const pTarget = new Vector2();
223
- let dx, dy;
224
- this.index2point(indices[0], pCurrent);
225
- this.pointAdd(pCurrent.x, pCurrent.y, value);
226
- for (let i = 1; i < length; i++) {
227
- this.index2point(indices[i], pTarget);
228
- dx = pTarget.x - pCurrent.x;
229
- dy = pTarget.y - pCurrent.y;
230
- if (dx !== 0) {
231
- //drop values to multiple of 1
232
- dx /= Math.abs(dx);
233
- while (pCurrent.x !== pTarget.x) {
234
- pCurrent.x += dx;
235
- this.pointAdd(pCurrent.x, pCurrent.y, value);
236
- }
237
- }
238
- if (dy !== 0) {
239
- //drop values to multiple of 1
240
- dy /= Math.abs(dy);
241
- while (pCurrent.y !== pTarget.y) {
242
- pCurrent.y += dy;
243
- this.pointAdd(pCurrent.x, pCurrent.y, value);
244
- }
245
- }
246
- }
247
- }
248
- };
249
-
250
- /**
251
- *
252
- * @param {Number} index
253
- * @param {Vector2} point
254
- */
255
- GridField.prototype.index2point = function (index, point) {
256
- const width = this.width;
257
-
258
- point.set(index % width, Math.floor(index / width));
259
- };
260
-
261
- /**
262
- *
263
- * @param {Number} index
264
- * @param {Array.<Number>} result
265
- */
266
- GridField.prototype.calcNeighbors = function (index, result) {
267
- const width = this.width;
268
- const height = this.height;
269
-
270
- const x = index % width;
271
- const y = (index / width) | 0;
272
- if (x > 0) {
273
- result.push(index - 1);
274
- }
275
- if (x < width - 1) {
276
- result.push(index + 1);
277
- }
278
- if (y > 0) {
279
- result.push(index - width);
280
- }
281
- if (y < height - 1) {
282
- result.push(index + width);
283
- }
284
- };
285
-
286
-
287
- /**
288
- *
289
- * @param {Number} index1
290
- * @param {Number} index2
291
- * @returns {Number}
292
- */
293
- GridField.prototype.manhattanDistanceByIndices = function (index1, index2) {
294
- const width = this.width;
295
-
296
- const x1 = index1 % width;
297
- const y1 = Math.floor(index1 / width);
298
- //
299
- const x2 = index2 % width;
300
- const y2 = Math.floor(index2 / width);
301
- //
302
- const dx = Math.abs(x1 - x2);
303
- const dy = Math.abs(y1 - y2);
304
- return dx + dy;
305
- };
306
-
307
- /**
308
- *
309
- * @param {Vector2} start
310
- * @param {Vector2} goal
311
- * @param {Number} crossingPenalty
312
- * @param {Number} bendPenalty
313
- * @returns {Number[]} path of indices
314
- */
315
- GridField.prototype.findPath = function (start, goal, crossingPenalty, bendPenalty) {
316
- assert.notEqual(start, null, 'start is null');
317
- assert.notEqual(start, undefined, 'start is undefined');
318
-
319
- assert.notEqual(goal, null, 'goal is null');
320
- assert.notEqual(goal, undefined, 'goal is undefined');
321
-
322
- const startIndex = this.point2index(start.x, start.y);
323
- const goalIndex = this.point2index(goal.x, goal.y);
324
-
325
- return gridAStarSearch(this.field, this.width, this.height, startIndex, goalIndex, crossingPenalty, bendPenalty, 255);
326
- };
327
-
328
- export default GridField;