Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Rectangle.union to take rectangles crossing the IDL into account. #4732

Merged
merged 3 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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