bruce-models 2.1.1 → 2.1.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.
@@ -6986,6 +6986,7 @@
6986
6986
  this.IsFetched = null;
6987
6987
  this.FetchPageIndex = 0;
6988
6988
  this.Boundaries = null;
6989
+ this.Fetching = false;
6989
6990
  }
6990
6991
  GetBounds() {
6991
6992
  // Entity data works in -180 to 180 range.
@@ -7012,93 +7013,47 @@
7012
7013
  class Grid {
7013
7014
  constructor() {
7014
7015
  this.cells = {};
7015
- this.patches = [];
7016
7016
  }
7017
7017
  GetCellsForView(viewRect) {
7018
+ const cells = [];
7019
+ const minLat = viewRect.south;
7020
+ const minLon = viewRect.west;
7021
+ const maxLat = viewRect.north;
7022
+ const maxLon = viewRect.east;
7018
7023
  const MAX_CELLS = 150;
7019
- const { south: minLat, west: minLon, north: maxLat, east: maxLon } = viewRect;
7020
7024
  const cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
7021
- const [curMinLon, curMinLat] = [minLon, minLat].map((v) => floorValueToCellSize(cellDegreeSize, v));
7022
- const [width, height] = [maxLon - curMinLon, maxLat - curMinLat].map((v) => v / cellDegreeSize);
7023
- const ids = [];
7024
- const cells = [];
7025
- let max = [curMinLon, curMinLat];
7026
- const intersections = this.intersections(viewRect);
7027
- const addCell = (x, y) => {
7028
- const lon1 = x * cellDegreeSize + curMinLon;
7029
- const lat1 = y * cellDegreeSize + curMinLat;
7030
- const lon2 = lon1 + cellDegreeSize;
7031
- const lat2 = lat1 + cellDegreeSize;
7032
- const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon1, lon2, lat1, lat2);
7033
- /*
7034
- {
7035
- const cell_bounds = { south: lat1, west: lon1, north: lat2, east: lon2 };
7036
- const subcells = [];
7037
- for (const id of intersections) {
7038
- const c = this.cells[id].GetBounds();
7039
- if (contains(c, cell_bounds)) {
7040
- cell.Fetched = true;
7041
- return;
7042
- }
7043
- if (intersects(c, cell_bounds)) {
7044
- const cropped = crop(c, cell.GetBounds());
7045
- subcells.push(cropped);
7046
- }
7047
- }
7048
- let filled = 0;
7049
- while (subcells.length > 0) {
7050
- const c = subcells.pop();
7051
- filled += area(c);
7052
- for (const s of subcells) {
7053
- filled -= intersection(s, c);
7054
- }
7055
- }
7056
- if (filled + Number.EPSILON * 2 > area(cell.GetBounds())) {
7057
- cell.Fetched = true;
7058
- return;
7059
- }
7060
-
7061
- let [x2, y2] = max;
7062
- x2 = Math.max(x2, lon2);
7063
- y2 = Math.max(y2, lat2);
7064
- max = [x2, y2];
7065
- }
7066
- */
7067
- ids.push(id);
7068
- cells.push(cell);
7069
- cells[id] = cell;
7070
- };
7025
+ const curMinLon = floorValueToCellSize(cellDegreeSize, minLon);
7026
+ const curMinLat = floorValueToCellSize(cellDegreeSize, minLat);
7027
+ const width = (maxLon - curMinLon) / cellDegreeSize;
7028
+ const height = (maxLat - curMinLat) / cellDegreeSize;
7029
+ const centerX = (minLon + maxLon) / 2;
7030
+ const centerY = (minLat + maxLat) / 2;
7071
7031
  for (let x = 0; x < width; x++) {
7072
7032
  for (let y = 0; y < height; y++) {
7073
- addCell(x, y);
7074
- if (cells.length >= MAX_CELLS) {
7033
+ const lon = x * cellDegreeSize + curMinLon;
7034
+ const lat = y * cellDegreeSize + curMinLat;
7035
+ const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
7036
+ cells.push(cell);
7037
+ if (cells.length > MAX_CELLS) {
7075
7038
  break;
7076
7039
  }
7077
7040
  }
7078
7041
  }
7079
- const [x2, y2] = max;
7080
- if (x2 != curMinLon && y2 != curMinLat) {
7081
- this.patches.push([{ west: curMinLon, east: x2, south: curMinLat, north: y2 }, ids]);
7082
- }
7042
+ // Sort cells so that the ones closest to the center are first
7043
+ cells.sort((a, b) => {
7044
+ const aCenterX = (a.Boundaries.minLongitude + a.Boundaries.maxLongitude) / 2;
7045
+ const aCenterY = (a.Boundaries.minLatitude + a.Boundaries.maxLatitude) / 2;
7046
+ const bCenterX = (b.Boundaries.minLongitude + b.Boundaries.maxLongitude) / 2;
7047
+ const bCenterY = (b.Boundaries.minLatitude + b.Boundaries.maxLatitude) / 2;
7048
+ const aDist = Math.sqrt(Math.pow(aCenterX - centerX, 2) + Math.pow(aCenterY - centerY, 2));
7049
+ const bDist = Math.sqrt(Math.pow(bCenterX - centerX, 2) + Math.pow(bCenterY - centerY, 2));
7050
+ return aDist - bDist;
7051
+ });
7083
7052
  return cells;
7084
7053
  }
7085
- intersections(withRect) {
7086
- return this.patches
7087
- .filter(([rect, _]) => intersects(rect, withRect))
7088
- .map(([_, ids]) => ids)
7089
- .reduce((all, ids) => {
7090
- all.push(...ids);
7091
- return all;
7092
- }, []);
7093
- }
7094
7054
  }
7095
7055
  EntityGlobe.Grid = Grid;
7096
7056
  })(exports.EntityGlobe || (exports.EntityGlobe = {}));
7097
- function intersects(l, r) {
7098
- const { west: w, south: s, north: n, east: e } = l;
7099
- const { west: wr, south: sr, north: nr, east: er } = r;
7100
- return !(e <= wr || w >= er || n <= sr || s >= nr);
7101
- }
7102
7057
  function floorValueToCellSize(size, value) {
7103
7058
  return Math.floor(value / size) * size;
7104
7059
  }
@@ -7332,6 +7287,7 @@
7332
7287
  let retryDelay = 0;
7333
7288
  let prevFirstId = "";
7334
7289
  let prevLastId = "";
7290
+ let prevTicks = 0;
7335
7291
  while ((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId) {
7336
7292
  yield delay(RETRY_DELAY_INCREMENT);
7337
7293
  }
@@ -7361,8 +7317,12 @@
7361
7317
  }
7362
7318
  const curCell = cells[curCellIndex];
7363
7319
  if (curCell.IsFetched()) {
7320
+ curCell.Fetching = false;
7364
7321
  curCellIndex += 1;
7365
- if (!cells[curCellIndex]) {
7322
+ if (cells[curCellIndex]) {
7323
+ cells[curCellIndex].Fetching = true;
7324
+ }
7325
+ else {
7366
7326
  curCellIndex = null;
7367
7327
  }
7368
7328
  (_b = this.onScanUpdate) === null || _b === void 0 ? void 0 : _b.Trigger(cells);
@@ -7402,6 +7362,7 @@
7402
7362
  // Only mark as fetched when ALL pages are done.
7403
7363
  if (entities.length <= 0) {
7404
7364
  curCell.Fetched = true;
7365
+ curCell.Fetching = false;
7405
7366
  (_d = this.onScanUpdate) === null || _d === void 0 ? void 0 : _d.Trigger(cells);
7406
7367
  continue;
7407
7368
  }
@@ -7410,11 +7371,15 @@
7410
7371
  const first = (_f = (_e = entities[0]) === null || _e === void 0 ? void 0 : _e.Bruce) === null || _f === void 0 ? void 0 : _f.ID;
7411
7372
  const last = (_h = (_g = entities[entities.length - 1]) === null || _g === void 0 ? void 0 : _g.Bruce) === null || _h === void 0 ? void 0 : _h.ID;
7412
7373
  if (prevFirstId == first && prevLastId == last) {
7413
- break;
7374
+ prevTicks += 1;
7375
+ if (prevTicks > 3) {
7376
+ break;
7377
+ }
7414
7378
  }
7415
7379
  else {
7416
7380
  prevFirstId = first;
7417
7381
  prevLastId = last;
7382
+ prevTicks = 0;
7418
7383
  }
7419
7384
  }
7420
7385
  curCell.FetchPageIndex++;
@@ -7423,7 +7388,7 @@
7423
7388
  retryDelay = 0;
7424
7389
  }
7425
7390
  catch (e) {
7426
- console.log(e);
7391
+ console.error(e);
7427
7392
  // Request failed so let's add a delay and try again soon.
7428
7393
  retryDelay += RETRY_DELAY_INCREMENT;
7429
7394
  retryAttempts -= 1;