geojs 1.11.0 → 1.11.1

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 = "190e4728c8b60b908db47954c996b369d725fd31";
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.1";
39961
39961
 
39962
39962
  /***/ }),
39963
39963
 
@@ -86391,6 +86391,361 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__999__;
86391
86391
 
86392
86392
  /***/ }),
86393
86393
 
86394
+ /***/ 5866:
86395
+ /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
86396
+
86397
+ "use strict";
86398
+ __webpack_require__.r(__webpack_exports__);
86399
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
86400
+ /* harmony export */ "default": function() { return /* binding */ KDBush; }
86401
+ /* harmony export */ });
86402
+ 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); }
86403
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
86404
+ 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."); }
86405
+ 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); }
86406
+ 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; }
86407
+ 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; } }
86408
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
86409
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
86410
+ 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); } }
86411
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
86412
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
86413
+ 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); }
86414
+ var ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
86415
+
86416
+ /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
86417
+
86418
+ var VERSION = 1; // serialized format version
86419
+ var HEADER_SIZE = 8;
86420
+ var KDBush = /*#__PURE__*/function () {
86421
+ /**
86422
+ * Creates an index that will hold a given number of items.
86423
+ * @param {number} numItems
86424
+ * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
86425
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
86426
+ * @param {ArrayBuffer} [data] (For internal use only)
86427
+ */
86428
+ function KDBush(numItems) {
86429
+ var nodeSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
86430
+ var ArrayType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Float64Array;
86431
+ var data = arguments.length > 3 ? arguments[3] : undefined;
86432
+ _classCallCheck(this, KDBush);
86433
+ if (isNaN(numItems) || numItems < 0) throw new Error("Unpexpected numItems value: ".concat(numItems, "."));
86434
+ this.numItems = +numItems;
86435
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
86436
+ this.ArrayType = ArrayType;
86437
+ this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
86438
+ var arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
86439
+ var coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
86440
+ var idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
86441
+ var padCoords = (8 - idsByteSize % 8) % 8;
86442
+ if (arrayTypeIndex < 0) {
86443
+ throw new Error("Unexpected typed array class: ".concat(ArrayType, "."));
86444
+ }
86445
+ if (data && data instanceof ArrayBuffer) {
86446
+ // reconstruct an index from a buffer
86447
+ this.data = data;
86448
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86449
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86450
+ this._pos = numItems * 2;
86451
+ this._finished = true;
86452
+ } else {
86453
+ // initialize a new index
86454
+ this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
86455
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
86456
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
86457
+ this._pos = 0;
86458
+ this._finished = false;
86459
+
86460
+ // set header
86461
+ new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
86462
+ new Uint16Array(this.data, 2, 1)[0] = nodeSize;
86463
+ new Uint32Array(this.data, 4, 1)[0] = numItems;
86464
+ }
86465
+ }
86466
+
86467
+ /**
86468
+ * Add a point to the index.
86469
+ * @param {number} x
86470
+ * @param {number} y
86471
+ * @returns {number} An incremental index associated with the added item (starting from `0`).
86472
+ */
86473
+ _createClass(KDBush, [{
86474
+ key: "add",
86475
+ value: function add(x, y) {
86476
+ var index = this._pos >> 1;
86477
+ this.ids[index] = index;
86478
+ this.coords[this._pos++] = x;
86479
+ this.coords[this._pos++] = y;
86480
+ return index;
86481
+ }
86482
+
86483
+ /**
86484
+ * Perform indexing of the added points.
86485
+ */
86486
+ }, {
86487
+ key: "finish",
86488
+ value: function finish() {
86489
+ var numAdded = this._pos >> 1;
86490
+ if (numAdded !== this.numItems) {
86491
+ throw new Error("Added ".concat(numAdded, " items when expected ").concat(this.numItems, "."));
86492
+ }
86493
+ // kd-sort both arrays for efficient search
86494
+ sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
86495
+ this._finished = true;
86496
+ return this;
86497
+ }
86498
+
86499
+ /**
86500
+ * Search the index for items within a given bounding box.
86501
+ * @param {number} minX
86502
+ * @param {number} minY
86503
+ * @param {number} maxX
86504
+ * @param {number} maxY
86505
+ * @returns {number[]} An array of indices correponding to the found items.
86506
+ */
86507
+ }, {
86508
+ key: "range",
86509
+ value: function range(minX, minY, maxX, maxY) {
86510
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86511
+ var ids = this.ids,
86512
+ coords = this.coords,
86513
+ nodeSize = this.nodeSize;
86514
+ var stack = [0, ids.length - 1, 0];
86515
+ var result = [];
86516
+
86517
+ // recursively search for items in range in the kd-sorted arrays
86518
+ while (stack.length) {
86519
+ var axis = stack.pop() || 0;
86520
+ var right = stack.pop() || 0;
86521
+ var left = stack.pop() || 0;
86522
+
86523
+ // if we reached "tree node", search linearly
86524
+ if (right - left <= nodeSize) {
86525
+ for (var i = left; i <= right; i++) {
86526
+ var _x = coords[2 * i];
86527
+ var _y = coords[2 * i + 1];
86528
+ if (_x >= minX && _x <= maxX && _y >= minY && _y <= maxY) result.push(ids[i]);
86529
+ }
86530
+ continue;
86531
+ }
86532
+
86533
+ // otherwise find the middle index
86534
+ var m = left + right >> 1;
86535
+
86536
+ // include the middle item if it's in range
86537
+ var x = coords[2 * m];
86538
+ var y = coords[2 * m + 1];
86539
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
86540
+
86541
+ // queue search in halves that intersect the query
86542
+ if (axis === 0 ? minX <= x : minY <= y) {
86543
+ stack.push(left);
86544
+ stack.push(m - 1);
86545
+ stack.push(1 - axis);
86546
+ }
86547
+ if (axis === 0 ? maxX >= x : maxY >= y) {
86548
+ stack.push(m + 1);
86549
+ stack.push(right);
86550
+ stack.push(1 - axis);
86551
+ }
86552
+ }
86553
+ return result;
86554
+ }
86555
+
86556
+ /**
86557
+ * Search the index for items within a given radius.
86558
+ * @param {number} qx
86559
+ * @param {number} qy
86560
+ * @param {number} r Query radius.
86561
+ * @returns {number[]} An array of indices correponding to the found items.
86562
+ */
86563
+ }, {
86564
+ key: "within",
86565
+ value: function within(qx, qy, r) {
86566
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
86567
+ var ids = this.ids,
86568
+ coords = this.coords,
86569
+ nodeSize = this.nodeSize;
86570
+ var stack = [0, ids.length - 1, 0];
86571
+ var result = [];
86572
+ var r2 = r * r;
86573
+
86574
+ // recursively search for items within radius in the kd-sorted arrays
86575
+ while (stack.length) {
86576
+ var axis = stack.pop() || 0;
86577
+ var right = stack.pop() || 0;
86578
+ var left = stack.pop() || 0;
86579
+
86580
+ // if we reached "tree node", search linearly
86581
+ if (right - left <= nodeSize) {
86582
+ for (var i = left; i <= right; i++) {
86583
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
86584
+ }
86585
+ continue;
86586
+ }
86587
+
86588
+ // otherwise find the middle index
86589
+ var m = left + right >> 1;
86590
+
86591
+ // include the middle item if it's in range
86592
+ var x = coords[2 * m];
86593
+ var y = coords[2 * m + 1];
86594
+ if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
86595
+
86596
+ // queue search in halves that intersect the query
86597
+ if (axis === 0 ? qx - r <= x : qy - r <= y) {
86598
+ stack.push(left);
86599
+ stack.push(m - 1);
86600
+ stack.push(1 - axis);
86601
+ }
86602
+ if (axis === 0 ? qx + r >= x : qy + r >= y) {
86603
+ stack.push(m + 1);
86604
+ stack.push(right);
86605
+ stack.push(1 - axis);
86606
+ }
86607
+ }
86608
+ return result;
86609
+ }
86610
+ }], [{
86611
+ key: "from",
86612
+ value:
86613
+ /**
86614
+ * Creates an index from raw `ArrayBuffer` data.
86615
+ * @param {ArrayBuffer} data
86616
+ */
86617
+ function from(data) {
86618
+ if (!(data instanceof ArrayBuffer)) {
86619
+ throw new Error('Data must be an instance of ArrayBuffer.');
86620
+ }
86621
+ var _Uint8Array = new Uint8Array(data, 0, 2),
86622
+ _Uint8Array2 = _slicedToArray(_Uint8Array, 2),
86623
+ magic = _Uint8Array2[0],
86624
+ versionAndType = _Uint8Array2[1];
86625
+ if (magic !== 0xdb) {
86626
+ throw new Error('Data does not appear to be in a KDBush format.');
86627
+ }
86628
+ var version = versionAndType >> 4;
86629
+ if (version !== VERSION) {
86630
+ throw new Error("Got v".concat(version, " data when expected v").concat(VERSION, "."));
86631
+ }
86632
+ var ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
86633
+ if (!ArrayType) {
86634
+ throw new Error('Unrecognized array type.');
86635
+ }
86636
+ var _Uint16Array = new Uint16Array(data, 2, 1),
86637
+ _Uint16Array2 = _slicedToArray(_Uint16Array, 1),
86638
+ nodeSize = _Uint16Array2[0];
86639
+ var _Uint32Array = new Uint32Array(data, 4, 1),
86640
+ _Uint32Array2 = _slicedToArray(_Uint32Array, 1),
86641
+ numItems = _Uint32Array2[0];
86642
+ return new KDBush(numItems, nodeSize, ArrayType, data);
86643
+ }
86644
+ }]);
86645
+ return KDBush;
86646
+ }();
86647
+ /**
86648
+ * @param {Uint16Array | Uint32Array} ids
86649
+ * @param {InstanceType<TypedArrayConstructor>} coords
86650
+ * @param {number} nodeSize
86651
+ * @param {number} left
86652
+ * @param {number} right
86653
+ * @param {number} axis
86654
+ */
86655
+
86656
+ function sort(ids, coords, nodeSize, left, right, axis) {
86657
+ if (right - left <= nodeSize) return;
86658
+ var m = left + right >> 1; // middle index
86659
+
86660
+ // sort ids and coords around the middle index so that the halves lie
86661
+ // either left/right or top/bottom correspondingly (taking turns)
86662
+ select(ids, coords, m, left, right, axis);
86663
+
86664
+ // recursively kd-sort first half and second half on the opposite axis
86665
+ sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
86666
+ sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
86667
+ }
86668
+
86669
+ /**
86670
+ * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
86671
+ * [left..k-1] items are smaller than k-th item (on either x or y axis)
86672
+ * @param {Uint16Array | Uint32Array} ids
86673
+ * @param {InstanceType<TypedArrayConstructor>} coords
86674
+ * @param {number} k
86675
+ * @param {number} left
86676
+ * @param {number} right
86677
+ * @param {number} axis
86678
+ */
86679
+ function select(ids, coords, k, left, right, axis) {
86680
+ while (right > left) {
86681
+ if (right - left > 600) {
86682
+ var n = right - left + 1;
86683
+ var m = k - left + 1;
86684
+ var z = Math.log(n);
86685
+ var s = 0.5 * Math.exp(2 * z / 3);
86686
+ var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
86687
+ var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
86688
+ var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
86689
+ select(ids, coords, k, newLeft, newRight, axis);
86690
+ }
86691
+ var t = coords[2 * k + axis];
86692
+ var i = left;
86693
+ var j = right;
86694
+ swapItem(ids, coords, left, k);
86695
+ if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
86696
+ while (i < j) {
86697
+ swapItem(ids, coords, i, j);
86698
+ i++;
86699
+ j--;
86700
+ while (coords[2 * i + axis] < t) i++;
86701
+ while (coords[2 * j + axis] > t) j--;
86702
+ }
86703
+ if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);else {
86704
+ j++;
86705
+ swapItem(ids, coords, j, right);
86706
+ }
86707
+ if (j <= k) left = j + 1;
86708
+ if (k <= j) right = j - 1;
86709
+ }
86710
+ }
86711
+
86712
+ /**
86713
+ * @param {Uint16Array | Uint32Array} ids
86714
+ * @param {InstanceType<TypedArrayConstructor>} coords
86715
+ * @param {number} i
86716
+ * @param {number} j
86717
+ */
86718
+ function swapItem(ids, coords, i, j) {
86719
+ swap(ids, i, j);
86720
+ swap(coords, 2 * i, 2 * j);
86721
+ swap(coords, 2 * i + 1, 2 * j + 1);
86722
+ }
86723
+
86724
+ /**
86725
+ * @param {InstanceType<TypedArrayConstructor>} arr
86726
+ * @param {number} i
86727
+ * @param {number} j
86728
+ */
86729
+ function swap(arr, i, j) {
86730
+ var tmp = arr[i];
86731
+ arr[i] = arr[j];
86732
+ arr[j] = tmp;
86733
+ }
86734
+
86735
+ /**
86736
+ * @param {number} ax
86737
+ * @param {number} ay
86738
+ * @param {number} bx
86739
+ * @param {number} by
86740
+ */
86741
+ function sqDist(ax, ay, bx, by) {
86742
+ var dx = ax - bx;
86743
+ var dy = ay - by;
86744
+ return dx * dx + dy * dy;
86745
+ }
86746
+
86747
+ /***/ }),
86748
+
86394
86749
  /***/ 1485:
86395
86750
  /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
86396
86751
 
@@ -86548,345 +86903,6 @@ __webpack_require__.r(__webpack_exports__);
86548
86903
  });
86549
86904
 
86550
86905
 
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
86906
  /***/ })
86891
86907
 
86892
86908
  /******/ });