Skip to content

Commit

Permalink
Merge pull request #1 from nobelium/checking
Browse files Browse the repository at this point in the history
Explicitly checked for 'undefined'
  • Loading branch information
nobelium committed Apr 25, 2013
2 parents 3a54459 + b14d91e commit f5f9aea
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 79 deletions.
8 changes: 5 additions & 3 deletions Source/Core/BoxTessellator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ define([
'./DeveloperError',
'./Cartesian3',
'./ComponentDatatype',
'./PrimitiveType'
'./PrimitiveType',
'./defaultValue'
], function(
DeveloperError,
Cartesian3,
ComponentDatatype,
PrimitiveType) {
PrimitiveType,
defaultValue) {
"use strict";

/**
Expand All @@ -27,7 +29,7 @@ define([
* @exception {DeveloperError} All dimensions' components must be greater than or equal to zero.
*/
compute : function(template) {
template = template || {};
template = defaultValue(template, {});
var minimumCorner;
var maximumCorner;

Expand Down
10 changes: 6 additions & 4 deletions Source/Core/CatmullRomSpline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ define([
'./Matrix4',
'./Cartesian3',
'./Cartesian4',
'./HermiteSpline'
'./HermiteSpline',
'./defaultValue'
],
function(
DeveloperError,
Matrix4,
Cartesian3,
Cartesian4,
HermiteSpline) {
HermiteSpline,
defaultValue) {
"use strict";

/**
Expand Down Expand Up @@ -45,7 +47,7 @@ define([
* var spline = new CatmullRomSpline(controlPoints);
*/
var CatmullRomSpline = function(controlPoints, firstTangent, lastTangent) {
if (!controlPoints || !(controlPoints instanceof Array) || controlPoints.length < 3) {
if (typeof controlPoints === 'undefined' || !(controlPoints instanceof Array) || controlPoints.length < 3) {
throw new DeveloperError('controlPoints is required and must be an array of objects with point and time properties, with a length of at least 3.');
}

Expand Down Expand Up @@ -127,7 +129,7 @@ define([
CatmullRomSpline.prototype._findIndex = function(time) {
// Take advantage of temporal coherence by checking current, next and previous intervals
// for containment of time.
var i = this._lastTimeIndex || 0;
var i = defaultValue(this._lastTimeIndex, 0);
if (time >= this._points[i].time) {
if (i + 1 < this._points.length && time < this._points[i + 1].time) {
return i;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/LinearApproximation.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ define([
var x0 = xTable[0];
var x1 = xTable[1];


if(x0 === x1){
throw new DeveloperError('Divide by zero error: xTable[0] and xTable[1] are equal');
}

for (i = 0; i < yStride; i++) {
y0 = yTable[i];
y1 = yTable[i + yStride];
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/PlaneTessellator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
define([
'./DeveloperError',
'./Cartesian2',
'./PrimitiveType'
'./PrimitiveType',
'./defaultValue'
], function(
DeveloperError,
Cartesian2,
PrimitiveType) {
PrimitiveType,
defaultValue) {
"use strict";

/**
Expand All @@ -24,8 +26,8 @@ define([
* @exception {DeveloperError} Resolution must be greater than one in both the x and y directions.
*/
compute : function(template) {
template = template || {};
var resolution = template.resolution || new Cartesian2(2, 2);
template = defaultValue(template, {});
var resolution = defaultValue(template.resolution, new Cartesian2(2, 2));
var onInterpolation = template.onInterpolation; // Can be undefined

if (resolution.x <= 1 || resolution.y <= 1) {
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/ScreenSpaceEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ define([
'./Cartesian2',
'./JulianDate',
'./ScreenSpaceEventType',
'./KeyboardEventModifier'
'./KeyboardEventModifier',
'./defaultValue'
], function(
DeveloperError,
destroyObject,
Cartesian2,
JulianDate,
ScreenSpaceEventType,
KeyboardEventModifier) {
KeyboardEventModifier,
defaultValue) {
"use strict";

/**
Expand Down Expand Up @@ -61,7 +63,7 @@ define([
// or determined based on the platform?
this._clickPixelTolerance = 5;

this._element = element || document;
this._element = defaultValue(element, document);

this._register();
};
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/Shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ define([
'./Cartesian2',
'./Cartesian3',
'./Quaternion',
'./Matrix3'
'./Matrix3',
'./defaultValue'
], function(
DeveloperError,
CesiumMath,
Cartesian2,
Cartesian3,
Quaternion,
Matrix3) {
Matrix3,
defaultValue) {
"use strict";

function _computeEllipseQuadrant(cb, cbRadius, aSqr, bSqr, ab, ecc, mag, unitPos, eastVec, northVec, bearing,
Expand Down Expand Up @@ -102,7 +104,7 @@ define([
* Cartographic.fromDegrees(-75.59777, 40.03883, 0.0)), 100000.0));
*/
computeCircleBoundary : function(ellipsoid, center, radius, granularity) {
if (!ellipsoid || !center || !radius) {
if (typeof ellipsoid === 'undefined' || typeof center === 'undefined' || typeof radius === 'undefined') {
throw new DeveloperError('ellipsoid, center, and radius are required.');
}

Expand Down Expand Up @@ -153,7 +155,7 @@ define([
* Cartographic.fromDegrees(-75.59777, 40.03883)), 500000.0, 300000.0, Math.toRadians(60)));
*/
computeEllipseBoundary : function(ellipsoid, center, semiMajorAxis, semiMinorAxis, bearing, granularity) {
if (!ellipsoid || !center || !semiMajorAxis || !semiMinorAxis) {
if (typeof ellipsoid === 'undefined' || typeof center === 'undefined' || typeof semiMajorAxis === 'undefined' || typeof semiMinorAxis === 'undefined') {
throw new DeveloperError('ellipsoid, center, semiMajorAxis, and semiMinorAxis are required.');
}

Expand Down
22 changes: 8 additions & 14 deletions Source/Core/Spherical.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*global define*/
define(function() {
define(['./defaultValue'], function(defaultValue) {
"use strict";

/**
Expand All @@ -13,9 +13,9 @@ define(function() {
* @param {Number} [magnitude=1.0] The linear coordinate measured from the origin.
*/
var Spherical = function(clock, cone, magnitude) {
this.clock = typeof clock === 'undefined' ? 0.0 : clock;
this.cone = typeof cone === 'undefined' ? 0.0 : cone;
this.magnitude = typeof magnitude === 'undefined' ? 1.0 : magnitude;
this.clock = defaultValue(clock, 0.0);
this.cone = defaultValue(cone, 0.0);
this.magnitude = defaultValue(magnitude, 1.0);
};

/**
Expand All @@ -28,9 +28,7 @@ define(function() {
* @returns The modified result parameter, or a new instance if one was not provided.
*/
Spherical.fromCartesian3 = function(cartesian3, result) {
if (typeof result === 'undefined') {
result = new Spherical();
}
result = defaultValue(result, new Spherical());
var x = cartesian3.x;
var y = cartesian3.y;
var z = cartesian3.z;
Expand All @@ -51,9 +49,7 @@ define(function() {
* @return The modified result parameter or a new instance if result was undefined.
*/
Spherical.clone = function(spherical, result) {
if (typeof result === 'undefined') {
result = new Spherical();
}
result = defaultValue(result, new Spherical());
result.clock = spherical.clock;
result.cone = spherical.cone;
result.magnitude = spherical.magnitude;
Expand All @@ -70,9 +66,7 @@ define(function() {
* @return The modified result parameter or a new instance if result was undefined.
*/
Spherical.normalize = function(spherical, result) {
if (typeof result === 'undefined') {
result = new Spherical();
}
result = defaultValue(result, new Spherical());
result.clock = spherical.clock;
result.cone = spherical.cone;
result.magnitude = 1.0;
Expand Down Expand Up @@ -108,7 +102,7 @@ define(function() {
* @return true if the first spherical is within the provided epsilon of the second spherical, false otherwise.
*/
Spherical.equalsEpsilon = function(left, right, epsilon) {
epsilon = typeof epsilon === 'undefined' ? 0.0 : epsilon;
epsilon = defaultValue(epsilon, 0.0);
return (left === right) ||
((typeof left !== 'undefined') &&
(typeof right !== 'undefined') &&
Expand Down
19 changes: 12 additions & 7 deletions Source/Core/Tipsify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/*global define*/
define(['./DeveloperError'], function(DeveloperError) {
define([
'./DeveloperError',
'./defaultValue'
], function(
DeveloperError,
defaultValue) {
"use strict";

/**
Expand Down Expand Up @@ -35,13 +40,13 @@ define(['./DeveloperError'], function(DeveloperError) {
* var indices = [0, 1, 2, 3, 4, 5];
* var maxIndex = 5;
* var cacheSize = 3;
* var acmr = Tipsify.calculateACMR(indices, maxIndex, cacheSize);
* var acmr = Tipsify.calculateACMR({"indices":indices, "maxIndex":maxIndex, "cacheSize":cacheSize});
*/
Tipsify.calculateACMR = function(description) {
description = description || {};
description = defaultValue(description, {});
var indices = description.indices;
var maximumIndex = description.maximumIndex;
var cacheSize = description.cacheSize || 24;
var cacheSize = defaultValue(description.cacheSize, 24);

if (!indices) {
throw new DeveloperError('indices is required.');
Expand Down Expand Up @@ -110,13 +115,13 @@ define(['./DeveloperError'], function(DeveloperError) {
* var indices = [0, 1, 2, 3, 4, 5];
* var maxIndex = 5;
* var cacheSize = 3;
* var reorderedIndices = Tipsify.tipsify(indices, maxIndex, cacheSize);
* var reorderedIndices = Tipsify.tipsify({"indices":indices, "maxIndex":maxIndex, "cacheSize":cacheSize});
*/
Tipsify.tipsify = function(description) {
description = description || {};
description = defaultValue(description, {});
var indices = description.indices;
var maximumIndex = description.maximumIndex;
var cacheSize = description.cacheSize || 24;
var cacheSize = defaultValue(description.cacheSize, 24);

var cursor;

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/pointInsideTriangle2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(['./DeveloperError'], function(DeveloperError) {
* @exception {DeveloperError} point, p0, p1, and p2 are required.
*/
var pointInsideTriangle2D = function(point, p0, p1, p2) {
if (!point || !p0 || !p1 || !p2) {
if (typeof point === 'undefined' || typeof p0 === 'undefined' || typeof p1 === 'undefined' || typeof p2 === 'undefined') {
throw new DeveloperError('point, p0, p1, and p2 are required.');
}

Expand Down
46 changes: 24 additions & 22 deletions Source/Scene/AnimationCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
define([
'../Core/DeveloperError',
'../Core/clone',
'../ThirdParty/Tween'
'../ThirdParty/Tween',
'../Core/defaultValue'
], function(
DeveloperError,
clone,
Tween) {
Tween,
defaultValue) {
"use strict";

/**
Expand All @@ -27,14 +29,14 @@ define([
* @exception {DeveloperError} duration is required.
*/
AnimationCollection.prototype.add = function(template) {
var t = template || {};
var t = defaultValue(template, {});

if (typeof t.duration === 'undefined') {
throw new DeveloperError('duration is required.');
}

t.delayDuration = (typeof t.delayDuration === 'undefined') ? 0 : t.delayDuration;
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = defaultValue(t.easingFunction, Tween.Easing.Linear.None);

var value = clone(t.startValue);
var tween = new Tween.Tween(value);
Expand All @@ -46,7 +48,7 @@ define([
t.onUpdate(value);
});
}
tween.onComplete(t.onComplete || null);
tween.onComplete(defaultValue(t.onComplete, null));
tween.start();

return {
Expand Down Expand Up @@ -81,13 +83,13 @@ define([
}

// Default to fade in
start = (typeof start === 'undefined') ? 0.0 : start;
stop = (typeof stop === 'undefined') ? 1.0 : stop;
start = defaultValue(start, 0.0);
stop = defaultValue(stop, 1.0);

var t = template || {};
t.duration = (typeof t.duration === 'undefined') ? 3000 : t.duration;
t.delayDuration = (typeof t.delayDuration === 'undefined') ? 0 : t.delayDuration;
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = defaultValue(t.easingFunction, Tween.Easing.Linear.None);

var value = {
alpha : start
Expand All @@ -104,7 +106,7 @@ define([
material.uniforms[properties[i]].alpha = value.alpha;
}
});
tween.onComplete(t.onComplete || null);
tween.onComplete(defaultValue(t.onComplete, null));
tween.start();

return {
Expand Down Expand Up @@ -133,10 +135,10 @@ define([
throw new DeveloperError('object must have the specified property.');
}

var t = template || {};
t.duration = (typeof t.duration === 'undefined') ? 3000 : t.duration;
t.delayDuration = (typeof t.delayDuration === 'undefined') ? 0 : t.delayDuration;
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = defaultValue(t.easingFunction, Tween.Easing.Linear.None);

var value = {
value : start
Expand All @@ -150,7 +152,7 @@ define([
tween.onUpdate(function() {
object[property] = value.value;
});
tween.onComplete(t.onComplete || null);
tween.onComplete(defaultValue(t.onComplete, null));
tween.start();

return {
Expand All @@ -174,10 +176,10 @@ define([
throw new DeveloperError('material must have an offset property.');
}

var t = template || {};
t.duration = (typeof t.duration === 'undefined') ? 3000 : t.duration;
t.delayDuration = (typeof t.delayDuration === 'undefined') ? 0 : t.delayDuration;
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = defaultValue(t.easingFunction, Tween.Easing.Linear.None);

var value = {
offset : material.uniforms.offset
Expand Down
Loading

0 comments on commit f5f9aea

Please sign in to comment.