Skip to content

Commit

Permalink
Merge pull request #7533 from AnalyticalGraphicsInc/fixPolygonRectang…
Browse files Browse the repository at this point in the history
…leIdl

base polygon geometry rectangle IDL handling on Rectangle.fromCartesianArray
  • Loading branch information
Hannah authored Feb 5, 2019
2 parents 998cf0a + d65bf8e commit 44c5a17
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Change Log
##### Fixes :wrench:
* Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383)
* Fixed Node.js support for the `Resource` class and any functionality using it internally.
* Fixed an issue where some ground polygons crossing the Prime Meridian would have incorrect bounding rectangles. [#7533](https://github.com/AnalyticalGraphicsInc/cesium/pull/7533)

### 1.54 - 2019-02-01

Expand Down
26 changes: 17 additions & 9 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ define([
var startCartographicScratch = new Cartographic();
var endCartographicScratch = new Cartographic();
var idlCross = {
west : 0.0,
east : 0.0
westOverIDL : 0.0,
eastOverIDL : 0.0
};
var ellipsoidGeodesic = new EllipsoidGeodesic();
function computeRectangle(positions, ellipsoid, arcType, granularity, result) {
Expand All @@ -406,8 +406,8 @@ define([
result.south = Number.POSITIVE_INFINITY;
result.north = Number.NEGATIVE_INFINITY;

idlCross.west = Number.POSITIVE_INFINITY;
idlCross.east = Number.NEGATIVE_INFINITY;
idlCross.westOverIDL = Number.POSITIVE_INFINITY;
idlCross.eastOverIDL = Number.NEGATIVE_INFINITY;

var inverseChordLength = 1.0 / CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
var positionsLength = positions.length;
Expand All @@ -429,9 +429,16 @@ define([
ellipsoidGeodesic.setEndPoints(startCartographic, endCartographic);
interpolateAndGrowRectangle(ellipsoidGeodesic, inverseChordLength, result, idlCross);

if (result.east - result.west > idlCross.west - idlCross.east) {
result.east = idlCross.east;
result.west = idlCross.west;
if (result.east - result.west > idlCross.eastOverIDL - idlCross.westOverIDL) {
result.west = idlCross.westOverIDL;
result.east = idlCross.eastOverIDL;

if (result.east > CesiumMath.PI) {
result.east = result.east - CesiumMath.TWO_PI;
}
if (result.west > CesiumMath.PI) {
result.west = result.west - CesiumMath.TWO_PI;
}
}

return result;
Expand All @@ -456,8 +463,9 @@ define([
result.south = Math.min(result.south, latitude);
result.north = Math.max(result.north, latitude);

idlCross.west = longitude > 0.0 ? Math.min(longitude, idlCross.west) : idlCross.west;
idlCross.east = longitude < 0.0 ? Math.max(longitude, idlCross.east) : idlCross.east;
var lonAdjusted = longitude >= 0 ? longitude : longitude + CesiumMath.TWO_PI;
idlCross.westOverIDL = Math.min(idlCross.westOverIDL, lonAdjusted);
idlCross.eastOverIDL = Math.max(idlCross.eastOverIDL, lonAdjusted);
}
}

Expand Down
27 changes: 26 additions & 1 deletion Specs/Core/PolygonGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defineSuite([
'Core/arrayFill',
'Core/BoundingSphere',
'Core/Cartesian3',
'Core/Cartographic',
'Core/Ellipsoid',
'Core/GeometryOffsetAttribute',
'Core/GeometryPipeline',
Expand All @@ -17,6 +18,7 @@ defineSuite([
arrayFill,
BoundingSphere,
Cartesian3,
Cartographic,
Ellipsoid,
GeometryOffsetAttribute,
GeometryPipeline,
Expand Down Expand Up @@ -1095,7 +1097,7 @@ defineSuite([
expect(CesiumMath.toDegrees(boundingRhumb.west)).toEqualEpsilon(-90.0, CesiumMath.EPSILON10);
});

it('computes rectangles that cross the IDL', function() {
it('computes rectangles for rhumbline polygons that cross the IDL', function() {
var pRhumb = new PolygonGeometry({
vertexFormat : VertexFormat.POSITION_AND_ST,
polygonHierarchy: {
Expand All @@ -1116,6 +1118,29 @@ defineSuite([
expect(CesiumMath.toDegrees(boundingRhumb.west)).toEqualEpsilon(175.0, CesiumMath.EPSILON10);
});

it('computes rectangles for geodesic polygons that cross the IDL', function() {
var minLon = Cartographic.fromDegrees(-178, 3);
var minLat = Cartographic.fromDegrees(-179, -4);
var maxLon = Cartographic.fromDegrees(178, 3);
var maxLat = Cartographic.fromDegrees(179, 4);
var cartesianArray = Ellipsoid.WGS84.cartographicArrayToCartesianArray([minLat, minLon, maxLat, maxLon]);

var pGeodesic = new PolygonGeometry({
vertexFormat : VertexFormat.POSITION_AND_ST,
polygonHierarchy: {
positions : cartesianArray
},
granularity: CesiumMath.RADIANS_PER_DEGREE,
arcType : ArcType.GEODESIC
});

var boundingGeodesic = pGeodesic.rectangle;
expect(boundingGeodesic.east).toEqualEpsilon(minLon.longitude, CesiumMath.EPSILON10);
expect(boundingGeodesic.south).toEqualEpsilon(minLat.latitude, CesiumMath.EPSILON10);
expect(boundingGeodesic.west).toEqualEpsilon(maxLon.longitude, CesiumMath.EPSILON10);
expect(boundingGeodesic.north).toEqualEpsilon(maxLat.latitude, CesiumMath.EPSILON10);
});

it('computeRectangle', function() {
var options = {
vertexFormat : VertexFormat.POSITION_AND_ST,
Expand Down

0 comments on commit 44c5a17

Please sign in to comment.