mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Implement #equals() in Point, Size and Rectangle without argument reading.
Closes #235
This commit is contained in:
parent
e6721cdbd6
commit
d1932124d7
4 changed files with 14 additions and 8 deletions
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue