Skip to content

Commit

Permalink
Fixed #11
Browse files Browse the repository at this point in the history
Vertex2D now stands alone and is simply composed of 3 Points2D
  • Loading branch information
ls-yannick committed Jan 2, 2013
1 parent 005bfc0 commit 41ad2d6
Showing 1 changed file with 12 additions and 47 deletions.
59 changes: 12 additions & 47 deletions lib/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Cannon.Math.Point2D.polar = function(length, angle)
/**
A vertex class used for geometrical shapes. Has x and y properties as well as 2 control points
*/
Cannon.Math.Vertex2D = Cannon.Math.Point2D.extend({
Cannon.Math.Vertex2D = Cannon.ClassFactory.extend({
/**
This constructor accepts both numbers and Point2D as parameters.
You can define up to 3 points, each one either as a Point2D or as 2 arguments defining x and y.
Expand All @@ -121,60 +121,25 @@ Cannon.Math.Vertex2D = Cannon.Math.Point2D.extend({
@constructor
*/
__construct: function()
{
this._super(false);
{
//main point
var p = this.__processPoint(arguments[0], arguments[0], arguments[1]);
if (p){
this.x = p.x;
this.y = p.y;
}
else
{
this.x = 0;
this.y = 0;
Cannon.Logger.log('Unable to process Cannon.Vertex constructor arguments, used (0, 0) instead', Cannon.Logger.Warning);
}

this.point = this.__processPoint(arguments[0], arguments[0], arguments[1]);
//control point 1
var cp1 = this.__processPoint(arguments[1], arguments[2], arguments[3]);
if (cp1)
{
this.cp1x = cp1.x;
this.cp1y = cp1.y;
}
else
{
this.cp1x = this.x;
this.cp1y = this.y;
}

this.controlPoint1 = this.__processPoint(arguments[1], arguments[2], arguments[3]);
//control point 2
var cp2 = this.__processPoint(arguments[2], arguments[4], arguments[5]);
if (cp2)
{
this.cp2x = cp2.x;
this.cp2y = cp2.y;
}
else
{
this.cp2x = this.cp1x;
this.cp2y = this.cp1y;
}
this.controlPoint2 = this.__processPoint(arguments[2], arguments[4], arguments[5]);
},
__processPoint: function(point, x, y){
//returns an object because we dont need all the methods asssociated with Point2D
if (Cannon.Utils.instanceOf(point, Cannon.Math.Point2D) || (point && point.x && point.y))
{
return {x: point.x, y: point.y};
if (Cannon.Utils.instanceOf(point, Cannon.Math.Point2D) || (point && point.x && point.y)){
return new Cannon.Math.Point2D(point.x, point.y);
}
else if (Cannon.Utils.isNumber(x) && Cannon.Utils.isNumber(y))
{
return {x: x, y: y};
else if (Cannon.Utils.isNumber(x) && Cannon.Utils.isNumber(y)){
return new Cannon.Math.Point2D(x, y);
}
else
{
return false;
else{
Cannon.Logger.log('Unable to process Cannon.Vertex constructor arguments, used (0, 0) instead', Cannon.Logger.Warning);
return new Cannon.Math.Point2D(0, 0);
}
},
/**
Expand Down

0 comments on commit 41ad2d6

Please sign in to comment.