Skip to content

Commit

Permalink
fixed default values for arguments - fixes jdan#23
Browse files Browse the repository at this point in the history
  • Loading branch information
manuq authored and jdan committed May 1, 2014
1 parent 2e7c35e commit 673f6eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions js/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

function Point(x, y, z) {
if (this instanceof Point) {
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
this.x = (typeof x === 'number') ? x : 0;
this.y = (typeof y === 'number') ? y : 0;
this.z = (typeof z === 'number') ? z : 0;
} else {
return new Point(x, y, z);
}
Expand Down Expand Up @@ -36,7 +36,7 @@
dy = dz = dx;
/* If just dz is missing, set it equal to 1 */
} else {
dz = (dz || 1);
dz = (typeof dz === 'number') ? dz : 1;
}

p.x *= dx;
Expand Down
16 changes: 8 additions & 8 deletions js/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
* along the z-axis
*/
Shape.extrude = function (path, height) {
height = height || 1;
height = (typeof height === 'number') ? height : 1;

var i, topPath = path.translate(0, 0, height);
var shape = new Shape();
Expand Down Expand Up @@ -117,9 +117,9 @@
* A prism located at origin with dimensions dx, dy, dz
*/
Shape.Prism = function (origin, dx, dy, dz) {
dx = dx || 1;
dy = dy || 1;
dz = dz || 1;
dx = (typeof dx === 'number') ? dx : 1;
dy = (typeof dy === 'number') ? dy : 1;
dz = (typeof dz === 'number') ? dz : 1;

var Path = Isomer.Path;
var Point = Isomer.Point;
Expand Down Expand Up @@ -165,9 +165,9 @@


Shape.Pyramid = function (origin, dx, dy, dz) {
dx = dx || 1;
dy = dy || 1;
dz = dz || 1;
dx = (typeof dx === 'number') ? dx : 1;
dy = (typeof dy === 'number') ? dy : 1;
dz = (typeof dz === 'number') ? dz : 1;

var Path = Isomer.Path;
var Point = Isomer.Point;
Expand Down Expand Up @@ -198,7 +198,7 @@


Shape.Cylinder = function (origin, radius, vertices, height) {
radius = radius || 1;
radius = (typeof radius === 'number') ? radius : 1;

var Path = Isomer.Path;

Expand Down
6 changes: 3 additions & 3 deletions js/vector.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(function (exports) {

function Vector(i, j, k) {
this.i = i || 0;
this.j = j || 0;
this.k = k || 0;
this.i = (typeof i === 'number') ? i : 0;
this.j = (typeof j === 'number') ? j : 0;
this.k = (typeof k === 'number') ? k : 0;
}

/**
Expand Down

0 comments on commit 673f6eb

Please # to comment.