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:

Instance Methods

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

Returns
This coordinate with ceil'd fields.

Returns a new copy of the coordinate.

Returns
A clone of this 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.

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

Returns
This coordinate with rounded fields.

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.

Returns a nice string representing the coordinate.

Returns
In the form (50, 73).

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

X-value

Y-value

Static Functions

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.

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.

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.

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.

Returns the magnitude of a coordinate.

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

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.

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.