@woosh/meep-engine 2.134.4 → 2.135.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.
- package/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/editor/tools/v2/TransformControlsGizmo.js +1 -1
- package/editor/view/node-graph/NodeGraphEditorView.js +2 -2
- package/package.json +1 -1
- package/src/core/assert.d.ts +0 -2
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +0 -6
- package/src/core/color/Color.d.ts +0 -5
- package/src/core/color/Color.d.ts.map +1 -1
- package/src/core/color/Color.js +1 -7
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.js +386 -386
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_2d.js +1 -1
- package/src/core/geom/2d/quad-tree-binary/QuadTree.js +714 -714
- package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +160 -160
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +96 -96
- package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +1 -1
- package/src/core/geom/packing/max-rect/findBestContainer.js +4 -4
- package/src/core/geom/packing/max-rect/packOneBox.js +2 -2
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts +23 -0
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.js +96 -0
- package/src/core/graph/layout/box/BoxLayouter.js +7 -7
- package/src/core/graph/layout/box/position_box_next_to_box.js +6 -6
- package/src/core/math/computeWholeDivisorLow.js +33 -33
- package/src/core/math/linalg/eigen/eigen_values_find_spectral_gap.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts +10 -0
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_eigenvalues_in_place.js +8 -7
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.js +11 -5
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +15 -0
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_qr_in_place.js +8 -2
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts +17 -0
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.js +107 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts +19 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js +161 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts +15 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.js +200 -0
- package/src/core/math/solveCubic.d.ts +15 -0
- package/src/core/math/solveCubic.d.ts.map +1 -0
- package/src/core/math/solveCubic.js +82 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.d.ts +23 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.js +109 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts +25 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.js +44 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts +16 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.js +120 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +11 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +451 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts +12 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.js +339 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts +15 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.js +21 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.d.ts +24 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.js +37 -0
- package/src/core/math/spline/v3_computeCatmullRomSplineUniformDistance.js +1 -1
- package/src/core/model/node-graph/visual/NodeGraphVisualData.js +1 -1
- package/src/core/model/reactive/model/util/createRandomReactiveExpression.js +185 -185
- package/src/core/process/delay.js +16 -16
- package/src/engine/animation/async/TimeSeries.js +300 -300
- package/src/engine/animation/curve/AnimationCurve.d.ts +3 -2
- package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
- package/src/engine/animation/curve/AnimationCurve.js +3 -2
- package/src/engine/animation/curve/draw/position_canvas_to_curve.js +2 -2
- package/src/engine/animation/curve/draw/position_curve_to_canvas.js +2 -2
- package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +145 -145
- package/src/engine/ecs/gui/position/ViewportPositionSystem.js +2 -2
- package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
- package/src/engine/ecs/transform/Transform.d.ts +0 -10
- package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
- package/src/engine/ecs/transform/Transform.js +0 -12
- package/src/engine/graphics/composit/CompositLayer.js +254 -254
- package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_linear.js +2 -2
- package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +3 -3
- package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +201 -201
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
- package/src/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +2 -2
- package/src/engine/graphics/render/forward_plus/LightManager.js +1226 -1226
- package/src/engine/graphics/render/forward_plus/model/PointLight.js +1 -1
- package/src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +2 -2
- package/src/engine/graphics/texture/atlas/TextureAtlasDebugger.js +1 -1
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.js +145 -145
- package/src/engine/graphics/texture/sampler/serialization/TextureBinaryBufferSerializer.js +2 -2
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts +2 -6
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts.map +1 -1
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.js +0 -10
- package/src/engine/intelligence/mcts/MonteCarlo.js +275 -275
- package/src/engine/navigation/ecs/path_following/PathFollower.js +222 -222
- package/src/generation/grid/GridData.js +220 -220
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +385 -385
- package/src/view/elements/image/SvgImageView.js +1 -1
- package/src/view/elements/windrose/WindRoseDiagram.js +369 -369
- package/src/view/minimap/gl/MinimapFogOfWar.js +3 -3
- package/src/view/util/DomSizeObserver.js +1 -1
- package/src/core/binary/clz32.d.ts +0 -6
- package/src/core/binary/clz32.d.ts.map +0 -1
- package/src/core/binary/clz32.js +0 -5
- package/src/core/binary/type/dataTypeFromTypedArray.d.ts +0 -8
- package/src/core/binary/type/dataTypeFromTypedArray.d.ts.map +0 -1
- package/src/core/binary/type/dataTypeFromTypedArray.js +0 -11
- package/src/core/collection/array/computeHashIntegerArray.d.ts +0 -1
- package/src/core/collection/array/computeHashIntegerArray.d.ts.map +0 -1
- package/src/core/collection/array/computeHashIntegerArray.js +0 -7
- package/src/core/collection/array/typed/typedArrayToDataType.d.ts +0 -6
- package/src/core/collection/array/typed/typedArrayToDataType.d.ts.map +0 -1
- package/src/core/collection/array/typed/typedArrayToDataType.js +0 -6
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts +0 -6
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts.map +0 -1
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.js +0 -7
- package/src/core/graph/eigen/eigen_values_find_spectral_gap.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts +0 -8
- package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_householder_in_place.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_qr_in_place.d.ts +0 -9
- package/src/core/graph/eigen/matrix_qr_in_place.d.ts.map +0 -1
- package/src/core/math/spline/cubicCurve.d.ts +0 -6
- package/src/core/math/spline/cubicCurve.d.ts.map +0 -1
- package/src/core/math/spline/cubicCurve.js +0 -6
- package/src/core/math/spline/spline_bezier2.d.ts +0 -6
- package/src/core/math/spline/spline_bezier2.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier2.js +0 -6
- package/src/core/math/spline/spline_bezier3.d.ts +0 -6
- package/src/core/math/spline/spline_bezier3.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier3.js +0 -6
- package/src/core/math/spline/spline_bezier3_bounds.d.ts +0 -6
- package/src/core/math/spline/spline_bezier3_bounds.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier3_bounds.js +0 -6
- package/src/core/math/spline/spline_hermite3.d.ts +0 -6
- package/src/core/math/spline/spline_hermite3.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3.js +0 -6
- package/src/core/math/spline/spline_hermite3_bounds.d.ts +0 -6
- package/src/core/math/spline/spline_hermite3_bounds.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3_bounds.js +0 -6
- package/src/core/math/spline/spline_hermite3_to_bezier.d.ts +0 -2
- package/src/core/math/spline/spline_hermite3_to_bezier.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3_to_bezier.js +0 -6
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts +0 -37
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts.map +0 -1
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -70
- /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.d.ts +0 -0
- /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.js +0 -0
- /package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.d.ts +0 -0
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
import { assert } from "../../core/assert.js";
|
|
2
|
-
import { qt_collect_by_circle } from "../../core/geom/2d/quad-tree/qt_collect_by_circle.js";
|
|
3
|
-
import { QuadTreeNode } from "../../core/geom/2d/quad-tree/QuadTreeNode.js";
|
|
4
|
-
import { max2 } from "../../core/math/max2.js";
|
|
5
|
-
import { OffsetScaleTransform2D } from "../../engine/ecs/terrain/ecs/OffsetScaleTransform2D.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @type {QuadTreeDatum<MarkerNode>[]}
|
|
10
|
-
*/
|
|
11
|
-
const marker_collection = [];
|
|
12
|
-
|
|
13
|
-
export class GridData {
|
|
14
|
-
|
|
15
|
-
width = 0;
|
|
16
|
-
height = 0;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @readonly
|
|
20
|
-
* @type {OffsetScaleTransform2D}
|
|
21
|
-
*/
|
|
22
|
-
transform = new OffsetScaleTransform2D();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @readonly
|
|
26
|
-
* @type {QuadTreeNode<MarkerNode>}
|
|
27
|
-
*/
|
|
28
|
-
markers = new QuadTreeNode();
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Discrete data layers
|
|
32
|
-
* @readonly
|
|
33
|
-
* @type {GridDataLayer[]}
|
|
34
|
-
*/
|
|
35
|
-
layers = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {GridDataLayer} layer
|
|
41
|
-
*/
|
|
42
|
-
addLayer(layer) {
|
|
43
|
-
assert.equal(layer.isGridDataLayer, true, 'layer.GridDataLayer !== true');
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const existing = this.getLayerById(layer.id);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (existing === layer) {
|
|
50
|
-
//layer is already attached
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (existing !== undefined) {
|
|
55
|
-
throw new Error(`Layer with ID '${layer.id}' already exists. ID must be unique`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
layer.resize(this.width, this.height);
|
|
59
|
-
|
|
60
|
-
this.layers.push(layer);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param {string} id
|
|
66
|
-
* @returns {GridDataLayer|undefined}
|
|
67
|
-
*/
|
|
68
|
-
getLayerById(id) {
|
|
69
|
-
assert.isString(id, 'id');
|
|
70
|
-
|
|
71
|
-
const layers = this.layers;
|
|
72
|
-
|
|
73
|
-
const n = layers.length;
|
|
74
|
-
|
|
75
|
-
for (let i = 0; i < n; i++) {
|
|
76
|
-
const layer = layers[i];
|
|
77
|
-
|
|
78
|
-
if (layer.id === id) {
|
|
79
|
-
return layer;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
* @param {number} x
|
|
89
|
-
* @param {number} y
|
|
90
|
-
* @param {number} radius
|
|
91
|
-
* @param {MarkerNodeMatcher} matcher
|
|
92
|
-
* @returns {boolean}
|
|
93
|
-
*/
|
|
94
|
-
containsMarkerInCircle(x, y, radius, matcher) {
|
|
95
|
-
return this.countMarkerInCircle(x, y, radius, matcher) > 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {number} x
|
|
101
|
-
* @param {number} y
|
|
102
|
-
* @param {number} radius
|
|
103
|
-
* @param {MarkerNodeMatcher} matcher
|
|
104
|
-
* @returns {number}
|
|
105
|
-
*/
|
|
106
|
-
countMarkerInCircle(x, y, radius, matcher) {
|
|
107
|
-
const match_count = qt_collect_by_circle(marker_collection, 0, this.markers, x, y, radius);
|
|
108
|
-
|
|
109
|
-
let result = 0;
|
|
110
|
-
|
|
111
|
-
for (let i = 0; i < match_count; i++) {
|
|
112
|
-
const marker_datum = marker_collection[i];
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @type {MarkerNode|null}
|
|
117
|
-
*/
|
|
118
|
-
const marker = marker_datum.data;
|
|
119
|
-
|
|
120
|
-
const distance_limit = radius + marker.size;
|
|
121
|
-
|
|
122
|
-
const distance_limit_sqr = distance_limit * distance_limit;
|
|
123
|
-
|
|
124
|
-
// check refined containment
|
|
125
|
-
const position = marker.position;
|
|
126
|
-
|
|
127
|
-
const dx = x - position.x;
|
|
128
|
-
const dy = y - position.y;
|
|
129
|
-
|
|
130
|
-
const distance_sqr = dx * dx + dy * dy;
|
|
131
|
-
|
|
132
|
-
if (distance_sqr > distance_limit_sqr) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (matcher.match(marker)) {
|
|
137
|
-
result++;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
* @param tileSize
|
|
147
|
-
*/
|
|
148
|
-
computeScale(tileSize) {
|
|
149
|
-
this.transform.scale_x = tileSize;
|
|
150
|
-
this.transform.scale_y = tileSize;
|
|
151
|
-
|
|
152
|
-
this.transform.offset_x = tileSize / 2;
|
|
153
|
-
this.transform.offset_y = tileSize / 2;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {MarkerNode} node
|
|
159
|
-
*/
|
|
160
|
-
addMarker(node) {
|
|
161
|
-
const p = node.position;
|
|
162
|
-
|
|
163
|
-
const x = p.x;
|
|
164
|
-
const y = p.y;
|
|
165
|
-
|
|
166
|
-
const r = node.size;
|
|
167
|
-
|
|
168
|
-
this.markers.add(node, x - r, y - r, x + r, y + r);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
* @param {number} width
|
|
174
|
-
* @param {number} height
|
|
175
|
-
*/
|
|
176
|
-
resize(width, height) {
|
|
177
|
-
assert.isNumber(width, 'width');
|
|
178
|
-
assert.isNumber(height, 'height');
|
|
179
|
-
|
|
180
|
-
assert.isNonNegativeInteger(width, 'width');
|
|
181
|
-
assert.isNonNegativeInteger(height, 'height');
|
|
182
|
-
|
|
183
|
-
assert.
|
|
184
|
-
assert.
|
|
185
|
-
|
|
186
|
-
if (width === this.width && height === this.height) {
|
|
187
|
-
//no need, already the right size
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
this.width = width;
|
|
192
|
-
this.height = height;
|
|
193
|
-
|
|
194
|
-
const layers = this.layers;
|
|
195
|
-
|
|
196
|
-
const n = layers.length;
|
|
197
|
-
|
|
198
|
-
for (let i = 0; i < n; i++) {
|
|
199
|
-
const layer = layers[i];
|
|
200
|
-
|
|
201
|
-
layer.resize(width, height);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// resize the quad tree pre-emptively, to avoid expensive re-balancing operations later on
|
|
205
|
-
this.markers.resize(
|
|
206
|
-
-max2(1, width * 0.5),
|
|
207
|
-
-max2(1, height * 0.5),
|
|
208
|
-
max2(width + 1, width * 1.5),
|
|
209
|
-
max2(height + 1, height * 1.5)
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @readonly
|
|
218
|
-
* @type {boolean}
|
|
219
|
-
*/
|
|
220
|
-
GridData.prototype.isGridData = true;
|
|
1
|
+
import { assert } from "../../core/assert.js";
|
|
2
|
+
import { qt_collect_by_circle } from "../../core/geom/2d/quad-tree/qt_collect_by_circle.js";
|
|
3
|
+
import { QuadTreeNode } from "../../core/geom/2d/quad-tree/QuadTreeNode.js";
|
|
4
|
+
import { max2 } from "../../core/math/max2.js";
|
|
5
|
+
import { OffsetScaleTransform2D } from "../../engine/ecs/terrain/ecs/OffsetScaleTransform2D.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {QuadTreeDatum<MarkerNode>[]}
|
|
10
|
+
*/
|
|
11
|
+
const marker_collection = [];
|
|
12
|
+
|
|
13
|
+
export class GridData {
|
|
14
|
+
|
|
15
|
+
width = 0;
|
|
16
|
+
height = 0;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @readonly
|
|
20
|
+
* @type {OffsetScaleTransform2D}
|
|
21
|
+
*/
|
|
22
|
+
transform = new OffsetScaleTransform2D();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @readonly
|
|
26
|
+
* @type {QuadTreeNode<MarkerNode>}
|
|
27
|
+
*/
|
|
28
|
+
markers = new QuadTreeNode();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Discrete data layers
|
|
32
|
+
* @readonly
|
|
33
|
+
* @type {GridDataLayer[]}
|
|
34
|
+
*/
|
|
35
|
+
layers = [];
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {GridDataLayer} layer
|
|
41
|
+
*/
|
|
42
|
+
addLayer(layer) {
|
|
43
|
+
assert.equal(layer.isGridDataLayer, true, 'layer.GridDataLayer !== true');
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const existing = this.getLayerById(layer.id);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (existing === layer) {
|
|
50
|
+
//layer is already attached
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (existing !== undefined) {
|
|
55
|
+
throw new Error(`Layer with ID '${layer.id}' already exists. ID must be unique`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
layer.resize(this.width, this.height);
|
|
59
|
+
|
|
60
|
+
this.layers.push(layer);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {string} id
|
|
66
|
+
* @returns {GridDataLayer|undefined}
|
|
67
|
+
*/
|
|
68
|
+
getLayerById(id) {
|
|
69
|
+
assert.isString(id, 'id');
|
|
70
|
+
|
|
71
|
+
const layers = this.layers;
|
|
72
|
+
|
|
73
|
+
const n = layers.length;
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
const layer = layers[i];
|
|
77
|
+
|
|
78
|
+
if (layer.id === id) {
|
|
79
|
+
return layer;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param {number} x
|
|
89
|
+
* @param {number} y
|
|
90
|
+
* @param {number} radius
|
|
91
|
+
* @param {MarkerNodeMatcher} matcher
|
|
92
|
+
* @returns {boolean}
|
|
93
|
+
*/
|
|
94
|
+
containsMarkerInCircle(x, y, radius, matcher) {
|
|
95
|
+
return this.countMarkerInCircle(x, y, radius, matcher) > 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param {number} x
|
|
101
|
+
* @param {number} y
|
|
102
|
+
* @param {number} radius
|
|
103
|
+
* @param {MarkerNodeMatcher} matcher
|
|
104
|
+
* @returns {number}
|
|
105
|
+
*/
|
|
106
|
+
countMarkerInCircle(x, y, radius, matcher) {
|
|
107
|
+
const match_count = qt_collect_by_circle(marker_collection, 0, this.markers, x, y, radius);
|
|
108
|
+
|
|
109
|
+
let result = 0;
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < match_count; i++) {
|
|
112
|
+
const marker_datum = marker_collection[i];
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @type {MarkerNode|null}
|
|
117
|
+
*/
|
|
118
|
+
const marker = marker_datum.data;
|
|
119
|
+
|
|
120
|
+
const distance_limit = radius + marker.size;
|
|
121
|
+
|
|
122
|
+
const distance_limit_sqr = distance_limit * distance_limit;
|
|
123
|
+
|
|
124
|
+
// check refined containment
|
|
125
|
+
const position = marker.position;
|
|
126
|
+
|
|
127
|
+
const dx = x - position.x;
|
|
128
|
+
const dy = y - position.y;
|
|
129
|
+
|
|
130
|
+
const distance_sqr = dx * dx + dy * dy;
|
|
131
|
+
|
|
132
|
+
if (distance_sqr > distance_limit_sqr) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (matcher.match(marker)) {
|
|
137
|
+
result++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param tileSize
|
|
147
|
+
*/
|
|
148
|
+
computeScale(tileSize) {
|
|
149
|
+
this.transform.scale_x = tileSize;
|
|
150
|
+
this.transform.scale_y = tileSize;
|
|
151
|
+
|
|
152
|
+
this.transform.offset_x = tileSize / 2;
|
|
153
|
+
this.transform.offset_y = tileSize / 2;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param {MarkerNode} node
|
|
159
|
+
*/
|
|
160
|
+
addMarker(node) {
|
|
161
|
+
const p = node.position;
|
|
162
|
+
|
|
163
|
+
const x = p.x;
|
|
164
|
+
const y = p.y;
|
|
165
|
+
|
|
166
|
+
const r = node.size;
|
|
167
|
+
|
|
168
|
+
this.markers.add(node, x - r, y - r, x + r, y + r);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param {number} width
|
|
174
|
+
* @param {number} height
|
|
175
|
+
*/
|
|
176
|
+
resize(width, height) {
|
|
177
|
+
assert.isNumber(width, 'width');
|
|
178
|
+
assert.isNumber(height, 'height');
|
|
179
|
+
|
|
180
|
+
assert.isNonNegativeInteger(width, 'width');
|
|
181
|
+
assert.isNonNegativeInteger(height, 'height');
|
|
182
|
+
|
|
183
|
+
assert.isFinite(width, 'width');
|
|
184
|
+
assert.isFinite(height, 'width');
|
|
185
|
+
|
|
186
|
+
if (width === this.width && height === this.height) {
|
|
187
|
+
//no need, already the right size
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
this.width = width;
|
|
192
|
+
this.height = height;
|
|
193
|
+
|
|
194
|
+
const layers = this.layers;
|
|
195
|
+
|
|
196
|
+
const n = layers.length;
|
|
197
|
+
|
|
198
|
+
for (let i = 0; i < n; i++) {
|
|
199
|
+
const layer = layers[i];
|
|
200
|
+
|
|
201
|
+
layer.resize(width, height);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// resize the quad tree pre-emptively, to avoid expensive re-balancing operations later on
|
|
205
|
+
this.markers.resize(
|
|
206
|
+
-max2(1, width * 0.5),
|
|
207
|
+
-max2(1, height * 0.5),
|
|
208
|
+
max2(width + 1, width * 1.5),
|
|
209
|
+
max2(height + 1, height * 1.5)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @readonly
|
|
218
|
+
* @type {boolean}
|
|
219
|
+
*/
|
|
220
|
+
GridData.prototype.isGridData = true;
|