From 28289869c77cad2c1d997107a6a1cb3a8f0a251f Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 5 Jan 2021 17:14:51 -0500 Subject: [PATCH 1/2] add Cartesian2.cross --- Source/Core/Cartesian2.js | 16 ++++++++++++++++ Specs/Core/Cartesian2Spec.js | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 64a5ca0422bf..1f5a30d42855 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -406,6 +406,22 @@ Cartesian2.dot = function (left, right) { return left.x * right.x + left.y * right.y; }; +/** + * Computes the cross (outer) product of two Cartesians. + * + * @param {Cartesian2} left The first Cartesian. + * @param {Cartesian2} right The second Cartesian. + * @returns {Number} The cross product. + */ +Cartesian2.cross = function (left, right) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object("left", left); + Check.typeOf.object("right", right); + //>>includeEnd('debug'); + + return left.x * right.y - left.y * right.x; +}; + /** * Computes the componentwise product of two Cartesians. * diff --git a/Specs/Core/Cartesian2Spec.js b/Specs/Core/Cartesian2Spec.js index 591d66f99f5d..305748e49161 100644 --- a/Specs/Core/Cartesian2Spec.js +++ b/Specs/Core/Cartesian2Spec.js @@ -402,6 +402,14 @@ describe("Core/Cartesian2", function () { expect(result).toEqual(expectedResult); }); + it("cross", function () { + var left = new Cartesian2(0.0, 1.0); + var right = new Cartesian2(1.0, 0.0); + var expectedResult = -1.0; + var result = Cartesian2.cross(left, right); + expect(result).toEqual(expectedResult); + }); + it("add works with a result parameter", function () { var left = new Cartesian2(2.0, 3.0); var right = new Cartesian2(4.0, 5.0); From b86c97d6ed31b102ac7955c82afdd6e25b5069dc Mon Sep 17 00:00:00 2001 From: Hannah Date: Thu, 7 Jan 2021 12:51:08 -0500 Subject: [PATCH 2/2] Update Cartesian2.js --- Source/Core/Cartesian2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 1f5a30d42855..986b109eb4f4 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -407,7 +407,7 @@ Cartesian2.dot = function (left, right) { }; /** - * Computes the cross (outer) product of two Cartesians. + * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0 * * @param {Cartesian2} left The first Cartesian. * @param {Cartesian2} right The second Cartesian.