bruce-models 2.1.2 → 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.
@@ -7014,7 +7014,7 @@
7014
7014
  constructor() {
7015
7015
  this.cells = {};
7016
7016
  }
7017
- GetCellsForView(viewRect) {
7017
+ GetCellsForView(cameraPos, viewRect) {
7018
7018
  const cells = [];
7019
7019
  const minLat = viewRect.south;
7020
7020
  const minLon = viewRect.west;
@@ -7024,31 +7024,35 @@
7024
7024
  const cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
7025
7025
  const curMinLon = floorValueToCellSize(cellDegreeSize, minLon);
7026
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;
7027
+ let centerX = cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.longitude;
7028
+ let centerY = cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.latitude;
7029
+ if (isNaN(centerX) || isNaN(centerY)) {
7030
+ centerX = (minLon + maxLon) / 2;
7031
+ centerY = (minLat + maxLat) / 2;
7032
+ }
7033
+ const width = Math.ceil((maxLon - curMinLon) / cellDegreeSize);
7034
+ const height = Math.ceil((maxLat - curMinLat) / cellDegreeSize);
7035
+ const cellDistances = [];
7031
7036
  for (let x = 0; x < width; x++) {
7032
7037
  for (let y = 0; y < height; y++) {
7033
7038
  const lon = x * cellDegreeSize + curMinLon;
7034
7039
  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) {
7038
- break;
7039
- }
7040
+ const cellCenterX = lon + cellDegreeSize / 2;
7041
+ const cellCenterY = lat + cellDegreeSize / 2;
7042
+ const dist = Math.sqrt(Math.pow(cellCenterX - centerX, 2) + Math.pow(cellCenterY - centerY, 2));
7043
+ cellDistances.push({ x, y, dist });
7044
+ }
7045
+ }
7046
+ cellDistances.sort((a, b) => a.dist - b.dist);
7047
+ for (const { x, y } of cellDistances) {
7048
+ const lon = x * cellDegreeSize + curMinLon;
7049
+ const lat = y * cellDegreeSize + curMinLat;
7050
+ const [id, cell] = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
7051
+ cells.push(cell);
7052
+ if (cells.length >= MAX_CELLS) {
7053
+ break;
7040
7054
  }
7041
7055
  }
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
- });
7052
7056
  return cells;
7053
7057
  }
7054
7058
  }
@@ -7298,7 +7302,7 @@
7298
7302
  if (alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
7299
7303
  return;
7300
7304
  }
7301
- const cells = this.cells.GetCellsForView(this.viewRect);
7305
+ const cells = this.cells.GetCellsForView(this.viewCenter, this.viewRect);
7302
7306
  (_a = this.onScanUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(cells);
7303
7307
  let curCellIndex = cells.length > 0 ? 0 : null;
7304
7308
  let postedScanning = false;