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.
@@ -7092,6 +7092,7 @@ var EntityGlobe;
7092
7092
  this.IsFetched = null;
7093
7093
  this.FetchPageIndex = 0;
7094
7094
  this.Boundaries = null;
7095
+ this.Fetching = false;
7095
7096
  }
7096
7097
  GetBounds() {
7097
7098
  // Entity data works in -180 to 180 range.
@@ -7118,93 +7119,47 @@ var EntityGlobe;
7118
7119
  class Grid {
7119
7120
  constructor() {
7120
7121
  this.cells = {};
7121
- this.patches = [];
7122
7122
  }
7123
7123
  GetCellsForView(viewRect) {
7124
+ const cells = [];
7125
+ const minLat = viewRect.south;
7126
+ const minLon = viewRect.west;
7127
+ const maxLat = viewRect.north;
7128
+ const maxLon = viewRect.east;
7124
7129
  const MAX_CELLS = 150;
7125
- const { south: minLat, west: minLon, north: maxLat, east: maxLon } = viewRect;
7126
7130
  const cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
7127
- const [curMinLon, curMinLat] = [minLon, minLat].map((v) => floorValueToCellSize(cellDegreeSize, v));
7128
- const [width, height] = [maxLon - curMinLon, maxLat - curMinLat].map((v) => v / cellDegreeSize);
7129
- const ids = [];
7130
- const cells = [];
7131
- let max = [curMinLon, curMinLat];
7132
- const intersections = this.intersections(viewRect);
7133
- const addCell = (x, y) => {
7134
- const lon1 = x * cellDegreeSize + curMinLon;
7135
- const lat1 = y * cellDegreeSize + curMinLat;
7136
- const lon2 = lon1 + cellDegreeSize;
7137
- const lat2 = lat1 + cellDegreeSize;
7138
- const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon1, lon2, lat1, lat2);
7139
- /*
7140
- {
7141
- const cell_bounds = { south: lat1, west: lon1, north: lat2, east: lon2 };
7142
- const subcells = [];
7143
- for (const id of intersections) {
7144
- const c = this.cells[id].GetBounds();
7145
- if (contains(c, cell_bounds)) {
7146
- cell.Fetched = true;
7147
- return;
7148
- }
7149
- if (intersects(c, cell_bounds)) {
7150
- const cropped = crop(c, cell.GetBounds());
7151
- subcells.push(cropped);
7152
- }
7153
- }
7154
- let filled = 0;
7155
- while (subcells.length > 0) {
7156
- const c = subcells.pop();
7157
- filled += area(c);
7158
- for (const s of subcells) {
7159
- filled -= intersection(s, c);
7160
- }
7161
- }
7162
- if (filled + Number.EPSILON * 2 > area(cell.GetBounds())) {
7163
- cell.Fetched = true;
7164
- return;
7165
- }
7166
-
7167
- let [x2, y2] = max;
7168
- x2 = Math.max(x2, lon2);
7169
- y2 = Math.max(y2, lat2);
7170
- max = [x2, y2];
7171
- }
7172
- */
7173
- ids.push(id);
7174
- cells.push(cell);
7175
- cells[id] = cell;
7176
- };
7131
+ const curMinLon = floorValueToCellSize(cellDegreeSize, minLon);
7132
+ const curMinLat = floorValueToCellSize(cellDegreeSize, minLat);
7133
+ const width = (maxLon - curMinLon) / cellDegreeSize;
7134
+ const height = (maxLat - curMinLat) / cellDegreeSize;
7135
+ const centerX = (minLon + maxLon) / 2;
7136
+ const centerY = (minLat + maxLat) / 2;
7177
7137
  for (let x = 0; x < width; x++) {
7178
7138
  for (let y = 0; y < height; y++) {
7179
- addCell(x, y);
7180
- if (cells.length >= MAX_CELLS) {
7139
+ const lon = x * cellDegreeSize + curMinLon;
7140
+ const lat = y * cellDegreeSize + curMinLat;
7141
+ const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
7142
+ cells.push(cell);
7143
+ if (cells.length > MAX_CELLS) {
7181
7144
  break;
7182
7145
  }
7183
7146
  }
7184
7147
  }
7185
- const [x2, y2] = max;
7186
- if (x2 != curMinLon && y2 != curMinLat) {
7187
- this.patches.push([{ west: curMinLon, east: x2, south: curMinLat, north: y2 }, ids]);
7188
- }
7148
+ // Sort cells so that the ones closest to the center are first
7149
+ cells.sort((a, b) => {
7150
+ const aCenterX = (a.Boundaries.minLongitude + a.Boundaries.maxLongitude) / 2;
7151
+ const aCenterY = (a.Boundaries.minLatitude + a.Boundaries.maxLatitude) / 2;
7152
+ const bCenterX = (b.Boundaries.minLongitude + b.Boundaries.maxLongitude) / 2;
7153
+ const bCenterY = (b.Boundaries.minLatitude + b.Boundaries.maxLatitude) / 2;
7154
+ const aDist = Math.sqrt(Math.pow(aCenterX - centerX, 2) + Math.pow(aCenterY - centerY, 2));
7155
+ const bDist = Math.sqrt(Math.pow(bCenterX - centerX, 2) + Math.pow(bCenterY - centerY, 2));
7156
+ return aDist - bDist;
7157
+ });
7189
7158
  return cells;
7190
7159
  }
7191
- intersections(withRect) {
7192
- return this.patches
7193
- .filter(([rect, _]) => intersects(rect, withRect))
7194
- .map(([_, ids]) => ids)
7195
- .reduce((all, ids) => {
7196
- all.push(...ids);
7197
- return all;
7198
- }, []);
7199
- }
7200
7160
  }
7201
7161
  EntityGlobe.Grid = Grid;
7202
7162
  })(EntityGlobe || (EntityGlobe = {}));
7203
- function intersects(l, r) {
7204
- const { west: w, south: s, north: n, east: e } = l;
7205
- const { west: wr, south: sr, north: nr, east: er } = r;
7206
- return !(e <= wr || w >= er || n <= sr || s >= nr);
7207
- }
7208
7163
  function floorValueToCellSize(size, value) {
7209
7164
  return Math.floor(value / size) * size;
7210
7165
  }
@@ -7444,6 +7399,7 @@ var EntityFilterGetter;
7444
7399
  let retryDelay = 0;
7445
7400
  let prevFirstId = "";
7446
7401
  let prevLastId = "";
7402
+ let prevTicks = 0;
7447
7403
  while ((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId) {
7448
7404
  yield delay(RETRY_DELAY_INCREMENT);
7449
7405
  }
@@ -7473,8 +7429,12 @@ var EntityFilterGetter;
7473
7429
  }
7474
7430
  const curCell = cells[curCellIndex];
7475
7431
  if (curCell.IsFetched()) {
7432
+ curCell.Fetching = false;
7476
7433
  curCellIndex += 1;
7477
- if (!cells[curCellIndex]) {
7434
+ if (cells[curCellIndex]) {
7435
+ cells[curCellIndex].Fetching = true;
7436
+ }
7437
+ else {
7478
7438
  curCellIndex = null;
7479
7439
  }
7480
7440
  (_b = this.onScanUpdate) === null || _b === void 0 ? void 0 : _b.Trigger(cells);
@@ -7514,6 +7474,7 @@ var EntityFilterGetter;
7514
7474
  // Only mark as fetched when ALL pages are done.
7515
7475
  if (entities.length <= 0) {
7516
7476
  curCell.Fetched = true;
7477
+ curCell.Fetching = false;
7517
7478
  (_d = this.onScanUpdate) === null || _d === void 0 ? void 0 : _d.Trigger(cells);
7518
7479
  continue;
7519
7480
  }
@@ -7522,11 +7483,15 @@ var EntityFilterGetter;
7522
7483
  const first = (_f = (_e = entities[0]) === null || _e === void 0 ? void 0 : _e.Bruce) === null || _f === void 0 ? void 0 : _f.ID;
7523
7484
  const last = (_h = (_g = entities[entities.length - 1]) === null || _g === void 0 ? void 0 : _g.Bruce) === null || _h === void 0 ? void 0 : _h.ID;
7524
7485
  if (prevFirstId == first && prevLastId == last) {
7525
- break;
7486
+ prevTicks += 1;
7487
+ if (prevTicks > 3) {
7488
+ break;
7489
+ }
7526
7490
  }
7527
7491
  else {
7528
7492
  prevFirstId = first;
7529
7493
  prevLastId = last;
7494
+ prevTicks = 0;
7530
7495
  }
7531
7496
  }
7532
7497
  curCell.FetchPageIndex++;
@@ -7535,7 +7500,7 @@ var EntityFilterGetter;
7535
7500
  retryDelay = 0;
7536
7501
  }
7537
7502
  catch (e) {
7538
- console.log(e);
7503
+ console.error(e);
7539
7504
  // Request failed so let's add a delay and try again soon.
7540
7505
  retryDelay += RETRY_DELAY_INCREMENT;
7541
7506
  retryAttempts -= 1;