@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.
package/build/worker.js CHANGED
@@ -5374,68 +5374,11 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5374
5374
  // src/filters/tileFeaturesRaster.ts
5375
5375
  import {
5376
5376
  cellToChildren as _cellToChildren,
5377
+ cellToBoundary,
5377
5378
  cellToTile,
5378
5379
  geometryToCells as geometryToCells2,
5379
5380
  getResolution as getResolution2
5380
5381
  } from "quadbin";
5381
-
5382
- // src/utils/CellSet.ts
5383
- var EMPTY_U32 = 2 ** 32 - 1;
5384
- var CellSet = class {
5385
- constructor(cells) {
5386
- /** List of cells stored by the set. Stored by reference, without copying. */
5387
- __publicField(this, "cells");
5388
- /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
5389
- __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
5390
- /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
5391
- __publicField(this, "hashTable");
5392
- this.cells = cells;
5393
- this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
5394
- for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
5395
- this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
5396
- }
5397
- }
5398
- has(cell) {
5399
- const hashIndex = this.hashLookup(cell);
5400
- return this.hashTable[hashIndex] !== EMPTY_U32;
5401
- }
5402
- hashLookup(cell) {
5403
- this.cellView.setBigUint64(0, cell);
5404
- const hashval = hash(this.cellView);
5405
- const hashmod = this.hashTable.length - 1;
5406
- let bucket = hashval & hashmod;
5407
- for (let probe = 0; probe <= hashmod; probe++) {
5408
- const cellIndex = this.hashTable[bucket];
5409
- if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
5410
- return bucket;
5411
- }
5412
- bucket = bucket + probe + 1 & hashmod;
5413
- }
5414
- throw new Error("Hash table full.");
5415
- }
5416
- };
5417
- function hash(view, h = 0) {
5418
- const m = 1540483477;
5419
- const r = 24;
5420
- for (let i = 0, il = view.byteLength / 4; i < il; i++) {
5421
- let k = view.getUint32(i * 4);
5422
- k = Math.imul(k, m) >>> 0;
5423
- k = (k ^ k >> r) >>> 0;
5424
- k = Math.imul(k, m) >>> 0;
5425
- h = Math.imul(h, m) >>> 0;
5426
- h = (h ^ k) >>> 0;
5427
- }
5428
- return h;
5429
- }
5430
- function hashBuckets(initialCount) {
5431
- let buckets = 1;
5432
- while (buckets < initialCount + initialCount / 4) {
5433
- buckets *= 2;
5434
- }
5435
- return buckets;
5436
- }
5437
-
5438
- // src/filters/tileFeaturesRaster.ts
5439
5382
  function tileFeaturesRaster({
5440
5383
  tiles,
5441
5384
  ...options
@@ -5449,15 +5392,20 @@ function tileFeaturesRaster({
5449
5392
  const tileResolution = getResolution2(tiles[0].index.q);
5450
5393
  const tileBlockSize = tiles[0].data.blockSize;
5451
5394
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5452
- const spatialFilterCells = new CellSet(
5453
- geometryToCells2(options.spatialFilter, cellResolution)
5454
- );
5455
5395
  const data = /* @__PURE__ */ new Map();
5456
5396
  for (const tile of tiles) {
5457
5397
  const parent = tile.index.q;
5458
- const children = cellToChildrenSorted(parent, cellResolution);
5459
- for (let i = 0; i < children.length; i++) {
5460
- if (!spatialFilterCells.has(children[i])) continue;
5398
+ const tilePolygon = cellToBoundary(parent);
5399
+ const tileFilter = turf_intersect_default(
5400
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
5401
+ );
5402
+ const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
5403
+ const tileFilterCells = needsFilter ? new Set(geometryToCells2(tileFilter.geometry, cellResolution)) : null;
5404
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5405
+ for (let i = 0; i < tileSortedCells.length; i++) {
5406
+ if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
5407
+ continue;
5408
+ }
5461
5409
  const cellData = {};
5462
5410
  let cellDataExists = false;
5463
5411
  for (const band in tile.data.cells.numericProps) {
@@ -5469,7 +5417,7 @@ function tileFeaturesRaster({
5469
5417
  }
5470
5418
  }
5471
5419
  if (cellDataExists) {
5472
- data.set(children[i], cellData);
5420
+ data.set(tileSortedCells[i], cellData);
5473
5421
  }
5474
5422
  }
5475
5423
  }