From 5f24bf8da5045329364006ae8d021c2b9dbcb548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 3 Dec 2013 21:54:36 +0100 Subject: [PATCH] Implement Rectangle#getArea() and use it in reorientPath() --- src/basic/Rectangle.js | 12 +++++++++++- src/path/PathItem.Boolean.js | 5 ++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 27199f71..a84638b4 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -470,11 +470,21 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{ * @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} */ isEmpty: function() { - return this.width == 0 || this.height == 0; + return this.width === 0 || this.height === 0; }, /** diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index cc222cd4..657525e8 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -81,9 +81,8 @@ PathItem.inject(new function() { bounds = new Array(length), counters = new Array(length), clockwise; - children.sort(function(a, b){ - var b1 = a.getBounds(), b2 = b.getBounds(); - return b2._width * b2._height - b1._width * b1._height; + children.sort(function(a, b) { + return b.getBounds().getArea() - a.getBounds().getArea(); }); path.addChildren(children); clockwise = children[0].isClockwise();