diff --git a/CHANGES.md b/CHANGES.md index f4ec93291961..3042d8fbdb46 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Change Log * Fixed tooltips for gallery thumbnails in Sandcastle [#4702](https://github.com/AnalyticalGraphicsInc/cesium/pull/4702) * Fixed `Rectangle.union` to correctly account for rectangles that cross the IDL [#4732](https://github.com/AnalyticalGraphicsInc/cesium/pull/4732). * Fixed texture rotation for `RectangleGeometry` [#2737](https://github.com/AnalyticalGraphicsInc/cesium/issues/2737) +* Added `divideComponents` function to `Cartesian2`, `Cartesian3`, and `Cartesian4`. [#4750](https://github.com/AnalyticalGraphicsInc/cesium/pull/4750) * Added `WebGLConstants` enum. Previously, this was part of the private Renderer API. [#4731](https://github.com/AnalyticalGraphicsInc/cesium/pull/4731) * Fixed an bug that caused `GroundPrimitive` to render incorrectly on systems without the `WEBGL_depth_texture` extension. [#4747](https://github.com/AnalyticalGraphicsInc/cesium/pull/4747) * Fixed default Mapbox token and added a watermark to notify users that they need to sign up for their own token. diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 0b4927d01d54..92e6d6715b8f 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -470,6 +470,32 @@ define([ return result; }; + /** + * Computes the componentwise quotient of two Cartesians. + * + * @param {Cartesian2} left The first Cartesian. + * @param {Cartesian2} right The second Cartesian. + * @param {Cartesian2} result The object onto which to store the result. + * @returns {Cartesian2} The modified result parameter. + */ + Cartesian2.divideComponents = function(left, right, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required'); + } + if (!defined(right)) { + throw new DeveloperError('right is required'); + } + if (!defined(result)) { + throw new DeveloperError('result is required'); + } + //>>includeEnd('debug'); + + result.x = left.x / right.x; + result.y = left.y / right.y; + return result; + }; + /** * Computes the componentwise sum of two Cartesians. * diff --git a/Source/Core/Cartesian3.js b/Source/Core/Cartesian3.js index a2e1f2f268f7..0c8325d43cab 100644 --- a/Source/Core/Cartesian3.js +++ b/Source/Core/Cartesian3.js @@ -510,6 +510,33 @@ define([ return result; }; + /** + * Computes the componentwise quotient of two Cartesians. + * + * @param {Cartesian3} left The first Cartesian. + * @param {Cartesian3} right The second Cartesian. + * @param {Cartesian3} result The object onto which to store the result. + * @returns {Cartesian3} The modified result parameter. + */ + Cartesian3.divideComponents = function(left, right, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required'); + } + if (!defined(right)) { + throw new DeveloperError('right is required'); + } + if (!defined(result)) { + throw new DeveloperError('result is required'); + } + //>>includeEnd('debug'); + + result.x = left.x / right.x; + result.y = left.y / right.y; + result.z = left.z / right.z; + return result; + }; + /** * Computes the componentwise sum of two Cartesians. * diff --git a/Source/Core/Cartesian4.js b/Source/Core/Cartesian4.js index f9ca0bddc60d..33627bf01915 100644 --- a/Source/Core/Cartesian4.js +++ b/Source/Core/Cartesian4.js @@ -513,6 +513,34 @@ define([ return result; }; + /** + * Computes the componentwise quotient of two Cartesians. + * + * @param {Cartesian4} left The first Cartesian. + * @param {Cartesian4} right The second Cartesian. + * @param {Cartesian4} result The object onto which to store the result. + * @returns {Cartesian4} The modified result parameter. + */ + Cartesian4.divideComponents = function(left, right, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required'); + } + if (!defined(right)) { + throw new DeveloperError('right is required'); + } + if (!defined(result)) { + throw new DeveloperError('result is required'); + } + //>>includeEnd('debug'); + + result.x = left.x / right.x; + result.y = left.y / right.y; + result.z = left.z / right.z; + result.w = left.w / right.w; + return result; + }; + /** * Computes the componentwise sum of two Cartesians. * diff --git a/Specs/Core/Cartesian2Spec.js b/Specs/Core/Cartesian2Spec.js index 4087a64e6959..a2af6188b0e1 100644 --- a/Specs/Core/Cartesian2Spec.js +++ b/Specs/Core/Cartesian2Spec.js @@ -328,6 +328,25 @@ defineSuite([ expect(left).toEqual(expectedResult); }); + it('divideComponents works with a result parameter', function() { + var left = new Cartesian2(2.0, 3.0); + var right = new Cartesian2(4.0, 5.0); + var result = new Cartesian2(); + var expectedResult = new Cartesian2(0.5, 0.6); + var returnedResult = Cartesian2.divideComponents(left, right, result); + expect(result).toBe(returnedResult); + expect(result).toEqual(expectedResult); + }); + + it('divideComponents works with a result parameter that is an input parameter', function() { + var left = new Cartesian2(2.0, 3.0); + var right = new Cartesian2(4.0, 5.0); + var expectedResult = new Cartesian2(0.5, 0.6); + var returnedResult = Cartesian2.divideComponents(left, right, left); + expect(left).toBe(returnedResult); + expect(left).toEqual(expectedResult); + }); + it('dot', function() { var left = new Cartesian2(2.0, 3.0); var right = new Cartesian2(4.0, 5.0); @@ -614,6 +633,20 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throw with no left parameter', function() { + var right = new Cartesian2(4.0, 5.0); + expect(function() { + Cartesian2.divideComponents(undefined, right); + }).toThrowDeveloperError(); + }); + + it('divideComponents throw with no right parameter', function() { + var left = new Cartesian2(4.0, 5.0); + expect(function() { + Cartesian2.divideComponents(left, undefined); + }).toThrowDeveloperError(); + }); + it('add throws with no left parameter', function() { expect(function() { Cartesian2.add(undefined, new Cartesian2()); @@ -761,6 +794,12 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throws with no result', function() { + expect(function() { + Cartesian2.divideComponents(new Cartesian2(), new Cartesian2()); + }).toThrowDeveloperError(); + }); + it('add throws with no result', function() { expect(function() { Cartesian2.add(new Cartesian2(), new Cartesian2()); diff --git a/Specs/Core/Cartesian3Spec.js b/Specs/Core/Cartesian3Spec.js index 188e6ee724a2..854b0e62a1b7 100644 --- a/Specs/Core/Cartesian3Spec.js +++ b/Specs/Core/Cartesian3Spec.js @@ -400,6 +400,25 @@ defineSuite([ expect(left).toEqual(expectedResult); }); + it('divideComponents works with a result parameter', function() { + var left = new Cartesian3(2.0, 3.0, 6.0); + var right = new Cartesian3(4.0, 5.0, 8.0); + var result = new Cartesian3(); + var expectedResult = new Cartesian3(0.5, 0.6, 0.75); + var returnedResult = Cartesian3.divideComponents(left, right, result); + expect(result).toBe(returnedResult); + expect(result).toEqual(expectedResult); + }); + + it('divideComponents works with a result parameter that is an input parameter', function() { + var left = new Cartesian3(2.0, 3.0, 6.0); + var right = new Cartesian3(4.0, 5.0, 8.0); + var expectedResult = new Cartesian3(0.5, 0.6, 0.75); + var returnedResult = Cartesian3.divideComponents(left, right, left); + expect(left).toBe(returnedResult); + expect(left).toEqual(expectedResult); + }); + it('dot', function() { var left = new Cartesian3(2.0, 3.0, 6.0); var right = new Cartesian3(4.0, 5.0, 7.0); @@ -742,6 +761,20 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throw with no left parameter', function() { + var right = new Cartesian3(4.0, 5.0, 6.0); + expect(function() { + Cartesian3.divideComponents(undefined, right); + }).toThrowDeveloperError(); + }); + + it('divideComponents throw with no right parameter', function() { + var left = new Cartesian3(4.0, 5.0, 6.0); + expect(function() { + Cartesian3.divideComponents(left, undefined); + }).toThrowDeveloperError(); + }); + it('dot throws with no right parameter', function() { expect(function() { Cartesian3.dot(new Cartesian3(), undefined); @@ -1149,6 +1182,12 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throws with no result', function() { + expect(function() { + Cartesian3.divideComponents(new Cartesian3(), new Cartesian3()); + }).toThrowDeveloperError(); + }); + it('add throws with no result', function() { expect(function() { Cartesian3.add(new Cartesian3(), new Cartesian3()); diff --git a/Specs/Core/Cartesian4Spec.js b/Specs/Core/Cartesian4Spec.js index 4e9cbb91737b..a2e877a6aef7 100644 --- a/Specs/Core/Cartesian4Spec.js +++ b/Specs/Core/Cartesian4Spec.js @@ -464,6 +464,25 @@ defineSuite([ expect(left).toEqual(expectedResult); }); + it('divideComponents works with a result parameter', function() { + var left = new Cartesian4(2.0, 3.0, 6.0, 15.0); + var right = new Cartesian4(4.0, 5.0, 8.0, 2.0); + var result = new Cartesian4(); + var expectedResult = new Cartesian4(0.5, 0.6, 0.75, 7.5); + var returnedResult = Cartesian4.divideComponents(left, right, result); + expect(result).toBe(returnedResult); + expect(result).toEqual(expectedResult); + }); + + it('divideComponents works with a result parameter that is an input parameter', function() { + var left = new Cartesian4(2.0, 3.0, 6.0, 15.0); + var right = new Cartesian4(4.0, 5.0, 8.0, 2.0); + var expectedResult = new Cartesian4(0.5, 0.6, 0.75, 7.5); + var returnedResult = Cartesian4.divideComponents(left, right, left); + expect(left).toBe(returnedResult); + expect(left).toEqual(expectedResult); + }); + it('dot', function() { var left = new Cartesian4(2.0, 3.0, 6.0, 8.0); var right = new Cartesian4(4.0, 5.0, 7.0, 9.0); @@ -740,6 +759,20 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throw with no left parameter', function() { + var right = new Cartesian4(4.0, 5.0, 6.0, 7.0); + expect(function() { + Cartesian4.divideComponents(undefined, right); + }).toThrowDeveloperError(); + }); + + it('divideComponents throw with no right parameter', function() { + var left = new Cartesian4(4.0, 5.0, 6.0, 7.0); + expect(function() { + Cartesian4.divideComponents(left, undefined); + }).toThrowDeveloperError(); + }); + it('dot throws with no right parameter', function() { expect(function() { Cartesian4.dot(new Cartesian4(), undefined); @@ -866,6 +899,12 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('divideComponents throws with no result', function() { + expect(function() { + Cartesian4.divideComponents(new Cartesian4(), new Cartesian4()); + }).toThrowDeveloperError(); + }); + it('add throws with no result', function() { expect(function() { Cartesian4.add(new Cartesian4(), new Cartesian4());