geojs 1.11.0 → 1.11.2

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/geo.lean.js CHANGED
@@ -19585,7 +19585,7 @@ var markerFeature = function markerFeature(arg) {
19585
19585
  var $ = __webpack_require__(5638);
19586
19586
  var timestamp = __webpack_require__(6618);
19587
19587
  var util = __webpack_require__(4634);
19588
- var KDBush = __webpack_require__(379);
19588
+ var KDBush = __webpack_require__(5866);
19589
19589
  KDBush = KDBush.__esModule ? KDBush.default : KDBush;
19590
19590
 
19591
19591
  /**
@@ -21942,7 +21942,7 @@ var pointFeature = function pointFeature(arg) {
21942
21942
  var ClusterGroup = __webpack_require__(9808);
21943
21943
  var geo_event = __webpack_require__(5108);
21944
21944
  var util = __webpack_require__(4634);
21945
- var KDBush = __webpack_require__(379);
21945
+ var KDBush = __webpack_require__(5866);
21946
21946
  KDBush = KDBush.__esModule ? KDBush.default : KDBush;
21947
21947
 
21948
21948
  /**
@@ -25078,7 +25078,7 @@ module.exports = sceneObject;
25078
25078
  * @constant
25079
25079
  * @type {string}
25080
25080
  */
25081
- module.exports = "d817607d58d9dbf80f89b42e116b769e3789138f";
25081
+ module.exports = "c1123d90202a0e8629d90d57aefed8d2fc800864";
25082
25082
 
25083
25083
  /***/ }),
25084
25084
 
@@ -36956,7 +36956,7 @@ module.exports = vectorFeature;
36956
36956
  * @constant
36957
36957
  * @type {string}
36958
36958
  */
36959
- module.exports = "1.11.0";
36959
+ module.exports = "1.11.2";
36960
36960
 
36961
36961
  /***/ }),
36962
36962
 
@@ -40812,6 +40812,14 @@ vgl.texture = function () {
40812
40812
  }
40813
40813
  };
40814
40814
 
40815
+ /**
40816
+ * Return the texture handle.
40817
+ *
40818
+ * @returns {number}
40819
+ */
40820
+ this.textureHandle = function () {
40821
+ return this.m_textureHandle;
40822
+ };
40815
40823
  return this;
40816
40824
  };
40817
40825
  inherit(vgl.texture, vgl.materialAttribute);
@@ -40887,15 +40895,6 @@ vgl.lookupTable = function () {
40887
40895
  this.modified();
40888
40896
  return true;
40889
40897
  };
40890
-
40891
- /**
40892
- * Return the texture handle.
40893
- *
40894
- * @returns {number}
40895
- */
40896
- this.textureHandle = function () {
40897
- return this.m_textureHandle;
40898
- };
40899
40898
  return this;
40900
40899
  };
40901
40900
  inherit(vgl.lookupTable, vgl.texture);
@@ -73846,6 +73845,361 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__3877__;
73846
73845
 
73847
73846
  /***/ }),
73848
73847
 
73848
+ /***/ 5866:
73849
+ /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
73850
+
73851
+ "use strict";
73852
+ __webpack_require__.r(__webpack_exports__);
73853
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
73854
+ /* harmony export */ "default": function() { return /* binding */ KDBush; }
73855
+ /* harmony export */ });
73856
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
73857
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
73858
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
73859
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
73860
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
73861
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
73862
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
73863
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
73864
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
73865
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
73866
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
73867
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
73868
+ var ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
73869
+
73870
+ /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
73871
+
73872
+ var VERSION = 1; // serialized format version
73873
+ var HEADER_SIZE = 8;
73874
+ var KDBush = /*#__PURE__*/function () {
73875
+ /**
73876
+ * Creates an index that will hold a given number of items.
73877
+ * @param {number} numItems
73878
+ * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
73879
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
73880
+ * @param {ArrayBuffer} [data] (For internal use only)
73881
+ */
73882
+ function KDBush(numItems) {
73883
+ var nodeSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
73884
+ var ArrayType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Float64Array;
73885
+ var data = arguments.length > 3 ? arguments[3] : undefined;
73886
+ _classCallCheck(this, KDBush);
73887
+ if (isNaN(numItems) || numItems < 0) throw new Error("Unpexpected numItems value: ".concat(numItems, "."));
73888
+ this.numItems = +numItems;
73889
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
73890
+ this.ArrayType = ArrayType;
73891
+ this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
73892
+ var arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
73893
+ var coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
73894
+ var idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
73895
+ var padCoords = (8 - idsByteSize % 8) % 8;
73896
+ if (arrayTypeIndex < 0) {
73897
+ throw new Error("Unexpected typed array class: ".concat(ArrayType, "."));
73898
+ }
73899
+ if (data && data instanceof ArrayBuffer) {
73900
+ // reconstruct an index from a buffer
73901
+ this.data = data;
73902
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
73903
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
73904
+ this._pos = numItems * 2;
73905
+ this._finished = true;
73906
+ } else {
73907
+ // initialize a new index
73908
+ this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
73909
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
73910
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
73911
+ this._pos = 0;
73912
+ this._finished = false;
73913
+
73914
+ // set header
73915
+ new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
73916
+ new Uint16Array(this.data, 2, 1)[0] = nodeSize;
73917
+ new Uint32Array(this.data, 4, 1)[0] = numItems;
73918
+ }
73919
+ }
73920
+
73921
+ /**
73922
+ * Add a point to the index.
73923
+ * @param {number} x
73924
+ * @param {number} y
73925
+ * @returns {number} An incremental index associated with the added item (starting from `0`).
73926
+ */
73927
+ _createClass(KDBush, [{
73928
+ key: "add",
73929
+ value: function add(x, y) {
73930
+ var index = this._pos >> 1;
73931
+ this.ids[index] = index;
73932
+ this.coords[this._pos++] = x;
73933
+ this.coords[this._pos++] = y;
73934
+ return index;
73935
+ }
73936
+
73937
+ /**
73938
+ * Perform indexing of the added points.
73939
+ */
73940
+ }, {
73941
+ key: "finish",
73942
+ value: function finish() {
73943
+ var numAdded = this._pos >> 1;
73944
+ if (numAdded !== this.numItems) {
73945
+ throw new Error("Added ".concat(numAdded, " items when expected ").concat(this.numItems, "."));
73946
+ }
73947
+ // kd-sort both arrays for efficient search
73948
+ sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
73949
+ this._finished = true;
73950
+ return this;
73951
+ }
73952
+
73953
+ /**
73954
+ * Search the index for items within a given bounding box.
73955
+ * @param {number} minX
73956
+ * @param {number} minY
73957
+ * @param {number} maxX
73958
+ * @param {number} maxY
73959
+ * @returns {number[]} An array of indices correponding to the found items.
73960
+ */
73961
+ }, {
73962
+ key: "range",
73963
+ value: function range(minX, minY, maxX, maxY) {
73964
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
73965
+ var ids = this.ids,
73966
+ coords = this.coords,
73967
+ nodeSize = this.nodeSize;
73968
+ var stack = [0, ids.length - 1, 0];
73969
+ var result = [];
73970
+
73971
+ // recursively search for items in range in the kd-sorted arrays
73972
+ while (stack.length) {
73973
+ var axis = stack.pop() || 0;
73974
+ var right = stack.pop() || 0;
73975
+ var left = stack.pop() || 0;
73976
+
73977
+ // if we reached "tree node", search linearly
73978
+ if (right - left <= nodeSize) {
73979
+ for (var i = left; i <= right; i++) {
73980
+ var _x = coords[2 * i];
73981
+ var _y = coords[2 * i + 1];
73982
+ if (_x >= minX && _x <= maxX && _y >= minY && _y <= maxY) result.push(ids[i]);
73983
+ }
73984
+ continue;
73985
+ }
73986
+
73987
+ // otherwise find the middle index
73988
+ var m = left + right >> 1;
73989
+
73990
+ // include the middle item if it's in range
73991
+ var x = coords[2 * m];
73992
+ var y = coords[2 * m + 1];
73993
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
73994
+
73995
+ // queue search in halves that intersect the query
73996
+ if (axis === 0 ? minX <= x : minY <= y) {
73997
+ stack.push(left);
73998
+ stack.push(m - 1);
73999
+ stack.push(1 - axis);
74000
+ }
74001
+ if (axis === 0 ? maxX >= x : maxY >= y) {
74002
+ stack.push(m + 1);
74003
+ stack.push(right);
74004
+ stack.push(1 - axis);
74005
+ }
74006
+ }
74007
+ return result;
74008
+ }
74009
+
74010
+ /**
74011
+ * Search the index for items within a given radius.
74012
+ * @param {number} qx
74013
+ * @param {number} qy
74014
+ * @param {number} r Query radius.
74015
+ * @returns {number[]} An array of indices correponding to the found items.
74016
+ */
74017
+ }, {
74018
+ key: "within",
74019
+ value: function within(qx, qy, r) {
74020
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
74021
+ var ids = this.ids,
74022
+ coords = this.coords,
74023
+ nodeSize = this.nodeSize;
74024
+ var stack = [0, ids.length - 1, 0];
74025
+ var result = [];
74026
+ var r2 = r * r;
74027
+
74028
+ // recursively search for items within radius in the kd-sorted arrays
74029
+ while (stack.length) {
74030
+ var axis = stack.pop() || 0;
74031
+ var right = stack.pop() || 0;
74032
+ var left = stack.pop() || 0;
74033
+
74034
+ // if we reached "tree node", search linearly
74035
+ if (right - left <= nodeSize) {
74036
+ for (var i = left; i <= right; i++) {
74037
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
74038
+ }
74039
+ continue;
74040
+ }
74041
+
74042
+ // otherwise find the middle index
74043
+ var m = left + right >> 1;
74044
+
74045
+ // include the middle item if it's in range
74046
+ var x = coords[2 * m];
74047
+ var y = coords[2 * m + 1];
74048
+ if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
74049
+
74050
+ // queue search in halves that intersect the query
74051
+ if (axis === 0 ? qx - r <= x : qy - r <= y) {
74052
+ stack.push(left);
74053
+ stack.push(m - 1);
74054
+ stack.push(1 - axis);
74055
+ }
74056
+ if (axis === 0 ? qx + r >= x : qy + r >= y) {
74057
+ stack.push(m + 1);
74058
+ stack.push(right);
74059
+ stack.push(1 - axis);
74060
+ }
74061
+ }
74062
+ return result;
74063
+ }
74064
+ }], [{
74065
+ key: "from",
74066
+ value:
74067
+ /**
74068
+ * Creates an index from raw `ArrayBuffer` data.
74069
+ * @param {ArrayBuffer} data
74070
+ */
74071
+ function from(data) {
74072
+ if (!(data instanceof ArrayBuffer)) {
74073
+ throw new Error('Data must be an instance of ArrayBuffer.');
74074
+ }
74075
+ var _Uint8Array = new Uint8Array(data, 0, 2),
74076
+ _Uint8Array2 = _slicedToArray(_Uint8Array, 2),
74077
+ magic = _Uint8Array2[0],
74078
+ versionAndType = _Uint8Array2[1];
74079
+ if (magic !== 0xdb) {
74080
+ throw new Error('Data does not appear to be in a KDBush format.');
74081
+ }
74082
+ var version = versionAndType >> 4;
74083
+ if (version !== VERSION) {
74084
+ throw new Error("Got v".concat(version, " data when expected v").concat(VERSION, "."));
74085
+ }
74086
+ var ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
74087
+ if (!ArrayType) {
74088
+ throw new Error('Unrecognized array type.');
74089
+ }
74090
+ var _Uint16Array = new Uint16Array(data, 2, 1),
74091
+ _Uint16Array2 = _slicedToArray(_Uint16Array, 1),
74092
+ nodeSize = _Uint16Array2[0];
74093
+ var _Uint32Array = new Uint32Array(data, 4, 1),
74094
+ _Uint32Array2 = _slicedToArray(_Uint32Array, 1),
74095
+ numItems = _Uint32Array2[0];
74096
+ return new KDBush(numItems, nodeSize, ArrayType, data);
74097
+ }
74098
+ }]);
74099
+ return KDBush;
74100
+ }();
74101
+ /**
74102
+ * @param {Uint16Array | Uint32Array} ids
74103
+ * @param {InstanceType<TypedArrayConstructor>} coords
74104
+ * @param {number} nodeSize
74105
+ * @param {number} left
74106
+ * @param {number} right
74107
+ * @param {number} axis
74108
+ */
74109
+
74110
+ function sort(ids, coords, nodeSize, left, right, axis) {
74111
+ if (right - left <= nodeSize) return;
74112
+ var m = left + right >> 1; // middle index
74113
+
74114
+ // sort ids and coords around the middle index so that the halves lie
74115
+ // either left/right or top/bottom correspondingly (taking turns)
74116
+ select(ids, coords, m, left, right, axis);
74117
+
74118
+ // recursively kd-sort first half and second half on the opposite axis
74119
+ sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
74120
+ sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
74121
+ }
74122
+
74123
+ /**
74124
+ * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
74125
+ * [left..k-1] items are smaller than k-th item (on either x or y axis)
74126
+ * @param {Uint16Array | Uint32Array} ids
74127
+ * @param {InstanceType<TypedArrayConstructor>} coords
74128
+ * @param {number} k
74129
+ * @param {number} left
74130
+ * @param {number} right
74131
+ * @param {number} axis
74132
+ */
74133
+ function select(ids, coords, k, left, right, axis) {
74134
+ while (right > left) {
74135
+ if (right - left > 600) {
74136
+ var n = right - left + 1;
74137
+ var m = k - left + 1;
74138
+ var z = Math.log(n);
74139
+ var s = 0.5 * Math.exp(2 * z / 3);
74140
+ var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
74141
+ var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
74142
+ var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
74143
+ select(ids, coords, k, newLeft, newRight, axis);
74144
+ }
74145
+ var t = coords[2 * k + axis];
74146
+ var i = left;
74147
+ var j = right;
74148
+ swapItem(ids, coords, left, k);
74149
+ if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
74150
+ while (i < j) {
74151
+ swapItem(ids, coords, i, j);
74152
+ i++;
74153
+ j--;
74154
+ while (coords[2 * i + axis] < t) i++;
74155
+ while (coords[2 * j + axis] > t) j--;
74156
+ }
74157
+ if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);else {
74158
+ j++;
74159
+ swapItem(ids, coords, j, right);
74160
+ }
74161
+ if (j <= k) left = j + 1;
74162
+ if (k <= j) right = j - 1;
74163
+ }
74164
+ }
74165
+
74166
+ /**
74167
+ * @param {Uint16Array | Uint32Array} ids
74168
+ * @param {InstanceType<TypedArrayConstructor>} coords
74169
+ * @param {number} i
74170
+ * @param {number} j
74171
+ */
74172
+ function swapItem(ids, coords, i, j) {
74173
+ swap(ids, i, j);
74174
+ swap(coords, 2 * i, 2 * j);
74175
+ swap(coords, 2 * i + 1, 2 * j + 1);
74176
+ }
74177
+
74178
+ /**
74179
+ * @param {InstanceType<TypedArrayConstructor>} arr
74180
+ * @param {number} i
74181
+ * @param {number} j
74182
+ */
74183
+ function swap(arr, i, j) {
74184
+ var tmp = arr[i];
74185
+ arr[i] = arr[j];
74186
+ arr[j] = tmp;
74187
+ }
74188
+
74189
+ /**
74190
+ * @param {number} ax
74191
+ * @param {number} ay
74192
+ * @param {number} bx
74193
+ * @param {number} by
74194
+ */
74195
+ function sqDist(ax, ay, bx, by) {
74196
+ var dx = ax - bx;
74197
+ var dy = ay - by;
74198
+ return dx * dx + dy * dy;
74199
+ }
74200
+
74201
+ /***/ }),
74202
+
73849
74203
  /***/ 1485:
73850
74204
  /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
73851
74205
 
@@ -74003,345 +74357,6 @@ __webpack_require__.r(__webpack_exports__);
74003
74357
  });
74004
74358
 
74005
74359
 
74006
- /***/ }),
74007
-
74008
- /***/ 379:
74009
- /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
74010
-
74011
- "use strict";
74012
- __webpack_require__.r(__webpack_exports__);
74013
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
74014
- /* harmony export */ "default": function() { return /* binding */ KDBush; }
74015
- /* harmony export */ });
74016
-
74017
- const ARRAY_TYPES = [
74018
- Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,
74019
- Int32Array, Uint32Array, Float32Array, Float64Array
74020
- ];
74021
-
74022
- /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
74023
-
74024
- const VERSION = 1; // serialized format version
74025
- const HEADER_SIZE = 8;
74026
-
74027
- class KDBush {
74028
-
74029
- /**
74030
- * Creates an index from raw `ArrayBuffer` data.
74031
- * @param {ArrayBuffer} data
74032
- */
74033
- static from(data) {
74034
- if (!(data instanceof ArrayBuffer)) {
74035
- throw new Error('Data must be an instance of ArrayBuffer.');
74036
- }
74037
- const [magic, versionAndType] = new Uint8Array(data, 0, 2);
74038
- if (magic !== 0xdb) {
74039
- throw new Error('Data does not appear to be in a KDBush format.');
74040
- }
74041
- const version = versionAndType >> 4;
74042
- if (version !== VERSION) {
74043
- throw new Error(`Got v${version} data when expected v${VERSION}.`);
74044
- }
74045
- const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
74046
- if (!ArrayType) {
74047
- throw new Error('Unrecognized array type.');
74048
- }
74049
- const [nodeSize] = new Uint16Array(data, 2, 1);
74050
- const [numItems] = new Uint32Array(data, 4, 1);
74051
-
74052
- return new KDBush(numItems, nodeSize, ArrayType, data);
74053
- }
74054
-
74055
- /**
74056
- * Creates an index that will hold a given number of items.
74057
- * @param {number} numItems
74058
- * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
74059
- * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
74060
- * @param {ArrayBuffer} [data] (For internal use only)
74061
- */
74062
- constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {
74063
- if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
74064
-
74065
- this.numItems = +numItems;
74066
- this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
74067
- this.ArrayType = ArrayType;
74068
- this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
74069
-
74070
- const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
74071
- const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
74072
- const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
74073
- const padCoords = (8 - idsByteSize % 8) % 8;
74074
-
74075
- if (arrayTypeIndex < 0) {
74076
- throw new Error(`Unexpected typed array class: ${ArrayType}.`);
74077
- }
74078
-
74079
- if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer
74080
- this.data = data;
74081
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
74082
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
74083
- this._pos = numItems * 2;
74084
- this._finished = true;
74085
- } else { // initialize a new index
74086
- this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
74087
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
74088
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
74089
- this._pos = 0;
74090
- this._finished = false;
74091
-
74092
- // set header
74093
- new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
74094
- new Uint16Array(this.data, 2, 1)[0] = nodeSize;
74095
- new Uint32Array(this.data, 4, 1)[0] = numItems;
74096
- }
74097
- }
74098
-
74099
- /**
74100
- * Add a point to the index.
74101
- * @param {number} x
74102
- * @param {number} y
74103
- * @returns {number} An incremental index associated with the added item (starting from `0`).
74104
- */
74105
- add(x, y) {
74106
- const index = this._pos >> 1;
74107
- this.ids[index] = index;
74108
- this.coords[this._pos++] = x;
74109
- this.coords[this._pos++] = y;
74110
- return index;
74111
- }
74112
-
74113
- /**
74114
- * Perform indexing of the added points.
74115
- */
74116
- finish() {
74117
- const numAdded = this._pos >> 1;
74118
- if (numAdded !== this.numItems) {
74119
- throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);
74120
- }
74121
- // kd-sort both arrays for efficient search
74122
- sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
74123
-
74124
- this._finished = true;
74125
- return this;
74126
- }
74127
-
74128
- /**
74129
- * Search the index for items within a given bounding box.
74130
- * @param {number} minX
74131
- * @param {number} minY
74132
- * @param {number} maxX
74133
- * @param {number} maxY
74134
- * @returns {number[]} An array of indices correponding to the found items.
74135
- */
74136
- range(minX, minY, maxX, maxY) {
74137
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
74138
-
74139
- const {ids, coords, nodeSize} = this;
74140
- const stack = [0, ids.length - 1, 0];
74141
- const result = [];
74142
-
74143
- // recursively search for items in range in the kd-sorted arrays
74144
- while (stack.length) {
74145
- const axis = stack.pop() || 0;
74146
- const right = stack.pop() || 0;
74147
- const left = stack.pop() || 0;
74148
-
74149
- // if we reached "tree node", search linearly
74150
- if (right - left <= nodeSize) {
74151
- for (let i = left; i <= right; i++) {
74152
- const x = coords[2 * i];
74153
- const y = coords[2 * i + 1];
74154
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[i]);
74155
- }
74156
- continue;
74157
- }
74158
-
74159
- // otherwise find the middle index
74160
- const m = (left + right) >> 1;
74161
-
74162
- // include the middle item if it's in range
74163
- const x = coords[2 * m];
74164
- const y = coords[2 * m + 1];
74165
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
74166
-
74167
- // queue search in halves that intersect the query
74168
- if (axis === 0 ? minX <= x : minY <= y) {
74169
- stack.push(left);
74170
- stack.push(m - 1);
74171
- stack.push(1 - axis);
74172
- }
74173
- if (axis === 0 ? maxX >= x : maxY >= y) {
74174
- stack.push(m + 1);
74175
- stack.push(right);
74176
- stack.push(1 - axis);
74177
- }
74178
- }
74179
-
74180
- return result;
74181
- }
74182
-
74183
- /**
74184
- * Search the index for items within a given radius.
74185
- * @param {number} qx
74186
- * @param {number} qy
74187
- * @param {number} r Query radius.
74188
- * @returns {number[]} An array of indices correponding to the found items.
74189
- */
74190
- within(qx, qy, r) {
74191
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
74192
-
74193
- const {ids, coords, nodeSize} = this;
74194
- const stack = [0, ids.length - 1, 0];
74195
- const result = [];
74196
- const r2 = r * r;
74197
-
74198
- // recursively search for items within radius in the kd-sorted arrays
74199
- while (stack.length) {
74200
- const axis = stack.pop() || 0;
74201
- const right = stack.pop() || 0;
74202
- const left = stack.pop() || 0;
74203
-
74204
- // if we reached "tree node", search linearly
74205
- if (right - left <= nodeSize) {
74206
- for (let i = left; i <= right; i++) {
74207
- if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
74208
- }
74209
- continue;
74210
- }
74211
-
74212
- // otherwise find the middle index
74213
- const m = (left + right) >> 1;
74214
-
74215
- // include the middle item if it's in range
74216
- const x = coords[2 * m];
74217
- const y = coords[2 * m + 1];
74218
- if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
74219
-
74220
- // queue search in halves that intersect the query
74221
- if (axis === 0 ? qx - r <= x : qy - r <= y) {
74222
- stack.push(left);
74223
- stack.push(m - 1);
74224
- stack.push(1 - axis);
74225
- }
74226
- if (axis === 0 ? qx + r >= x : qy + r >= y) {
74227
- stack.push(m + 1);
74228
- stack.push(right);
74229
- stack.push(1 - axis);
74230
- }
74231
- }
74232
-
74233
- return result;
74234
- }
74235
- }
74236
-
74237
- /**
74238
- * @param {Uint16Array | Uint32Array} ids
74239
- * @param {InstanceType<TypedArrayConstructor>} coords
74240
- * @param {number} nodeSize
74241
- * @param {number} left
74242
- * @param {number} right
74243
- * @param {number} axis
74244
- */
74245
- function sort(ids, coords, nodeSize, left, right, axis) {
74246
- if (right - left <= nodeSize) return;
74247
-
74248
- const m = (left + right) >> 1; // middle index
74249
-
74250
- // sort ids and coords around the middle index so that the halves lie
74251
- // either left/right or top/bottom correspondingly (taking turns)
74252
- select(ids, coords, m, left, right, axis);
74253
-
74254
- // recursively kd-sort first half and second half on the opposite axis
74255
- sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
74256
- sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
74257
- }
74258
-
74259
- /**
74260
- * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
74261
- * [left..k-1] items are smaller than k-th item (on either x or y axis)
74262
- * @param {Uint16Array | Uint32Array} ids
74263
- * @param {InstanceType<TypedArrayConstructor>} coords
74264
- * @param {number} k
74265
- * @param {number} left
74266
- * @param {number} right
74267
- * @param {number} axis
74268
- */
74269
- function select(ids, coords, k, left, right, axis) {
74270
-
74271
- while (right > left) {
74272
- if (right - left > 600) {
74273
- const n = right - left + 1;
74274
- const m = k - left + 1;
74275
- const z = Math.log(n);
74276
- const s = 0.5 * Math.exp(2 * z / 3);
74277
- const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
74278
- const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
74279
- const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
74280
- select(ids, coords, k, newLeft, newRight, axis);
74281
- }
74282
-
74283
- const t = coords[2 * k + axis];
74284
- let i = left;
74285
- let j = right;
74286
-
74287
- swapItem(ids, coords, left, k);
74288
- if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
74289
-
74290
- while (i < j) {
74291
- swapItem(ids, coords, i, j);
74292
- i++;
74293
- j--;
74294
- while (coords[2 * i + axis] < t) i++;
74295
- while (coords[2 * j + axis] > t) j--;
74296
- }
74297
-
74298
- if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);
74299
- else {
74300
- j++;
74301
- swapItem(ids, coords, j, right);
74302
- }
74303
-
74304
- if (j <= k) left = j + 1;
74305
- if (k <= j) right = j - 1;
74306
- }
74307
- }
74308
-
74309
- /**
74310
- * @param {Uint16Array | Uint32Array} ids
74311
- * @param {InstanceType<TypedArrayConstructor>} coords
74312
- * @param {number} i
74313
- * @param {number} j
74314
- */
74315
- function swapItem(ids, coords, i, j) {
74316
- swap(ids, i, j);
74317
- swap(coords, 2 * i, 2 * j);
74318
- swap(coords, 2 * i + 1, 2 * j + 1);
74319
- }
74320
-
74321
- /**
74322
- * @param {InstanceType<TypedArrayConstructor>} arr
74323
- * @param {number} i
74324
- * @param {number} j
74325
- */
74326
- function swap(arr, i, j) {
74327
- const tmp = arr[i];
74328
- arr[i] = arr[j];
74329
- arr[j] = tmp;
74330
- }
74331
-
74332
- /**
74333
- * @param {number} ax
74334
- * @param {number} ay
74335
- * @param {number} bx
74336
- * @param {number} by
74337
- */
74338
- function sqDist(ax, ay, bx, by) {
74339
- const dx = ax - bx;
74340
- const dy = ay - by;
74341
- return dx * dx + dy * dy;
74342
- }
74343
-
74344
-
74345
74360
  /***/ })
74346
74361
 
74347
74362
  /******/ });