Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Add an equals method to goog.math.Coordinate and make the existing eq…
Browse files Browse the repository at this point in the history
…uals method on goog.math.Vec2 take '*' instead of another goog.math.Vec2.

RELNOTES: NONE

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132601819
  • Loading branch information
joeltine committed Sep 9, 2016
1 parent dea9235 commit effb406
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
11 changes: 11 additions & 0 deletions closure/goog/math/coordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions closure/goog/math/coordinate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 5 additions & 7 deletions closure/goog/math/vec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
1 change: 1 addition & 0 deletions closure/goog/math/vec2_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down

0 comments on commit effb406

Please sign in to comment.