Skip to content

Commit

Permalink
Merge pull request #4507 from lasalvavida/idl-rectangles
Browse files Browse the repository at this point in the history
Rotate back across the globe when points cross the IDL
  • Loading branch information
Hannah authored Oct 24, 2016
2 parents 4a6d632 + 2fe71f0 commit 8ba579b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Source/Core/RectangleGeometryLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ define([
var granYSin = 0.0;
var granXSin = 0.0;

if (defined(rotation) && rotation !== 0) { // rotation doesn't work when center is on/near IDL
if (defined(rotation) && rotation !== 0) {
var cosRotation = Math.cos(rotation);
granYCos *= cosRotation;
granXCos *= cosRotation;
Expand All @@ -118,6 +118,10 @@ define([
granYSin = granularityY * sinRotation;
granXSin = granularityX * sinRotation;

if (center.longitude < nwCorner.longitude) {
center.longitude += CesiumMath.TWO_PI;
}

nwCartesian = proj.project(nwCorner, nwCartesian);
centerCartesian = proj.project(center, centerCartesian);

Expand Down
18 changes: 18 additions & 0 deletions Specs/Core/RectangleGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,24 @@ defineSuite([
}).not.toThrowDeveloperError();
});

it('can create rectangle geometry where the nw corner and the center are on opposite sides of the IDL', function() {
var rectangle = new Rectangle(
Math.PI - 0.005,
CesiumMath.PI_OVER_SIX + 0.02,
0.01 - Math.PI,
CesiumMath.PI_OVER_SIX + 0.04
);

var geometry = new RectangleGeometry({
rectangle: rectangle,
rotation: 0.5
});

expect(function() {
RectangleGeometry.createGeometry(geometry);
}).not.toThrowDeveloperError();
});

var rectangle = new RectangleGeometry({
vertexFormat : VertexFormat.POSITION_ONLY,
rectangle : new Rectangle(-2.0, -1.0, 0.0, 1.0),
Expand Down

0 comments on commit 8ba579b

Please sign in to comment.