# Class goog.math.Coordinate

code »

Class for representing coordinates and positions.

## Constructor

goog.math.Coordinate ( opt_x, opt_y )

Parameters
opt_x: `number=` Left, defaults to 0. opt_y: `number=` Top, defaults to 0.

Show:Public Protected Private

## Instance Methods

code »ceil ( ) ⇒ `!goog.math.Coordinate`

Rounds the x and y fields to the next larger integer values.

Returns
This coordinate with ceil'd fields.

code »clone ( ) ⇒ `!goog.math.Coordinate`

Returns a new copy of the coordinate.

Returns
A clone of this coordinate.

code »floor ( ) ⇒ `!goog.math.Coordinate`

Rounds the x and y fields to the next smaller integer values.

Returns
This coordinate with floored fields.

code »rotateDegrees ( degrees, opt_center )

Rotates this coordinate clockwise about the origin (or, optionally, the given center) by the given angle, in degrees.

Parameters
degrees: `number` The angle by which to rotate this coordinate clockwise about the given center, in degrees. opt_center: `!goog.math.Coordinate=` The center of rotation. Defaults to (0, 0) if not given.

code »rotateRadians ( radians, opt_center )

Rotates this coordinate clockwise about the origin (or, optionally, the given center) by the given angle, in radians.

Parameters
radians: `number` The angle by which to rotate this coordinate clockwise about the given center, in radians. opt_center: `!goog.math.Coordinate=` The center of rotation. Defaults to (0, 0) if not given.

code »round ( ) ⇒ `!goog.math.Coordinate`

Rounds the x and y fields to the nearest integer values.

Returns
This coordinate with rounded fields.

code »scale ( sx, opt_sy ) ⇒ `!goog.math.Coordinate`

Scales this coordinate by the given scale factors. The x and y values are scaled by `sx` and `opt_sy` respectively. If `opt_sy` is not given, then `sx` is used for both x and y.

Parameters
sx: `number` The scale factor to use for the x dimension. opt_sy: `number=` The scale factor to use for the y dimension.
Returns
This coordinate after scaling.

code »toString ( ) ⇒ `string`

Returns a nice string representing the coordinate.

Returns
In the form (50, 73).

code »translate ( tx, opt_ty ) ⇒ `!goog.math.Coordinate`

Translates this box by the given offsets. If a `goog.math.Coordinate` is given, then the x and y values are translated by the coordinate's x and y. Otherwise, x and y are translated by `tx` and `opt_ty` respectively.

Parameters
tx: `(number|goog.math.Coordinate)` The value to translate x by or the the coordinate to translate this coordinate by. opt_ty: `number=` The value to translate y by.
Returns
This coordinate after translating.

## Instance Properties

code »x : `number`

X-value

code »y : `number`

Y-value

## Static Functions

code »goog.math.Coordinate.azimuth ( a ) ⇒ `number`

Returns the angle from the origin to a coordinate.

Parameters
a: `!goog.math.Coordinate` A Coordinate.
Returns
The angle, in degrees, clockwise from the positive X axis to `a`.

code »goog.math.Coordinate.difference ( a, b ) ⇒ `!goog.math.Coordinate`

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

Parameters
a: `!goog.math.Coordinate` A Coordinate. b: `!goog.math.Coordinate` A Coordinate.
Returns
A Coordinate representing the difference between `a` and `b`.

code »goog.math.Coordinate.distance ( a, b ) ⇒ `number`

Returns the distance between two coordinates.

Parameters
a: `!goog.math.Coordinate` A Coordinate. b: `!goog.math.Coordinate` A Coordinate.
Returns
The distance between `a` and `b`.

code »goog.math.Coordinate.equals ( a, b ) ⇒ `boolean`

Compares coordinates for equality.

Parameters
a: `goog.math.Coordinate` A Coordinate. b: `goog.math.Coordinate` A Coordinate.
Returns
True iff the coordinates are equal, or if both are null.

code »goog.math.Coordinate.magnitude ( a ) ⇒ `number`

Returns the magnitude of a coordinate.

Parameters
a: `!goog.math.Coordinate` A Coordinate.
Returns
The distance between the origin and `a`.

code »goog.math.Coordinate.squaredDistance ( a, b ) ⇒ `number`

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.)

Parameters
a: `!goog.math.Coordinate` A Coordinate. b: `!goog.math.Coordinate` A Coordinate.
Returns
The squared distance between `a` and `b`.

code »goog.math.Coordinate.sum ( a, b ) ⇒ `!goog.math.Coordinate`

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

Parameters
a: `!goog.math.Coordinate` A Coordinate. b: `!goog.math.Coordinate` A Coordinate.
Returns
A Coordinate representing the sum of the two coordinates.