The goog.math.Coordinate Class

goog.math.Coordinate(opt_x, opt_y)

Class for representing coordinates and positions.

opt_x {number=}
Left, defaults to 0.
opt_y {number=}
Top, defaults to 0.

.azimuth(a)

Returns the angle from the origin to a coordinate.

a {!goog.math.Coordinate}
A Coordinate.
returns {number}
The angle, in degrees, clockwise from the positive X axis to {@code a}.

.clone()

Returns a new copy of the coordinate.

returns {!goog.math.Coordinate}
A clone of this coordinate.

.difference(a, b)

Returns the difference between two coordinates as a new goog.math.Coordinate.

a {!goog.math.Coordinate}
A Coordinate.
b {!goog.math.Coordinate}
A Coordinate.
returns {!goog.math.Coordinate}
A Coordinate representing the difference between {@code a} and {@code b}.

.distance(a, b)

Returns the distance between two coordinates.

a {!goog.math.Coordinate}
A Coordinate.
b {!goog.math.Coordinate}
A Coordinate.
returns {number}
The distance between {@code a} and {@code b}.

.equals(a, b)

Compares coordinates for equality.

a {goog.math.Coordinate}
A Coordinate.
b {goog.math.Coordinate}
A Coordinate.
returns {boolean}
True iff the coordinates are equal, or if both are null.

.magnitude(a)

Returns the magnitude of a coordinate.

a {!goog.math.Coordinate}
A Coordinate.
returns {number}
The distance between the origin and {@code a}.

.squaredDistance(a, b)

Returns the squared distance between two coordinates. Squared distances can be used for comparisons when the actual value is not required. Performance note: eliminating the square root is an optimization often used in lower-level languages, but the speed difference is not nearly as pronounced in JavaScript (only a few percent.)

a {!goog.math.Coordinate}
A Coordinate.
b {!goog.math.Coordinate}
A Coordinate.
returns {number}
The squared distance between {@code a} and {@code b}.

.sum(a, b)

Returns the sum of two coordinates as a new goog.math.Coordinate.

a {!goog.math.Coordinate}
A Coordinate.
b {!goog.math.Coordinate}
A Coordinate.
returns {!goog.math.Coordinate}
A Coordinate representing the sum of the two coordinates.

.toString()

Returns a nice string representing the coordinate.

returns {string}
In the form (50, 73).

.x {number}

X-value

.y {number}

Y-value