Hide menu
Loading...
Searching...
No Matches
Direction2d

Defines direction in 2D space.

Constructors

new Direction2d()

new Direction2d(x?, y?): Direction2d

Parameters

x?

number

X coordinate of 2D direction.

y?

number

Y coordinate of 2D direction.

Returns

Direction2d

Accessors

x

Get Signature

get x(): number

Returns x coordinate of 2D direction.

Returns

number

Set Signature

set x(x): void

Sets x coordinate of 2D direction.

Parameters

x

number

X coordinate.

Returns

void


y

Get Signature

get y(): number

Returns y coordinate of 2D direction.

Returns

number

Set Signature

set y(y): void

Sets y coordinate of 2D direction.

Parameters

y

number

Y coordinate.

Returns

void

Methods

add()

add(other): this

Adds other direction coordinates to this direction coordinates.

Parameters

other

Direction2d

Other direction.

Returns

this


added()

added(other): Direction2d

Returns new Direction2d object with coordinates received by performing a add() operation to this object.

Parameters

other

Direction2d

Other direction.

Returns

Direction2d


angle()

angle(other): number

Returns angle between this and other directions.

Parameters

other

Direction2d

Other direction.

Returns

number


clone()

clone(): Direction2d

Creates new Direction2d direction with coordinates same as this.

Returns

Direction2d


copy()

copy(other): this

Copies the coordinates of the other direction to this.

Parameters

other

Direction2d

Copied object.

Returns

this


crossed()

crossed(other): number

Returns cross product of this and other directions.

Parameters

other

Direction2d

Other direction.

Returns

number


dot()

dot(other): number

Returns dot product of this and other directions.

Parameters

other

Direction2d

Other direction.

Returns

number


isEqual()

isEqual(other, tolerance?): boolean

Returns true if other direction are equal to this direction within provided tolerance (1e-7 by default). Returns false otherwise.

Parameters

other

Direction2d

Other 2D direction.

tolerance?

number

Angular comparison tolerance;

Returns

boolean


isNormal()

isNormal(other, tolerance?): boolean

Returns true if other direction is perpendicular to this within provided tolerance (1e-7 by default).

Parameters

other

Direction2d

Other direction.

tolerance?

number

Returns

boolean


isOpposite()

isOpposite(other, tolerance?): boolean

Returns true if other direction is opposite to this within provided tolerance (1e-7 by default).

Parameters

other

Direction2d

Other direction.

tolerance?

number

Returns

boolean


isParallel()

isParallel(other, tolerance?): boolean

Returns true if other direction is parallel to this within provided tolerance (1e-7 by default).

Parameters

other

Direction2d

Other direction.

tolerance?

number

Returns

boolean


multiplied()

Call Signature

multiplied(other): Direction2d

Returns new Direction2d object with coordinates received by performing a multiply() operation to this object.

Parameters

other

Direction2d

Other direction.

Returns

Direction2d

Call Signature

multiplied(matrix): Direction2d

Returns new Direction2d object with coordinates received by performing a multiply() operation to this object.

Parameters

matrix

Matrix2d

2D matrix.

Returns

Direction2d


multiply()

Call Signature

multiply(other): this

Multiplies this direction coordinates with other direction coordinates.

Parameters

other

Direction2d

Other direction.

Returns

this

Call Signature

multiply(matrix): this

Multiplies this direction coordinates with matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

this


reverse()

reverse(): this

Reverses coordinates of this direction.

Returns

this


reversed()

reversed(): Direction2d

Returns new Direction2d object with coordinates received by performing a reverse() operation to this object.

Returns

Direction2d


setCoord()

setCoord(x?, y?): this

Sets x and y coordinates of this object and normalizes these coordinates.

Parameters

x?

number

X coordinate of 2D direction.

y?

number

Y coordinate of 2D direction.

Returns

this


setX()

setX(x): this

Sets x coordinate of 2D direction.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets y coordinate of 2D direction.

Parameters

y

number

Y coordinate.

Returns

this


subtract()

subtract(other): this

Subtracts other direction coordinates from this direction coordinates.

Parameters

other

Direction2d

Other direction.

Returns

this


subtracted()

subtracted(other): Direction2d

Returns new Direction2d object with coordinates received by performing a subtract() operation to this object.

Parameters

other

Direction2d

Other direction.

Returns

Direction2d


toJSON()

toJSON(): BaseXY

Returns JSON representation of this direction.

Returns

BaseXY


toString()

toString(precision): string

Returns string representation of this direction with provided precision (3 by default).

Parameters

precision

number = 3

Precision.

Returns

string


transform()

transform(transformation): this

Transforms coordinates of this direction according to transformation.

Parameters

transformation

Transformation2d

Transformation.

Returns

this


transformed()

transformed(transformation): Direction2d

Returns new Direction2d object with coordinates received by performing a transform() operation to this object.

Parameters

transformation

Transformation2d

Transformation.

Returns

Direction2d


fromVector()

static fromVector(vector): Direction2d

Creates new Direction2d object from Vector2d interface.

Parameters

vector

Vector2d

2D vector.

Returns

Direction2d


fromXY()

static fromXY(xy): Direction2d

Creates new Direction2d object from object implementing BaseXY interface.

Parameters

xy

BaseXY

Object implementing BaseXY interface.

Returns

Direction2d


xDir()

static xDir(): Direction2d

Returns Direction with (1, 0) coordinates.

Returns

Direction2d


yDir()

static yDir(): Direction2d

Returns Direction with (0, 1) coordinates.

Returns

Direction2d