mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Implement Rectangle#getArea() and use it in reorientPath()
This commit is contained in:
parent
4926e2c8da
commit
5f24bf8da5
2 changed files with 13 additions and 4 deletions
|
@ -470,11 +470,21 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @type Point
|
* @type Point
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The area of the rectangle in square points.
|
||||||
|
*
|
||||||
|
* @type Number
|
||||||
|
* @bean
|
||||||
|
*/
|
||||||
|
getArea: function() {
|
||||||
|
return this.width * this.height;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {Boolean} {@true the rectangle is empty}
|
* @return {Boolean} {@true the rectangle is empty}
|
||||||
*/
|
*/
|
||||||
isEmpty: function() {
|
isEmpty: function() {
|
||||||
return this.width == 0 || this.height == 0;
|
return this.width === 0 || this.height === 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,9 +81,8 @@ PathItem.inject(new function() {
|
||||||
bounds = new Array(length),
|
bounds = new Array(length),
|
||||||
counters = new Array(length),
|
counters = new Array(length),
|
||||||
clockwise;
|
clockwise;
|
||||||
children.sort(function(a, b){
|
children.sort(function(a, b) {
|
||||||
var b1 = a.getBounds(), b2 = b.getBounds();
|
return b.getBounds().getArea() - a.getBounds().getArea();
|
||||||
return b2._width * b2._height - b1._width * b1._height;
|
|
||||||
});
|
});
|
||||||
path.addChildren(children);
|
path.addChildren(children);
|
||||||
clockwise = children[0].isClockwise();
|
clockwise = children[0].isClockwise();
|
||||||
|
|
Loading…
Reference in a new issue