geojs 1.10.18 → 1.10.19

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 = "0539eada54b7f6ea9a63f07e3526680cebc61e30";
28082
+ module.exports = "27f3b67c529425dab8dc95621608e32b848d9c27";
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.10.18";
39960
+ module.exports = "1.10.19";
39961
39961
 
39962
39962
  /***/ }),
39963
39963
 
@@ -94408,6 +94408,361 @@ module.exports = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJo
94408
94408
 
94409
94409
  /***/ }),
94410
94410
 
94411
+ /***/ 5866:
94412
+ /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
94413
+
94414
+ "use strict";
94415
+ __webpack_require__.r(__webpack_exports__);
94416
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
94417
+ /* harmony export */ "default": function() { return /* binding */ KDBush; }
94418
+ /* harmony export */ });
94419
+ 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); }
94420
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
94421
+ 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."); }
94422
+ 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); }
94423
+ 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; }
94424
+ 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; } }
94425
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
94426
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
94427
+ 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); } }
94428
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
94429
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
94430
+ 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); }
94431
+ var ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
94432
+
94433
+ /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
94434
+
94435
+ var VERSION = 1; // serialized format version
94436
+ var HEADER_SIZE = 8;
94437
+ var KDBush = /*#__PURE__*/function () {
94438
+ /**
94439
+ * Creates an index that will hold a given number of items.
94440
+ * @param {number} numItems
94441
+ * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
94442
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
94443
+ * @param {ArrayBuffer} [data] (For internal use only)
94444
+ */
94445
+ function KDBush(numItems) {
94446
+ var nodeSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
94447
+ var ArrayType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Float64Array;
94448
+ var data = arguments.length > 3 ? arguments[3] : undefined;
94449
+ _classCallCheck(this, KDBush);
94450
+ if (isNaN(numItems) || numItems < 0) throw new Error("Unpexpected numItems value: ".concat(numItems, "."));
94451
+ this.numItems = +numItems;
94452
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
94453
+ this.ArrayType = ArrayType;
94454
+ this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
94455
+ var arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
94456
+ var coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
94457
+ var idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
94458
+ var padCoords = (8 - idsByteSize % 8) % 8;
94459
+ if (arrayTypeIndex < 0) {
94460
+ throw new Error("Unexpected typed array class: ".concat(ArrayType, "."));
94461
+ }
94462
+ if (data && data instanceof ArrayBuffer) {
94463
+ // reconstruct an index from a buffer
94464
+ this.data = data;
94465
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
94466
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
94467
+ this._pos = numItems * 2;
94468
+ this._finished = true;
94469
+ } else {
94470
+ // initialize a new index
94471
+ this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
94472
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
94473
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
94474
+ this._pos = 0;
94475
+ this._finished = false;
94476
+
94477
+ // set header
94478
+ new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
94479
+ new Uint16Array(this.data, 2, 1)[0] = nodeSize;
94480
+ new Uint32Array(this.data, 4, 1)[0] = numItems;
94481
+ }
94482
+ }
94483
+
94484
+ /**
94485
+ * Add a point to the index.
94486
+ * @param {number} x
94487
+ * @param {number} y
94488
+ * @returns {number} An incremental index associated with the added item (starting from `0`).
94489
+ */
94490
+ _createClass(KDBush, [{
94491
+ key: "add",
94492
+ value: function add(x, y) {
94493
+ var index = this._pos >> 1;
94494
+ this.ids[index] = index;
94495
+ this.coords[this._pos++] = x;
94496
+ this.coords[this._pos++] = y;
94497
+ return index;
94498
+ }
94499
+
94500
+ /**
94501
+ * Perform indexing of the added points.
94502
+ */
94503
+ }, {
94504
+ key: "finish",
94505
+ value: function finish() {
94506
+ var numAdded = this._pos >> 1;
94507
+ if (numAdded !== this.numItems) {
94508
+ throw new Error("Added ".concat(numAdded, " items when expected ").concat(this.numItems, "."));
94509
+ }
94510
+ // kd-sort both arrays for efficient search
94511
+ sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
94512
+ this._finished = true;
94513
+ return this;
94514
+ }
94515
+
94516
+ /**
94517
+ * Search the index for items within a given bounding box.
94518
+ * @param {number} minX
94519
+ * @param {number} minY
94520
+ * @param {number} maxX
94521
+ * @param {number} maxY
94522
+ * @returns {number[]} An array of indices correponding to the found items.
94523
+ */
94524
+ }, {
94525
+ key: "range",
94526
+ value: function range(minX, minY, maxX, maxY) {
94527
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
94528
+ var ids = this.ids,
94529
+ coords = this.coords,
94530
+ nodeSize = this.nodeSize;
94531
+ var stack = [0, ids.length - 1, 0];
94532
+ var result = [];
94533
+
94534
+ // recursively search for items in range in the kd-sorted arrays
94535
+ while (stack.length) {
94536
+ var axis = stack.pop() || 0;
94537
+ var right = stack.pop() || 0;
94538
+ var left = stack.pop() || 0;
94539
+
94540
+ // if we reached "tree node", search linearly
94541
+ if (right - left <= nodeSize) {
94542
+ for (var i = left; i <= right; i++) {
94543
+ var _x = coords[2 * i];
94544
+ var _y = coords[2 * i + 1];
94545
+ if (_x >= minX && _x <= maxX && _y >= minY && _y <= maxY) result.push(ids[i]);
94546
+ }
94547
+ continue;
94548
+ }
94549
+
94550
+ // otherwise find the middle index
94551
+ var m = left + right >> 1;
94552
+
94553
+ // include the middle item if it's in range
94554
+ var x = coords[2 * m];
94555
+ var y = coords[2 * m + 1];
94556
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
94557
+
94558
+ // queue search in halves that intersect the query
94559
+ if (axis === 0 ? minX <= x : minY <= y) {
94560
+ stack.push(left);
94561
+ stack.push(m - 1);
94562
+ stack.push(1 - axis);
94563
+ }
94564
+ if (axis === 0 ? maxX >= x : maxY >= y) {
94565
+ stack.push(m + 1);
94566
+ stack.push(right);
94567
+ stack.push(1 - axis);
94568
+ }
94569
+ }
94570
+ return result;
94571
+ }
94572
+
94573
+ /**
94574
+ * Search the index for items within a given radius.
94575
+ * @param {number} qx
94576
+ * @param {number} qy
94577
+ * @param {number} r Query radius.
94578
+ * @returns {number[]} An array of indices correponding to the found items.
94579
+ */
94580
+ }, {
94581
+ key: "within",
94582
+ value: function within(qx, qy, r) {
94583
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
94584
+ var ids = this.ids,
94585
+ coords = this.coords,
94586
+ nodeSize = this.nodeSize;
94587
+ var stack = [0, ids.length - 1, 0];
94588
+ var result = [];
94589
+ var r2 = r * r;
94590
+
94591
+ // recursively search for items within radius in the kd-sorted arrays
94592
+ while (stack.length) {
94593
+ var axis = stack.pop() || 0;
94594
+ var right = stack.pop() || 0;
94595
+ var left = stack.pop() || 0;
94596
+
94597
+ // if we reached "tree node", search linearly
94598
+ if (right - left <= nodeSize) {
94599
+ for (var i = left; i <= right; i++) {
94600
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
94601
+ }
94602
+ continue;
94603
+ }
94604
+
94605
+ // otherwise find the middle index
94606
+ var m = left + right >> 1;
94607
+
94608
+ // include the middle item if it's in range
94609
+ var x = coords[2 * m];
94610
+ var y = coords[2 * m + 1];
94611
+ if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
94612
+
94613
+ // queue search in halves that intersect the query
94614
+ if (axis === 0 ? qx - r <= x : qy - r <= y) {
94615
+ stack.push(left);
94616
+ stack.push(m - 1);
94617
+ stack.push(1 - axis);
94618
+ }
94619
+ if (axis === 0 ? qx + r >= x : qy + r >= y) {
94620
+ stack.push(m + 1);
94621
+ stack.push(right);
94622
+ stack.push(1 - axis);
94623
+ }
94624
+ }
94625
+ return result;
94626
+ }
94627
+ }], [{
94628
+ key: "from",
94629
+ value:
94630
+ /**
94631
+ * Creates an index from raw `ArrayBuffer` data.
94632
+ * @param {ArrayBuffer} data
94633
+ */
94634
+ function from(data) {
94635
+ if (!(data instanceof ArrayBuffer)) {
94636
+ throw new Error('Data must be an instance of ArrayBuffer.');
94637
+ }
94638
+ var _Uint8Array = new Uint8Array(data, 0, 2),
94639
+ _Uint8Array2 = _slicedToArray(_Uint8Array, 2),
94640
+ magic = _Uint8Array2[0],
94641
+ versionAndType = _Uint8Array2[1];
94642
+ if (magic !== 0xdb) {
94643
+ throw new Error('Data does not appear to be in a KDBush format.');
94644
+ }
94645
+ var version = versionAndType >> 4;
94646
+ if (version !== VERSION) {
94647
+ throw new Error("Got v".concat(version, " data when expected v").concat(VERSION, "."));
94648
+ }
94649
+ var ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
94650
+ if (!ArrayType) {
94651
+ throw new Error('Unrecognized array type.');
94652
+ }
94653
+ var _Uint16Array = new Uint16Array(data, 2, 1),
94654
+ _Uint16Array2 = _slicedToArray(_Uint16Array, 1),
94655
+ nodeSize = _Uint16Array2[0];
94656
+ var _Uint32Array = new Uint32Array(data, 4, 1),
94657
+ _Uint32Array2 = _slicedToArray(_Uint32Array, 1),
94658
+ numItems = _Uint32Array2[0];
94659
+ return new KDBush(numItems, nodeSize, ArrayType, data);
94660
+ }
94661
+ }]);
94662
+ return KDBush;
94663
+ }();
94664
+ /**
94665
+ * @param {Uint16Array | Uint32Array} ids
94666
+ * @param {InstanceType<TypedArrayConstructor>} coords
94667
+ * @param {number} nodeSize
94668
+ * @param {number} left
94669
+ * @param {number} right
94670
+ * @param {number} axis
94671
+ */
94672
+
94673
+ function sort(ids, coords, nodeSize, left, right, axis) {
94674
+ if (right - left <= nodeSize) return;
94675
+ var m = left + right >> 1; // middle index
94676
+
94677
+ // sort ids and coords around the middle index so that the halves lie
94678
+ // either left/right or top/bottom correspondingly (taking turns)
94679
+ select(ids, coords, m, left, right, axis);
94680
+
94681
+ // recursively kd-sort first half and second half on the opposite axis
94682
+ sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
94683
+ sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
94684
+ }
94685
+
94686
+ /**
94687
+ * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
94688
+ * [left..k-1] items are smaller than k-th item (on either x or y axis)
94689
+ * @param {Uint16Array | Uint32Array} ids
94690
+ * @param {InstanceType<TypedArrayConstructor>} coords
94691
+ * @param {number} k
94692
+ * @param {number} left
94693
+ * @param {number} right
94694
+ * @param {number} axis
94695
+ */
94696
+ function select(ids, coords, k, left, right, axis) {
94697
+ while (right > left) {
94698
+ if (right - left > 600) {
94699
+ var n = right - left + 1;
94700
+ var m = k - left + 1;
94701
+ var z = Math.log(n);
94702
+ var s = 0.5 * Math.exp(2 * z / 3);
94703
+ var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
94704
+ var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
94705
+ var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
94706
+ select(ids, coords, k, newLeft, newRight, axis);
94707
+ }
94708
+ var t = coords[2 * k + axis];
94709
+ var i = left;
94710
+ var j = right;
94711
+ swapItem(ids, coords, left, k);
94712
+ if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
94713
+ while (i < j) {
94714
+ swapItem(ids, coords, i, j);
94715
+ i++;
94716
+ j--;
94717
+ while (coords[2 * i + axis] < t) i++;
94718
+ while (coords[2 * j + axis] > t) j--;
94719
+ }
94720
+ if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);else {
94721
+ j++;
94722
+ swapItem(ids, coords, j, right);
94723
+ }
94724
+ if (j <= k) left = j + 1;
94725
+ if (k <= j) right = j - 1;
94726
+ }
94727
+ }
94728
+
94729
+ /**
94730
+ * @param {Uint16Array | Uint32Array} ids
94731
+ * @param {InstanceType<TypedArrayConstructor>} coords
94732
+ * @param {number} i
94733
+ * @param {number} j
94734
+ */
94735
+ function swapItem(ids, coords, i, j) {
94736
+ swap(ids, i, j);
94737
+ swap(coords, 2 * i, 2 * j);
94738
+ swap(coords, 2 * i + 1, 2 * j + 1);
94739
+ }
94740
+
94741
+ /**
94742
+ * @param {InstanceType<TypedArrayConstructor>} arr
94743
+ * @param {number} i
94744
+ * @param {number} j
94745
+ */
94746
+ function swap(arr, i, j) {
94747
+ var tmp = arr[i];
94748
+ arr[i] = arr[j];
94749
+ arr[j] = tmp;
94750
+ }
94751
+
94752
+ /**
94753
+ * @param {number} ax
94754
+ * @param {number} ay
94755
+ * @param {number} bx
94756
+ * @param {number} by
94757
+ */
94758
+ function sqDist(ax, ay, bx, by) {
94759
+ var dx = ax - bx;
94760
+ var dy = ay - by;
94761
+ return dx * dx + dy * dy;
94762
+ }
94763
+
94764
+ /***/ }),
94765
+
94411
94766
  /***/ 1485:
94412
94767
  /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
94413
94768
 
@@ -94565,345 +94920,6 @@ __webpack_require__.r(__webpack_exports__);
94565
94920
  });
94566
94921
 
94567
94922
 
94568
- /***/ }),
94569
-
94570
- /***/ 379:
94571
- /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
94572
-
94573
- "use strict";
94574
- __webpack_require__.r(__webpack_exports__);
94575
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
94576
- /* harmony export */ "default": function() { return /* binding */ KDBush; }
94577
- /* harmony export */ });
94578
-
94579
- const ARRAY_TYPES = [
94580
- Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,
94581
- Int32Array, Uint32Array, Float32Array, Float64Array
94582
- ];
94583
-
94584
- /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
94585
-
94586
- const VERSION = 1; // serialized format version
94587
- const HEADER_SIZE = 8;
94588
-
94589
- class KDBush {
94590
-
94591
- /**
94592
- * Creates an index from raw `ArrayBuffer` data.
94593
- * @param {ArrayBuffer} data
94594
- */
94595
- static from(data) {
94596
- if (!(data instanceof ArrayBuffer)) {
94597
- throw new Error('Data must be an instance of ArrayBuffer.');
94598
- }
94599
- const [magic, versionAndType] = new Uint8Array(data, 0, 2);
94600
- if (magic !== 0xdb) {
94601
- throw new Error('Data does not appear to be in a KDBush format.');
94602
- }
94603
- const version = versionAndType >> 4;
94604
- if (version !== VERSION) {
94605
- throw new Error(`Got v${version} data when expected v${VERSION}.`);
94606
- }
94607
- const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
94608
- if (!ArrayType) {
94609
- throw new Error('Unrecognized array type.');
94610
- }
94611
- const [nodeSize] = new Uint16Array(data, 2, 1);
94612
- const [numItems] = new Uint32Array(data, 4, 1);
94613
-
94614
- return new KDBush(numItems, nodeSize, ArrayType, data);
94615
- }
94616
-
94617
- /**
94618
- * Creates an index that will hold a given number of items.
94619
- * @param {number} numItems
94620
- * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
94621
- * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
94622
- * @param {ArrayBuffer} [data] (For internal use only)
94623
- */
94624
- constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {
94625
- if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
94626
-
94627
- this.numItems = +numItems;
94628
- this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
94629
- this.ArrayType = ArrayType;
94630
- this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
94631
-
94632
- const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
94633
- const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
94634
- const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
94635
- const padCoords = (8 - idsByteSize % 8) % 8;
94636
-
94637
- if (arrayTypeIndex < 0) {
94638
- throw new Error(`Unexpected typed array class: ${ArrayType}.`);
94639
- }
94640
-
94641
- if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer
94642
- this.data = data;
94643
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
94644
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
94645
- this._pos = numItems * 2;
94646
- this._finished = true;
94647
- } else { // initialize a new index
94648
- this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
94649
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
94650
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
94651
- this._pos = 0;
94652
- this._finished = false;
94653
-
94654
- // set header
94655
- new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
94656
- new Uint16Array(this.data, 2, 1)[0] = nodeSize;
94657
- new Uint32Array(this.data, 4, 1)[0] = numItems;
94658
- }
94659
- }
94660
-
94661
- /**
94662
- * Add a point to the index.
94663
- * @param {number} x
94664
- * @param {number} y
94665
- * @returns {number} An incremental index associated with the added item (starting from `0`).
94666
- */
94667
- add(x, y) {
94668
- const index = this._pos >> 1;
94669
- this.ids[index] = index;
94670
- this.coords[this._pos++] = x;
94671
- this.coords[this._pos++] = y;
94672
- return index;
94673
- }
94674
-
94675
- /**
94676
- * Perform indexing of the added points.
94677
- */
94678
- finish() {
94679
- const numAdded = this._pos >> 1;
94680
- if (numAdded !== this.numItems) {
94681
- throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);
94682
- }
94683
- // kd-sort both arrays for efficient search
94684
- sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
94685
-
94686
- this._finished = true;
94687
- return this;
94688
- }
94689
-
94690
- /**
94691
- * Search the index for items within a given bounding box.
94692
- * @param {number} minX
94693
- * @param {number} minY
94694
- * @param {number} maxX
94695
- * @param {number} maxY
94696
- * @returns {number[]} An array of indices correponding to the found items.
94697
- */
94698
- range(minX, minY, maxX, maxY) {
94699
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
94700
-
94701
- const {ids, coords, nodeSize} = this;
94702
- const stack = [0, ids.length - 1, 0];
94703
- const result = [];
94704
-
94705
- // recursively search for items in range in the kd-sorted arrays
94706
- while (stack.length) {
94707
- const axis = stack.pop() || 0;
94708
- const right = stack.pop() || 0;
94709
- const left = stack.pop() || 0;
94710
-
94711
- // if we reached "tree node", search linearly
94712
- if (right - left <= nodeSize) {
94713
- for (let i = left; i <= right; i++) {
94714
- const x = coords[2 * i];
94715
- const y = coords[2 * i + 1];
94716
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[i]);
94717
- }
94718
- continue;
94719
- }
94720
-
94721
- // otherwise find the middle index
94722
- const m = (left + right) >> 1;
94723
-
94724
- // include the middle item if it's in range
94725
- const x = coords[2 * m];
94726
- const y = coords[2 * m + 1];
94727
- if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
94728
-
94729
- // queue search in halves that intersect the query
94730
- if (axis === 0 ? minX <= x : minY <= y) {
94731
- stack.push(left);
94732
- stack.push(m - 1);
94733
- stack.push(1 - axis);
94734
- }
94735
- if (axis === 0 ? maxX >= x : maxY >= y) {
94736
- stack.push(m + 1);
94737
- stack.push(right);
94738
- stack.push(1 - axis);
94739
- }
94740
- }
94741
-
94742
- return result;
94743
- }
94744
-
94745
- /**
94746
- * Search the index for items within a given radius.
94747
- * @param {number} qx
94748
- * @param {number} qy
94749
- * @param {number} r Query radius.
94750
- * @returns {number[]} An array of indices correponding to the found items.
94751
- */
94752
- within(qx, qy, r) {
94753
- if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
94754
-
94755
- const {ids, coords, nodeSize} = this;
94756
- const stack = [0, ids.length - 1, 0];
94757
- const result = [];
94758
- const r2 = r * r;
94759
-
94760
- // recursively search for items within radius in the kd-sorted arrays
94761
- while (stack.length) {
94762
- const axis = stack.pop() || 0;
94763
- const right = stack.pop() || 0;
94764
- const left = stack.pop() || 0;
94765
-
94766
- // if we reached "tree node", search linearly
94767
- if (right - left <= nodeSize) {
94768
- for (let i = left; i <= right; i++) {
94769
- if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
94770
- }
94771
- continue;
94772
- }
94773
-
94774
- // otherwise find the middle index
94775
- const m = (left + right) >> 1;
94776
-
94777
- // include the middle item if it's in range
94778
- const x = coords[2 * m];
94779
- const y = coords[2 * m + 1];
94780
- if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
94781
-
94782
- // queue search in halves that intersect the query
94783
- if (axis === 0 ? qx - r <= x : qy - r <= y) {
94784
- stack.push(left);
94785
- stack.push(m - 1);
94786
- stack.push(1 - axis);
94787
- }
94788
- if (axis === 0 ? qx + r >= x : qy + r >= y) {
94789
- stack.push(m + 1);
94790
- stack.push(right);
94791
- stack.push(1 - axis);
94792
- }
94793
- }
94794
-
94795
- return result;
94796
- }
94797
- }
94798
-
94799
- /**
94800
- * @param {Uint16Array | Uint32Array} ids
94801
- * @param {InstanceType<TypedArrayConstructor>} coords
94802
- * @param {number} nodeSize
94803
- * @param {number} left
94804
- * @param {number} right
94805
- * @param {number} axis
94806
- */
94807
- function sort(ids, coords, nodeSize, left, right, axis) {
94808
- if (right - left <= nodeSize) return;
94809
-
94810
- const m = (left + right) >> 1; // middle index
94811
-
94812
- // sort ids and coords around the middle index so that the halves lie
94813
- // either left/right or top/bottom correspondingly (taking turns)
94814
- select(ids, coords, m, left, right, axis);
94815
-
94816
- // recursively kd-sort first half and second half on the opposite axis
94817
- sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
94818
- sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
94819
- }
94820
-
94821
- /**
94822
- * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
94823
- * [left..k-1] items are smaller than k-th item (on either x or y axis)
94824
- * @param {Uint16Array | Uint32Array} ids
94825
- * @param {InstanceType<TypedArrayConstructor>} coords
94826
- * @param {number} k
94827
- * @param {number} left
94828
- * @param {number} right
94829
- * @param {number} axis
94830
- */
94831
- function select(ids, coords, k, left, right, axis) {
94832
-
94833
- while (right > left) {
94834
- if (right - left > 600) {
94835
- const n = right - left + 1;
94836
- const m = k - left + 1;
94837
- const z = Math.log(n);
94838
- const s = 0.5 * Math.exp(2 * z / 3);
94839
- const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
94840
- const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
94841
- const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
94842
- select(ids, coords, k, newLeft, newRight, axis);
94843
- }
94844
-
94845
- const t = coords[2 * k + axis];
94846
- let i = left;
94847
- let j = right;
94848
-
94849
- swapItem(ids, coords, left, k);
94850
- if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
94851
-
94852
- while (i < j) {
94853
- swapItem(ids, coords, i, j);
94854
- i++;
94855
- j--;
94856
- while (coords[2 * i + axis] < t) i++;
94857
- while (coords[2 * j + axis] > t) j--;
94858
- }
94859
-
94860
- if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);
94861
- else {
94862
- j++;
94863
- swapItem(ids, coords, j, right);
94864
- }
94865
-
94866
- if (j <= k) left = j + 1;
94867
- if (k <= j) right = j - 1;
94868
- }
94869
- }
94870
-
94871
- /**
94872
- * @param {Uint16Array | Uint32Array} ids
94873
- * @param {InstanceType<TypedArrayConstructor>} coords
94874
- * @param {number} i
94875
- * @param {number} j
94876
- */
94877
- function swapItem(ids, coords, i, j) {
94878
- swap(ids, i, j);
94879
- swap(coords, 2 * i, 2 * j);
94880
- swap(coords, 2 * i + 1, 2 * j + 1);
94881
- }
94882
-
94883
- /**
94884
- * @param {InstanceType<TypedArrayConstructor>} arr
94885
- * @param {number} i
94886
- * @param {number} j
94887
- */
94888
- function swap(arr, i, j) {
94889
- const tmp = arr[i];
94890
- arr[i] = arr[j];
94891
- arr[j] = tmp;
94892
- }
94893
-
94894
- /**
94895
- * @param {number} ax
94896
- * @param {number} ay
94897
- * @param {number} bx
94898
- * @param {number} by
94899
- */
94900
- function sqDist(ax, ay, bx, by) {
94901
- const dx = ax - bx;
94902
- const dy = ay - by;
94903
- return dx * dx + dy * dy;
94904
- }
94905
-
94906
-
94907
94923
  /***/ })
94908
94924
 
94909
94925
  /******/ });