Implements 2D coordinate storage and operations.
new XY(
x?,y?):XY
Creates coordinates from component values.
If components are omitted, the coordinates are initialized to (0, 0).
number
X coordinate.
number
Y coordinate.
XY
get x():
number
X coordinate.
number
set x(
x):void
Sets the X coordinate.
number
X coordinate.
void
X coordinate.
get y():
number
Y coordinate.
number
set y(
y):void
Sets the Y coordinate.
number
Y coordinate.
void
Y coordinate.
add(
other):this
Adds other to these coordinates component-wise.
XY
Other coordinates.
this
added(
other):XY
Returns a new object resulting from adding other.
XY
Other coordinates.
XY
angle(
other):number
Returns the angle between these coordinates and other.
Returns NaN if either set of coordinates is null.
XY
Other coordinates.
number
clone():
XY
Creates a new object with the same coordinates.
XY
copy(
other):this
Copies the coordinates of other.
XY
Coordinates to copy.
this
crossed(
other):number
Returns the scalar cross product of these coordinates and other.
XY
Other coordinates.
number
divide(
scalar):this
Divides these coordinates by scalar.
number
Scalar value.
this
divided(
scalar):XY
Returns a new object resulting from dividing these coordinates by scalar.
number
Scalar value.
XY
dot(
other):number
Returns the dot product of these coordinates and other.
XY
Other coordinates.
number
staticfromXY(xy):XY
Creates coordinates from an object implementing the BaseXY interface.
Object implementing BaseXY interface.
XY
get(
index):number
Returns the coordinate value:
index equals 0index equals 1Throws a RangeError if index is not in the range [0, 1].
number
Coordinate index.
number
isEqual(
other,tolerance?):boolean
Returns whether these coordinates are equal to other within the provided tolerance.
XY
Other coordinates.
number = XY.coincidenceTolerance
Coordinate comparison tolerance (1e-9 by default).
boolean
isNormal(
other,tolerance?):boolean
Returns whether other is perpendicular within the provided angular tolerance.
XY
Other coordinates.
number = XY.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
isNull():
boolean
Returns whether the coordinates are effectively zero within the coincidence tolerance.
boolean
isOpposite(
other,tolerance?):boolean
Returns whether other is opposite within the provided angular tolerance.
XY
Other coordinates.
number = XY.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
isParallel(
other,tolerance?):boolean
Returns whether other is parallel within the provided angular tolerance.
XY
Other coordinates.
number = XY.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
modulus():
number
Returns the modulus of the coordinates.
number
multiplied(
other):XY
Returns a new object resulting from multiplying these coordinates by other.
XY
Other coordinates.
XY
multiplied(
scalar):XY
Returns a new object resulting from multiplying these coordinates by scalar.
number
Scalar value.
XY
multiplied(
matrix):XY
Returns a new object resulting from multiplying these coordinates by matrix.
2D matrix.
XY
multiply(
other):this
Multiplies these coordinates by other component-wise.
XY
Other coordinates.
this
multiply(
matrix):this
Multiplies these coordinates by a 2D matrix.
2D matrix.
this
multiply(
scalar):this
Multiplies these coordinates by a scalar value.
number
Scalar value.
this
normalize():
this
Normalizes the coordinates.
Null coordinates remain unchanged.
this
normalized():
XY
Returns a new object with normalized coordinates.
XY
reverse():
this
Reverses the coordinates.
this
reversed():
XY
Returns a new object resulting from reversing these coordinates.
XY
set(
index,value):this
Sets the coordinate value:
index equals 0index equals 1Throws a RangeError if index is not in the range [0, 1].
number
Coordinate index.
number
Coordinate value.
this
setCoord(
x?,y?):this
Sets the specified coordinates.
number
X coordinate.
number
Y coordinate.
this
setX(
x):this
Sets the X coordinate.
number
X coordinate.
this
setY(
y):this
Sets the Y coordinate.
number
Y coordinate.
this
squareModulus():
number
Returns the squared modulus of the coordinates.
number
subtract(
other):this
Subtracts other from these coordinates component-wise.
XY
Other coordinates.
this
subtracted(
other):XY
Returns a new object resulting from subtracting other.
XY
Other coordinates.
XY
toJSON():
BaseXY
Returns the JSON representation of the coordinates.
toString(
precision?):string
Returns a string representation of the coordinates with the provided precision.
number = 3
Precision.
string