Value of the x coordinate.
Value of the y coordinate.
Gets the x coordinate.
Gets the y coordinate.
Returns the point at [0,0].
Equivalent to new Point(0,0)
.
Returns the distance to another point.
Point to measure the distance to.
Divides the x & y coordinates by a value and returns the resulting point.
Amount to divide the coordinates by.
Divides the x & y coordinates by different amounts in the x- and y-direction. Returns the resulting point.
Amount to divide the x coordinate by.
Amount to divide the y coordinate by.
Point to compare against.
Multiplies the x & y coordinates by a value and returns the resulting point.
Amount to multiply by.
Multiplies the x & y coordinates by different amounts in the x- and y-direction. Returns the resulting point.
Amount to multiply the x coordinate by.
Amount to multiply the y coordinate by.
Subtracts the x & y coordinates of another point or vector and returns the resulting point.
Subtracts an x & y value from the point and returns the resulting point.
Value to subtract from the x coordinate.
Value to subtract from the y coordinate.
Gets the point as a string in the format: (x,y)
.
Creates a copy of the point with a different x coordinate.
New x coordinate.
Creates a copy of the point with a different y coordinate.
New y coordinate.
Translates the geometry from one coordinate system to another while keeping
the geometry in the same position. In other words, if the geometry is currently
described relative to planeFrom
, after changeBasis,
it will be in the same position but described relative to planeTo
.
The coordinate system the geometry is currently described relative to.
The coordinate system to describe the geometry relative to.
The geometry in the new coordinate system.
Rotates the geometry about (0,0).
Angle to rotate the geometry (in radians). The direction is counter-clockwise.
Rotates the geometry about a point.
Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
Point to pivot the geometry about.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry about a point and returns the resized geometry.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Center of scaling. Everything will shrink or expand away from this point.
Transforms the point by a transform matrix and returns the resulting point.
import { Point, Transform, Vector } from 'shapetypes';
// Create a point
const p = new Point(3, 4);
// Translate point using a transform matrix
const matrix = Transform.translate(new Vector(10, 20));
const transformed = p.transform(matrix);
console.log(transformed.toString());
// => (13,24)
// Translate point using the direct method
const direct = p.translate(new Vector(10, 20));
console.log(direct.toString());
// => (13,24)
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction and distance to move the geometry.
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction to move the geometry.
The distance to move the geometry.
Generated using TypeDoc
A two-dimensional point. The point is defined by an x coordinate and a y coordinate.
Example
import { Point, Vector } from 'shapetypes'; // Create a point const p = new Point(3, 4); // Get properties of the point console.log(p.x); // => 3 // Copy the point and change a parameter const other = p.withX(-1); console.log(other.x); // => -1 // Measure distance between points const distance = p.distanceTo(other); console.log(distance); // => 4 // Translate the point const shifted = p.translate(new Vector(10, 20)); console.log(shifted.toString()); // => '(13,24)'