Search API
  • Preparing search index...
  • The search index is not available

Class Point

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.

Constructor Summary Details

Name Description
Point(x, y)

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

Parameters:
{number=} x
The x value.
{number=} y
The y value.

Properties Summary Details

Name, Value Type Description
x
{number}

Gets or sets the x value of the Point.

y
{number}

Gets or sets the y value of the Point.

Method Summary Details

Name, Return Type Description
add(p)
{Point}

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

See also:
Parameters:
{Point} p
The Point to add to this Point.
Returns:
{Point} this.
copy()
{Point}

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

Returns:
{Point}
direction(px, py)
{number}

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

See also:
Parameters:
{number} px
{number} py
Returns:
{number} the angle, in degrees, of the line from this Point to the given point.
<static>
Point.direction(px, py, qx, qy)
{number}

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

Parameters:
{number} px
{number} py
{number} qx
{number} qy
Returns:
{number}
directionPoint(p)
{number}

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

See also:
Parameters:
{Point} p
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.
<static>
Point.distanceLineSegmentSquared(px, py, ax, ay, bx, by)
{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.More...

Parameters:
{number} px
{number} py
{number} ax
{number} ay
{number} bx
{number} by
Returns:
{number} the euclidean distance.
distanceSquared(px, py)
{number}

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

Parameters:
{number} px
{number} py
Returns:
{number} the square of the euclidean distance.
<static>
Point.distanceSquared(px, py, qx, qy)
{number}

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

Parameters:
{number} px
{number} py
{number} qx
{number} qy
Returns:
{number}
distanceSquaredPoint(p)
{number}

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

See also:
Parameters:
{Point} p
the other Point to measure to.
Returns:
{number} the square of the euclidean distance.
equals(p)
{boolean}

Indicates whether the given Point is equal to this Point.More...

See also:
Parameters:
{Point} p
The Point to compare to the current Point.
Returns:
{boolean} True if the two Points have identical X and Y values, false otherwise.
equalTo(x, y)
{boolean}

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

See also:
Parameters:
{number} x
{number} y
Returns:
{boolean} True if the two Points have identical X and Y values, false otherwise.
isReal()
{boolean}

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

Returns:
{boolean}
normalize()
{Point}

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

Returns:
{Point} this.
offset(dx, dy)
{Point}

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

See also:
Parameters:
{number} dx
{number} dy
Returns:
{Point} this.
<static>
Point.parse(str)
{Point}

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

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

Parameters:
{string} str
Returns:
{Point}
projectOntoLineSegment(px, py, qx, qy)
{Point} 1.3

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

Parameters:
{number} px
one end of the finite line segment
{number} py
one end of the finite line segment
{number} qx
the other end of the finite line segment
{number} qy
the other end of the finite line segment
Returns:
{Point} this modified Point
projectOntoLineSegmentPoint(p, q)
{Point} 1.3

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

Parameters:
{Point} p
one end of the finite line segment
{Point} q
the other end of the finite line segment
Returns:
{Point} this modified Point
rotate(angle)
{Point}

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

Parameters:
{number} angle
an angle in degrees.
Returns:
{Point} this.
scale(sx, sy)
{Point}

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

Parameters:
{number} sx
{number} sy
Returns:
{Point} this.
set(p)
{Point}

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

Parameters:
{Point} p
the given Point.
Returns:
{Point} this.
setRectSpot(r, spot)
{Point}

Modify this Point so that its X and Y values correspond to a particular Spot in a given Rect.More...

The result is meaningless if Spot.isNoSpot is true for the given Spot.

See also:
Parameters:
{Rect} r
the Rect for which we are finding the point.
{Spot} spot
the Spot; Spot.isSpot must be true for this Spot.
Returns:
{Point} this.
setSpot(x, y, w, h, spot)
{Point}

Modify this Point so that its X and Y values correspond to a particular Spot in a given rectangle.More...

The result is meaningless if Spot.isNoSpot is true for the given Spot.

See also:
Parameters:
{number} x
The X coordinate of the Rect for which we are finding the point.
{number} y
The Y coordinate of the Rect for which we are finding the point.
{number} w
The Width of the Rect for which we are finding the point.
{number} h
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.
setTo(x, y)
{Point}

Modify this Point with new X and Y values.More...

Parameters:
{number} x
{number} y
Returns:
{Point} this.
snapToGrid(originx, originy, cellwidth, cellheight)
{Point} 1.3

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

Parameters:
{number} originx
the top-left point of one of the grid cells
{number} originy
the top-left point of one of the grid cells
{number} cellwidth
the size of each grid cell -- must be a real number larger than zero
{number} cellheight
the size of each grid cell -- must be a real number larger than zero
Returns:
{Point} this modified Point
snapToGridPoint(origin, cellsize)
{Point} 1.3

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

Parameters:
{Point} origin
the top-left point of one of the grid cells
{Size} cellsize
the size of each grid cell
Returns:
{Point} this modified Point
<static>
Point.stringify(val)
{string}

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

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

Parameters:
{Point} val
Returns:
{string}
subtract(p)
{Point}

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

See also:
Parameters:
{Point} p
The Point to subtract from the current Point.
Returns:
{Point} this.