Skip to content

Commit 51698b3

Browse files
committed
base polygon geometry rectangle IDL handling on Rectangle.fromCartesianArray
1 parent 6f5dd4f commit 51698b3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Source/Core/PolygonGeometry.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ define([
379379
var startCartographicScratch = new Cartographic();
380380
var endCartographicScratch = new Cartographic();
381381
var idlCross = {
382-
west : 0.0,
383-
east : 0.0
382+
westOverIDL : 0.0,
383+
eastOverIDL : 0.0
384384
};
385385
var ellipsoidGeodesic = new EllipsoidGeodesic();
386386
function computeRectangle(positions, ellipsoid, arcType, granularity, result) {
@@ -406,8 +406,8 @@ define([
406406
result.south = Number.POSITIVE_INFINITY;
407407
result.north = Number.NEGATIVE_INFINITY;
408408

409-
idlCross.west = Number.POSITIVE_INFINITY;
410-
idlCross.east = Number.NEGATIVE_INFINITY;
409+
idlCross.westOverIDL = Number.POSITIVE_INFINITY;
410+
idlCross.eastOverIDL = Number.NEGATIVE_INFINITY;
411411

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

432-
if (result.east - result.west > idlCross.west - idlCross.east) {
433-
result.east = idlCross.east;
434-
result.west = idlCross.west;
432+
if (result.east - result.west > idlCross.eastOverIDL - idlCross.westOverIDL) {
433+
result.west = idlCross.westOverIDL;
434+
result.east = idlCross.eastOverIDL;
435+
436+
if (result.east > CesiumMath.PI) {
437+
result.east = result.east - CesiumMath.TWO_PI;
438+
}
439+
if (result.west > CesiumMath.PI) {
440+
result.west = result.west - CesiumMath.TWO_PI;
441+
}
435442
}
436443

437444
return result;
@@ -456,8 +463,9 @@ define([
456463
result.south = Math.min(result.south, latitude);
457464
result.north = Math.max(result.north, latitude);
458465

459-
idlCross.west = longitude > 0.0 ? Math.min(longitude, idlCross.west) : idlCross.west;
460-
idlCross.east = longitude < 0.0 ? Math.max(longitude, idlCross.east) : idlCross.east;
466+
var lonAdjusted = longitude >= 0 ? longitude : longitude + CesiumMath.TWO_PI;
467+
idlCross.westOverIDL = Math.min(idlCross.westOverIDL, lonAdjusted);
468+
idlCross.eastOverIDL = Math.max(idlCross.eastOverIDL, lonAdjusted);
461469
}
462470
}
463471

0 commit comments

Comments
 (0)