Implement Rectangle#getArea() and use it in reorientPath()

This commit is contained in:
Jürg Lehni 2013-12-03 21:54:36 +01:00
parent 4926e2c8da
commit 5f24bf8da5
2 changed files with 13 additions and 4 deletions

View file

@ -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;
}, },
/** /**

View file

@ -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();