# Class Point

GoJS® Diagramming Components
version 3.0.7
by Northwoods Software®

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

Use the static functions Point.parse and Point.stringify to convert to and from a standard string representation that is independent of the current locale.

When an instance of this class is the value of a property of a GraphObject class or Diagram or CommandHandler or a Tool class, you should treat the object as if it were frozen or read-only -- you cannot modify its properties. This allows the property to return a value without allocating a new instance. If you need to do your own calculations with the value, call copy to make a new instance with the same values that you can modify.

Many methods modify the object's properties and then return a reference to "this" object. The only instance method to allocate a new object is the copy method. The static Point.parse method also allocates a new object.

The "Debug" implementation of this class is significantly slower than the "Release" implementation, mostly due to additional error checking.

You cannot inherit from this class.

#####
Index

### Constructors

constructor

### Accessors

x
y

### Methods

add
compareWithLineSegmentPoint
copy
direction
directionPoint
distanceSquared
distanceSquaredPoint
equalTo
equals
isReal
normalize
offset
projectOntoLineSegment
projectOntoLineSegmentPoint
rotate
scale
set
setRectSpot
setSpot
setTo
snapToGrid
snapToGridPoint
subtract
compareWithLineSegment
direction
distanceLineSegmentSquared
distanceSquared
intersectingLineSegments
parse
stringify
stringifyFixed

## Constructors

### constructor

- new Point(x?: number, y?: number): Point

- The default constructor produces the Point(0,0). This constructor may take either zero arguments or two arguments.

  #### Parameters

  - ##### `Optional` x: number

    The x value.

  - ##### `Optional` y: number

    The y value.

  #### Returns Point

## Accessors

### x
: number

- Gets or sets the x value of the Point.

### y
: number

- Gets or sets the y value of the Point.

## Methods

### add

- 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

  this.

  `see`
  - offset
  - subtract

### compareWithLineSegmentPoint

- compareWithLineSegmentPoint(p: Point, q: Point): number

- Compare this point with a finite line segment given by two Points.

  This method compares this point with a finite line segment determined by the given two Points. If the point is on the finite line segment, this returns zero. If the point is on the left side of the segment, this returns a positive number. If the point is on the right side of the segment, this returns a negative number. If the point is on the infinitely extended line but not within the segment, then this returns a positive number if the point is beyond the end of the segment when going from A1 to A2, or this returns a negative number if the point comes before the segment's start at A1.

  #### Parameters

  - ##### p: Point

    the start of the finite line segment

  - ##### q: Point

    the end of the finite line segment

  #### Returns number

  <0 if this Point is on the right side of the line segment, or >0 if this Point is on the left side, or zero if exactly on the finite line segment

  `since`

  2.2

### `Virtual` copy

- copy(): Point

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

  #### Returns Point

### direction

- 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

  the angle, in degrees, of the line from this Point to the given point.

  `see`

  directionPoint

### directionPoint

- 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

  the angle, in degrees, of the line from this Point to the given point.

  `see`

  direction

### distanceSquared

- 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

  the square of the euclidean distance.

  `see`

  distanceSquaredPoint

### distanceSquaredPoint

- 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

  the square of the euclidean distance.

  `see`

  distanceSquared

### equalTo

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

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

  #### Parameters

  - ##### x: number

  - ##### y: number

  #### Returns boolean

  True if the two Points have identical X and Y values, false otherwise.

  `see`

  equals

### equals

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

  #### Returns boolean

  True if the two Points have identical X and Y values, false otherwise.

  `see`

  equalTo

### isReal

- isReal(): boolean

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

  #### Returns boolean

### normalize

- 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

  this.

### offset

- 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

  this.

  `see`
  - add
  - subtract

### projectOntoLineSegment

- projectOntoLineSegment(px: number, py: number, qx: number, qy: number): Point

- Modify this point to be the closest point to this point that is on a finite line segment.

  #### Parameters

  - ##### px: number

    one end of the finite line segment

  - ##### py: number

    one end of the finite line segment

  - ##### qx: number

    the other end of the finite line segment

  - ##### qy: number

    the other end of the finite line segment

  #### Returns Point

  this modified Point

### projectOntoLineSegmentPoint

- projectOntoLineSegmentPoint(p: Point, q: Point): Point

- Modify this point to be the closest point to this point that is on a finite line segment.

  #### Parameters

  - ##### p: Point

    one end of the finite line segment

  - ##### q: Point

    the other end of the finite line segment

  #### Returns Point

  this modified Point

### rotate

- 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

  this.

### scale

- 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

  this.

### set

- 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

  this.

### setRectSpot

- 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

  this.

  `see`

  setSpot

### setSpot

- 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

  this the point of the spot in the rectangle.

  `see`

  setRectSpot

### setTo

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

- Modify this Point with new X and Y values.

  #### Parameters

  - ##### x: number

  - ##### y: number

  #### Returns Point

  this.

### snapToGrid

- snapToGrid(originx: number, originy: number, cellwidth: number, cellheight: number): Point

- Modify this point to be at the nearest point on an infinite grid, given the grid's origin and size of each grid cell.

  #### Parameters

  - ##### originx: number

    the top-left point of one of the grid cells

  - ##### originy: number

    the top-left point of one of the grid cells

  - ##### cellwidth: number

    the size of each grid cell -- must be a real number larger than zero

  - ##### cellheight: number

    the size of each grid cell -- must be a real number larger than zero

  #### Returns Point

  this modified Point

### snapToGridPoint

- snapToGridPoint(origin: Point, cellsize: Size): Point

- Modify this point to be at the nearest point on an infinite grid, given the grid's origin and size of each grid cell.

  #### Parameters

  - ##### origin: Point

    the top-left point of one of the grid cells

  - ##### cellsize: Size

    the size of each grid cell

  #### Returns Point

  this modified Point

### subtract

- 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

  this.

  `see`
  - offset
  - add

### `Static` compareWithLineSegment

- compareWithLineSegment(a1x: number, a1y: number, a2x: number, a2y: number, px: number, py: number): number

- This static function compares a point with a finite line segment.

  If the point is on the finite line segment, this returns zero. If the point is on the left side of the segment, this returns a positive number. If the point is on the right side of the segment, this returns a negative number. If the point is on the infinitely extended line but not within the segment, then this returns a positive number if the point is beyond the end of the segment when going from A1 to A2, or this returns a negative number if the point comes before the segment's start at A1.

  #### Parameters

  - ##### a1x: number

  - ##### a1y: number

  - ##### a2x: number

  - ##### a2y: number

  - ##### px: number

  - ##### py: number

  #### Returns number

  <0 if on the right side, or >0 if on the left side, or zero if exactly on the finite line segment

  `since`

  2.2

### `Static` direction

- direction(px: number, py: number, qx: number, qy: number): number

- This static function 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

### `Static` distanceLineSegmentSquared

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

- This static function 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

  the euclidean distance.

### `Static` distanceSquared

- distanceSquared(px: number, py: number, qx: number, qy: number): number

- This static function 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

### `Static` intersectingLineSegments

- intersectingLineSegments(a1x: number, a1y: number, a2x: number, a2y: number, b1x: number, b1y: number, b2x: number, b2y: number): boolean

- This static function is true if two finite straight line segments intersect each other.

  #### Parameters

  - ##### a1x: number

  - ##### a1y: number

  - ##### a2x: number

  - ##### a2y: number

  - ##### b1x: number

  - ##### b1y: number

  - ##### b2x: number

  - ##### b2y: number

  #### Returns boolean

  True if the two given finite line segments intersect with each other, false otherwise.

  `since`

  2.2

### `Static` parse

- parse(str: string): Point

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

  `go.Point.parse("1 2")` produces the Point `new go.Point(1, 2)`.

  #### Parameters

  - ##### str: string

  #### Returns Point

### `Static` stringify

- stringify(val: Point): string

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

  `go.Point.stringify(new go.Point(1, 2))` produces the string "1 2".

  #### Parameters

  - ##### val: Point

  #### Returns string

### `Static` stringifyFixed

- stringifyFixed(digits: number): ((val: Point) => string)

- This static function returns a function that can be used as a back converter for a Binding to write out a Point's values as numbers with a fixed number of digits after the decimal point.

  This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.

  Example:

        new go.Binding("location", "loc", go.Point.parse, go.Point.stringifyFixed(2))

  #### Parameters

  - ##### digits: number

    must be a non-negative integer

  #### Returns ((val: Point) => string)

  a function that converts a Point to a string without so many decimals

  - - (val: Point): string

    - This static function returns a function that can be used as a back converter for a Binding to write out a Point's values as numbers with a fixed number of digits after the decimal point.

      This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.

      Example:

            new go.Binding("location", "loc", go.Point.parse, go.Point.stringifyFixed(2))

      #### Parameters

      - ##### val: Point

      #### Returns string

      a function that converts a Point to a string without so many decimals

      `since`

      3.0

  `since`

  3.0

Copyright © 1998-2024 by Northwoods Software Corporation.