Point class

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.

Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

Point.new([num? x, num? y])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
x num

Available on Point, provided by the Point$Typings extension

Gets or sets the x value of the Point.
getter/setter pair
y num

Available on Point, provided by the Point$Typings extension

Gets or sets the y value of the Point.
getter/setter pair

Methods

add(Point p) Point

Available on Point, provided by the Point$Typings extension

Modify this point so that is the sum of the current Point and the x and y co-ordinates of the given Point. @param {Point} p The Point to add to this Point. @return {Point} this. @see #offset @see #subtract
compareWithLineSegmentPoint(Point p, Point q) num

Available on Point, provided by the Point$Typings extension

Compare this point with a finite line segment given by two Points.
copy() Point

Available on Point, provided by the Point$Typings extension

Create a copy of this Point, with the same values. @expose @return {Point}
direction(num px, num py) num

Available on Point, provided by the Point$Typings extension

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. @param {number} px @param {number} py @return {number} the angle, in degrees, of the line from this Point to the given point. @see #directionPoint
directionPoint(Point p) num

Available on Point, provided by the Point$Typings extension

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. @param {Point} p the other Point to which to measure the relative angle. @return {number} the angle, in degrees, of the line from this Point to the given point. @see #direction
distanceSquared(num px, num py) num

Available on Point, provided by the Point$Typings extension

Returns the square of the distance from this point to a given point (px, py). @param {number} px @param {number} py @return {number} the square of the euclidean distance. @see #distanceSquaredPoint
distanceSquaredPoint(Point p) num

Available on Point, provided by the Point$Typings extension

Returns the square of the distance from this Point to a given Point. @param {Point} p the other Point to measure to. @return {number} the square of the euclidean distance. @see #distanceSquared
equals(Point p) bool

Available on Point, provided by the Point$Typings extension

Indicates whether the given Point is equal to this Point. @param {Point} p The Point to compare to the current Point. @return {boolean} True if the two Points have identical X and Y values, false otherwise. @see #equalTo
equalsApprox(Point p) bool

Available on Point, provided by the Point$Typings extension

(undocumented) True when the given Point is nearly equal to this Point. @param {Point} p The Point to compare to the current Point. @return {boolean} True if the two Points have X and Y values that are equal with a tolerance of 0.5, false otherwise.
equalTo(num x, num y) bool

Available on Point, provided by the Point$Typings extension

Indicates whether the given point (x, y) is equal to this Point. @param {number} x @param {number} y @return {boolean} True if the two Points have identical X and Y values, false otherwise. @see #equals
isReal() bool

Available on Point, provided by the Point$Typings extension

True if this Point has X and Y values that are real numbers and not infinity. @return {boolean}
normalize() Point

Available on Point, provided by the Point$Typings extension

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. @return {Point} this.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(num dx, num dy) Point

Available on Point, provided by the Point$Typings extension

Modify this point by shifting its values with the given DX and DY offsets. @param {number} dx @param {number} dy @return {Point} this. @see #add @see #subtract
projectOntoLineSegment(num px, num py, num qx, num qy) Point

Available on Point, provided by the Point$Typings extension

Modify this point to be the closest point to this point that is on a finite line segment. @param {number} px one end of the finite line segment @param {number} py one end of the finite line segment @param {number} qx the other end of the finite line segment @param {number} qy the other end of the finite line segment @return {Point} this modified Point @since 1.3
projectOntoLineSegmentPoint(Point p, Point q) Point

Available on Point, provided by the Point$Typings extension

Modify this point to be the closest point to this point that is on a finite line segment. @param {Point} p one end of the finite line segment @param {Point} q the other end of the finite line segment @return {Point} this modified Point @since 1.3
rotate(num angle) Point

Available on Point, provided by the Point$Typings extension

Modify this Point so that has been rotated about the origin by the given angle. @param {number} angle an angle in degrees. @return {Point} this.
scale(num sx, num sy) Point

Available on Point, provided by the Point$Typings extension

Modify this Point so that its X and Y values have been scaled by given factors along the X and Y axes. @param {number} sx @param {number} sy @return {Point} this.
set(Point p) Point

Available on Point, provided by the Point$Typings extension

Modify this Point so that its X and Y values are the same as the given Point. @param {Point} p the given Point. @return {Point} this.
setRectSpot(Rect r, Spot spot) Point

Available on Point, provided by the Point$Typings extension

Modify this Point so that its X and Y values correspond to a particular Spot in a given Rect.
setSpot(num x, num y, num w, num h, Spot spot) Point

Available on Point, provided by the Point$Typings extension

Modify this Point so that its X and Y values correspond to a particular Spot in a given rectangle.
setTo(num x, num y) Point

Available on Point, provided by the Point$Typings extension

Modify this Point with new X and Y values. @param {number} x @param {number} y @return {Point} this.
snapToGrid(num originx, num originy, num cellwidth, num cellheight) Point

Available on Point, provided by the Point$Typings extension

Modify this point to be at the nearest point on an infinite grid, given the grid's origin and size of each grid cell. @param {number} originx the top-left point of one of the grid cells @param {number} originy the top-left point of one of the grid cells @param {number} cellwidth the size of each grid cell -- must be a real number larger than zero @param {number} cellheight the size of each grid cell -- must be a real number larger than zero @return {Point} this modified Point @since 1.3
snapToGridPoint(Point origin, Size cellsize) Point

Available on Point, provided by the Point$Typings extension

Modify this point to be at the nearest point on an infinite grid, given the grid's origin and size of each grid cell. @param {Point} origin the top-left point of one of the grid cells @param {Size} cellsize the size of each grid cell @return {Point} this modified Point @since 1.3
subtract(Point p) Point

Available on Point, provided by the Point$Typings extension

Modify this point so that is the difference of this Point and the x and y co-ordinates of the given Point. @param {Point} p The Point to subtract from the current Point. @return {Point} this. @see #offset @see #add
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

alloc() Point
allocAt(num x, num y) Point
compareWithLineSegment(num a1x, num a1y, num a2x, num a2y, num px, num py) num
This static function compares a point with a finite line segment.
direction(num px, num py, num qx, num qy) num
This static function returns the angle in degrees of the line from point P to point Q.
distanceLineSegmentSquared(num px, num py, num ax, num ay, num bx, num by) num
This static function returns the square of the distance from the point P to the finite line segment from point A to point B.
distanceSquared(num px, num py, num qx, num qy) num
This static function returns the square of the distance from the point P to the point Q.
free(Point temp) → void
intersectingLineSegments(num a1x, num a1y, num a2x, num a2y, num b1x, num b1y, num b2x, num b2y) bool
This static function is true if two finite straight line segments intersect each other.
parse(String str) Point
This static function can be used to read in a Point from a string that was produced by Point.stringify.
stringify(Point val) String
This static function can be used to write out a Point as a string that can be read by Point.parse.