diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 3f937c955db8..7dab44b7218e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -36,6 +36,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Kangning Li](https://github.com/likangning93) * [Erik Andersson](https://github.com/erikmaarten) * [Austin Eng](https://github.com/austinEng) + * [Shehzan Mohammed](https://github.com/shehzan10) * [NICTA](http://www.nicta.com.au/) * [Chris Cooper](https://github.com/chris-cooper) * [Kevin Ring](https://github.com/kring) diff --git a/Source/Core/Matrix2.js b/Source/Core/Matrix2.js index ead1b25b2aa8..6fc6f8512d8b 100644 --- a/Source/Core/Matrix2.js +++ b/Source/Core/Matrix2.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian2', + './Check', './defaultValue', './defined', './defineProperties', @@ -8,6 +9,7 @@ define([ './freezeObject' ], function( Cartesian2, + Check, defaultValue, defined, defineProperties, @@ -57,13 +59,8 @@ define([ */ Matrix2.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -86,9 +83,7 @@ define([ */ Matrix2.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -148,9 +143,7 @@ define([ */ Matrix2.fromArray = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -175,9 +168,7 @@ define([ */ Matrix2.fromColumnMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values parameter is required'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); return Matrix2.clone(values, result); @@ -193,9 +184,7 @@ define([ */ Matrix2.fromRowMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values is required.'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); if (!defined(result)) { @@ -224,9 +213,7 @@ define([ */ Matrix2.fromScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(scale)) { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.object(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -257,9 +244,7 @@ define([ */ Matrix2.fromUniformScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (typeof scale !== 'number') { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.number(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -290,9 +275,7 @@ define([ */ Matrix2.fromRotation = function(angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(angle)) { - throw new DeveloperError('angle is required.'); - } + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var cosAngle = Math.cos(angle); @@ -320,9 +303,7 @@ define([ */ Matrix2.toArray = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); if (!defined(result)) { @@ -353,12 +334,13 @@ define([ */ Matrix2.getElementIndex = function(column, row) { //>>includeStart('debug', pragmas.debug); - if (typeof row !== 'number' || row < 0 || row > 1) { - throw new DeveloperError('row must be 0 or 1.'); - } - if (typeof column !== 'number' || column < 0 || column > 1) { - throw new DeveloperError('column must be 0 or 1.'); - } + Check.typeOf.number(row, 'row'); + Check.numeric.minimum(row, 0); + Check.numeric.maximum(row, 1); + + Check.typeOf.number(column, 'column'); + Check.numeric.minimum(column, 0); + Check.numeric.maximum(column, 1); //>>includeEnd('debug'); return column * 2 + row; @@ -376,15 +358,13 @@ define([ */ Matrix2.getColumn = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var startIndex = index * 2; @@ -409,18 +389,14 @@ define([ */ Matrix2.setColumn = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix2.clone(matrix, result); @@ -442,15 +418,13 @@ define([ */ Matrix2.getRow = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[index]; @@ -474,18 +448,14 @@ define([ */ Matrix2.setRow = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix2.clone(matrix, result); @@ -505,12 +475,8 @@ define([ */ Matrix2.getScale = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Cartesian2.magnitude(Cartesian2.fromElements(matrix[0], matrix[1], scratchColumn)); @@ -542,15 +508,9 @@ define([ */ Matrix2.multiply = 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'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = left[0] * right[0] + left[2] * right[1]; @@ -575,15 +535,9 @@ define([ */ Matrix2.add = 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'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] + right[0]; @@ -603,15 +557,9 @@ define([ */ Matrix2.subtract = 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'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] - right[0]; @@ -631,15 +579,9 @@ define([ */ Matrix2.multiplyByVector = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[0] * cartesian.x + matrix[2] * cartesian.y; @@ -660,15 +602,9 @@ define([ */ Matrix2.multiplyByScalar = function(matrix, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scalar; @@ -696,15 +632,9 @@ define([ */ Matrix2.multiplyByScale = function(matrix, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(scale)) { - throw new DeveloperError('scale is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(scale, 'scale'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scale.x; @@ -723,12 +653,8 @@ define([ */ Matrix2.negate = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = -matrix[0]; @@ -747,12 +673,8 @@ define([ */ Matrix2.transpose = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = matrix[0]; @@ -776,12 +698,8 @@ define([ */ Matrix2.abs = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = Math.abs(matrix[0]); @@ -832,9 +750,7 @@ define([ */ Matrix2.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon must be a number'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) ||