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

added examples in Matrix4 #686

Closed
wants to merge 3 commits into from
Closed
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
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
4 changes: 4 additions & 0 deletions Source/Core/LinearApproximation.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ 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
108 changes: 108 additions & 0 deletions Source/Core/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,17 @@ define([
* @return {Array} The modified Array parameter or a new Array instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //converts a matrix of order 4 to an array
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
* var a = Matrix4.toArray(m);
*
* //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]
*
*/
Matrix4.toArray = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -867,6 +878,23 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //returns a Cartesian4 instance with values from the specified column
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* //Example 1: Creates a Cartesian instance
* var a = Matrix4.getColumn(m, 2);
*
* //Example 1: Creates a Cartesian instance
* var a = new Cartesian4();
* Matrix4.getColumn(m, 2, a);
*
* //creates a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
*
*/
Matrix4.getColumn = function(matrix, index, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -908,6 +936,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //create a new matrix of order 4 with new column values from the Cartesian4 instance
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.setColumn(m, 2, new Cartesian4(99.0, 98.0, 97.0, 96.0));
*
* // m still remains the same
* // a = [10.0, 11.0, 99.0, 13.0]
* // [14.0, 15.0, 98.0, 17.0]
* // [18.0, 19.0, 97.0, 21.0]
* // [22.0, 23.0, 96.0, 25.0]
*
*/
Matrix4.setColumn = function(matrix, index, cartesian, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -941,6 +985,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //returns a Cartesian4 instance with values from the specified column
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* //Example 1: Creates a Cartesian instance
* var a = Matrix4.getColumn(m, 2);
*
* //Example 1: Creates a Cartesian instance
* var a = new Cartesian4();
* Matrix4.getColumn(m, 2, a);
*
* //creates a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
*/
Matrix4.getRow = function(matrix, index, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -981,6 +1041,22 @@ define([
* @exception {DeveloperError} index is required and must be 0, 1, 2, or 3.
*
* @see Cartesian4
*
* @example
* //create a new matrix of order 4 with new row values from the Cartesian4 instance
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.setRow(m, 2, new Cartesian4(99.0, 98.0, 97.0, 96.0));
*
* // m still remains the same
* // a = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [99.0, 98.0, 97.0, 96.0]
* // [22.0, 23.0, 24.0, 25.0]
*
*/
Matrix4.setRow = function(matrix, index, cartesian, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1354,6 +1430,22 @@ define([
* @return {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //create a new matrix of order 4
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.negate(m);
*
* // m still remains the same
* // a = [-10.0, -11.0, -12.0, -13.0]
* // [-14.0, -15.0, -16.0, -17.0]
* // [-18.0, -19.0, -20.0, -21.0]
* // [-22.0, -23.0, -24.0, -25.0]
*
*/
Matrix4.negate = function(matrix, result) {
if (typeof matrix === 'undefined') {
Expand Down Expand Up @@ -1394,6 +1486,22 @@ define([
* @return {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
*
* @exception {DeveloperError} matrix is required.
*
* @example
* //create a new matrix of order 4 which is a transpose of the given matrix
* // m = [10.0, 11.0, 12.0, 13.0]
* // [14.0, 15.0, 16.0, 17.0]
* // [18.0, 19.0, 20.0, 21.0]
* // [22.0, 23.0, 24.0, 25.0]
*
* var a = Matrix4.negate(m);
*
* // m still remains the same
* // a = [10.0, 14.0, 18.0, 22.0]
* // [11.0, 15.0, 19.0, 23.0]
* // [12.0, 16.0, 20.0, 24.0]
* // [13.0, 17.0, 21.0, 25.0]
*
*/
Matrix4.transpose = function(matrix, result) {
if (typeof matrix === 'undefined') {
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
Loading