From 40972efb2fa830506bb80ed01f0289c6bb3ec4da Mon Sep 17 00:00:00 2001 From: Kangning Li Date: Mon, 2 Jul 2018 17:11:17 -0400 Subject: [PATCH 1/3] fixes for some test failures on IE and Firefox --- Source/Core/GroundPolylineGeometry.js | 8 ++++---- Specs/Core/CircleGeometrySpec.js | 8 ++++---- Specs/Core/GeometryPipelineSpec.js | 16 ++++++++-------- Specs/Core/GroundPolylineGeometrySpec.js | 12 ++++++------ Specs/Core/RectangleGeometrySpec.js | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Source/Core/GroundPolylineGeometry.js b/Source/Core/GroundPolylineGeometry.js index aae3f794b073..5d5651f0a338 100644 --- a/Source/Core/GroundPolylineGeometry.js +++ b/Source/Core/GroundPolylineGeometry.js @@ -648,11 +648,11 @@ define([ var absStartLon = Math.abs(start.longitude); var absEndLon = Math.abs(end.longitude); if (CesiumMath.equalsEpsilon(absStartLon, CesiumMath.PI, CesiumMath.EPSILON11)) { - var endSign = Math.sign(end.longitude); + var endSign = CesiumMath.sign(end.longitude); start.longitude = endSign * (absStartLon - CesiumMath.EPSILON11); return 1; } else if (CesiumMath.equalsEpsilon(absEndLon, CesiumMath.PI, CesiumMath.EPSILON11)) { - var startSign = Math.sign(start.longitude); + var startSign = CesiumMath.sign(start.longitude); end.longitude = startSign * (absEndLon - CesiumMath.EPSILON11); return 2; } @@ -861,7 +861,7 @@ define([ startGeometryNormal2D.x = 0.0; // If start longitude is negative and end longitude is less negative, relative right is unit -Y // If start longitude is positive and end longitude is less positive, relative right is unit +Y - startGeometryNormal2D.y = Math.sign(startCartographic.longitude - Math.abs(endCartographic.longitude)); + startGeometryNormal2D.y = CesiumMath.sign(startCartographic.longitude - Math.abs(endCartographic.longitude)); startGeometryNormal2D.z = 0.0; } else { // End is close to IDL - snap end normal to align with IDL @@ -869,7 +869,7 @@ define([ endGeometryNormal2D.x = 0.0; // If end longitude is negative and start longitude is less negative, relative right is unit Y // If end longitude is positive and start longitude is less positive, relative right is unit -Y - endGeometryNormal2D.y = Math.sign(startCartographic.longitude - endCartographic.longitude); + endGeometryNormal2D.y = CesiumMath.sign(startCartographic.longitude - endCartographic.longitude); endGeometryNormal2D.z = 0.0; } } diff --git a/Specs/Core/CircleGeometrySpec.js b/Specs/Core/CircleGeometrySpec.js index c31b377543e0..423255b02f0b 100644 --- a/Specs/Core/CircleGeometrySpec.js +++ b/Specs/Core/CircleGeometrySpec.js @@ -158,10 +158,10 @@ defineSuite([ }); var r = ellipse.rectangle; - expect(r.north).toEqual(0.698966597893341); - expect(r.south).toEqual(0.698652226072367); - expect(r.east).toEqual(-1.3192254919753026); - expect(r.west).toEqual(-1.3196344953554853); + expect(r.north).toEqualEpsilon(0.698966597893341, CesiumMath.EPSILON7); + expect(r.south).toEqualEpsilon(0.698652226072367, CesiumMath.EPSILON7); + expect(r.east).toEqualEpsilon(-1.3192254919753026, CesiumMath.EPSILON7); + expect(r.west).toEqualEpsilon(-1.3196344953554853, CesiumMath.EPSILON7); }); it('computing textureCoordinateRotationPoints property', function() { diff --git a/Specs/Core/GeometryPipelineSpec.js b/Specs/Core/GeometryPipelineSpec.js index 82baca70d79d..c52f9185e539 100644 --- a/Specs/Core/GeometryPipelineSpec.js +++ b/Specs/Core/GeometryPipelineSpec.js @@ -1949,10 +1949,10 @@ defineSuite([ var index; // Expect eastern hemisphere vertices to all be 255 or 127 at the end of the value - expect(newScalars.indexOf(127)).not.toBe(-1); - expect(newVec4s.indexOf(127)).not.toBe(-1); - expect(newVec3s.indexOf(127)).not.toBe(-1); - expect(newVec2s.indexOf(127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newScalars, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec4s, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec3s, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec2s, 127)).not.toBe(-1); for (i = 0; i < 3; i++) { expect(newScalars[i] === 255 || newScalars[i] === 127).toBe(true); @@ -1981,10 +1981,10 @@ defineSuite([ newScalars = westHemisphereGeometry.attributes.scalars.values; // Expect eastern hemisphere vertices to all be 0 or 127 at the end of the value - expect(newScalars.indexOf(127)).not.toBe(-1); - expect(newVec4s.indexOf(127)).not.toBe(-1); - expect(newVec3s.indexOf(127)).not.toBe(-1); - expect(newVec2s.indexOf(127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newScalars, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec4s, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec3s, 127)).not.toBe(-1); + expect(Array.prototype.indexOf.call(newVec2s, 127)).not.toBe(-1); for (i = 0; i < 4; i++) { expect(newScalars[i] === 0 || newScalars[i] === 127).toBe(true); diff --git a/Specs/Core/GroundPolylineGeometrySpec.js b/Specs/Core/GroundPolylineGeometrySpec.js index 67119f55136b..2ad75c7a7dba 100644 --- a/Specs/Core/GroundPolylineGeometrySpec.js +++ b/Specs/Core/GroundPolylineGeometrySpec.js @@ -33,11 +33,11 @@ defineSuite([ var values = attribute.values; var componentsPerAttribute = attribute.componentsPerAttribute; var vertexCount = values.length / componentsPerAttribute; - var firstVertex = values.slice(0, componentsPerAttribute); + var firstVertex = Array.prototype.slice.call(values, 0, componentsPerAttribute); var identical = true; for (var i = 1; i < vertexCount; i++) { var index = i * componentsPerAttribute; - var vertex = values.slice(index, index + componentsPerAttribute); + var vertex = Array.prototype.slice.call(values, index, index + componentsPerAttribute); for (var j = 0; j < componentsPerAttribute; j++) { if (vertex[j] !== firstVertex[j]) { identical = false; @@ -89,21 +89,21 @@ defineSuite([ var values = endNormalAndTextureCoordinateNormalizationX.values; for (i = 0; i < 4; i++) { index = i * 4 + 3; - expect(Math.sign(values[index])).toEqual(1.0); + expect(CesiumMath.sign(values[index])).toEqual(1.0); } for (i = 4; i < 8; i++) { index = i * 4 + 3; - expect(Math.sign(values[index])).toEqual(-1.0); + expect(CesiumMath.sign(values[index])).toEqual(-1.0); } values = texcoordNormalization2D.values; for (i = 0; i < 4; i++) { index = i * 2; - expect(Math.sign(values[index])).toEqual(1.0); + expect(CesiumMath.sign(values[index])).toEqual(1.0); } for (i = 4; i < 8; i++) { index = i * 2; - expect(Math.sign(values[index])).toEqual(-1.0); + expect(CesiumMath.sign(values[index])).toEqual(-1.0); } // Expect rightNormalAndTextureCoordinateNormalizationY and texcoordNormalization2D.y to encode if the vertex is on the bottom diff --git a/Specs/Core/RectangleGeometrySpec.js b/Specs/Core/RectangleGeometrySpec.js index fbd189b3eb4c..ba6d2457d232 100644 --- a/Specs/Core/RectangleGeometrySpec.js +++ b/Specs/Core/RectangleGeometrySpec.js @@ -380,10 +380,10 @@ defineSuite([ }); var r = geometry.rectangle; - expect(CesiumMath.toDegrees(r.north)).toEqual(1.414213562373095); - expect(CesiumMath.toDegrees(r.south)).toEqual(-1.414213562373095); - expect(CesiumMath.toDegrees(r.east)).toEqual(1.414213562373095); - expect(CesiumMath.toDegrees(r.west)).toEqual(-1.4142135623730951); + expect(CesiumMath.toDegrees(r.north)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON7); + expect(CesiumMath.toDegrees(r.south)).toEqualEpsilon(-1.414213562373095, CesiumMath.EPSILON7); + expect(CesiumMath.toDegrees(r.east)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON7); + expect(CesiumMath.toDegrees(r.west)).toEqualEpsilon(-1.4142135623730951, CesiumMath.EPSILON7); }); it('computing textureCoordinateRotationPoints property', function() { From 4c5987fc184484db869659bae424e8ce6863d3d1 Mon Sep 17 00:00:00 2001 From: Kangning Li Date: Mon, 2 Jul 2018 17:19:27 -0400 Subject: [PATCH 2/3] use Core/arraySlice --- Specs/Core/GeometryPipelineSpec.js | 16 +++++++++------- Specs/Core/GroundPolylineGeometrySpec.js | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Specs/Core/GeometryPipelineSpec.js b/Specs/Core/GeometryPipelineSpec.js index c52f9185e539..53db1c40525b 100644 --- a/Specs/Core/GeometryPipelineSpec.js +++ b/Specs/Core/GeometryPipelineSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'Core/GeometryPipeline', + 'Core/arraySlice', 'Core/AttributeCompression', 'Core/BoundingSphere', 'Core/BoxGeometry', @@ -22,6 +23,7 @@ defineSuite([ 'Core/VertexFormat' ], function( GeometryPipeline, + arraySlice, AttributeCompression, BoundingSphere, BoxGeometry, @@ -1739,7 +1741,7 @@ defineSuite([ minimum : new Cartesian3(-250000.0, -250000.0, -250000.0) })); expect(geometry.attributes.normal).toBeDefined(); - var originalNormals = Array.prototype.slice.call(geometry.attributes.normal.values); + var originalNormals = arraySlice(geometry.attributes.normal.values); geometry = GeometryPipeline.compressVertices(geometry); @@ -1763,7 +1765,7 @@ defineSuite([ minimum : new Cartesian3(-250000.0, -250000.0, -250000.0) })); expect(geometry.attributes.st).toBeDefined(); - var originalST = Array.prototype.slice.call(geometry.attributes.st.values); + var originalST = arraySlice(geometry.attributes.st.values); geometry = GeometryPipeline.compressVertices(geometry); @@ -1794,8 +1796,8 @@ defineSuite([ })); expect(geometry.attributes.normal).toBeDefined(); expect(geometry.attributes.st).toBeDefined(); - var originalNormals = Array.prototype.slice.call(geometry.attributes.normal.values); - var originalST = Array.prototype.slice.call(geometry.attributes.st.values); + var originalNormals = arraySlice(geometry.attributes.normal.values); + var originalST = arraySlice(geometry.attributes.st.values); geometry = GeometryPipeline.compressVertices(geometry); @@ -1826,9 +1828,9 @@ defineSuite([ expect(geometry.attributes.normal).toBeDefined(); expect(geometry.attributes.tangent).toBeDefined(); expect(geometry.attributes.bitangent).toBeDefined(); - var originalNormals = Array.prototype.slice.call(geometry.attributes.normal.values); - var originalTangents = Array.prototype.slice.call(geometry.attributes.tangent.values); - var originalBitangents = Array.prototype.slice.call(geometry.attributes.bitangent.values); + var originalNormals = arraySlice(geometry.attributes.normal.values); + var originalTangents = arraySlice(geometry.attributes.tangent.values); + var originalBitangents = arraySlice(geometry.attributes.bitangent.values); geometry = GeometryPipeline.compressVertices(geometry); diff --git a/Specs/Core/GroundPolylineGeometrySpec.js b/Specs/Core/GroundPolylineGeometrySpec.js index 2ad75c7a7dba..558c9ddd3a63 100644 --- a/Specs/Core/GroundPolylineGeometrySpec.js +++ b/Specs/Core/GroundPolylineGeometrySpec.js @@ -1,6 +1,7 @@ defineSuite([ 'Core/GroundPolylineGeometry', 'Core/ApproximateTerrainHeights', + 'Core/arraySlice', 'Core/Cartesian3', 'Core/Cartographic', 'Core/Math', @@ -11,6 +12,7 @@ defineSuite([ ], function( GroundPolylineGeometry, ApproximateTerrainHeights, + arraySlice, Cartesian3, Cartographic, CesiumMath, @@ -33,11 +35,11 @@ defineSuite([ var values = attribute.values; var componentsPerAttribute = attribute.componentsPerAttribute; var vertexCount = values.length / componentsPerAttribute; - var firstVertex = Array.prototype.slice.call(values, 0, componentsPerAttribute); + var firstVertex = arraySlice(values, 0, componentsPerAttribute); var identical = true; for (var i = 1; i < vertexCount; i++) { var index = i * componentsPerAttribute; - var vertex = Array.prototype.slice.call(values, index, index + componentsPerAttribute); + var vertex = arraySlice(values, index, index + componentsPerAttribute); for (var j = 0; j < componentsPerAttribute; j++) { if (vertex[j] !== firstVertex[j]) { identical = false; From 93f5992874ad221f676c5a2c8902756928a2af14 Mon Sep 17 00:00:00 2001 From: Kangning Li Date: Mon, 2 Jul 2018 17:33:14 -0400 Subject: [PATCH 3/3] finer epsilons --- Specs/Core/CircleGeometrySpec.js | 8 ++++---- Specs/Core/RectangleGeometrySpec.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Specs/Core/CircleGeometrySpec.js b/Specs/Core/CircleGeometrySpec.js index 423255b02f0b..aa4e4a2dc35e 100644 --- a/Specs/Core/CircleGeometrySpec.js +++ b/Specs/Core/CircleGeometrySpec.js @@ -158,10 +158,10 @@ defineSuite([ }); var r = ellipse.rectangle; - expect(r.north).toEqualEpsilon(0.698966597893341, CesiumMath.EPSILON7); - expect(r.south).toEqualEpsilon(0.698652226072367, CesiumMath.EPSILON7); - expect(r.east).toEqualEpsilon(-1.3192254919753026, CesiumMath.EPSILON7); - expect(r.west).toEqualEpsilon(-1.3196344953554853, CesiumMath.EPSILON7); + expect(r.north).toEqualEpsilon(0.698966597893341, CesiumMath.EPSILON15); + expect(r.south).toEqualEpsilon(0.698652226072367, CesiumMath.EPSILON15); + expect(r.east).toEqualEpsilon(-1.3192254919753026, CesiumMath.EPSILON15); + expect(r.west).toEqualEpsilon(-1.3196344953554853, CesiumMath.EPSILON15); }); it('computing textureCoordinateRotationPoints property', function() { diff --git a/Specs/Core/RectangleGeometrySpec.js b/Specs/Core/RectangleGeometrySpec.js index ba6d2457d232..e3b649df6400 100644 --- a/Specs/Core/RectangleGeometrySpec.js +++ b/Specs/Core/RectangleGeometrySpec.js @@ -380,10 +380,10 @@ defineSuite([ }); var r = geometry.rectangle; - expect(CesiumMath.toDegrees(r.north)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON7); - expect(CesiumMath.toDegrees(r.south)).toEqualEpsilon(-1.414213562373095, CesiumMath.EPSILON7); - expect(CesiumMath.toDegrees(r.east)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON7); - expect(CesiumMath.toDegrees(r.west)).toEqualEpsilon(-1.4142135623730951, CesiumMath.EPSILON7); + expect(CesiumMath.toDegrees(r.north)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON15); + expect(CesiumMath.toDegrees(r.south)).toEqualEpsilon(-1.414213562373095, CesiumMath.EPSILON15); + expect(CesiumMath.toDegrees(r.east)).toEqualEpsilon(1.414213562373095, CesiumMath.EPSILON15); + expect(CesiumMath.toDegrees(r.west)).toEqualEpsilon(-1.4142135623730951, CesiumMath.EPSILON15); }); it('computing textureCoordinateRotationPoints property', function() {