bruce-models 2.1.1 → 2.1.3

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,51 @@ var EntityGlobe;
7118
7119
  class Grid {
7119
7120
  constructor() {
7120
7121
  this.cells = {};
7121
- this.patches = [];
7122
7122
  }
7123
- GetCellsForView(viewRect) {
7123
+ GetCellsForView(cameraPos, 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
+ let centerX = cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.longitude;
7134
+ let centerY = cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.latitude;
7135
+ if (isNaN(centerX) || isNaN(centerY)) {
7136
+ centerX = (minLon + maxLon) / 2;
7137
+ centerY = (minLat + maxLat) / 2;
7138
+ }
7139
+ const width = Math.ceil((maxLon - curMinLon) / cellDegreeSize);
7140
+ const height = Math.ceil((maxLat - curMinLat) / cellDegreeSize);
7141
+ const cellDistances = [];
7177
7142
  for (let x = 0; x < width; x++) {
7178
7143
  for (let y = 0; y < height; y++) {
7179
- addCell(x, y);
7180
- if (cells.length >= MAX_CELLS) {
7181
- break;
7182
- }
7144
+ const lon = x * cellDegreeSize + curMinLon;
7145
+ const lat = y * cellDegreeSize + curMinLat;
7146
+ const cellCenterX = lon + cellDegreeSize / 2;
7147
+ const cellCenterY = lat + cellDegreeSize / 2;
7148
+ const dist = Math.sqrt(Math.pow(cellCenterX - centerX, 2) + Math.pow(cellCenterY - centerY, 2));
7149
+ cellDistances.push({ x, y, dist });
7150
+ }
7151
+ }
7152
+ cellDistances.sort((a, b) => a.dist - b.dist);
7153
+ for (const { x, y } of cellDistances) {
7154
+ const lon = x * cellDegreeSize + curMinLon;
7155
+ const lat = y * cellDegreeSize + curMinLat;
7156
+ const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
7157
+ cells.push(cell);
7158
+ if (cells.length >= MAX_CELLS) {
7159
+ break;
7183
7160
  }
7184
7161
  }
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
- }
7189
7162
  return cells;
7190
7163
  }
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
7164
  }
7201
7165
  EntityGlobe.Grid = Grid;
7202
7166
  })(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
7167
  function floorValueToCellSize(size, value) {
7209
7168
  return Math.floor(value / size) * size;
7210
7169
  }
@@ -7444,6 +7403,7 @@ var EntityFilterGetter;
7444
7403
  let retryDelay = 0;
7445
7404
  let prevFirstId = "";
7446
7405
  let prevLastId = "";
7406
+ let prevTicks = 0;
7447
7407
  while ((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId) {
7448
7408
  yield delay(RETRY_DELAY_INCREMENT);
7449
7409
  }
@@ -7454,7 +7414,7 @@ var EntityFilterGetter;
7454
7414
  if (alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
7455
7415
  return;
7456
7416
  }
7457
- const cells = this.cells.GetCellsForView(this.viewRect);
7417
+ const cells = this.cells.GetCellsForView(this.viewCenter, this.viewRect);
7458
7418
  (_a = this.onScanUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(cells);
7459
7419
  let curCellIndex = cells.length > 0 ? 0 : null;
7460
7420
  let postedScanning = false;
@@ -7473,8 +7433,12 @@ var EntityFilterGetter;
7473
7433
  }
7474
7434
  const curCell = cells[curCellIndex];
7475
7435
  if (curCell.IsFetched()) {
7436
+ curCell.Fetching = false;
7476
7437
  curCellIndex += 1;
7477
- if (!cells[curCellIndex]) {
7438
+ if (cells[curCellIndex]) {
7439
+ cells[curCellIndex].Fetching = true;
7440
+ }
7441
+ else {
7478
7442
  curCellIndex = null;
7479
7443
  }
7480
7444
  (_b = this.onScanUpdate) === null || _b === void 0 ? void 0 : _b.Trigger(cells);
@@ -7514,6 +7478,7 @@ var EntityFilterGetter;
7514
7478
  // Only mark as fetched when ALL pages are done.
7515
7479
  if (entities.length <= 0) {
7516
7480
  curCell.Fetched = true;
7481
+ curCell.Fetching = false;
7517
7482
  (_d = this.onScanUpdate) === null || _d === void 0 ? void 0 : _d.Trigger(cells);
7518
7483
  continue;
7519
7484
  }
@@ -7522,11 +7487,15 @@ var EntityFilterGetter;
7522
7487
  const first = (_f = (_e = entities[0]) === null || _e === void 0 ? void 0 : _e.Bruce) === null || _f === void 0 ? void 0 : _f.ID;
7523
7488
  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
7489
  if (prevFirstId == first && prevLastId == last) {
7525
- break;
7490
+ prevTicks += 1;
7491
+ if (prevTicks > 3) {
7492
+ break;
7493
+ }
7526
7494
  }
7527
7495
  else {
7528
7496
  prevFirstId = first;
7529
7497
  prevLastId = last;
7498
+ prevTicks = 0;
7530
7499
  }
7531
7500
  }
7532
7501
  curCell.FetchPageIndex++;
@@ -7535,7 +7504,7 @@ var EntityFilterGetter;
7535
7504
  retryDelay = 0;
7536
7505
  }
7537
7506
  catch (e) {
7538
- console.log(e);
7507
+ console.error(e);
7539
7508
  // Request failed so let's add a delay and try again soon.
7540
7509
  retryDelay += RETRY_DELAY_INCREMENT;
7541
7510
  retryAttempts -= 1;