Skip to content

Commit

Permalink
Merge pull request #4732 from AnalyticalGraphicsInc/rect-union-idl
Browse files Browse the repository at this point in the history
Fixed Rectangle.union to take rectangles crossing the IDL into account.
  • Loading branch information
pjcozzi authored Dec 8, 2016
2 parents 94eb9d6 + 6e11d3d commit cdd66dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

* Added the ability to blend a `Model` with a color/translucency. Added `color`, `colorBlendMode`, and `colorBlendAmount` properties to `Model`, `ModelGraphics`, and CZML. Added `ColorBlendMode` enum. [#4547](https://github.com/AnalyticalGraphicsInc/cesium/pull/4547)
* Fixed tooltips for gallery thumbnails in Sandcastle [#4702](https://github.com/AnalyticalGraphicsInc/cesium/pull/4702)
* Fixed `Rectangle.union` to correctly account for rectangles that cross the IDL [#4732](https://github.com/AnalyticalGraphicsInc/cesium/pull/4732).
* Fixed texture rotation for `RectangleGeometry` [#2737](https://github.com/AnalyticalGraphicsInc/cesium/issues/2737)

### 1.28 - 2016-12-01
Expand Down
25 changes: 23 additions & 2 deletions Source/Core/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,30 @@ define([
result = new Rectangle();
}

result.west = Math.min(rectangle.west, otherRectangle.west);
var rectangleEast = rectangle.east;
var rectangleWest = rectangle.west;

var otherRectangleEast = otherRectangle.east;
var otherRectangleWest = otherRectangle.west;

if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
rectangleEast += CesiumMath.TWO_PI;
} else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
otherRectangleEast += CesiumMath.TWO_PI;
}

if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
otherRectangleWest += CesiumMath.TWO_PI;
} else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
rectangleWest += CesiumMath.TWO_PI;
}

var west = CesiumMath.convertLongitudeRange(Math.min(rectangleWest, otherRectangleWest));
var east = CesiumMath.convertLongitudeRange(Math.max(rectangleEast, otherRectangleEast));

result.west = west;
result.south = Math.min(rectangle.south, otherRectangle.south);
result.east = Math.max(rectangle.east, otherRectangle.east);
result.east = east;
result.north = Math.max(rectangle.north, otherRectangle.north);

return result;
Expand Down
24 changes: 24 additions & 0 deletions Specs/Core/RectangleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,30 @@ defineSuite([
expect(returnedResult).toEqual(expected);
});

it('union works with first rectangle crossing the IDL', function() {
var rectangle1 = new Rectangle(0.5, 0.1, -0.5, 0.9);
var rectangle2 = new Rectangle(-0.85, 0.0, -0.4, 0.8);
var expected = new Rectangle(0.5, 0.0, -0.4, 0.9);
var returnedResult = Rectangle.union(rectangle1, rectangle2);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('union works with second rectangle crossing the IDL', function() {
var rectangle1 = new Rectangle(0.5, 0.1, 0.75, 0.9);
var rectangle2 = new Rectangle(0.6, 0.0, -0.2, 0.8);
var expected = new Rectangle(0.5, 0.0, -0.2, 0.9);
var returnedResult = Rectangle.union(rectangle1, rectangle2);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('union works with both rectangles crossing the IDL', function() {
var rectangle1 = new Rectangle(0.5, 0.1, -0.4, 0.9);
var rectangle2 = new Rectangle(0.4, 0.0, -0.5, 0.8);
var expected = new Rectangle(0.4, 0.0, -0.4, 0.9);
var returnedResult = Rectangle.union(rectangle1, rectangle2);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('expand works if rectangle needs to grow right', function() {
var rectangle = new Rectangle(0.5, 0.1, 0.75, 0.9);
var cartographic = new Cartographic(0.85, 0.5);
Expand Down

0 comments on commit cdd66dc

Please sign in to comment.