Class Pnt2d.PntDouble

java.lang.Object
imagingbook.common.geometry.basic.Pnt2d.PntDouble
All Implemented Interfaces:
Pnt2d, Primitive2d, ShapeProducer
Enclosing interface:
Pnt2d

public static class Pnt2d.PntDouble extends Object implements Pnt2d
Immutable 2D point implementation with double coordinates. This class implements the Pnt2d interface. A protected constructor is provided but the preferred way of instantiation is by one of the static factory methods, such as from(double, double), from(double[]), etc. Access to the coordinate values is provided by the methods getX() and getY(), but the actual field variables x, y are also publicly accessible (for better performance and less clutter).
  • Field Details

    • ZERO

      public static final Pnt2d.PntDouble ZERO
      Singleton point instance with zero coordinates.
    • x

      public final double x
      The (immutable) x-coordinate of this point
    • y

      public final double y
      The (immutable) y-coordinate of this point
  • Constructor Details

    • PntDouble

      protected PntDouble(double x, double y)
      Constructor.
      Parameters:
      x - x-coordinate
      y - y-coordinate
  • Method Details

    • duplicate

      Description copied from interface: Pnt2d
      Returns a copy of this point which is of the same type as the original.
      Specified by:
      duplicate in interface Pnt2d
      Returns:
      a new instance.
    • from

      public static Pnt2d.PntDouble from(double[] xy)
      Returns a new Pnt2d.PntDouble instance.
      Parameters:
      xy - x/y-coordinate array
      Returns:
      the new point
    • from

      public static Pnt2d.PntDouble from(double x, double y)
      Returns a new Pnt2d.PntDouble instance.
      Parameters:
      x - x-coordinate value
      y - y-coordinate value
      Returns:
      the new point
    • from

      public static Pnt2d.PntDouble from(Pnt2d p)
      Returns a new Pnt2d.PntDouble instance with the same coordinates as the given point. Equivalent to duplicate().
      Parameters:
      p - the original point
      Returns:
      the new point
    • from

      public static Pnt2d.PntDouble from(Point2D p)
      Returns a new Pnt2d.PntDouble instance with the same coordinates as the given AWT Point2D.
      Parameters:
      p - the original AWT point
      Returns:
      the new point
    • from

      public static Pnt2d.PntDouble from(Vector2D vec)
      Returns a new Pnt2d.PntDouble instance with the same coordinates as the given Apache Commons Math Vector2D.
      Parameters:
      vec - the original coordinate vector
      Returns:
      the new point
    • getX

      public double getX()
      Description copied from interface: Pnt2d
      Returns the x-coordinate of this point.
      Specified by:
      getX in interface Pnt2d
      Returns:
      the x-coordinate value
    • getY

      public double getY()
      Description copied from interface: Pnt2d
      Returns the y-coordinate of this point.
      Specified by:
      getY in interface Pnt2d
      Returns:
      the y-coordinate value
    • getXint

      public int getXint()
      Description copied from interface: Pnt2d
      Returns the x-coordinate of this point as a (truncated) integer value.
      Specified by:
      getXint in interface Pnt2d
      Returns:
      the integer x-coordinate of this point.
    • getYint

      public int getYint()
      Description copied from interface: Pnt2d
      Returns the y-coordinate of this point as a (truncated) integer value.
      Specified by:
      getYint in interface Pnt2d
      Returns:
      the integer y-coordinate of this point.
    • plus

      public Pnt2d.PntDouble plus(double dx, double dy)
      Description copied from interface: Pnt2d
      Returns a new point whose coordinates are the sum of this point and the specified double coordinates.
      Specified by:
      plus in interface Pnt2d
      Parameters:
      dx - the x-coordinate to be added
      dy - the y-coordinate to be added
      Returns:
      a new point
    • minus

      Description copied from interface: Pnt2d
      Returns a new point whose coordinates are the difference of this point and the given point.
      Specified by:
      minus in interface Pnt2d
      Parameters:
      p - the point to be subtracted
      Returns:
      a new point
    • equals

      public boolean equals(Object p)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      The number of output digits is specified by the current settings of PrintPrecision. Use PrintPrecision.set(int) or PrintPrecision.reset() to change.
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object