Skip to content

Commit

Permalink
Replaces DeveloperError(s) with Check(s) in Color.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimatedRNG committed Jun 5, 2017
1 parent 90ac137 commit 18ba5d5
Showing 1 changed file with 46 additions and 116 deletions.
162 changes: 46 additions & 116 deletions Source/Core/Color.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*global define*/
define([
'./Check',
'./defaultValue',
'./defined',
'./DeveloperError',
'./FeatureDetection',
'./freezeObject',
'./Math'
], function(
Check,
defaultValue,
defined,
DeveloperError,
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}

Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 18ba5d5

Please sign in to comment.