From d1932124d74c3be9539663e617c4d909d7d1e665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 12 Jun 2013 15:28:29 -0700 Subject: [PATCH] Implement #equals() in Point, Size and Rectangle without argument reading. Closes #235 --- src/basic/Point.js | 6 ++++-- src/basic/Rectangle.js | 8 +++++--- src/basic/Size.js | 6 ++++-- src/path/Segment.js | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/basic/Point.js b/src/basic/Point.js index b73a4f4c..41c6c3be 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -198,8 +198,10 @@ var Point = Base.extend(/** @lends Point# */{ * console.log(point != new Point(1, 1)); // true */ equals: function(point) { - point = Point.read(arguments, 0, 0, true); // readNull - return point ? this.x == point.x && this.y == point.y : false; + return point === this || point && (this.x === point.x + && this.y === point.y + || Array.isArray(point) && this.x === point[0] + && this.y === point[1]) || false; }, /** diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index e6ee987d..cd4cc91c 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -201,9 +201,11 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{ * @return {Boolean} {@true if the rectangles are equal} */ equals: function(rect) { - rect = Rectangle.read(arguments); - return this.x == rect.x && this.y == rect.y - && this.width == rect.width && this.height == rect.height; + return rect === this || rect && (this.x === rect.x && this.y === rect.y + && this.width === rect.width && this.height=== rect.height + || Array.isArray(rect) && this.x === rect[0] + && this.y === rect[1] && this.width === rect[2] + && this.height === rect[3]) || false; }, /** diff --git a/src/basic/Size.js b/src/basic/Size.js index 3981630b..b9282c96 100644 --- a/src/basic/Size.js +++ b/src/basic/Size.js @@ -155,8 +155,10 @@ var Size = Base.extend(/** @lends Size# */{ * console.log(size != new Size(1, 1)); // true */ equals: function(size) { - size = Size.read(arguments); - return this.width == size.width && this.height == size.height; + return size === this || size && (this.width === size.width + && this.height === size.height + || Array.isArray(size) && this.width === size[0] + && this.height === size[1]) || false; }, /** diff --git a/src/path/Segment.js b/src/path/Segment.js index 9ed40a7c..f597d703 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -413,7 +413,7 @@ var Segment = Base.extend(/** @lends Segment# */{ }, equals: function(segment) { - return segment == this || segment + return segment === this || segment && this._point.equals(segment._point) && this._handleIn.equals(segment._handleIn) && this._handleOut.equals(segment._handleOut);