Hide menu
Loading...
Searching...
No Matches
Point2d

Defines point in 2D space.

Constructors

new Point2d()

new Point2d(x?, y?): Point2d

Parameters

x?

number

X coordinate of 2D point.

y?

number

Y coordinate of 2D point.

Returns

Point2d

Accessors

x

Get Signature

get x(): number

Returns x coordinate of 2D point.

Returns

number

Set Signature

set x(x): void

Sets x coordinate of 2D point.

Parameters

x

number

X coordinate.

Returns

void


y

Get Signature

get y(): number

Returns y coordinate of 2D point.

Returns

number

Set Signature

set y(y): void

Sets y coordinate of 2D point.

Parameters

y

number

Y coordinate.

Returns

void

Methods

add()

add(other): this

Adds other vector coordinates to this point coordinates.

Parameters

other

Vector2d

Other 2D vector.

Returns

this


added()

Call Signature

added(other): Point2d

Returns new Point2d object with coordinates received by performing an add() operation to this object.

Parameters

other

Vector2d

Other vector.

Returns

Point2d

Call Signature

added(other): Point2d

Returns new Point2d object with coordinates received by performing an add operation to this object.

Parameters

other

Point2d

Other point.

Returns

Point2d


clone()

clone(): Point2d

Creates new Point object with coordinates same as this.

Returns

Point2d


copy()

copy(other): this

Copies the coordinates of the other point to this.

Parameters

other

Point2d

Copied object.

Returns

this


distance()

distance(other): number

Returns distance between other point and this point.

Parameters

other

Point2d

Other point.

Returns

number


divide()

divide(scalar): this

Divide this point coordinates by scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


divided()

divided(scalar): Point2d

Returns new Point2d object with coordinates received by performing a divide() operation to this object.

Parameters

scalar

number

Scalar value.

Returns

Point2d


get()

get(index): number

Returns coordinate value of 2D point:

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

Throws exception if index is not in range [0, 1].

Parameters

index

number

Coordinate index.

Returns

number


isEqual()

isEqual(other, tolerance?): boolean

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

Parameters

other

Point2d

Other 2D point.

tolerance?

number

Coordinates comparison tolerance;

Returns

boolean


multiplied()

Call Signature

multiplied(matrix): Point2d

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

Parameters

matrix

Matrix2d

2D matrix.

Returns

Point2d

Call Signature

multiplied(scalar): Point2d

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

Parameters

scalar

number

Scalar value.

Returns

Point2d


multiply()

Call Signature

multiply(matrix): this

Multiplies this vector coordinates with 2D matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

this

Call Signature

multiply(scalar): this

Multiplies this vector coordinates with scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


set()

set(index, value): this

Sets coordinate value of 2D point:

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

Throws exception if index is not in range [0, 1].

Parameters

index

number

Coordinate index.

value

number

Coordinate value.

Returns

this


setCoord()

setCoord(x?, y?): this

Sets x and y coordinates of this object.

Parameters

x?

number

X coordinate of 2D point.

y?

number

Y coordinate of 2D point.

Returns

this


setX()

setX(x): this

Sets x coordinate of 2D point.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets y coordinate of 2D point.

Parameters

y

number

Y coordinate.

Returns

this


subtract()

subtract(other): this

Subtracts other vector coordinates from this point coordinates.

Parameters

other

Vector2d

Other vector.

Returns

this


subtracted()

Call Signature

subtracted(other): Point2d

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

Parameters

other

Vector2d

Other vector.

Returns

Point2d

Call Signature

subtracted(other): Vector2d

Returns new Point2d object with coordinates received by performing a subtract operation to this object.

Parameters

other

Point2d

Other point.

Returns

Vector2d


toJSON()

toJSON(): BaseXY

Returns JSON representation of this point.

Returns

BaseXY


toString()

toString(precision): string

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

Parameters

precision

number = 3

Precision.

Returns

string


transform()

transform(transformation): this

Transforms coordinates of this point according to transformation.

Parameters

transformation

Transformation2d

Transformation.

Returns

this


transformed()

transformed(transformation): Point2d

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

Parameters

transformation

Transformation2d

Transformation.

Returns

Point2d


fromXY()

static fromXY(xy): Point2d

Creates new Point2d object from object implementing BaseXY interface.

Parameters

xy

BaseXY

Object implementing BaseXY interface.

Returns

Point2d


origin()

static origin(): Point2d

Returns Point2d with (0, 0) coordinates.

Returns

Point2d