diff --git a/Source/Core/Color.js b/Source/Core/Color.js index 3b0efe8d5bd3..e1986ba14f86 100644 --- a/Source/Core/Color.js +++ b/Source/Core/Color.js @@ -1,5 +1,6 @@ /*global define*/ define([ + './Check', './defaultValue', './defined', './DeveloperError', @@ -7,6 +8,7 @@ define([ './freezeObject', './Math' ], function( + Check, defaultValue, defined, DeveloperError, @@ -84,9 +86,9 @@ define([ */ Color.fromCartesian4 = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + + Check.typeOf.object('cartesian', cartesian); + //>>includeEnd('debug'); if (!defined(result)) { @@ -141,12 +143,10 @@ define([ */ Color.fromAlpha = function(color, alpha, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(color)) { - throw new DeveloperError('color is required'); - } - if (!defined(alpha)) { - throw new DeveloperError('alpha is required'); - } + + Check.defined('color', color); + Check.defined('alpha', alpha); + //>>includeEnd('debug'); if (!defined(result)) { @@ -287,10 +287,7 @@ define([ var minimumRed = defaultValue(options.minimumRed, 0); var maximumRed = defaultValue(options.maximumRed, 1.0); - //>>includeStart('debug', pragmas.debug); - if (minimumRed > maximumRed) { - throw new DeveloperError("minimumRed must be less than or equal to maximumRed"); - } + Check.typeOf.number.lessThanOrEquals('minimumRed', minimumRed, maximumRed); //>>includeEnd('debug'); red = minimumRed + (CesiumMath.nextRandomNumber() * (maximumRed - minimumRed)); @@ -302,11 +299,9 @@ define([ var maximumGreen = defaultValue(options.maximumGreen, 1.0); //>>includeStart('debug', pragmas.debug); - if (minimumGreen > maximumGreen) { - throw new DeveloperError("minimumGreen must be less than or equal to maximumGreen"); - } + //>>includeEnd('debug'); - + Check.typeOf.number.lessThanOrEquals('minimumGreen', minimumGreen, maximumGreen); green = minimumGreen + (CesiumMath.nextRandomNumber() * (maximumGreen - minimumGreen)); } @@ -316,10 +311,8 @@ define([ var maximumBlue = defaultValue(options.maximumBlue, 1.0); //>>includeStart('debug', pragmas.debug); - if (minimumBlue > maximumBlue) { - throw new DeveloperError("minimumBlue must be less than or equal to maximumBlue"); - } //>>includeEnd('debug'); + Check.typeOf.number.lessThanOrEquals('minimumBlue', minimumBlue, maximumBlue); blue = minimumBlue + (CesiumMath.nextRandomNumber() * (maximumBlue - minimumBlue)); } @@ -330,10 +323,8 @@ define([ var maximumAlpha = defaultValue(options.maximumAlpha, 1.0); //>>includeStart('debug', pragmas.debug); - if (minimumAlpha > maximumAlpha) { - throw new DeveloperError("minimumAlpha must be less than or equal to maximumAlpha"); - } //>>includeEnd('debug'); + Check.typeOf.number.lessThanOrEquals('minumumAlpha', minimumAlpha, maximumAlpha); alpha = minimumAlpha + (CesiumMath.nextRandomNumber() * (maximumAlpha - minimumAlpha)); } @@ -374,10 +365,8 @@ define([ */ Color.fromCssColorString = function(color, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(color)) { - throw new DeveloperError('color is required'); - } //>>includeEnd('debug'); + Check.defined('color', color); if (!defined(result)) { result = new Color(); @@ -445,14 +434,11 @@ define([ */ Color.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'); - } //>>includeEnd('debug'); + Check.defined('value', value); + Check.defined('array', array); + startingIndex = defaultValue(startingIndex, 0); array[startingIndex++] = value.red; array[startingIndex++] = value.green; @@ -472,10 +458,8 @@ define([ */ Color.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } //>>includeEnd('debug'); + Check.defined('array', array); startingIndex = defaultValue(startingIndex, 0); if (!defined(result)) { @@ -676,16 +660,10 @@ define([ */ Color.prototype.brighten = function(magnitude, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(magnitude)) { - throw new DeveloperError('magnitude is required.'); - } - if (magnitude < 0.0) { - throw new DeveloperError('magnitude must be positive.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } //>>includeEnd('debug'); + Check.typeOf.number('magnitude', magnitude); + Check.typeOf.number.greaterThanOrEquals('magnitude', magnitude, 0.0); + Check.defined('result', result); magnitude = (1.0 - magnitude); result.red = 1.0 - ((1.0 - this.red) * magnitude); @@ -707,16 +685,10 @@ define([ */ Color.prototype.darken = function(magnitude, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(magnitude)) { - throw new DeveloperError('magnitude is required.'); - } - if (magnitude < 0.0) { - throw new DeveloperError('magnitude must be positive.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } //>>includeEnd('debug'); + Check.typeOf.number('magnitude', magnitude); + Check.typeOf.number.greaterThanOrEquals('magnitude', magnitude, 0.0); + Check.defined('result', result); magnitude = (1.0 - magnitude); result.red = this.red * magnitude; @@ -750,16 +722,10 @@ define([ */ Color.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'); - } //>>includeEnd('debug'); + Check.defined('left', left); + Check.defined('right', right); + Check.defined('result', result); result.red = left.red + right.red; result.green = left.green + right.green; @@ -778,16 +744,10 @@ define([ */ Color.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'); - } //>>includeEnd('debug'); + Check.defined('left', left); + Check.defined('right', right); + Check.defined('result', result); result.red = left.red - right.red; result.green = left.green - right.green; @@ -806,16 +766,10 @@ define([ */ Color.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'); - } //>>includeEnd('debug'); + Check.defined('left', left); + Check.defined('right', right); + Check.defined('result', result); result.red = left.red * right.red; result.green = left.green * right.green; @@ -834,16 +788,10 @@ define([ */ Color.divide = 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'); + Check.defined('left', left); + Check.defined('right', right); + Check.defined('result', result); result.red = left.red / right.red; result.green = left.green / right.green; @@ -862,16 +810,10 @@ define([ */ Color.mod = 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'); + Check.defined('left', left); + Check.defined('right', right); + Check.defined('result', result); result.red = left.red % right.red; result.green = left.green % right.green; @@ -890,16 +832,10 @@ define([ */ Color.multiplyByScalar = function(color, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(color)) { - throw new DeveloperError('cartesian 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'); - } //>>includeEnd('debug'); + Check.defined('color', color); + Check.typeOf.number('scalar', scalar); + Check.defined('result', result); result.red = color.red * scalar; result.green = color.green * scalar; @@ -918,16 +854,10 @@ define([ */ Color.divideByScalar = function(color, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(color)) { - throw new DeveloperError('cartesian 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'); - } //>>includeEnd('debug'); + Check.defined('color', color); + Check.typeOf.number('scalar', scalar); + Check.defined('result', result); result.red = color.red / scalar; result.green = color.green / scalar;