Interface Pnt2d

All Superinterfaces:
Primitive2d, ShapeProducer
All Known Implementing Classes:
Corner, LocalMinMaxFinder.ExtremalPoint, PixelMap.Pixel, Pnt2d.PntDouble, Pnt2d.PntInt, SiftDescriptor

public interface Pnt2d extends ShapeProducer, Primitive2d
Interface specifying the behavior of simple 2D points. It is used to adapt to different (legacy) point implementations with a common API. To some extent this is similar to the functionality provided by Point2D and Point but was re-implemented to avoid dependency on AWT and for more flexibility in naming and class structure. Since defined as an interface, Pnt2d can be easily implemented by other point-like structures, e.g. corners (see Corner).
Two concrete (nested) classes are defined for points with double and int coordinates, respectively. See Pnt2d.PntDouble and Pnt2d.PntInt for how to instantiate such point objects.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Immutable 2D point implementation with double coordinates.
    static class 
    Immutable 2D point implementation with int coordinates.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final double
    The default tolerance for matching coordinates (1E-6).
  • Method Summary

    Modifier and Type
    Method
    Description
    default double
    cross(Pnt2d other)
    Calculates and returns the 2D pseudo cross product of this point and another point (both points are interpreted as 2D vectors).
    default double
    distance(Pnt2d other)
    Returns the L2 (Euclidean) distance between this point and the given point.
    default double
    Returns the squared L2 distance between this point and the given point.
    default double
    distL1(Pnt2d other)
    Returns the L1 (Manhattan) distance between this point and the given point.
    default double
    distL2(Pnt2d other)
    Returns the L2 (Euclidean) distance between this point and the given point.
    default double
    dot(Pnt2d other)
    Calculates and returns the dot product of this point and another point (both points are interpreted as 2D vectors)
    default Pnt2d
    Returns a copy of this point which is of the same type as the original.
    default boolean
    equals(Pnt2d p, double tolerance)
    Tests if this point matches the given point, i.e., if both coordinate differences are zero (< than the specified tolerance).
    static Pnt2d
    from(double[] xy)
    Creates and returns a new point of type Pnt2d.PntDouble with the specified coordinates.
    static Pnt2d
    from(double x, double y)
    Creates and returns a new point of type Pnt2d.PntDouble with the specified coordinates.
    static Pnt2d
    from(int[] xy)
    Creates and returns a new point of type Pnt2d.PntInt with the specified coordinates.
    static Pnt2d
    from(int x, int y)
    Creates and returns a new point of type Pnt2d.PntInt with the specified coordinates.
    static Pnt2d
     
    static Pnt2d
     
    default double
    Implementation required by Primitive2d interface.
    default Shape
    getShape(double scale)
    Returns a round dot (Shape instance) for drawing this point.
    double
    Returns the x-coordinate of this point.
    default int
    Returns the x-coordinate of this point as a (truncated) integer value.
    double
    Returns the y-coordinate of this point.
    default int
    Returns the y-coordinate of this point as a (truncated) integer value.
    default Pnt2d
    minus(double dx, double dy)
    Returns a new point whose coordinates are the difference of this point and the given point (specified as a coordinate pair).
    default Pnt2d
    Returns a new point whose coordinates are the difference of this point and the given point.
    default Pnt2d
    mult(double s)
    Returns a new point whose coordinates are multiplied by the specified scalar value.
    default Pnt2d
    Returns a point (vector) perpendicular to this point (vector).
    default Pnt2d
    plus(double dx, double dy)
    Returns a new point whose coordinates are the sum of this point and the specified double coordinates.
    default Pnt2d
    Returns a new point whose coordinates are the sum of this point and the given point.
    Returns this point's coordinates as a new AWT Point2D.Double point.
    default double[]
    Returns this point's coordinates as a new 2-element double array.
    default RealVector
    Returns this point's coordinates as a new RealVector instance (for interfacing with Apache Commons Math).
    default Vector2D
    Returns this point's coordinates as a new Vector2D instance (for interfacing with Apache Commons Math).

    Methods inherited from interface imagingbook.common.geometry.shape.ShapeProducer

    getShape, getShapes, getShapes
  • Field Details

  • Method Details

    • getX

      double getX()
      Returns the x-coordinate of this point.
      Returns:
      the x-coordinate value
    • getY

      double getY()
      Returns the y-coordinate of this point.
      Returns:
      the y-coordinate value
    • getXint

      default int getXint()
      Returns the x-coordinate of this point as a (truncated) integer value.
      Returns:
      the integer x-coordinate of this point.
    • getYint

      default int getYint()
      Returns the y-coordinate of this point as a (truncated) integer value.
      Returns:
      the integer y-coordinate of this point.
    • from

      static Pnt2d from(int x, int y)
      Creates and returns a new point of type Pnt2d.PntInt with the specified coordinates. See also Pnt2d.PntInt.from(int, int).
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the new point
    • from

      static Pnt2d from(int[] xy)
      Creates and returns a new point of type Pnt2d.PntInt with the specified coordinates. See also Pnt2d.PntInt.from(int[]).
      Parameters:
      xy - coordinates
      Returns:
      the new point
    • from

      static Pnt2d from(double x, double y)
      Creates and returns a new point of type Pnt2d.PntDouble with the specified coordinates. See also Pnt2d.PntDouble.from(double, double).
      Parameters:
      x - coordinate
      y - coordinate
      Returns:
      the new point
    • from

      static Pnt2d from(double[] xy)
      Creates and returns a new point of type Pnt2d.PntDouble with the specified coordinates. See also Pnt2d.PntDouble.from(double[]).
      Parameters:
      xy - coordinates
      Returns:
      the new point
    • from

      static Pnt2d from(Pnt2d p)
    • from

      static Pnt2d from(Point2D p)
    • toDoubleArray

      default double[] toDoubleArray()
      Returns this point's coordinates as a new 2-element double array.
      Returns:
      the array
    • toAwtPoint2D

      Returns this point's coordinates as a new AWT Point2D.Double point.
      Returns:
      the new point
    • toVector2D

      default Vector2D toVector2D()
      Returns this point's coordinates as a new Vector2D instance (for interfacing with Apache Commons Math).
      Returns:
      a new vector
    • toRealVector

      Returns this point's coordinates as a new RealVector instance (for interfacing with Apache Commons Math).
      Returns:
      a new vector
    • duplicate

      default Pnt2d duplicate()
      Returns a copy of this point which is of the same type as the original.
      Returns:
      a new instance.
    • plus

      default Pnt2d plus(Pnt2d p)
      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.
      Parameters:
      p - the point to be added
      Returns:
      a new point
    • plus

      default Pnt2d plus(double dx, double dy)
      Returns a new point whose coordinates are the sum of this point and the specified double coordinates.
      Parameters:
      dx - the x-coordinate to be added
      dy - the y-coordinate to be added
      Returns:
      a new point
    • minus

      default Pnt2d minus(Pnt2d p)
      Returns a new point whose coordinates are the difference of this point and the given point.
      Parameters:
      p - the point to be subtracted
      Returns:
      a new point
    • mult

      default Pnt2d mult(double s)
      Returns a new point whose coordinates are multiplied by the specified scalar value.
      Parameters:
      s - some scalar value
      Returns:
      a new point
    • minus

      default Pnt2d minus(double dx, double dy)
      Returns a new point whose coordinates are the difference of this point and the given point (specified as a coordinate pair).
      Parameters:
      dx - x-coordinate
      dy - y-coordinate
      Returns:
      a new point
    • perp

      default Pnt2d perp()
      Returns a point (vector) perpendicular to this point (vector).
      Returns:
      a perpendicular vector
    • dot

      default double dot(Pnt2d other)
      Calculates and returns the dot product of this point and another point (both points are interpreted as 2D vectors)
      Parameters:
      other - the point (vector) to be multiplied by this vector
      Returns:
      a new point (vector)
    • cross

      default double cross(Pnt2d other)
      Calculates and returns the 2D pseudo cross product of this point and another point (both points are interpreted as 2D vectors). The result of a.cross(b) is equivalent to a.perp().dot(b).
      Parameters:
      other - the point (vector) to be multiplied to the perpendicular vector of this vector
      Returns:
      a new point (vector)
    • equals

      default boolean equals(Pnt2d p, double tolerance)
      Tests if this point matches the given point, i.e., if both coordinate differences are zero (< than the specified tolerance).
      Parameters:
      p - the point to be matched to
      tolerance - the tolerance (see also TOLERANCE).
      Returns:
      true if both points match
    • distanceSq

      default double distanceSq(Pnt2d other)
      Returns the squared L2 distance between this point and the given point.
      Parameters:
      other - the other point
      Returns:
      the squared distance
    • distance

      default double distance(Pnt2d other)
      Returns the L2 (Euclidean) distance between this point and the given point. This method is equivalent to distL2(Pnt2d).
      Parameters:
      other - the other point
      Returns:
      the distance
    • getDistance

      default double getDistance(Pnt2d other)
      Implementation required by Primitive2d interface.
      Specified by:
      getDistance in interface Primitive2d
      Parameters:
      other - a 2D point
      Returns:
      the minimum distance (always positive)
    • distL2

      default double distL2(Pnt2d other)
      Returns the L2 (Euclidean) distance between this point and the given point. This method is equivalent to distance(Pnt2d).
      Parameters:
      other - the other point
      Returns:
      the distance
    • distL1

      default double distL1(Pnt2d other)
      Returns the L1 (Manhattan) distance between this point and the given point.
      Parameters:
      other - the other point
      Returns:
      the distance
    • getShape

      default Shape getShape(double scale)
      Returns a round dot (Shape instance) for drawing this point.
      Specified by:
      getShape in interface ShapeProducer
      Parameters:
      scale - the dot radius
      Returns:
      the shape