Skip to content

Commit

Permalink
Merge pull request #1 from ognjenb/orientedBoundingBox
Browse files Browse the repository at this point in the history
Oriented bounding box
  • Loading branch information
bagnell committed Nov 15, 2013
2 parents 20dad1b + 9e6ddcf commit 5d5cb49
Show file tree
Hide file tree
Showing 6 changed files with 927 additions and 7 deletions.
74 changes: 67 additions & 7 deletions Source/Core/Cartesian3.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,66 @@ define([
return Math.min(cartesian.x, cartesian.y, cartesian.z);
};

/**
* Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
* @memberof Cartesian3
*
* @param {Cartesian3} first A cartesian to compare.
* @param {Cartesian3} second A cartesian to compare.
* @param {Cartesian3} [result] The object into which to store the result.
* @returns {Cartesian3} A cartesian with the minimum components.
*
* @exception {DeveloperError} first cartesian is missing.
* @exception {DeveloperError} second cartesian is missing.
*/
Cartesian3.getMinimumByComponent = function(first, second, result) {
if (!defined(first)) {
throw new DeveloperError('first cartesian is missing');
}
if (!defined(second)) {
throw new DeveloperError('second cartesian is missing');
}
if (!defined(result)) {
result = new Cartesian3();
}

result.x = Math.min(first.x, second.x);
result.y = Math.min(first.y, second.y);
result.z = Math.min(first.z, second.z);

return result;
};

/**
* Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
* @memberof Cartesian3
*
* @param {Cartesian3} first A cartesian to compare.
* @param {Cartesian3} second A cartesian to compare.
* @param {Cartesian3} [result] The object into which to store the result.
* @returns {Cartesian3} A cartesian with the maximum components.
*
* @exception {DeveloperError} first cartesian is missing.
* @exception {DeveloperError} second cartesian is missing.
*/
Cartesian3.getMaximumByComponent = function(first, second, result) {
if (!defined(first)) {
throw new DeveloperError('first cartesian is missing');
}
if (!defined(second)) {
throw new DeveloperError('second cartesian is missing');
}

if (!defined(result)) {
result = new Cartesian3();
}

result.x = Math.max(first.x, second.x);
result.y = Math.max(first.y, second.y);
result.z = Math.max(first.z, second.z);
return result;
};

/**
* Computes the provided Cartesian's squared magnitude.
* @memberof Cartesian3
Expand Down Expand Up @@ -449,7 +509,7 @@ define([
throw new DeveloperError('scalar is required and must be a number.');
}
if (!defined(result)) {
return new Cartesian3(cartesian.x * scalar, cartesian.y * scalar, cartesian.z * scalar);
return new Cartesian3(cartesian.x * scalar, cartesian.y * scalar, cartesian.z * scalar);
}
result.x = cartesian.x * scalar;
result.y = cartesian.y * scalar;
Expand Down Expand Up @@ -634,12 +694,12 @@ define([
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
Cartesian3.equals = function(left, right) {
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(left.x === right.x) &&
(left.y === right.y) &&
(left.z === right.z));
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(left.x === right.x) &&
(left.y === right.y) &&
(left.z === right.z));
};

/**
Expand Down
32 changes: 32 additions & 0 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,38 @@ define([
return result;
};

/**
* Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
* @memberof Matrix3
*
* @param {Matrix3} matrix The matrix with signed elements.
* @param {Matrix3} [result] The object onto which to store the result.
* @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*/
Matrix3.abs = function(matrix, result) {
if (!defined(matrix)) {
throw new DeveloperError('matrix is required');
}
if (!defined(result)) {
return new Matrix3(Math.abs(matrix[0]), Math.abs(matrix[3]), Math.abs(matrix[6]),
Math.abs(matrix[1]), Math.abs(matrix[4]), Math.abs(matrix[7]),
Math.abs(matrix[2]), Math.abs(matrix[5]), Math.abs(matrix[8]));
}
result[0] = Math.abs(matrix[0]);
result[1] = Math.abs(matrix[1]);
result[2] = Math.abs(matrix[2]);
result[3] = Math.abs(matrix[3]);
result[4] = Math.abs(matrix[4]);
result[5] = Math.abs(matrix[5]);
result[6] = Math.abs(matrix[6]);
result[7] = Math.abs(matrix[7]);
result[8] = Math.abs(matrix[8]);

return result;
};

/**
* Compares the provided matrices componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
Expand Down
Loading

0 comments on commit 5d5cb49

Please sign in to comment.