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

Fix rhumb triangulation across IDL #8206

Closed
wants to merge 2 commits into from
Closed
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
71 changes: 37 additions & 34 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ define([

var scratchCarto1 = new Cartographic();
var scratchCarto2 = new Cartographic();

function adjustPosHeightsForNormal(position, p1, p2, ellipsoid) {
var carto1 = ellipsoid.cartesianToCartographic(position, scratchCarto1);
var height = carto1.height;
Expand Down Expand Up @@ -164,12 +165,12 @@ define([
length /= 2;
}

for ( var i = 0; i < length; i += 3) {
for (var i = 0; i < length; i += 3) {
var position = Cartesian3.fromArray(flatPositions, i, appendTextureCoordinatesCartesian3);

if (vertexFormat.st) {
var p = Matrix3.multiplyByVector(textureMatrix, position, scratchPosition);
p = ellipsoid.scaleToGeodeticSurface(p,p);
p = ellipsoid.scaleToGeodeticSurface(p, p);
var st = tangentPlane.projectPointOntoPlane(p, appendTextureCoordinatesCartesian2);
Cartesian2.subtract(st, origin, st);

Expand Down Expand Up @@ -242,7 +243,7 @@ define([
normals[attrIndex + bottomOffset] = normal.x;
normals[attrIndex1 + bottomOffset] = normal.y;
normals[attrIndex2 + bottomOffset] = normal.z;
} else if (bottom){
} else if (bottom) {
normals[attrIndex + bottomOffset] = -normal.x;
normals[attrIndex1 + bottomOffset] = -normal.y;
normals[attrIndex2 + bottomOffset] = -normal.z;
Expand Down Expand Up @@ -275,7 +276,7 @@ define([
tangents[attrIndex2 + bottomOffset] = -tangent.z;
}

if(top) {
if (top) {
if (perPositionHeight) {
tangents[attrIndex] = scratchPerPosTangent.x;
tangents[attrIndex1] = scratchPerPosTangent.y;
Expand Down Expand Up @@ -383,6 +384,7 @@ define([
eastOverIDL : 0.0
};
var ellipsoidGeodesic = new EllipsoidGeodesic();

function computeRectangle(positions, ellipsoid, arcType, granularity, result) {
result = defaultValue(result, new Rectangle());
if (!defined(positions) || positions.length < 3) {
Expand Down Expand Up @@ -445,6 +447,7 @@ define([
}

var interpolatedCartographicScratch = new Cartographic();

function interpolateAndGrowRectangle(ellipsoidGeodesic, inverseChordLength, result, idlCross) {
var segmentLength = ellipsoidGeodesic.surfaceDistance;

Expand All @@ -463,7 +466,7 @@ define([
result.south = Math.min(result.south, latitude);
result.north = Math.max(result.north, latitude);

var lonAdjusted = longitude >= 0 ? longitude : longitude + CesiumMath.TWO_PI;
var lonAdjusted = longitude >= 0 ? longitude : longitude + CesiumMath.TWO_PI;
idlCross.westOverIDL = Math.min(idlCross.westOverIDL, lonAdjusted);
idlCross.eastOverIDL = Math.max(idlCross.eastOverIDL, lonAdjusted);
}
Expand Down Expand Up @@ -910,23 +913,23 @@ define([
return computeRectangle(polygonHierarchy.positions, ellipsoid, arcType, granularity, result);
};

var cartographicScratchArray = [];
function cartesian3ToCartographicAsCartesian2(ellipsoid) {
return function (positions) {
return function(positions) {
var numberOfPoints = positions.length;

var i;
if (cartographicScratchArray.length < numberOfPoints) {
for (i = cartographicScratchArray.length; i < numberOfPoints; i++) {
cartographicScratchArray.push(new Cartographic());
var result = new Array(numberOfPoints);
var carto = ellipsoid.cartesianToCartographic(positions[0], scratchCarto1);
var lastLongitude = carto.longitude;
result[0] = new Cartesian2(carto.longitude, carto.latitude);

for (var i = 1; i < numberOfPoints; i++) {
carto = ellipsoid.cartesianToCartographic(positions[i], scratchCarto1);
var lon = carto.longitude;
if (Math.abs(lon - lastLongitude) > CesiumMath.PI) {
// assume the position crosses the IDL if the next adjacent position longitude changes to be more than 180 degrees
lon += CesiumMath.TWO_PI;
}
}

var cartographicPositions = ellipsoid.cartesianArrayToCartographicArray(positions, cartographicScratchArray);
var result = [];
for (i = 0; i < numberOfPoints; i++) {
var cartographicPosition = cartographicPositions[i];
result.push(new Cartesian2(cartographicPosition.longitude, cartographicPosition.latitude));
lastLongitude = lon;
result[i] = new Cartesian2(lon, carto.latitude);
}

return result;
Expand Down Expand Up @@ -982,18 +985,18 @@ define([
var extrude = polygonGeometry._perPositionHeightExtrude || !CesiumMath.equalsEpsilon(height, extrudedHeight, 0, CesiumMath.EPSILON2);

var options = {
perPositionHeight: perPositionHeight,
vertexFormat: vertexFormat,
geometry: undefined,
tangentPlane: tangentPlane,
boundingRectangle: boundingRectangle,
ellipsoid: ellipsoid,
stRotation: stRotation,
bottom: false,
top: true,
wall: false,
extrude: false,
arcType: arcType
perPositionHeight : perPositionHeight,
vertexFormat : vertexFormat,
geometry : undefined,
tangentPlane : tangentPlane,
boundingRectangle : boundingRectangle,
ellipsoid : ellipsoid,
stRotation : stRotation,
bottom : false,
top : true,
wall : false,
extrude : false,
arcType : arcType
};

var i;
Expand Down Expand Up @@ -1028,7 +1031,7 @@ define([

var walls = splitGeometry.walls;
options.wall = true;
for ( var k = 0; k < walls.length; k++) {
for (var k = 0; k < walls.length; k++) {
var wall = walls[k];
options.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(wall.geometry, height, extrudedHeight, ellipsoid, perPositionHeight);
wall.geometry = computeAttributes(options);
Expand All @@ -1052,7 +1055,7 @@ define([
geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute({
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
componentsPerAttribute : 1,
values: applyOffset
values : applyOffset
});
}

Expand Down Expand Up @@ -1099,7 +1102,7 @@ define([
extrudedHeight : minHeight,
height : maxHeight,
vertexFormat : VertexFormat.POSITION_ONLY,
shadowVolume: true,
shadowVolume : true,
arcType : polygonGeometry._arcType
});
};
Expand Down