@carto/api-client 0.5.7-alpha.5 → 0.5.7-alpha.6

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.
@@ -5452,8 +5452,8 @@
5452
5452
  }
5453
5453
  if (ring && y === ring[0][1]) ring.pop();
5454
5454
  }
5455
- function appendHashTiles(hash2, tiles2) {
5456
- var keys = Object.keys(hash2);
5455
+ function appendHashTiles(hash, tiles2) {
5456
+ var keys = Object.keys(hash);
5457
5457
  for (var i = 0; i < keys.length; i++) {
5458
5458
  tiles2.push(fromID(+keys[i]));
5459
5459
  }
@@ -5468,6 +5468,26 @@
5468
5468
  }
5469
5469
  var B2 = [0x5555555555555555n, 0x3333333333333333n, 0x0f0f0f0f0f0f0f0fn, 0x00ff00ff00ff00ffn, 0x0000ffff0000ffffn, 0x00000000ffffffffn];
5470
5470
  var S = [0n, 1n, 2n, 4n, 8n, 16n];
5471
+ var TILE_SIZE2 = 512;
5472
+ function cellToOffset(quadbin) {
5473
+ const {
5474
+ x,
5475
+ y,
5476
+ z
5477
+ } = cellToTile(quadbin);
5478
+ const scale2 = TILE_SIZE2 / (1 << z);
5479
+ return [x * scale2, TILE_SIZE2 - y * scale2, scale2];
5480
+ }
5481
+ function cellToWorldBounds(quadbin, coverage) {
5482
+ const [xOffset, yOffset, scale2] = cellToOffset(quadbin);
5483
+ return [[xOffset, yOffset], [xOffset + coverage * scale2, yOffset - coverage * scale2]];
5484
+ }
5485
+ function getCellPolygon(quadbin, coverage = 1) {
5486
+ const [topLeft, bottomRight] = cellToWorldBounds(quadbin, coverage);
5487
+ const [w, n] = worldToLngLat(topLeft);
5488
+ const [e, s] = worldToLngLat(bottomRight);
5489
+ return [e, n, e, s, w, s, w, n, e, n];
5490
+ }
5471
5491
  function tileToCell(tile) {
5472
5492
  if (tile.z < 0 || tile.z > 26) {
5473
5493
  throw new Error("Wrong zoom");
@@ -5540,6 +5560,14 @@
5540
5560
  z
5541
5561
  }));
5542
5562
  }
5563
+ function cellToBoundary(cell) {
5564
+ const bbox2 = getCellPolygon(cell);
5565
+ const boundary = [[bbox2[0], bbox2[1]], [bbox2[2], bbox2[3]], [bbox2[4], bbox2[5]], [bbox2[6], bbox2[7]], [bbox2[0], bbox2[1]]];
5566
+ return {
5567
+ type: "Polygon",
5568
+ coordinates: [boundary]
5569
+ };
5570
+ }
5543
5571
 
5544
5572
  // node_modules/@turf/bbox-clip/dist/esm/index.js
5545
5573
  function lineclip(points, bbox2, result) {
@@ -19756,62 +19784,6 @@
19756
19784
  var DEFAULT_AGGREGATION_EXP_ALIAS = "__aggregationValue";
19757
19785
  var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
19758
19786
 
19759
- // src/utils/CellSet.ts
19760
- var EMPTY_U32 = 2 ** 32 - 1;
19761
- var CellSet = class {
19762
- constructor(cells) {
19763
- /** List of cells stored by the set. Stored by reference, without copying. */
19764
- __publicField(this, "cells");
19765
- /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
19766
- __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
19767
- /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
19768
- __publicField(this, "hashTable");
19769
- this.cells = cells;
19770
- this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
19771
- for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
19772
- this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
19773
- }
19774
- }
19775
- has(cell) {
19776
- const hashIndex = this.hashLookup(cell);
19777
- return this.hashTable[hashIndex] !== EMPTY_U32;
19778
- }
19779
- hashLookup(cell) {
19780
- this.cellView.setBigUint64(0, cell);
19781
- const hashval = hash(this.cellView);
19782
- const hashmod = this.hashTable.length - 1;
19783
- let bucket = hashval & hashmod;
19784
- for (let probe = 0; probe <= hashmod; probe++) {
19785
- const cellIndex = this.hashTable[bucket];
19786
- if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
19787
- return bucket;
19788
- }
19789
- bucket = bucket + probe + 1 & hashmod;
19790
- }
19791
- throw new Error("Hash table full.");
19792
- }
19793
- };
19794
- function hash(view, h = 0) {
19795
- const m = 1540483477;
19796
- const r = 24;
19797
- for (let i = 0, il = view.byteLength / 4; i < il; i++) {
19798
- let k = view.getUint32(i * 4);
19799
- k = Math.imul(k, m) >>> 0;
19800
- k = (k ^ k >> r) >>> 0;
19801
- k = Math.imul(k, m) >>> 0;
19802
- h = Math.imul(h, m) >>> 0;
19803
- h = (h ^ k) >>> 0;
19804
- }
19805
- return h;
19806
- }
19807
- function hashBuckets(initialCount) {
19808
- let buckets = 1;
19809
- while (buckets < initialCount + initialCount / 4) {
19810
- buckets *= 2;
19811
- }
19812
- return buckets;
19813
- }
19814
-
19815
19787
  // src/filters/tileFeaturesRaster.ts
19816
19788
  function tileFeaturesRaster({
19817
19789
  tiles: tiles2,
@@ -19826,15 +19798,20 @@
19826
19798
  const tileResolution = getResolution(tiles2[0].index.q);
19827
19799
  const tileBlockSize = tiles2[0].data.blockSize;
19828
19800
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
19829
- const spatialFilterCells = new CellSet(
19830
- geometryToCells(options.spatialFilter, cellResolution)
19831
- );
19832
19801
  const data = /* @__PURE__ */ new Map();
19833
19802
  for (const tile of tiles2) {
19834
19803
  const parent = tile.index.q;
19835
- const children = cellToChildrenSorted(parent, cellResolution);
19836
- for (let i = 0; i < children.length; i++) {
19837
- if (!spatialFilterCells.has(children[i])) continue;
19804
+ const tilePolygon = cellToBoundary(parent);
19805
+ const tileFilter = turf_intersect_default(
19806
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
19807
+ );
19808
+ const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
19809
+ const tileFilterCells = needsFilter ? new Set(geometryToCells(tileFilter.geometry, cellResolution)) : null;
19810
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
19811
+ for (let i = 0; i < tileSortedCells.length; i++) {
19812
+ if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
19813
+ continue;
19814
+ }
19838
19815
  const cellData = {};
19839
19816
  let cellDataExists = false;
19840
19817
  for (const band in tile.data.cells.numericProps) {
@@ -19846,7 +19823,7 @@
19846
19823
  }
19847
19824
  }
19848
19825
  if (cellDataExists) {
19849
- data.set(children[i], cellData);
19826
+ data.set(tileSortedCells[i], cellData);
19850
19827
  }
19851
19828
  }
19852
19829
  }