bruce-models 0.8.0 → 0.8.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.
@@ -2321,9 +2321,9 @@
2321
2321
  var pointData = points[i];
2322
2322
  var coords = pointData.trim().split(splitterAxis);
2323
2323
  if (coords.length == 2 || coords.length == 3) {
2324
- var longitude = +coords[0];
2325
- var latitude = +coords[1];
2326
- var altitude = coords.length >= 3 ? +coords[2] : 0;
2324
+ var longitude = Number(coords[0]);
2325
+ var latitude = Number(coords[1]);
2326
+ var altitude = Number(coords.length >= 3 ? coords[2] : 0);
2327
2327
  if (longitude != null && latitude != null) {
2328
2328
  result.push({
2329
2329
  altitude: altitude,
@@ -3724,15 +3724,13 @@
3724
3724
  if (cell.Fetched) {
3725
3725
  return true;
3726
3726
  }
3727
- // TODO: If all cells of the size smaller are fetched then this is fetched.
3728
- // TODO: If this is a cell within a larger cell that is fetched then this is fetched.
3729
3727
  return false;
3730
3728
  }
3731
3729
  function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
3732
3730
  var id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
3733
3731
  var cell = getCell(cells, cellSize, lon, maxLon, lat, maxLat);
3734
3732
  if (!cell) {
3735
- cell = cells[id] = new Cell();
3733
+ cell = new Cell();
3736
3734
  cell.Boundaries = {
3737
3735
  minLatitude: lat,
3738
3736
  maxLatitude: maxLat,
@@ -3741,7 +3739,7 @@
3741
3739
  };
3742
3740
  cell.IsFetched = function () { return isCellFetched(cell); };
3743
3741
  }
3744
- return cell;
3742
+ return [id, cell];
3745
3743
  }
3746
3744
  (function (EntityGlobe) {
3747
3745
  var Grid = /** @class */ (function () {
@@ -3749,34 +3747,122 @@
3749
3747
  this.cells = {};
3750
3748
  }
3751
3749
  Grid.prototype.GetCellsForView = function (viewRect) {
3752
- var cells = [];
3753
- var minLat = viewRect.south;
3754
- var minLon = viewRect.west;
3755
- var maxLat = viewRect.north;
3756
- var maxLon = viewRect.east;
3750
+ var _this = this;
3757
3751
  var MAX_CELLS = 150;
3752
+ var minLat = viewRect.south, minLon = viewRect.west, maxLat = viewRect.north, maxLon = viewRect.east;
3758
3753
  var cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
3759
- var curMinLon = floorValueToCellSize(cellDegreeSize, minLon);
3760
- var curMinLat = floorValueToCellSize(cellDegreeSize, minLat);
3761
- var width = (maxLon - curMinLon) / cellDegreeSize;
3762
- var height = (maxLat - curMinLat) / cellDegreeSize;
3754
+ var _a = [minLon, minLat].map(function (v) { return floorValueToCellSize(cellDegreeSize, v); }), curMinLon = _a[0], curMinLat = _a[1];
3755
+ var _b = [maxLon - curMinLon, maxLat - curMinLat].map(function (v) { return v / cellDegreeSize; }), width = _b[0], height = _b[1];
3756
+ var ids = [];
3757
+ var cells = [];
3758
+ var max = [curMinLon, curMinLat];
3759
+ var intersections = this.intersections(viewRect);
3760
+ var addCell = function (x, y) {
3761
+ var lon1 = x * cellDegreeSize + curMinLon;
3762
+ var lat1 = y * cellDegreeSize + curMinLat;
3763
+ var lon2 = lon1 + cellDegreeSize;
3764
+ var lat2 = lat1 + cellDegreeSize;
3765
+ var _a = getOrCreateCell(_this.cells, cellDegreeSize, lon1, lon2, lat1, lat2), id = _a[0], cell = _a[1];
3766
+ {
3767
+ var cell_bounds = { south: lat1, west: lon1, north: lat2, east: lon2 };
3768
+ var subcells = [];
3769
+ for (var _i = 0, intersections_1 = intersections; _i < intersections_1.length; _i++) {
3770
+ var id_1 = intersections_1[_i];
3771
+ var c = _this.cells[id_1].GetBounds();
3772
+ if (contains(c, cell_bounds)) {
3773
+ cell.Fetched = true;
3774
+ return;
3775
+ }
3776
+ if (intersects(c, cell_bounds)) {
3777
+ var cropped = crop(c, cell.GetBounds());
3778
+ subcells.push(cropped);
3779
+ }
3780
+ }
3781
+ var filled = 0;
3782
+ while (subcells.length > 0) {
3783
+ var c = subcells.pop();
3784
+ filled += area(c);
3785
+ for (var _b = 0, subcells_1 = subcells; _b < subcells_1.length; _b++) {
3786
+ var s = subcells_1[_b];
3787
+ filled -= intersection(s, c);
3788
+ }
3789
+ }
3790
+ if (filled + Number.EPSILON * 2 > area(cell.GetBounds())) {
3791
+ cell.Fetched = true;
3792
+ return;
3793
+ }
3794
+ var x2_1 = max[0], y2_1 = max[1];
3795
+ x2_1 = Math.max(x2_1, lon2);
3796
+ y2_1 = Math.max(y2_1, lat2);
3797
+ max = [x2_1, y2_1];
3798
+ }
3799
+ ids.push(id);
3800
+ cells.push(cell);
3801
+ cells[id] = cell;
3802
+ };
3763
3803
  for (var x = 0; x < width; x++) {
3764
3804
  for (var y = 0; y < height; y++) {
3765
- var lon = x * cellDegreeSize + curMinLon;
3766
- var lat = y * cellDegreeSize + curMinLat;
3767
- var cell = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
3768
- cells.push(cell);
3769
- if (cells.length > MAX_CELLS) {
3805
+ addCell(x, y);
3806
+ if (cells.length >= MAX_CELLS) {
3770
3807
  break;
3771
3808
  }
3772
3809
  }
3773
3810
  }
3811
+ var x2 = max[0], y2 = max[1];
3812
+ if (x2 != curMinLon && y2 != curMinLat) {
3813
+ this.patches.push([{ west: curMinLon, east: x2, south: curMinLat, north: y2 }, ids]);
3814
+ }
3774
3815
  return cells;
3775
3816
  };
3817
+ Grid.prototype.intersections = function (withRect) {
3818
+ return this.patches
3819
+ .filter(function (_a) {
3820
+ var rect = _a[0], _ = _a[1];
3821
+ return intersects(rect, withRect);
3822
+ })
3823
+ .map(function (_a) {
3824
+ var _ = _a[0], ids = _a[1];
3825
+ return ids;
3826
+ })
3827
+ .reduce(function (all, ids) {
3828
+ all.push.apply(all, ids);
3829
+ return all;
3830
+ }, []);
3831
+ };
3776
3832
  return Grid;
3777
3833
  }());
3778
3834
  EntityGlobe.Grid = Grid;
3779
- })(exports.EntityGlobe || (exports.EntityGlobe = {}));
3835
+ })(exports.EntityGlobe || (exports.EntityGlobe = {}));
3836
+ function intersects(l, r) {
3837
+ var w = l.west, s = l.south, n = l.north, e = l.east;
3838
+ var wr = r.west, sr = r.south, nr = r.north, er = r.east;
3839
+ return !(e <= wr || w >= er || n <= sr || s >= nr);
3840
+ }
3841
+ function contains(l, r) {
3842
+ var w = l.west, s = l.south, n = l.north, e = l.east;
3843
+ var wr = r.west, sr = r.south, nr = r.north, er = r.east;
3844
+ return !(er < e || wr > w || nr > n || sr < s);
3845
+ }
3846
+ function crop(rect, by) {
3847
+ var w = rect.west, s = rect.south, n = rect.north, e = rect.east;
3848
+ var wc = by.west, sc = by.south, nc = by.north, ec = by.east;
3849
+ w = Math.max(w, ec);
3850
+ e = Math.min(e, wc);
3851
+ s = Math.max(s, nc);
3852
+ n = Math.min(n, sc);
3853
+ return { west: w, south: s, north: n, east: e };
3854
+ }
3855
+ function intersection(l, r) {
3856
+ var w = l.west, s = l.south, n = l.north, e = l.east;
3857
+ var wr = r.west, sr = r.south, nr = r.north, er = r.east;
3858
+ var x = Math.min(e, er) - Math.max(w, wr);
3859
+ var y = Math.min(n, nr) - Math.max(s, sr);
3860
+ return (x > 0 && y > 0) ? x * y : 0;
3861
+ }
3862
+ function area(rect) {
3863
+ var w = rect.west, s = rect.south, n = rect.north, e = rect.east;
3864
+ return Math.abs((e - w) * (n - s));
3865
+ }
3780
3866
 
3781
3867
  var MAX_AREA_IN_DEGREES = 90;
3782
3868
  var MAX_RETRY_ATTEMPTS = 1;