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

Add Cartesian2.cross #9305

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions Source/Core/Cartesian2.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ Cartesian2.dot = function (left, right) {
return left.x * right.x + left.y * right.y;
};

/**
* 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.
* @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.
*
Expand Down
8 changes: 8 additions & 0 deletions Specs/Core/Cartesian2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down