Skip to content

Commit

Permalink
Merge pull request #4750 from AnalyticalGraphicsInc/divide-components
Browse files Browse the repository at this point in the history
Added divideComponents to Cartesian2,3,4
  • Loading branch information
bagnell authored Dec 13, 2016
2 parents 0a4aa31 + 9d97ca3 commit 14a0710
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions Source/Core/Cartesian2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
27 changes: 27 additions & 0 deletions Source/Core/Cartesian3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
28 changes: 28 additions & 0 deletions Source/Core/Cartesian4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
39 changes: 39 additions & 0 deletions Specs/Core/Cartesian2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
39 changes: 39 additions & 0 deletions Specs/Core/Cartesian3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
39 changes: 39 additions & 0 deletions Specs/Core/Cartesian4Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 14a0710

Please sign in to comment.