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

Defines a 2D point.

Constructors

Constructor

new Point2d(x?, y?): Point2d

Creates a point from coordinates.

If coordinates are omitted, the point is created at (0, 0).

Parameters

x?

number

X coordinate of 2D point.

y?

number

Y coordinate of 2D point.

Returns

Point2d

Accessors

x

Get Signature

get x(): number

X coordinate of the point.

Returns

number

Set Signature

set x(x): void

Sets the X coordinate of the point.

Parameters

x

number

X coordinate.

Returns

void


y

Get Signature

get y(): number

Y coordinate of the point.

Returns

number

Set Signature

set y(y): void

Sets the Y coordinate of the point.

Parameters

y

number

Y coordinate.

Returns

void

Methods

add()

add(other): this

Adds the coordinates of other to this point.

Parameters

other

Vector2d

Other 2D vector.

Returns

this


added()

Call Signature

added(other): Point2d

Returns a new point resulting from adding other to this point.

Parameters

other

Vector2d

Other vector.

Returns

Point2d

Call Signature

added(other): Point2d

Returns a new point whose coordinates are the sums of the coordinates of this point and other.

Parameters

other

Point2d

Other point.

Returns

Point2d


clone()

clone(): Point2d

Creates a new point with the same coordinates as this point.

Returns

Point2d


copy()

copy(other): this

Copies the coordinates of other to this point.

Parameters

other

Point2d

Point to copy.

Returns

this


distance()

distance(other): number

Returns the distance between this point and other.

Parameters

other

Point2d

Other point.

Returns

number


divide()

divide(scalar): this

Divides the coordinates of this point by scalar.

Parameters

scalar

number

Scalar value.

Returns

this


divided()

divided(scalar): Point2d

Returns a new point resulting from dividing this point by scalar.

Parameters

scalar

number

Scalar value.

Returns

Point2d


fromXY()

static fromXY(xy): Point2d

Creates a point from an object implementing the BaseXY interface.

Parameters

xy

BaseXY

Object implementing BaseXY interface.

Returns

Point2d


get()

get(index): number

Returns the coordinate value of the point:

  • 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 this point is equal to other within the provided coordinate tolerance.

Parameters

other

Point2d

Other 2D point.

tolerance?

number = Point2d.coincidenceTolerance

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

Returns

boolean


multiplied()

Call Signature

multiplied(matrix): Point2d

Returns a new point resulting from multiplying this point by matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

Point2d

Call Signature

multiplied(scalar): Point2d

Returns a new point resulting from multiplying this point by scalar.

Parameters

scalar

number

Scalar value.

Returns

Point2d


multiply()

Call Signature

multiply(matrix): this

Multiplies the coordinates of this point by a 2D matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

this

Call Signature

multiply(scalar): this

Multiplies the coordinates of this point by a scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


origin()

static origin(): Point2d

Returns a point with coordinates (0, 0).

Returns

Point2d


set()

set(index, value): this

Sets the coordinate value of the point:

  • 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 of the point.

Parameters

x?

number

X coordinate of 2D point.

y?

number

Y coordinate of 2D point.

Returns

this


setX()

setX(x): this

Sets the X coordinate of the point.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets the Y coordinate of the point.

Parameters

y

number

Y coordinate.

Returns

this


squareDistance()

squareDistance(other): number

Returns the squared distance between this point and other.

Parameters

other

Point2d

Other point.

Returns

number


subtract()

subtract(other): this

Subtracts the coordinates of other from this point.

Parameters

other

Vector2d

Other vector.

Returns

this


subtracted()

Call Signature

subtracted(other): Point2d

Returns a new point resulting from subtracting other from this point.

Parameters

other

Vector2d

Other vector.

Returns

Point2d

Call Signature

subtracted(other): Vector2d

Returns the vector from other to this point.

Parameters

other

Point2d

Other point.

Returns

Vector2d


toJSON()

toJSON(): BaseXY

Returns the JSON representation of this point.

Returns

BaseXY


toString()

toString(precision?): string

Returns a string representation of this point with the provided precision.

Parameters

precision?

number = 3

Precision.

Returns

string


transform()

transform(transformation): this

Transforms this point according to transformation.

Parameters

transformation

Transformation2d

Transformation.

Returns

this


transformed()

transformed(transformation): Point2d

Returns a new point resulting from transforming this point.

Parameters

transformation

Transformation2d

Transformation.

Returns

Point2d