Point2D is a JavaScript object used to encapsulate a 2-dimensional coordinate. This code is used in the 2D Geometry section of this site.
constructor - new Point2D(x, y);
This method creates a new Point2D object. All initialization is handled by the init() method. All parameters for this method are described below
init() initialized all properties for this object.
x is a number that represents the x-coordinate of a point.
y is a number that represents the y-coordinate of a point.
add() returns a new Point2D that is the addition of this object and another Point2D.
addEquals() adds another Point2D to this object. The object is returned to allow multiple point operations to be chained together.
scalarAdd() returns a new Point2D that is equal to the addition of the specified scalar to both coordinates in the object.
scalarAddEquals(scalar): Point2D;
scalarAddEquals() adds the specified scalar to both coordinates of the object. The object is returned to allow multiple point operations to be chained together.
subtract() returns a new Point2D that is the subtraction another Point2D from this object.
subtractEquals(that): Point2D;
subtractEquals() subtracts another Point2D from this object. The object is returned to allow multiple point operations to be chained together.
scalarSubtract(scalar): Point2D;
scalarSubtract() returns a new Point2D that is equal to the subtraction of the specified scalar from both coordinates in the object.
scalarSubtractEquals(scalar): Point2D;
scalarSubtractEquals() subtracts the specified scalar from both coordinates of the object. The object is returned to allow multiple point operations to be chained together.
multiply() returns a new Point2D that equals this object whose coordinates have been multiplied by the specified scalar amount.
multiplyEquals(scalar): Point2D;
multiplyEquals() multiplies this object's coordinates by the specified amount. The object is returned to allow multiple point operations to be chained together.
divide() returns a new Point2D that equals this object whose coordinates have been divided by the specified scalar amount.
divideEquals(scalar): Point2D;
divideEquals() divides this object's coordinates by the specified amount. The object is returned to allow multiple point operations to be chained together.
eq() determines if this object's coordinates match the specified Point2D coordinates.
lt() determines if any of this object's coordinates are less than the specified Point2D coordinates.
lte() determines if any of this object's coordinates are less than the specified Point2D coordinates or if all coordinates match.
gt() determines if any of this object's coordinates are greater than the specified Point2D coordinates.
gte() determines if any of this object's coordinates are greater than the specified Point2D coordinates or if all coordinates match.
lerp(that, percent) : Point2D;
lerp() performs a linear interpolation between the current Point2D and another Point2D based on the percentage passed to this method.
distanceFrom() returns the shortest distance between this object and another Point2D.
min() returns a new Point2D whose coordinates are the minimum of each coordinate in this object and the specified Point2D.
max() returns a new Point2D whose coordinates are the maximum of each coordinate in this object and the specified Point2D.
toString() converts this object to a string representation.
setXY() sets the current object's coordinates to the specified values.
setFromPoint() copies the specified point's coordinates to this object.
swap() exchanges the coordinates of this object and the specified Point2D.