diff --git a/closure/goog/math/coordinate.js b/closure/goog/math/coordinate.js index a08b9cb841..0dc2469457 100644 --- a/closure/goog/math/coordinate.js +++ b/closure/goog/math/coordinate.js @@ -66,6 +66,17 @@ if (goog.DEBUG) { } +/** + * Returns whether the specified value is equal to this coordinate. + * @param {*} other Some other value. + * @return {boolean} Whether the specified value is equal to this coordinate. + */ +goog.math.Coordinate.prototype.equals = function(other) { + return other instanceof goog.math.Coordinate && + goog.math.Coordinate.equals(this, other); +}; + + /** * Compares coordinates for equality. * @param {goog.math.Coordinate} a A Coordinate. diff --git a/closure/goog/math/coordinate_test.js b/closure/goog/math/coordinate_test.js index fdd04d6645..e71537b689 100644 --- a/closure/goog/math/coordinate_test.js +++ b/closure/goog/math/coordinate_test.js @@ -83,6 +83,18 @@ function testCoordinateClone() { assertEquals(c.toString(), c.clone().toString()); } +function testCoordinateEquals() { + var a = new goog.math.Coordinate(1, 2); + + assertFalse(a.equals(null)); + assertFalse(a.equals({})); + assertFalse(a.equals(new goog.math.Coordinate(1, 3))); + assertFalse(a.equals(new goog.math.Coordinate(2, 2))); + + assertTrue(a.equals(a)); + assertTrue(a.equals(new goog.math.Coordinate(1, 2))); +} + function testCoordinateDifference() { assertObjectEquals( new goog.math.Coordinate(3, -40), diff --git a/closure/goog/math/vec2.js b/closure/goog/math/vec2.js index 2d0784decc..a1e7b4ffe1 100644 --- a/closure/goog/math/vec2.js +++ b/closure/goog/math/vec2.js @@ -199,14 +199,12 @@ goog.math.Vec2.rotateAroundPoint = function(v, axisPoint, angle) { }; -/** - * Compares this vector with another for equality. - * @param {!goog.math.Vec2} b The other vector. - * @return {boolean} Whether this vector has the same x and y as the given - * vector. - */ +/** @override */ goog.math.Vec2.prototype.equals = function(b) { - return this == b || !!b && this.x == b.x && this.y == b.y; + if (this == b) { + return true; + } + return b instanceof goog.math.Vec2 && !!b && this.x == b.x && this.y == b.y; }; diff --git a/closure/goog/math/vec2_test.js b/closure/goog/math/vec2_test.js index f8418cdf31..63ed34efc7 100644 --- a/closure/goog/math/vec2_test.js +++ b/closure/goog/math/vec2_test.js @@ -141,6 +141,7 @@ function testEquals() { var a = new goog.math.Vec2(1, 2); assertFalse(a.equals(null)); + assertFalse(a.equals({})); assertFalse(a.equals(new goog.math.Vec2(1, 3))); assertFalse(a.equals(new goog.math.Vec2(2, 2)));