Class Point

Direct Known Subclasses:
CranePosition

public class Point extends AbstractGeometricPrimitive
Class representing a point in 2D space. The point has x and y coordinates of type double. The point is a basic structural element of Segment and Polyline classes.

NaNs and infinite coordinates are allowed and there are no checks that prevent from creating points with such coordinates. But these coordinates are not supported in most methods which can cause errors. Thus, in documentation to majority of methods, the special cases with NaNs and infinite coordinates are not described

Author:
Andrey Malykhanov
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double
     
    protected double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new point with (0, 0) coordinates.
    Point(double x, double y)
    Creates a new point with the specified coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether this primitive contains the specified point
    double
    Returns the distance from this point to the specified point.
    boolean
    equals(Point point)
    Checks whether the other given point is equal to this point, i.e.
    boolean
    equals(Point point, EpsilonComparator comparator)
    Checks whether the other given point is equal to this point, i.e.
    boolean
     
    Returns a copy of this point, i.e.
    double
    Returns the x-coordinate (abscissa) of the point
    double
    Returns the y-coordinate (ordinate) of the point
    int
     
    double
    Returns the heading from this point towards the specified point, in radians.
    minus(Point point)
    Returns a new instance of point which is a result of coordinate-wise subtraction of this point and the specified point.
    multiply(double factor)
    Returns a new instance of point which is a result of coordinate-wise multiplication of this point by the specified factor
    plus(Point point)
    Returns a new instance of point which is a coordinate-wise sum of this point and the specified point.
    rotate(double angle)
    Returns a new instance of point which is the result of rotation of this point around the (0, 0) point by the specified angle in radians.
    rotateAround(double angle, Point rotationCenter)
    Returns a new instance of point which is the result of rotation of this point around the specified point (rotation center) by the specified angle in radians.
    double
    Returns the squared distance from this point to the specified point.
    Returns the string representing Java code that creates this primitive in its current state
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      protected double x
    • y

      protected double y
  • Constructor Details

    • Point

      public Point()
      Creates a new point with (0, 0) coordinates.
    • Point

      public Point(double x, double y)
      Creates a new point with the specified coordinates.
      Parameters:
      x - x-coordinate of the point
      y - y-coordinate of the point
  • Method Details

    • getX

      public double getX()
      Returns the x-coordinate (abscissa) of the point
      Returns:
      x-coordinate of the point
    • getY

      public double getY()
      Returns the y-coordinate (ordinate) of the point
      Returns:
      y-coordinate of the point
    • distanceTo

      public double distanceTo(Point p)
      Returns the distance from this point to the specified point. The returned value cannot be negative. Note that Math.sqrt(double) function is used inside this function, which can cause performance issues when used inside "hot" code parts, so consider using squaredDistanceTo(Point) when possible.

      Distance between finite point and infinite point is Double.POSITIVE_INFINITY

      Parameters:
      p - the specified point
      Returns:
      distance from this point to the specified point
    • squaredDistanceTo

      public double squaredDistanceTo(Point p)
      Returns the squared distance from this point to the specified point. The returned value cannot be negative.

      Squared distance between finite point and infinite point is Double.POSITIVE_INFINITY

      Parameters:
      p - the specified point
      Returns:
      distance from this point to the specified point
    • headingTo

      public double headingTo(Point p)
      Returns the heading from this point towards the specified point, in radians. The heading is calculated as angle between the base vector pointing downwards (in screen coordinate system) and the direction between the current point and the specified point. Counter-clockwise direction from the base vector is considered positive heading, clockwise - negative heading. The heading always lies in range (-PI, PI]. If points are equal, returns 0.

      Parameters:
      p - the specified point
      Returns:
      heading from this point towards the specified point, in radians. The value is always in range (-PI, PI] Creates a new point with (0, 0) coordinates.
    • plus

      public Point plus(Point point)
      Returns a new instance of point which is a coordinate-wise sum of this point and the specified point.
      Parameters:
      point - the specified point
      Returns:
      sum of this point and the specified point
    • minus

      public Point minus(Point point)
      Returns a new instance of point which is a result of coordinate-wise subtraction of this point and the specified point.
      Parameters:
      point - the specified point
      Returns:
      coordinate-wise difference of this point and the specified point
    • rotate

      public Point rotate(double angle)
      Returns a new instance of point which is the result of rotation of this point around the (0, 0) point by the specified angle in radians.

      In screen coordinate system, if the angle is positive, the rotation is directed clockwise. If the angle is negative, the rotation is directed counter-clockwise

      Parameters:
      angle - specified angle in radians
      Returns:
      result of rotation
    • multiply

      public Point multiply(double factor)
      Returns a new instance of point which is a result of coordinate-wise multiplication of this point by the specified factor
      Parameters:
      factor - specified factor
      Returns:
      result of coordinate-wise multiplication of this point by the specified factor
    • rotateAround

      public Point rotateAround(double angle, Point rotationCenter)
      Returns a new instance of point which is the result of rotation of this point around the specified point (rotation center) by the specified angle in radians. In screen coordinate system, if the angle is positive, the rotation is directed clockwise. If the angle is negative, the rotation is directed counter-clockwise

      Parameters:
      angle - specified angle in radians
      rotationCenter - specified rotation center
      Returns:
      result of rotation
    • containsPoint

      public boolean containsPoint(Point point)
      Description copied from class: AbstractGeometricPrimitive
      Checks whether this primitive contains the specified point
      Specified by:
      containsPoint in class AbstractGeometricPrimitive
      Parameters:
      point - the specified point
      Returns:
      true if this primitive contains the specified point, false otherwise
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(Point point)
      Checks whether the other given point is equal to this point, i.e. if both x and y points coordinates the other point equal correspondingly to x and y coordinates of this point.

      The equality of the coordinates is determined with respect to the default epsilon, that can be obtained by Compare.getEpsilon().

      Parameters:
      point - other given point
      Returns:
      true if the other given point is equal to this point, false otherwise
    • equals

      public boolean equals(Point point, EpsilonComparator comparator)
      Checks whether the other given point is equal to this point, i.e. if both x and y points coordinates the other point equal correspondingly to x and y coordinates of this point.

      The equality of the coordinates is determined with respect to the specified epsilon.

      Parameters:
      point - other given point
      comparator - specified comparator to compare length and distances
      Returns:
      true if the other given point is equal to this point, false otherwise
    • getCopy

      public Point getCopy()
      Returns a copy of this point, i.e. the point with the same coordinates
      Returns:
      copy of this point
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toCodeString

      public String toCodeString()
      Description copied from class: AbstractGeometricPrimitive
      Returns the string representing Java code that creates this primitive in its current state
      Specified by:
      toCodeString in class AbstractGeometricPrimitive
      Returns:
      Java code required to create this primitive in its current state