Class Point

A Point represents an x- and y-coordinate pair in two-dimensional space.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): Point

The default constructor produces the Point(0,0).

Returns

Point

constructor(x: number, y: number): Point

The two-argument constructor produces the Point(x, y).

Parameters

  • x: number
  • y: number

Returns

Point

Properties

public x: number

Gets or sets the x value of the Point.

public y: number

Gets or sets the y value of the Point.

Methods

public add(p: Point): Point

Modify this point so that is the sum of the current Point and the x and y co-ordinates of the given Point.

Parameters

  • p: Point

    The Point to add to this Point.

Returns

Point

public copy(): Point

Create a copy of this Point, with the same values.

Returns

Point

public static direction(px: number, py: number, qx: number, qy: number): number

This static method returns the angle in degrees of the line from point P to point Q.

Parameters

  • px: number
  • py: number
  • qx: number
  • qy: number

Returns

number

public direction(px: number, py: number): number

Compute the angle from this Point to a given (px,py) point. However, if the point is the same as this Point, the direction is zero.

Parameters

  • px: number
  • py: number

Returns

number

public directionPoint(p: Point): number

Compute the angle from this Point to a given Point. However, if the given Point is the same as this Point, the direction is zero.

Parameters

  • p: Point

    the other Point to which to measure the relative angle.

Returns

number

public static distanceLineSegmentSquared(px: number, py: number, ax: number, ay: number, bx: number, by: number): number

This static method returns the square of the distance from the point P to the finite line segment from point A to point B.

Parameters

  • px: number
  • py: number
  • ax: number
  • ay: number
  • bx: number
  • by: number

Returns

number

public distanceSquared(px: number, py: number): number

Returns the square of the distance from this point to a given point (px, py).

Parameters

  • px: number
  • py: number

Returns

number

public static distanceSquared(px: number, py: number, qx: number, qy: number): number

This static method returns the square of the distance from the point P to the point Q.

Parameters

  • px: number
  • py: number
  • qx: number
  • qy: number

Returns

number

public distanceSquaredPoint(p: Point): number

Returns the square of the distance from this Point to a given Point.

Parameters

  • p: Point

    the other Point to measure to.

Returns

number

public equalTo(x: number, y: number): boolean

Indicates whether the given point (x, y) is equal to this Point.

Parameters

  • x: number
  • y: number

    false otherwise.

Returns

boolean

public equals(p: Point): boolean

Indicates whether the given Point is equal to this Point.

Parameters

  • p: Point

    The Point to compare to the current Point. false otherwise.

Returns

boolean

public isReal(): boolean

True if this Point has X and Y values that are real numbers and not infinity.

Returns

boolean

public normalize(): Point

Modify this Point so that its X and Y values have been normalized to a unit length. However, if this Point is the origin (zero, zero), its length remains zero.

Returns

Point

public offset(dx: number, dy: number): Point

Modify this point by shifting its values with the given DX and DY offsets.

Parameters

  • dx: number
  • dy: number

Returns

Point

public static parse(str: string): Point

This static method can be used to read in a Point from a string that was produced by Point.stringify.

Parameters

  • str: string

Returns

Point

public rotate(angle: number): Point

Modify this Point so that has been rotated about the origin by the given angle.

Parameters

  • angle: number

    an angle in degrees.

Returns

Point

public scale(sx: number, sy: number): Point

Modify this Point so that its X and Y values have been scaled by given factors along the X and Y axes.

Parameters

  • sx: number
  • sy: number

Returns

Point

public set(p: Point): Point

Modify this Point so that its X and Y values are the same as the given Point.

Parameters

  • p: Point

    the given Point.

Returns

Point

public setRectSpot(r: Rect, spot: Spot): Point

Modify this Point so that its X and Y values correspond to a particular Spot in a given Rect. The result is meaningless if Spot#isNoSpot is true for the given Spot.

Parameters

  • r: Rect

    the Rect for which we are finding the point.

  • spot: Spot

    the Spot; Spot#isSpot must be true for this Spot.

Returns

Point

public setSpot(x: number, y: number, w: number, h: number, spot: Spot): Point

Modify this Point so that its X and Y values correspond to a particular Spot in a given rectangle. The result is meaningless if Spot#isNoSpot is true for the given Spot.

Parameters

  • x: number

    The X coordinate of the Rect for which we are finding the point.

  • y: number

    The Y coordinate of the Rect for which we are finding the point.

  • w: number

    The Width of the Rect for which we are finding the point.

  • h: number

    The Height of the Rect for which we are finding the point.

  • spot: Spot

    the Spot; Spot#isSpot must be true for this Spot.

Returns

Point

public setTo(x: number, y: number): Point

Modify this Point with new X and Y values.

Parameters

  • x: number
  • y: number

Returns

Point

public static stringify(val: Point): string

This static method can be used to write out a Point as a string that can be read by Point.parse.

Parameters

Returns

string

public subtract(p: Point): Point

Modify this point so that is the difference of this Point and the x and y co-ordinates of the given Point.

Parameters

  • p: Point

    The Point to subtract from the current Point.

Returns

Point