Class Pnt2d.PntInt

java.lang.Object
imagingbook.common.geometry.basic.Pnt2d.PntInt
All Implemented Interfaces:
Pnt2d, Primitive2d, ShapeProducer
Direct Known Subclasses:
LocalMinMaxFinder.ExtremalPoint, PixelMap.Pixel
Enclosing interface:
Pnt2d

public static class Pnt2d.PntInt extends Object implements Pnt2d
Immutable 2D point implementation with int 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(int, int), from(int[]), etc. The int coordinates can only be retrieved via the publicly accessible field variables x, y, while the methods getX() and getY() return double values for compatibility reasons.
  • Field Details

    • ZERO

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

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

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

    • PntInt

      protected PntInt(int x, int 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.PntInt from(Pnt2d.PntInt p)
      Returns a new Pnt2d.PntInt instance from a given point.
      Parameters:
      p - the original point
      Returns:
      the new point
    • from

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

      public static Pnt2d.PntInt from(int[] xy)
      Returns a new Pnt2d.PntInt instance.
      Parameters:
      xy - x/y-coordinates
      Returns:
      the new point
    • from

      public static Pnt2d.PntInt from(Pnt2d p)
      Returns a new Pnt2d.PntInt from a given Pnt2d instance. This only works if the argument is of type Pnt2d.PntInt, otherwise an exception is thrown.
      Parameters:
      p - a point of type Pnt2d.PntInt
      Returns:
      the new point
    • from

      public static Pnt2d.PntInt from(Point p)
      Returns a new Pnt2d.PntDouble instance with the same coordinates as the given AWT Point.
      Parameters:
      p - the original AWT point
      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.PntInt plus(int dx, int dy)
    • plus

    • plus

      public Pnt2d.PntInt plus(int[] dxy)
    • plus

      public Pnt2d plus(Pnt2d p)
      Description copied from interface: Pnt2d
      Returns a new point whose coordinates are the sum of this point and the given point. The concrete type of the returned object depends on the type of the original points.
      Specified by:
      plus in interface Pnt2d
      Parameters:
      p - the point to be added
      Returns:
      a new point
    • minus

    • minus

      public Pnt2d.PntInt minus(int dx, int dy)
    • minus

      public Pnt2d minus(Pnt2d p)
      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
    • distL1

      public int distL1(Pnt2d.PntInt p)
      Returns the L1 (Manhattan) distance between this point and the given point.
      Parameters:
      p - the other point
      Returns:
      the distance
    • distanceSq

      public int distanceSq(Pnt2d.PntInt other)
      Returns the squared L2 distance between this point and the given point.
      Parameters:
      other - the other point
      Returns:
      the squared distance
    • equals

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

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

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

      public int[] toIntArray()
      Returns this point's coordinates as a new 2-element int array.
      Returns:
      the array
    • toAwtPoint

      public Point toAwtPoint()
      Returns this point's coordinates as a new AWT Point point.
      Returns:
      the new point