diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index bef64c819ff8..b2fa29ca2bd4 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian3', + './Check', './defaultValue', './defined', './DeveloperError', @@ -10,6 +11,7 @@ define([ './Matrix3' ], function( Cartesian3, + Check, defaultValue, defined, DeveloperError, @@ -73,12 +75,8 @@ define([ */ Quaternion.fromAxisAngle = function(axis, angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(axis)) { - throw new DeveloperError('axis is required.'); - } - if (typeof angle !== 'number') { - throw new DeveloperError('angle is required and must be a number.'); - } + Check.typeOf.object(axis, 'axis'); + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var halfAngle = angle / 2.0; @@ -112,9 +110,7 @@ define([ */ Quaternion.fromRotationMatrix = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); var root; @@ -190,15 +186,9 @@ define([ */ Quaternion.fromHeadingPitchRoll = function(heading, pitch, roll, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(heading)) { - throw new DeveloperError('heading is required.'); - } - if (!defined(pitch)) { - throw new DeveloperError('pitch is required.'); - } - if (!defined(roll)) { - throw new DeveloperError('roll is required.'); - } + Check.typeOf.number(heading, 'heading'); + Check.typeOf.number(pitch, 'pitch'); + Check.typeOf.number(roll, 'roll'); //>>includeEnd('debug'); var rollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, roll, scratchHPRQuaternion); @@ -231,13 +221,8 @@ define([ */ Quaternion.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); @@ -260,9 +245,7 @@ define([ */ Quaternion.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); @@ -373,12 +356,8 @@ define([ */ Quaternion.conjugate = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -quaternion.x; @@ -396,9 +375,7 @@ define([ */ Quaternion.magnitudeSquared = function(quaternion) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); //>>includeEnd('debug'); return quaternion.x * quaternion.x + quaternion.y * quaternion.y + quaternion.z * quaternion.z + quaternion.w * quaternion.w; @@ -423,9 +400,7 @@ define([ */ Quaternion.normalize = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion); @@ -450,9 +425,7 @@ define([ */ Quaternion.inverse = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var magnitudeSquared = Quaternion.magnitudeSquared(quaternion); @@ -470,15 +443,9 @@ define([ */ Quaternion.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.x = left.x + right.x; @@ -498,15 +465,9 @@ define([ */ Quaternion.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.x = left.x - right.x; @@ -525,12 +486,8 @@ define([ */ Quaternion.negate = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -quaternion.x; @@ -549,12 +506,8 @@ define([ */ Quaternion.dot = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; @@ -570,15 +523,9 @@ define([ */ Quaternion.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 leftX = left.x; @@ -613,15 +560,9 @@ define([ */ Quaternion.multiplyByScalar = function(quaternion, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion 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(quaternion, 'quaternion'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = quaternion.x * scalar; @@ -641,15 +582,9 @@ define([ */ Quaternion.divideByScalar = function(quaternion, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion 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(quaternion, 'quaternion'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = quaternion.x / scalar; @@ -668,12 +603,8 @@ define([ */ Quaternion.computeAxis = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var w = quaternion.w; @@ -698,9 +629,7 @@ define([ */ Quaternion.computeAngle = function(quaternion) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); //>>includeEnd('debug'); if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) { @@ -721,18 +650,10 @@ define([ */ Quaternion.lerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch); @@ -756,18 +677,10 @@ define([ */ Quaternion.slerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var dot = Quaternion.dot(start, end); @@ -802,12 +715,8 @@ define([ */ Quaternion.log = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var theta = CesiumMath.acosClamped(quaternion.w); @@ -829,12 +738,8 @@ define([ */ Quaternion.exp = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var theta = Cartesian3.magnitude(cartesian); @@ -871,12 +776,10 @@ define([ */ Quaternion.computeInnerQuadrangle = function(q0, q1, q2, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(q2)) { - throw new DeveloperError('q0, q1, and q2 are required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(q2, 'q2'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var qInv = Quaternion.conjugate(q1, squadScratchQuaternion0); @@ -920,15 +823,12 @@ define([ */ Quaternion.squad = function(q0, q1, s0, s1, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) { - throw new DeveloperError('q0, q1, s0, and s1 are required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(s0, 's0'); + Check.typeOf.object(s1, 's1'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0); @@ -967,18 +867,10 @@ define([ */ Quaternion.fastSlerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = Quaternion.dot(start, end); @@ -1029,15 +921,12 @@ define([ */ Quaternion.fastSquad = function(q0, q1, s0, s1, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) { - throw new DeveloperError('q0, q1, s0, and s1 are required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(s0, 's0'); + Check.typeOf.object(s1, 's1'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0); @@ -1075,9 +964,7 @@ define([ */ Quaternion.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon is required and must be a number.'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) ||