Class: Point

Point(x, y)

Class representing a 2D point with x and y coordinates, and methods for common point operations such as distance calculation, addition, subtraction, multiplication, division, interpolation, and conversion to/from arrays. The Point class is designed to be immutable, with methods that return new Point instances instead of modifying the existing one.

Constructor

new Point(x, y)

Create a point by its coordinates
Parameters:
Name Type Description
x number x-coordinate
y number y-coordinate
Source:

Members

x

Returns the point x coordinate
Source:

x

Sets the point x coordinate
Source:

y

Returns the point y coordinate
Source:

y

Sets the point y coordinate
Source:

Methods

add(other) → {Point}

Add another point to this point
Parameters:
Name Type Description
other Point other point
Source:
Returns:
this point after addition
Type
Point

copy() → {Point}

Return a copy of the point
Source:
Returns:
copy of the point
Type
Point

distance(other) → {number}

Return the distance between two points
Parameters:
Name Type Description
other Point other point
Source:
Returns:
distance between the two points
Type
number

divide(scalar) → {Point}

Divide this point by a scalar
Parameters:
Name Type Description
scalar number scalar value
Source:
Returns:
this point after division
Type
Point

equals(other, epsilon) → {boolean}

Returns true if the point is equal to another point
Parameters:
Name Type Default Description
other Point other point
epsilon number 0.0001 tolerance for floating point comparison
Source:
Returns:
true if the points are equal
Type
boolean

lerp(other, t) → {Point}

Linearly interpolate between this point and another point
Parameters:
Name Type Description
other Point other point
t number interpolation factor [0, 1]
Source:
Returns:
this point after interpolation
Type
Point

multiply(scalar) → {Point}

Multiply this point by a scalar
Parameters:
Name Type Description
scalar number scalar value
Source:
Returns:
this point after multiplication
Type
Point

subtract(other) → {Point}

Subtract another point from this point
Parameters:
Name Type Description
other Point other point
Source:
Returns:
this point after subtraction
Type
Point

toArray() → {Array.<number>}

Returns the point as an array
Source:
Returns:
array representation of the point
Type
Array.<number>

toString() → {string}

Returns the point as a string
Source:
Returns:
string representation of the point
Type
string

(static) fromArray(arr) → {Point}

Create a point from an array of two numbers
Parameters:
Name Type Description
arr Array.<number> array of two numbers representing the point coordinates
Source:
Returns:
point created from the array
Type
Point