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.js CHANGED
@@ -22586,7 +22586,7 @@ var markerFeature = function markerFeature(arg) {
22586
22586
  var $ = __webpack_require__(5638);
22587
22587
  var timestamp = __webpack_require__(6618);
22588
22588
  var util = __webpack_require__(4634);
22589
- var KDBush = __webpack_require__(379);
22589
+ var KDBush = __webpack_require__(5866);
22590
22590
  KDBush = KDBush.__esModule ? KDBush.default : KDBush;
22591
22591
 
22592
22592
  /**
@@ -24943,7 +24943,7 @@ var pointFeature = function pointFeature(arg) {
24943
24943
  var ClusterGroup = __webpack_require__(9808);
24944
24944
  var geo_event = __webpack_require__(5108);
24945
24945
  var util = __webpack_require__(4634);
24946
- var KDBush = __webpack_require__(379);
24946
+ var KDBush = __webpack_require__(5866);
24947
24947
  KDBush = KDBush.__esModule ? KDBush.default : KDBush;
24948
24948
 
24949
24949
  /**
@@ -28079,7 +28079,7 @@ module.exports = sceneObject;
28079
28079
  * @constant
28080
28080
  * @type {string}
28081
28081
  */
28082
- module.exports = "d817607d58d9dbf80f89b42e116b769e3789138f";
28082
+ module.exports = "c1123d90202a0e8629d90d57aefed8d2fc800864";
28083
28083
 
28084
28084
  /***/ }),
28085
28085
 
@@ -39957,7 +39957,7 @@ module.exports = vectorFeature;
39957
39957
  * @constant
39958
39958
  * @type {string}
39959
39959
  */
39960
- module.exports = "1.11.0";
39960
+ module.exports = "1.11.2";
39961
39961
 
39962
39962
  /***/ }),
39963
39963
 
@@ -43813,6 +43813,14 @@ vgl.texture = function () {
43813
43813
  }
43814
43814
  };
43815
43815
 
43816
+ /**
43817
+ * Return the texture handle.
43818
+ *
43819
+ * @returns {number}
43820
+ */
43821
+ this.textureHandle = function () {
43822
+ return this.m_textureHandle;
43823
+ };
43816
43824
  return this;
43817
43825
  };
43818
43826
  inherit(vgl.texture, vgl.materialAttribute);
@@ -43888,15 +43896,6 @@ vgl.lookupTable = function () {
43888
43896
  this.modified();
43889
43897
  return true;
43890
43898
  };
43891
-
43892
- /**
43893
- * Return the texture handle.
43894
- *
43895
- * @returns {number}
43896
- */
43897
- this.textureHandle = function () {
43898
- return this.m_textureHandle;
43899
- };
43900
43899
  return this;
43901
43900
  };
43902
43901
  inherit(vgl.lookupTable, vgl.texture);
@@ -86391,6 +86390,361 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__999__;
86391
86390
 
86392
86391
  /***/ }),
86393
86392
 
86393
+ /***/ 5866:
86394
+ /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
86395
+
86396
+ "use strict";
86397
+ __webpack_require__.r(__webpack_exports__);
86398
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
86399
+ /* harmony export */ "default": function() { return /* binding */ KDBush; }
86400
+ /* harmony export */ });
86401
+ 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); }
86402
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
86403
+ 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."); }
86404
+ 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); }
86405
+ 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; }
86406
+ 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; } }
86407
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
86408
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
86409
+ 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); } }
86410
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
86411
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
86412
+ 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); }
86413
+ var ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
86414
+
86415
+ /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
86416
+
86417
+ var VERSION = 1; // serialized format version
86418
+ var HEADER_SIZE = 8;
86419
+ var KDBush = /*#__PURE__*/function () {
86420
+ /**
86421
+ * Creates an index that will hold a given number of items.
86422
+ * @param {number} numItems
86423
+ * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
86424
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
86425
+ * @param {ArrayBuffer} [data] (For internal use only)
86426
+ */
86427
+ function KDBush(numItems) {
86428
+ var nodeSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
86429
+ var ArrayType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Float64Array;
86430
+ var data = arguments.length > 3 ? arguments[3] : undefined;
86431
+ _classCallCheck(this, KDBush);
86432
+ if (isNaN(numItems) || numItems < 0) throw new Error("Unpexpected numItems value: ".concat(numItems, "."));
86433
+ this.numItems = +numItems;
86434
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
86435
+ this.ArrayType = ArrayType;
86436
+ this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
86437
+ var arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
86438
+ var coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
86439
+ var idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
86440
+ var padCoords = (8 - idsByteSize % 8) % 8;
86441
+ if (arrayTypeIndex < 0) {
86442
+ throw new Error("Unexpected typed array class: ".concat(ArrayType, "."));
86443
+ }
86444
+ if (data && data instanceof ArrayBuffer) {
86445
+ // reconstruct an index from a buffer
86446
+ this.data = data;
86447
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86448
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86449
+ this._pos = numItems * 2;
86450
+ this._finished = true;
86451
+ } else {
86452
+ // initialize a new index
86453
+ this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
86454
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86455
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86456
+ this._pos = 0;
86457
+ this._finished = false;
86458
+
86459
+ // set header
86460
+ new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
86461
+ new Uint16Array(this.data, 2, 1)[0] = nodeSize;
86462
+ new Uint32Array(this.data, 4, 1)[0] = numItems;
86463
+ }
86464
+ }
86465
+
86466
+ /**
86467
+ * Add a point to the index.
86468
+ * @param {number} x
86469
+ * @param {number} y
86470
+ * @returns {number} An incremental index associated with the added item (starting from `0`).
86471
+ */
86472
+ _createClass(KDBush, [{
86473
+ key: "add",
86474
+ value: function add(x, y) {
86475
+ var index = this._pos >> 1;
86476
+ this.ids[index] = index;
86477
+ this.coords[this._pos++] = x;
86478
+ this.coords[this._pos++] = y;
86479
+ return index;
86480
+ }
86481
+
86482
+ /**
86483
+ * Perform indexing of the added points.
86484
+ */
86485
+ }, {
86486
+ key: "finish",
86487
+ value: function finish() {
86488
+ var numAdded = this._pos >> 1;
86489
+ if (numAdded !== this.numItems) {
86490
+ throw new Error("Added ".concat(numAdded, " items when expected ").concat(this.numItems, "."));
86491
+ }
86492
+ // kd-sort both arrays for efficient search
86493
+ sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
86494
+ this._finished = true;
86495
+ return this;
86496
+ }
86497
+
86498
+ /**
86499
+ * Search the index for items within a given bounding box.
86500
+ * @param {number} minX
86501
+ * @param {number} minY
86502
+ * @param {number} maxX
86503
+ * @param {number} maxY
86504
+ * @returns {number[]} An array of indices correponding to the found items.
86505
+ */
86506
+ }, {
86507
+ key: "range",
86508
+ value: function range(minX, minY, maxX, maxY) {
86509
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86510
+ var ids = this.ids,
86511
+ coords = this.coords,
86512
+ nodeSize = this.nodeSize;
86513
+ var stack = [0, ids.length - 1, 0];
86514
+ var result = [];
86515
+
86516
+ // recursively search for items in range in the kd-sorted arrays
86517
+ while (stack.length) {
86518
+ var axis = stack.pop() || 0;
86519
+ var right = stack.pop() || 0;
86520
+ var left = stack.pop() || 0;
86521
+
86522
+ // if we reached "tree node", search linearly
86523
+ if (right - left <= nodeSize) {
86524
+ for (var i = left; i <= right; i++) {
86525
+ var _x = coords[2 * i];
86526
+ var _y = coords[2 * i + 1];
86527
+ if (_x >= minX && _x <= maxX && _y >= minY && _y <= maxY) result.push(ids[i]);
86528
+ }
86529
+ continue;
86530
+ }
86531
+
86532
+ // otherwise find the middle index
86533
+ var m = left + right >> 1;
86534
+
86535
+ // include the middle item if it's in range
86536
+ var x = coords[2 * m];
86537
+ var y = coords[2 * m + 1];
86538
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
86539
+
86540
+ // queue search in halves that intersect the query
86541
+ if (axis === 0 ? minX <= x : minY <= y) {
86542
+ stack.push(left);
86543
+ stack.push(m - 1);
86544
+ stack.push(1 - axis);
86545
+ }
86546
+ if (axis === 0 ? maxX >= x : maxY >= y) {
86547
+ stack.push(m + 1);
86548
+ stack.push(right);
86549
+ stack.push(1 - axis);
86550
+ }
86551
+ }
86552
+ return result;
86553
+ }
86554
+
86555
+ /**
86556
+ * Search the index for items within a given radius.
86557
+ * @param {number} qx
86558
+ * @param {number} qy
86559
+ * @param {number} r Query radius.
86560
+ * @returns {number[]} An array of indices correponding to the found items.
86561
+ */
86562
+ }, {
86563
+ key: "within",
86564
+ value: function within(qx, qy, r) {
86565
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86566
+ var ids = this.ids,
86567
+ coords = this.coords,
86568
+ nodeSize = this.nodeSize;
86569
+ var stack = [0, ids.length - 1, 0];
86570
+ var result = [];
86571
+ var r2 = r * r;
86572
+
86573
+ // recursively search for items within radius in the kd-sorted arrays
86574
+ while (stack.length) {
86575
+ var axis = stack.pop() || 0;
86576
+ var right = stack.pop() || 0;
86577
+ var left = stack.pop() || 0;
86578
+
86579
+ // if we reached "tree node", search linearly
86580
+ if (right - left <= nodeSize) {
86581
+ for (var i = left; i <= right; i++) {
86582
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
86583
+ }
86584
+ continue;
86585
+ }
86586
+
86587
+ // otherwise find the middle index
86588
+ var m = left + right >> 1;
86589
+
86590
+ // include the middle item if it's in range
86591
+ var x = coords[2 * m];
86592
+ var y = coords[2 * m + 1];
86593
+ if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
86594
+
86595
+ // queue search in halves that intersect the query
86596
+ if (axis === 0 ? qx - r <= x : qy - r <= y) {
86597
+ stack.push(left);
86598
+ stack.push(m - 1);
86599
+ stack.push(1 - axis);
86600
+ }
86601
+ if (axis === 0 ? qx + r >= x : qy + r >= y) {
86602
+ stack.push(m + 1);
86603
+ stack.push(right);
86604
+ stack.push(1 - axis);
86605
+ }
86606
+ }
86607
+ return result;
86608
+ }
86609
+ }], [{
86610
+ key: "from",
86611
+ value:
86612
+ /**
86613
+ * Creates an index from raw `ArrayBuffer` data.
86614
+ * @param {ArrayBuffer} data
86615
+ */
86616
+ function from(data) {
86617
+ if (!(data instanceof ArrayBuffer)) {
86618
+ throw new Error('Data must be an instance of ArrayBuffer.');
86619
+ }
86620
+ var _Uint8Array = new Uint8Array(data, 0, 2),
86621
+ _Uint8Array2 = _slicedToArray(_Uint8Array, 2),
86622
+ magic = _Uint8Array2[0],
86623
+ versionAndType = _Uint8Array2[1];
86624
+ if (magic !== 0xdb) {
86625
+ throw new Error('Data does not appear to be in a KDBush format.');
86626
+ }
86627
+ var version = versionAndType >> 4;
86628
+ if (version !== VERSION) {
86629
+ throw new Error("Got v".concat(version, " data when expected v").concat(VERSION, "."));
86630
+ }
86631
+ var ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
86632
+ if (!ArrayType) {
86633
+ throw new Error('Unrecognized array type.');
86634
+ }
86635
+ var _Uint16Array = new Uint16Array(data, 2, 1),
86636
+ _Uint16Array2 = _slicedToArray(_Uint16Array, 1),
86637
+ nodeSize = _Uint16Array2[0];
86638
+ var _Uint32Array = new Uint32Array(data, 4, 1),
86639
+ _Uint32Array2 = _slicedToArray(_Uint32Array, 1),
86640
+ numItems = _Uint32Array2[0];
86641
+ return new KDBush(numItems, nodeSize, ArrayType, data);
86642
+ }
86643
+ }]);
86644
+ return KDBush;
86645
+ }();
86646
+ /**
86647
+ * @param {Uint16Array | Uint32Array} ids
86648
+ * @param {InstanceType<TypedArrayConstructor>} coords
86649
+ * @param {number} nodeSize
86650
+ * @param {number} left
86651
+ * @param {number} right
86652
+ * @param {number} axis
86653
+ */
86654
+
86655
+ function sort(ids, coords, nodeSize, left, right, axis) {
86656
+ if (right - left <= nodeSize) return;
86657
+ var m = left + right >> 1; // middle index
86658
+
86659
+ // sort ids and coords around the middle index so that the halves lie
86660
+ // either left/right or top/bottom correspondingly (taking turns)
86661
+ select(ids, coords, m, left, right, axis);
86662
+
86663
+ // recursively kd-sort first half and second half on the opposite axis
86664
+ sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
86665
+ sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
86666
+ }
86667
+
86668
+ /**
86669
+ * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
86670
+ * [left..k-1] items are smaller than k-th item (on either x or y axis)
86671
+ * @param {Uint16Array | Uint32Array} ids
86672
+ * @param {InstanceType<TypedArrayConstructor>} coords
86673
+ * @param {number} k
86674
+ * @param {number} left
86675
+ * @param {number} right
86676
+ * @param {number} axis
86677
+ */
86678
+ function select(ids, coords, k, left, right, axis) {
86679
+ while (right > left) {
86680
+ if (right - left > 600) {
86681
+ var n = right - left + 1;
86682
+ var m = k - left + 1;
86683
+ var z = Math.log(n);
86684
+ var s = 0.5 * Math.exp(2 * z / 3);
86685
+ var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
86686
+ var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
86687
+ var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
86688
+ select(ids, coords, k, newLeft, newRight, axis);
86689
+ }
86690
+ var t = coords[2 * k + axis];
86691
+ var i = left;
86692
+ var j = right;
86693
+ swapItem(ids, coords, left, k);
86694
+ if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
86695
+ while (i < j) {
86696
+ swapItem(ids, coords, i, j);
86697
+ i++;
86698
+ j--;
86699
+ while (coords[2 * i + axis] < t) i++;
86700
+ while (coords[2 * j + axis] > t) j--;
86701
+ }
86702
+ if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);else {
86703
+ j++;
86704
+ swapItem(ids, coords, j, right);
86705
+ }
86706
+ if (j <= k) left = j + 1;
86707
+ if (k <= j) right = j - 1;
86708
+ }
86709
+ }
86710
+
86711
+ /**
86712
+ * @param {Uint16Array | Uint32Array} ids
86713
+ * @param {InstanceType<TypedArrayConstructor>} coords
86714
+ * @param {number} i
86715
+ * @param {number} j
86716
+ */
86717
+ function swapItem(ids, coords, i, j) {
86718
+ swap(ids, i, j);
86719
+ swap(coords, 2 * i, 2 * j);
86720
+ swap(coords, 2 * i + 1, 2 * j + 1);
86721
+ }
86722
+
86723
+ /**
86724
+ * @param {InstanceType<TypedArrayConstructor>} arr
86725
+ * @param {number} i
86726
+ * @param {number} j
86727
+ */
86728
+ function swap(arr, i, j) {
86729
+ var tmp = arr[i];
86730
+ arr[i] = arr[j];
86731
+ arr[j] = tmp;
86732
+ }
86733
+
86734
+ /**
86735
+ * @param {number} ax
86736
+ * @param {number} ay
86737
+ * @param {number} bx
86738
+ * @param {number} by
86739
+ */
86740
+ function sqDist(ax, ay, bx, by) {
86741
+ var dx = ax - bx;
86742
+ var dy = ay - by;
86743
+ return dx * dx + dy * dy;
86744
+ }
86745
+
86746
+ /***/ }),
86747
+
86394
86748
  /***/ 1485:
86395
86749
  /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
86396
86750
 
@@ -86548,345 +86902,6 @@ __webpack_require__.r(__webpack_exports__);
86548
86902
  });
86549
86903
 
86550
86904
 
86551
- /***/ }),
86552
-
86553
- /***/ 379:
86554
- /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
86555
-
86556
- "use strict";
86557
- __webpack_require__.r(__webpack_exports__);
86558
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
86559
- /* harmony export */ "default": function() { return /* binding */ KDBush; }
86560
- /* harmony export */ });
86561
-
86562
- const ARRAY_TYPES = [
86563
- Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,
86564
- Int32Array, Uint32Array, Float32Array, Float64Array
86565
- ];
86566
-
86567
- /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
86568
-
86569
- const VERSION = 1; // serialized format version
86570
- const HEADER_SIZE = 8;
86571
-
86572
- class KDBush {
86573
-
86574
- /**
86575
- * Creates an index from raw `ArrayBuffer` data.
86576
- * @param {ArrayBuffer} data
86577
- */
86578
- static from(data) {
86579
- if (!(data instanceof ArrayBuffer)) {
86580
- throw new Error('Data must be an instance of ArrayBuffer.');
86581
- }
86582
- const [magic, versionAndType] = new Uint8Array(data, 0, 2);
86583
- if (magic !== 0xdb) {
86584
- throw new Error('Data does not appear to be in a KDBush format.');
86585
- }
86586
- const version = versionAndType >> 4;
86587
- if (version !== VERSION) {
86588
- throw new Error(`Got v${version} data when expected v${VERSION}.`);
86589
- }
86590
- const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
86591
- if (!ArrayType) {
86592
- throw new Error('Unrecognized array type.');
86593
- }
86594
- const [nodeSize] = new Uint16Array(data, 2, 1);
86595
- const [numItems] = new Uint32Array(data, 4, 1);
86596
-
86597
- return new KDBush(numItems, nodeSize, ArrayType, data);
86598
- }
86599
-
86600
- /**
86601
- * Creates an index that will hold a given number of items.
86602
- * @param {number} numItems
86603
- * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
86604
- * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
86605
- * @param {ArrayBuffer} [data] (For internal use only)
86606
- */
86607
- constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {
86608
- if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
86609
-
86610
- this.numItems = +numItems;
86611
- this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
86612
- this.ArrayType = ArrayType;
86613
- this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
86614
-
86615
- const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
86616
- const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
86617
- const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
86618
- const padCoords = (8 - idsByteSize % 8) % 8;
86619
-
86620
- if (arrayTypeIndex < 0) {
86621
- throw new Error(`Unexpected typed array class: ${ArrayType}.`);
86622
- }
86623
-
86624
- if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer
86625
- this.data = data;
86626
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86627
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86628
- this._pos = numItems * 2;
86629
- this._finished = true;
86630
- } else { // initialize a new index
86631
- this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
86632
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86633
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86634
- this._pos = 0;
86635
- this._finished = false;
86636
-
86637
- // set header
86638
- new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
86639
- new Uint16Array(this.data, 2, 1)[0] = nodeSize;
86640
- new Uint32Array(this.data, 4, 1)[0] = numItems;
86641
- }
86642
- }
86643
-
86644
- /**
86645
- * Add a point to the index.
86646
- * @param {number} x
86647
- * @param {number} y
86648
- * @returns {number} An incremental index associated with the added item (starting from `0`).
86649
- */
86650
- add(x, y) {
86651
- const index = this._pos >> 1;
86652
- this.ids[index] = index;
86653
- this.coords[this._pos++] = x;
86654
- this.coords[this._pos++] = y;
86655
- return index;
86656
- }
86657
-
86658
- /**
86659
- * Perform indexing of the added points.
86660
- */
86661
- finish() {
86662
- const numAdded = this._pos >> 1;
86663
- if (numAdded !== this.numItems) {
86664
- throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);
86665
- }
86666
- // kd-sort both arrays for efficient search
86667
- sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
86668
-
86669
- this._finished = true;
86670
- return this;
86671
- }
86672
-
86673
- /**
86674
- * Search the index for items within a given bounding box.
86675
- * @param {number} minX
86676
- * @param {number} minY
86677
- * @param {number} maxX
86678
- * @param {number} maxY
86679
- * @returns {number[]} An array of indices correponding to the found items.
86680
- */
86681
- range(minX, minY, maxX, maxY) {
86682
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86683
-
86684
- const {ids, coords, nodeSize} = this;
86685
- const stack = [0, ids.length - 1, 0];
86686
- const result = [];
86687
-
86688
- // recursively search for items in range in the kd-sorted arrays
86689
- while (stack.length) {
86690
- const axis = stack.pop() || 0;
86691
- const right = stack.pop() || 0;
86692
- const left = stack.pop() || 0;
86693
-
86694
- // if we reached "tree node", search linearly
86695
- if (right - left <= nodeSize) {
86696
- for (let i = left; i <= right; i++) {
86697
- const x = coords[2 * i];
86698
- const y = coords[2 * i + 1];
86699
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[i]);
86700
- }
86701
- continue;
86702
- }
86703
-
86704
- // otherwise find the middle index
86705
- const m = (left + right) >> 1;
86706
-
86707
- // include the middle item if it's in range
86708
- const x = coords[2 * m];
86709
- const y = coords[2 * m + 1];
86710
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
86711
-
86712
- // queue search in halves that intersect the query
86713
- if (axis === 0 ? minX <= x : minY <= y) {
86714
- stack.push(left);
86715
- stack.push(m - 1);
86716
- stack.push(1 - axis);
86717
- }
86718
- if (axis === 0 ? maxX >= x : maxY >= y) {
86719
- stack.push(m + 1);
86720
- stack.push(right);
86721
- stack.push(1 - axis);
86722
- }
86723
- }
86724
-
86725
- return result;
86726
- }
86727
-
86728
- /**
86729
- * Search the index for items within a given radius.
86730
- * @param {number} qx
86731
- * @param {number} qy
86732
- * @param {number} r Query radius.
86733
- * @returns {number[]} An array of indices correponding to the found items.
86734
- */
86735
- within(qx, qy, r) {
86736
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86737
-
86738
- const {ids, coords, nodeSize} = this;
86739
- const stack = [0, ids.length - 1, 0];
86740
- const result = [];
86741
- const r2 = r * r;
86742
-
86743
- // recursively search for items within radius in the kd-sorted arrays
86744
- while (stack.length) {
86745
- const axis = stack.pop() || 0;
86746
- const right = stack.pop() || 0;
86747
- const left = stack.pop() || 0;
86748
-
86749
- // if we reached "tree node", search linearly
86750
- if (right - left <= nodeSize) {
86751
- for (let i = left; i <= right; i++) {
86752
- if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
86753
- }
86754
- continue;
86755
- }
86756
-
86757
- // otherwise find the middle index
86758
- const m = (left + right) >> 1;
86759
-
86760
- // include the middle item if it's in range
86761
- const x = coords[2 * m];
86762
- const y = coords[2 * m + 1];
86763
- if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
86764
-
86765
- // queue search in halves that intersect the query
86766
- if (axis === 0 ? qx - r <= x : qy - r <= y) {
86767
- stack.push(left);
86768
- stack.push(m - 1);
86769
- stack.push(1 - axis);
86770
- }
86771
- if (axis === 0 ? qx + r >= x : qy + r >= y) {
86772
- stack.push(m + 1);
86773
- stack.push(right);
86774
- stack.push(1 - axis);
86775
- }
86776
- }
86777
-
86778
- return result;
86779
- }
86780
- }
86781
-
86782
- /**
86783
- * @param {Uint16Array | Uint32Array} ids
86784
- * @param {InstanceType<TypedArrayConstructor>} coords
86785
- * @param {number} nodeSize
86786
- * @param {number} left
86787
- * @param {number} right
86788
- * @param {number} axis
86789
- */
86790
- function sort(ids, coords, nodeSize, left, right, axis) {
86791
- if (right - left <= nodeSize) return;
86792
-
86793
- const m = (left + right) >> 1; // middle index
86794
-
86795
- // sort ids and coords around the middle index so that the halves lie
86796
- // either left/right or top/bottom correspondingly (taking turns)
86797
- select(ids, coords, m, left, right, axis);
86798
-
86799
- // recursively kd-sort first half and second half on the opposite axis
86800
- sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
86801
- sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
86802
- }
86803
-
86804
- /**
86805
- * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
86806
- * [left..k-1] items are smaller than k-th item (on either x or y axis)
86807
- * @param {Uint16Array | Uint32Array} ids
86808
- * @param {InstanceType<TypedArrayConstructor>} coords
86809
- * @param {number} k
86810
- * @param {number} left
86811
- * @param {number} right
86812
- * @param {number} axis
86813
- */
86814
- function select(ids, coords, k, left, right, axis) {
86815
-
86816
- while (right > left) {
86817
- if (right - left > 600) {
86818
- const n = right - left + 1;
86819
- const m = k - left + 1;
86820
- const z = Math.log(n);
86821
- const s = 0.5 * Math.exp(2 * z / 3);
86822
- const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
86823
- const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
86824
- const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
86825
- select(ids, coords, k, newLeft, newRight, axis);
86826
- }
86827
-
86828
- const t = coords[2 * k + axis];
86829
- let i = left;
86830
- let j = right;
86831
-
86832
- swapItem(ids, coords, left, k);
86833
- if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
86834
-
86835
- while (i < j) {
86836
- swapItem(ids, coords, i, j);
86837
- i++;
86838
- j--;
86839
- while (coords[2 * i + axis] < t) i++;
86840
- while (coords[2 * j + axis] > t) j--;
86841
- }
86842
-
86843
- if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);
86844
- else {
86845
- j++;
86846
- swapItem(ids, coords, j, right);
86847
- }
86848
-
86849
- if (j <= k) left = j + 1;
86850
- if (k <= j) right = j - 1;
86851
- }
86852
- }
86853
-
86854
- /**
86855
- * @param {Uint16Array | Uint32Array} ids
86856
- * @param {InstanceType<TypedArrayConstructor>} coords
86857
- * @param {number} i
86858
- * @param {number} j
86859
- */
86860
- function swapItem(ids, coords, i, j) {
86861
- swap(ids, i, j);
86862
- swap(coords, 2 * i, 2 * j);
86863
- swap(coords, 2 * i + 1, 2 * j + 1);
86864
- }
86865
-
86866
- /**
86867
- * @param {InstanceType<TypedArrayConstructor>} arr
86868
- * @param {number} i
86869
- * @param {number} j
86870
- */
86871
- function swap(arr, i, j) {
86872
- const tmp = arr[i];
86873
- arr[i] = arr[j];
86874
- arr[j] = tmp;
86875
- }
86876
-
86877
- /**
86878
- * @param {number} ax
86879
- * @param {number} ay
86880
- * @param {number} bx
86881
- * @param {number} by
86882
- */
86883
- function sqDist(ax, ay, bx, by) {
86884
- const dx = ax - bx;
86885
- const dy = ay - by;
86886
- return dx * dx + dy * dy;
86887
- }
86888
-
86889
-
86890
86905
  /***/ })
86891
86906
 
86892
86907
  /******/ });