Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly checked for 'undefined' bug #694

Merged
merged 17 commits into from
Apr 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 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,8 @@ define([
* @exception {DeveloperError} All dimensions' components must be greater than or equal to zero.
*/
compute : function(template) {
template = (typeof template !== 'undefined') ? template : {};
template = defaultValue(template, {});

var minimumCorner;
var maximumCorner;

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 = (typeof template.resolution === "undefined") ? new Cartesian2(2, 2) : template.resolution;
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 = typeof element !== 'undefined' ? element : document;
this._element = defaultValue(element, document);

this._register();
};
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 = (typeof result === 'undefined') ? new Spherical() : result;
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 = (typeof result === 'undefined') ? new Spherical() : result;
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 = (typeof result === 'undefined') ? new Spherical() : result;
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
16 changes: 8 additions & 8 deletions Source/Core/Tipsify.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*global define*/
define([
'./defaultValue',
'./DeveloperError'
'./DeveloperError',
'./defaultValue'
], function(
defaultValue,
DeveloperError) {
DeveloperError,
defaultValue) {
"use strict";

/**
Expand Down Expand Up @@ -40,10 +40,10 @@ define([
* 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 = defaultValue(description.cacheSize, 24);
Expand Down Expand Up @@ -115,10 +115,10 @@ define([
* 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 = defaultValue(description.cacheSize, 24);
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 (typeof point === 'undefined' || typeof p0 === 'undefined' || typeof p1 === 'undefined' || typeof p2 === 'undefined') {
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
38 changes: 20 additions & 18 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,13 +29,13 @@ 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.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;

var value = clone(t.startValue);
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,12 +83,12 @@ 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;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;

var value = {
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,9 +135,9 @@ 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;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;

var value = {
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,9 +176,9 @@ 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;
var t = defaultValue(template, {});
t.duration = defaultValue(t.duration, 3000);
t.delayDuration = defaultValue(t.delayDuration, 0);
t.easingFunction = (typeof t.easingFunction === 'undefined') ? Tween.Easing.Linear.None : t.easingFunction;

var value = {
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ define([
}

Billboard.prototype.getPickId = function(context) {
this._pickId = this._pickId || context.createPickId(this._pickIdThis || this);
this._pickId = (typeof this._pickId === 'undefined') ? context.createPickId(defaultValue(this._pickIdThis, this)) : this._pickId;
return this._pickId;
};

Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/CameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ define([

var pickEllipsoid3DRay = new Ray();
function pickEllipsoid3D(controller, windowPosition, ellipsoid, result) {
ellipsoid = ellipsoid || Ellipsoid.WGS84;
ellipsoid = (typeof ellipsoid === 'undefined') ? Ellipsoid.WGS84 : ellipsoid;
var ray = controller.getPickRay(windowPosition, pickEllipsoid3DRay);
var intersection = IntersectionTests.rayEllipsoid(ray, ellipsoid);
if (!intersection) {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ define([
result = new Cartesian3();
}

ellipsoid = ellipsoid || Ellipsoid.WGS84;
ellipsoid = (typeof ellipsoid === 'undefined') ? Ellipsoid.WGS84 : ellipsoid;

if (this._mode === SceneMode.SCENE3D) {
result = pickEllipsoid3D(this, windowPosition, ellipsoid, result);
Expand Down
14 changes: 8 additions & 6 deletions Source/Scene/CustomSensorVolume.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*global define*/
define([
'../Core/defaultValue',
'../Core/DeveloperError',
'../Core/Color',
'../Core/combine',
Expand All @@ -22,6 +23,7 @@ define([
'../Shaders/CustomSensorVolumeFS',
'./SceneMode'
], function(
defaultValue,
DeveloperError,
Color,
combine,
Expand Down Expand Up @@ -59,10 +61,10 @@ define([
* @see SensorVolumeCollection#addCustom
*/
var CustomSensorVolume = function(template) {
var t = template || {};
var t = defaultValue(template, {});

this._pickId = undefined;
this._pickIdThis = t._pickIdThis || this;
this._pickIdThis = defaultValue(t._pickIdThis, this);

this._colorCommand = new DrawCommand();
this._pickCommand = new DrawCommand();
Expand Down Expand Up @@ -123,15 +125,15 @@ define([
* var center = ellipsoid.cartographicToCartesian(Cartographic.fromDegrees(-75.59777, 40.03883));
* sensor.modelMatrix = Transforms.eastNorthUpToFixedFrame(center);
*/
this.modelMatrix = t.modelMatrix || Matrix4.IDENTITY.clone();
this.modelMatrix = (typeof t.modelMatrix === 'undefined' ) ? Matrix4.IDENTITY.clone() : t.modelMatrix;

/**
* DOC_TBA
*
* @type BufferUsage
*/
this.bufferUsage = t.bufferUsage || BufferUsage.STATIC_DRAW;
this._bufferUsage = t.bufferUsage || BufferUsage.STATIC_DRAW;
this.bufferUsage = (typeof t.bufferUsage === 'undefined') ? BufferUsage.STATIC_DRAW : t.bufferUsage;
this._bufferUsage = this.bufferUsage;

/**
* DOC_TBA
Expand Down Expand Up @@ -313,7 +315,7 @@ define([
*/
CustomSensorVolume.prototype.update = function(context, frameState, commandList) {
this._mode = frameState.mode;
if (!this.show || this._mode !== SceneMode.SCENE3D) {
if (typeof this.show === 'undefined' || this._mode !== SceneMode.SCENE3D) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the original code is actually what we want. this.show is actually a boolean variable. With the check you added, this code executes even when show is false. That's what make this cleanup a little trickier than normal, you need to make sure boolean values stay the same.

return;
}

Expand Down
Loading