From b07e24697c643ec3c4628649781fd47f27495c71 Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Thu, 7 Feb 2019 17:05:53 -0500 Subject: [PATCH 1/3] Fix IDL intersection of rhumb lines by using the correct sign of PI --- Source/Core/EllipsoidRhumbLine.js | 6 +++++- Specs/Core/EllipsoidRhumbLineSpec.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/Core/EllipsoidRhumbLine.js b/Source/Core/EllipsoidRhumbLine.js index 9c1273f90b31..b79b449a7389 100644 --- a/Source/Core/EllipsoidRhumbLine.js +++ b/Source/Core/EllipsoidRhumbLine.js @@ -416,6 +416,10 @@ define([ intersectionLongitude = CesiumMath.negativePiToPi(intersectionLongitude); + if (CesiumMath.equalsEpsilon(Math.abs(intersectionLongitude), Math.PI, CesiumMath.EPSILON14)) { + intersectionLongitude = Math.sign(start.longitude) * Math.PI; + } + if (!defined(result)) { result = new Cartographic(); } @@ -454,7 +458,7 @@ define([ } while (!CesiumMath.equalsEpsilon(newPhi, phi, CesiumMath.EPSILON12)); result.longitude = intersectionLongitude; - result.latitude = phi; + result.latitude = newPhi; result.height = 0; return result; }; diff --git a/Specs/Core/EllipsoidRhumbLineSpec.js b/Specs/Core/EllipsoidRhumbLineSpec.js index 364a56402c5c..a099ebeab6ff 100644 --- a/Specs/Core/EllipsoidRhumbLineSpec.js +++ b/Specs/Core/EllipsoidRhumbLineSpec.js @@ -547,6 +547,25 @@ defineSuite([ expect(Cartographic.equalsEpsilon(pointUsingInterpolation, pointUsingIntersection, CesiumMath.EPSILON12)).toBe(true); }); + it('finds correct intersection with IDL', function() { + var start = Cartographic.fromDegrees(170, 10); + var end = Cartographic.fromDegrees(-170, 23); + + var rhumb = new EllipsoidRhumbLine(start, end); + + var idlIntersection1 = rhumb.findIntersectionWithLongitude(-Math.PI); + var idlIntersection2 = rhumb.findIntersectionWithLongitude(Math.PI); + + expect(Cartographic.equalsEpsilon(idlIntersection1, idlIntersection2, CesiumMath.EPSILON12)).toBe(true); + + rhumb.setEndPoints(end, start); + + idlIntersection1 = rhumb.findIntersectionWithLongitude(-Math.PI); + idlIntersection2 = rhumb.findIntersectionWithLongitude(Math.PI); + + expect(Cartographic.equalsEpsilon(idlIntersection1, idlIntersection2, CesiumMath.EPSILON12)).toBe(true); + }); + it('intersection with longitude handles E-W lines', function() { var start = new Cartographic(fifteenDegrees, 0.0); var end = new Cartographic(fortyfiveDegrees, 0.0); From a4eb129c5a53f8e32540f4e8b5c5a61cb426f3da Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Thu, 7 Feb 2019 17:08:57 -0500 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index e68ca412ffce..d36067da186d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Change Log * Fixed Node.js support for the `Resource` class and any functionality using it internally. * Fixed an issue where some ground polygons crossing the Prime Meridian would have incorrect bounding rectangles. [#7533](https://github.com/AnalyticalGraphicsInc/cesium/pull/7533) * Fixed an issue where polygons on terrain using rhumb lines where being rendered incorrectly. [#7538](https://github.com/AnalyticalGraphicsInc/cesium/pulls/7538) +* Fixed an issue with `EllipsoidRhumbLines.findIntersectionWithLongitude` when longitude was IDL. [#7551](https://github.com/AnalyticalGraphicsInc/cesium/issues/7551) ### 1.54 - 2019-02-01 From 25bdc63562e32ba176087a1882c4cc25a54ea850 Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Thu, 7 Feb 2019 20:44:56 -0500 Subject: [PATCH 3/3] Add checks for longitude value and sign in result --- Specs/Core/EllipsoidRhumbLineSpec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Specs/Core/EllipsoidRhumbLineSpec.js b/Specs/Core/EllipsoidRhumbLineSpec.js index a099ebeab6ff..a644f58c17ad 100644 --- a/Specs/Core/EllipsoidRhumbLineSpec.js +++ b/Specs/Core/EllipsoidRhumbLineSpec.js @@ -557,6 +557,8 @@ defineSuite([ var idlIntersection2 = rhumb.findIntersectionWithLongitude(Math.PI); expect(Cartographic.equalsEpsilon(idlIntersection1, idlIntersection2, CesiumMath.EPSILON12)).toBe(true); + expect(idlIntersection1.longitude).toEqualEpsilon(Math.PI, CesiumMath.EPSILON14); + expect(idlIntersection2.longitude).toEqualEpsilon(Math.PI, CesiumMath.EPSILON14); rhumb.setEndPoints(end, start); @@ -564,6 +566,8 @@ defineSuite([ idlIntersection2 = rhumb.findIntersectionWithLongitude(Math.PI); expect(Cartographic.equalsEpsilon(idlIntersection1, idlIntersection2, CesiumMath.EPSILON12)).toBe(true); + expect(idlIntersection1.longitude).toEqualEpsilon(-Math.PI, CesiumMath.EPSILON14); + expect(idlIntersection2.longitude).toEqualEpsilon(-Math.PI, CesiumMath.EPSILON14); }); it('intersection with longitude handles E-W lines', function() {