Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Point

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)'

Hierarchy

Index

Constructors

Accessors

Create Methods

Other Methods

Transform Methods

Constructors

constructor

  • new Point(x: number, y: number): Point
  • Parameters

    • x: number

      Value of the x coordinate.

    • y: number

      Value of the y coordinate.

    Returns Point

Accessors

x

  • get x(): number

y

  • get y(): number

Create Methods

Static origin

  • Returns the point at [0,0].

    Equivalent to new Point(0,0).

    Returns Point

Other Methods

add

  • Adds x & y coordinates of another point or vector and returns the resulting point.

    Parameters

    Returns Point

  • Adds an x & y value to the point and returns the resulting point.

    Parameters

    • x: number

      Value to add to the x coordinate.

    • y: number

      Value to add to the y coordinate.

    Returns Point

distanceTo

  • distanceTo(point: Point): number
  • Returns the distance to another point.

    Parameters

    • point: Point

      Point to measure the distance to.

    Returns number

divide

  • divide(denominator: number): Point
  • divide(denominatorX: number, denominatorY: number): Point
  • Divides the x & y coordinates by a value and returns the resulting point.

    Parameters

    • denominator: number

      Amount to divide the coordinates by.

    Returns Point

  • Divides the x & y coordinates by different amounts in the x- and y-direction. Returns the resulting point.

    Parameters

    • denominatorX: number

      Amount to divide the x coordinate by.

    • denominatorY: number

      Amount to divide the y coordinate by.

    Returns Point

equals

  • equals(comparison: Point, tolerance?: number): boolean
  • Checks whether another point has the same x and y values. Returns true if it does.

    Parameters

    • comparison: Point

      Point to compare against.

    • Default value tolerance: number = shapetypesSettings.absoluteTolerance

      The amount that the x and y values of the points can differ and still be considered equal.

    Returns boolean

multiply

  • multiply(factor: number): Point
  • multiply(factorX: number, factorY: number): Point
  • Multiplies the x & y coordinates by a value and returns the resulting point.

    Parameters

    • factor: number

      Amount to multiply by.

    Returns Point

  • Multiplies the x & y coordinates by different amounts in the x- and y-direction. Returns the resulting point.

    Parameters

    • factorX: number

      Amount to multiply the x coordinate by.

    • factorY: number

      Amount to multiply the y coordinate by.

    Returns Point

subtract

  • Subtracts the x & y coordinates of another point or vector and returns the resulting point.

    Parameters

    • subtrahend: Point | Vector

      Point or vector to subtract from the point.

    Returns Point

  • Subtracts an x & y value from the point and returns the resulting point.

    Parameters

    • x: number

      Value to subtract from the x coordinate.

    • y: number

      Value to subtract from the y coordinate.

    Returns Point

toString

  • toString(): string
  • Gets the point as a string in the format: (x,y).

    Returns string

withX

  • withX(newX: number): Point
  • Creates a copy of the point with a different x coordinate.

    Parameters

    • newX: number

      New x coordinate.

    Returns Point

withY

  • withY(newY: number): Point
  • Creates a copy of the point with a different y coordinate.

    Parameters

    • newY: number

      New y coordinate.

    Returns Point

Transform Methods

changeBasis

  • changeBasis(planeFrom: Plane, planeTo: Plane): this
  • 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.

    see

    Transform.changeBasis.

    Parameters

    • planeFrom: Plane

      The coordinate system the geometry is currently described relative to.

    • planeTo: Plane

      The coordinate system to describe the geometry relative to.

    Returns this

    The geometry in the new coordinate system.

planeToPlane

  • planeToPlane(planeFrom: Plane, planeTo: Plane): this

rotate

  • rotate(angle: number): this
  • rotate(angle: number, pivot: Point): this
  • Rotates the geometry about (0,0).

    see

    Transform.rotate.

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). The direction is counter-clockwise.

    Returns this

  • Rotates the geometry about a point.

    see

    Transform.rotate.

    category

    Transform

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.

    • pivot: Point

      Point to pivot the geometry about.

    Returns this

scale

  • scale(amount: number): this
  • scale(x: number, y: number): this
  • scale(x: number, y: number, center: Point): this
  • 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.

    see

    Transform.scale.

    Parameters

    • amount: number

      Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • 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.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • Scales the geometry about a point and returns the resized geometry.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • center: Point

      Center of scaling. Everything will shrink or expand away from this point.

    Returns this

transform

  • Transforms the point by a transform matrix and returns the resulting point.

    Example

    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)
    note

    If you're applying the same transformation a lot of geometry, creating the Transform matrix once and calling this function is faster than using the direct methods.

    Parameters

    Returns this

translate

  • translate(move: Vector): this
  • translate(move: Vector, distance: number | undefined): this
  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    Parameters

    • move: Vector

      The direction and distance to move the geometry.

    Returns this

  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    category

    Transform

    Parameters

    • move: Vector

      The direction to move the geometry.

    • distance: number | undefined

      The distance to move the geometry.

    Returns this

Generated using TypeDoc