Implement #equals() in Point, Size and Rectangle without argument reading.

Closes #235
This commit is contained in:
Jürg Lehni 2013-06-12 15:28:29 -07:00
parent e6721cdbd6
commit d1932124d7
4 changed files with 14 additions and 8 deletions

View file

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

View file

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

View file

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

View file

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