Skip to content

Commit

Permalink
Add fabric.Circle#getRadiusX, fabric.Circle#getRadiusY methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax committed Apr 9, 2011
1 parent 752eff2 commit cc0c508
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dist/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -7506,6 +7506,23 @@ fabric.util.animate = animate;
}
},

/**
* Returns horizontal radius of an object (according to how an object is scaled)
* @method getRadiusX
* @return {Number}
*/
getRadiusX: function() {
return this.get('radius') * this.get('scaleX');
},

/**
* Returns vertical radius of an object (according to how an object is scaled)
* @method getRadiusY
* @return {Number}
*/
getRadiusY: function() {
return this.get('radius') * this.get('scaleY');
},

/**
* Returns complexity of an instance
Expand Down
17 changes: 17 additions & 0 deletions src/circle.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@
}
},

/**
* Returns horizontal radius of an object (according to how an object is scaled)
* @method getRadiusX
* @return {Number}
*/
getRadiusX: function() {
return this.get('radius') * this.get('scaleX');
},

/**
* Returns vertical radius of an object (according to how an object is scaled)
* @method getRadiusY
* @return {Number}
*/
getRadiusY: function() {
return this.get('radius') * this.get('scaleY');
},

/**
* Returns complexity of an instance
Expand Down
25 changes: 25 additions & 0 deletions test/unit/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@
same(circle.type, 'circle');
});

test('getRadiusX, getRadiusY', function() {
var circle = new fabric.Circle({ radius: 10 });

ok(typeof circle.getRadiusX == 'function', 'getRadiusX should exist');
ok(typeof circle.getRadiusY == 'function', 'getRadiusY should exist');

equals(circle.getRadiusX(), 10);
equals(circle.getRadiusY(), 10);

circle.scale(2);

equals(circle.getRadiusX(), 20);
equals(circle.getRadiusY(), 20);

circle.set('scaleX', 3);

equals(circle.getRadiusX(), 30);
equals(circle.getRadiusY(), 20);

circle.set('scaleY', 4);

equals(circle.getRadiusX(), 30);
equals(circle.getRadiusY(), 40);
});

test('complexity', function() {
var circle = new fabric.Circle();
ok(typeof circle.complexity == 'function');
Expand Down

0 comments on commit cc0c508

Please sign in to comment.