diff --git a/CHANGES.md b/CHANGES.md index 2681c29068e6..37f9ed3848c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - Fixed 3D Tileset replacement refinement when leaf is empty. [#8996](https://github.com/CesiumGS/cesium/pull/8996) - Fixed a bug in the assessment of terrain tile visibility [#9033](https://github.com/CesiumGS/cesium/issues/9033) +- Fixed vertical polylines with `arcType: ArcType.RHUMB`, including lines drawn via GeoJSON. [#9028](https://github.com/CesiumGS/cesium/pull/9028) ### 1.71 - 2020-07-01 diff --git a/Source/Core/PolylinePipeline.js b/Source/Core/PolylinePipeline.js index 16660b1c9b75..da5c7b9f3993 100644 --- a/Source/Core/PolylinePipeline.js +++ b/Source/Core/PolylinePipeline.js @@ -25,8 +25,10 @@ PolylinePipeline.numberOfPointsRhumbLine = function (p0, p1, granularity) { var radiansDistanceSquared = Math.pow(p0.longitude - p1.longitude, 2) + Math.pow(p0.latitude - p1.latitude, 2); - return Math.ceil( - Math.sqrt(radiansDistanceSquared / (granularity * granularity)) + + return Math.max( + 1, + Math.ceil(Math.sqrt(radiansDistanceSquared / (granularity * granularity))) ); }; diff --git a/Specs/Core/PolylineGeometrySpec.js b/Specs/Core/PolylineGeometrySpec.js index 69600b0b63e6..96fd83dacff2 100644 --- a/Specs/Core/PolylineGeometrySpec.js +++ b/Specs/Core/PolylineGeometrySpec.js @@ -5,6 +5,7 @@ import { Ellipsoid } from "../../Source/Cesium.js"; import { PolylineGeometry } from "../../Source/Cesium.js"; import { VertexFormat } from "../../Source/Cesium.js"; import createPackableSpecs from "../createPackableSpecs.js"; +import CesiumMath from "../../Source/Core/Math.js"; describe("Core/PolylineGeometry", function () { it("constructor throws with no positions", function () { @@ -184,6 +185,64 @@ describe("Core/PolylineGeometry", function () { expect(geometry).not.toBeDefined(); }); + it("createGeometry returns positions if their endpoints'longtitude and latitude are the same for rhumb line", function () { + var positions = Cartesian3.fromDegreesArrayHeights([ + 30.0, + 30.0, + 10.0, + 30.0, + 30.0, + 5.0, + ]); + var geometry = PolylineGeometry.createGeometry( + new PolylineGeometry({ + positions: positions, + width: 10.0, + vertexFormat: VertexFormat.POSITION_ONLY, + arcType: ArcType.RHUMB, + }) + ); + + var attributePositions = geometry.attributes.position.values; + var geometryPosition = new Cartesian3(); + + Cartesian3.fromArray(attributePositions, 0, geometryPosition); + expect( + Cartesian3.equalsEpsilon( + geometryPosition, + positions[0], + CesiumMath.EPSILON7 + ) + ).toBe(true); + + Cartesian3.fromArray(attributePositions, 3, geometryPosition); + expect( + Cartesian3.equalsEpsilon( + geometryPosition, + positions[0], + CesiumMath.EPSILON7 + ) + ).toBe(true); + + Cartesian3.fromArray(attributePositions, 6, geometryPosition); + expect( + Cartesian3.equalsEpsilon( + geometryPosition, + positions[1], + CesiumMath.EPSILON7 + ) + ).toBe(true); + + Cartesian3.fromArray(attributePositions, 9, geometryPosition); + expect( + Cartesian3.equalsEpsilon( + geometryPosition, + positions[1], + CesiumMath.EPSILON7 + ) + ).toBe(true); + }); + var positions = [ new Cartesian3(1, 2, 3), new Cartesian3(4, 5, 6),