Hide menu
Loading...
Searching...
No Matches
XY

Implements 2D coordinate storage and operations.

Implements

Constructors

Constructor

new XY(x?, y?): XY

Creates coordinates from component values.

If components are omitted, the coordinates are initialized to (0, 0).

Parameters

x?

number

X coordinate.

y?

number

Y coordinate.

Returns

XY

Accessors

x

Get Signature

get x(): number

X coordinate.

Returns

number

Set Signature

set x(x): void

Sets the X coordinate.

Parameters

x

number

X coordinate.

Returns

void

X coordinate.

Implementation of

BaseXY.x


y

Get Signature

get y(): number

Y coordinate.

Returns

number

Set Signature

set y(y): void

Sets the Y coordinate.

Parameters

y

number

Y coordinate.

Returns

void

Y coordinate.

Implementation of

BaseXY.y

Methods

add()

add(other): this

Adds other to these coordinates component-wise.

Parameters

other

XY

Other coordinates.

Returns

this


added()

added(other): XY

Returns a new object resulting from adding other.

Parameters

other

XY

Other coordinates.

Returns

XY


angle()

angle(other): number

Returns the angle between these coordinates and other.

Returns NaN if either set of coordinates is null.

Parameters

other

XY

Other coordinates.

Returns

number


clone()

clone(): XY

Creates a new object with the same coordinates.

Returns

XY


copy()

copy(other): this

Copies the coordinates of other.

Parameters

other

XY

Coordinates to copy.

Returns

this


crossed()

crossed(other): number

Returns the scalar cross product of these coordinates and other.

Parameters

other

XY

Other coordinates.

Returns

number


divide()

divide(scalar): this

Divides these coordinates by scalar.

Parameters

scalar

number

Scalar value.

Returns

this


divided()

divided(scalar): XY

Returns a new object resulting from dividing these coordinates by scalar.

Parameters

scalar

number

Scalar value.

Returns

XY


dot()

dot(other): number

Returns the dot product of these coordinates and other.

Parameters

other

XY

Other coordinates.

Returns

number


fromXY()

static fromXY(xy): XY

Creates coordinates from an object implementing the BaseXY interface.

Parameters

xy

BaseXY

Object implementing BaseXY interface.

Returns

XY


get()

get(index): number

Returns the coordinate value:

  • X coordinate if index equals 0
  • Y coordinate if index equals 1

Throws a RangeError if index is not in the range [0, 1].

Parameters

index

number

Coordinate index.

Returns

number


isEqual()

isEqual(other, tolerance?): boolean

Returns whether these coordinates are equal to other within the provided tolerance.

Parameters

other

XY

Other coordinates.

tolerance?

number = XY.coincidenceTolerance

Coordinate comparison tolerance (1e-9 by default).

Returns

boolean


isNormal()

isNormal(other, tolerance?): boolean

Returns whether other is perpendicular within the provided angular tolerance.

Parameters

other

XY

Other coordinates.

tolerance?

number = XY.angularTolerance

Angular comparison tolerance (1e-7 by default).

Returns

boolean


isNull()

isNull(): boolean

Returns whether the coordinates are effectively zero within the coincidence tolerance.

Returns

boolean


isOpposite()

isOpposite(other, tolerance?): boolean

Returns whether other is opposite within the provided angular tolerance.

Parameters

other

XY

Other coordinates.

tolerance?

number = XY.angularTolerance

Angular comparison tolerance (1e-7 by default).

Returns

boolean


isParallel()

isParallel(other, tolerance?): boolean

Returns whether other is parallel within the provided angular tolerance.

Parameters

other

XY

Other coordinates.

tolerance?

number = XY.angularTolerance

Angular comparison tolerance (1e-7 by default).

Returns

boolean


modulus()

modulus(): number

Returns the modulus of the coordinates.

Returns

number


multiplied()

Call Signature

multiplied(other): XY

Returns a new object resulting from multiplying these coordinates by other.

Parameters

other

XY

Other coordinates.

Returns

XY

Call Signature

multiplied(scalar): XY

Returns a new object resulting from multiplying these coordinates by scalar.

Parameters

scalar

number

Scalar value.

Returns

XY

Call Signature

multiplied(matrix): XY

Returns a new object resulting from multiplying these coordinates by matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

XY


multiply()

Call Signature

multiply(other): this

Multiplies these coordinates by other component-wise.

Parameters

other

XY

Other coordinates.

Returns

this

Call Signature

multiply(matrix): this

Multiplies these coordinates by a 2D matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

this

Call Signature

multiply(scalar): this

Multiplies these coordinates by a scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


normalize()

normalize(): this

Normalizes the coordinates.

Null coordinates remain unchanged.

Returns

this


normalized()

normalized(): XY

Returns a new object with normalized coordinates.

Returns

XY


reverse()

reverse(): this

Reverses the coordinates.

Returns

this


reversed()

reversed(): XY

Returns a new object resulting from reversing these coordinates.

Returns

XY


set()

set(index, value): this

Sets the coordinate value:

  • X coordinate if index equals 0
  • Y coordinate if index equals 1

Throws a RangeError if index is not in the range [0, 1].

Parameters

index

number

Coordinate index.

value

number

Coordinate value.

Returns

this


setCoord()

setCoord(x?, y?): this

Sets the specified coordinates.

Parameters

x?

number

X coordinate.

y?

number

Y coordinate.

Returns

this


setX()

setX(x): this

Sets the X coordinate.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets the Y coordinate.

Parameters

y

number

Y coordinate.

Returns

this


squareModulus()

squareModulus(): number

Returns the squared modulus of the coordinates.

Returns

number


subtract()

subtract(other): this

Subtracts other from these coordinates component-wise.

Parameters

other

XY

Other coordinates.

Returns

this


subtracted()

subtracted(other): XY

Returns a new object resulting from subtracting other.

Parameters

other

XY

Other coordinates.

Returns

XY


toJSON()

toJSON(): BaseXY

Returns the JSON representation of the coordinates.

Returns

BaseXY


toString()

toString(precision?): string

Returns a string representation of the coordinates with the provided precision.

Parameters

precision?

number = 3

Precision.

Returns

string