Skip to content

Commit

Permalink
Merge pull request #3322 from AnalyticalGraphicsInc/rectangleCartoArr…
Browse files Browse the repository at this point in the history
…ayIDL

Modify Rectangle.fromCartographicArray to support rectangles that cross the IDL
  • Loading branch information
bagnell committed Dec 10, 2015
2 parents c796c61 + 1a4a3de commit 87bb36a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Change Log
* Removed `jsonp`. Use `loadJsonp` instead.
* Reduced the amount of both GPU and CPU memory used by terrain. The CPU memory was reduced by up to 40%.
* `CorridorGeometry` and `PolylineVolumeGeometry` render short segments [#3293](https://github.com/AnalyticalGraphicsInc/cesium/issues/3293)
* `Rectangle.fromCartographicArray` finds the smallest rectangle regardess of whether or not it crosses the international date line. [#3227](https://github.com/AnalyticalGraphicsInc/cesium/issues/3227)

### 1.16 - 2015-12-01

Expand Down
44 changes: 31 additions & 13 deletions Source/Core/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,45 @@ define([
}
//>>includeEnd('debug');

var minLon = Number.MAX_VALUE;
var maxLon = -Number.MAX_VALUE;
var minLat = Number.MAX_VALUE;
var maxLat = -Number.MAX_VALUE;
var west = Number.MAX_VALUE;
var east = -Number.MAX_VALUE;
var westOverIDL = Number.MAX_VALUE;
var eastOverIDL = -Number.MAX_VALUE;
var south = Number.MAX_VALUE;
var north = -Number.MAX_VALUE;

for ( var i = 0, len = cartographics.length; i < len; i++) {
var position = cartographics[i];
minLon = Math.min(minLon, position.longitude);
maxLon = Math.max(maxLon, position.longitude);
minLat = Math.min(minLat, position.latitude);
maxLat = Math.max(maxLat, position.latitude);
west = Math.min(west, position.longitude);
east = Math.max(east, position.longitude);
south = Math.min(south, position.latitude);
north = Math.max(north, position.latitude);

var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + CesiumMath.TWO_PI;
westOverIDL = Math.min(westOverIDL, lonAdjusted);
eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
}

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

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

if (!defined(result)) {
return new Rectangle(minLon, minLat, maxLon, maxLat);
return new Rectangle(west, south, east, north);
}

result.west = minLon;
result.south = minLat;
result.east = maxLon;
result.north = maxLat;
result.west = west;
result.south = south;
result.east = east;
result.north = north;
return result;
};

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/RectangleGeometryLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ define([

if (north < -CesiumMath.PI_OVER_TWO || north > CesiumMath.PI_OVER_TWO ||
south < -CesiumMath.PI_OVER_TWO || south > CesiumMath.PI_OVER_TWO) {
throw new DeveloperError('Rotated extent is invalid.');
throw new DeveloperError('Rotated rectangle is invalid. It crosses over either the north or south pole.');
}

rectangle.north = north;
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ define([
Camera.TRANSFORM_2D_INVERSE = Matrix4.inverseTransformation(Camera.TRANSFORM_2D, new Matrix4());

/**
* The default extent the camera will view on creation.
* The default rectangle the camera will view on creation.
* @type Rectangle
*/
Camera.DEFAULT_VIEW_RECTANGLE = Rectangle.fromDegrees(-95.0, -20.0, -70.0, 90.0);
Expand Down
13 changes: 13 additions & 0 deletions Specs/Core/RectangleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ defineSuite([
expect(rectangle.north).toEqual(maxLat.latitude);
});

it('fromCartographicArray produces rectangle that crosses 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 rectangle = Rectangle.fromCartographicArray([minLat, minLon, maxLat, maxLon]);
expect(rectangle.east).toEqual(minLon.longitude);
expect(rectangle.south).toEqual(minLat.latitude);
expect(rectangle.west).toEqual(maxLon.longitude);
expect(rectangle.north).toEqual(maxLat.latitude);
});

it('fromCartographicArray works with a result parameter.', function() {
var minLon = new Cartographic(-0.1, 0.3, 0.0);
var minLat = new Cartographic(0.0, -0.2, 0.0);
Expand Down

0 comments on commit 87bb36a

Please sign in to comment.