- All Superinterfaces:
Primitive2d
,ShapeProducer
- All Known Implementing Classes:
Corner
,LocalMinMaxFinder.ExtremalPoint
,PixelMap.Pixel
,Pnt2d.PntDouble
,Pnt2d.PntInt
,SiftDescriptor
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
Two concrete (nested) classes are defined for points with
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 ClassesModifier and TypeInterfaceDescriptionstatic class
Immutable 2D point implementation withdouble
coordinates.static class
Immutable 2D point implementation withint
coordinates. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
static final double
The default tolerance for matching coordinates (1E-6). -
Method Summary
Modifier and TypeMethodDescriptiondefault double
Calculates and returns the 2D pseudo cross product of this point and another point (both points are interpreted as 2D vectors).default double
Returns the L2 (Euclidean) distance between this point and the given point.default double
distanceSq
(Pnt2d other) Returns the squared L2 distance between this point and the given point.default double
Returns the L1 (Manhattan) distance between this point and the given point.default double
Returns the L2 (Euclidean) distance between this point and the given point.default double
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
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 typePnt2d.PntDouble
with the specified coordinates.static Pnt2d
from
(double x, double y) Creates and returns a new point of typePnt2d.PntDouble
with the specified coordinates.static Pnt2d
from
(int[] xy) Creates and returns a new point of typePnt2d.PntInt
with the specified coordinates.static Pnt2d
from
(int x, int y) Creates and returns a new point of typePnt2d.PntInt
with the specified coordinates.static Pnt2d
static Pnt2d
default double
getDistance
(Pnt2d other) Implementation required byPrimitive2d
interface.default Shape
getShape
(double scale) Returns a round dot (Shape
instance) for drawing this point.double
getX()
Returns the x-coordinate of this point.default int
getXint()
Returns the x-coordinate of this point as a (truncated) integer value.double
getY()
Returns the y-coordinate of this point.default int
getYint()
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
perp()
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 specifieddouble
coordinates.default Pnt2d
Returns a new point whose coordinates are the sum of this point and the given point.default Point2D.Double
Returns this point's coordinates as a new AWTPoint2D.Double
point.default double[]
Returns this point's coordinates as a new 2-elementdouble
array.default RealVector
Returns this point's coordinates as a newRealVector
instance (for interfacing with Apache Commons Math).default Vector2D
Returns this point's coordinates as a newVector2D
instance (for interfacing with Apache Commons Math).Methods inherited from interface imagingbook.common.geometry.shape.ShapeProducer
getShape, getShapes, getShapes
-
Field Details
-
TOLERANCE
The default tolerance for matching coordinates (1E-6).- See Also:
-
DefaultDotRadius
- See Also:
-
-
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
Returns the x-coordinate of this point as a (truncated) integer value.- Returns:
- the integer x-coordinate of this point.
-
getYint
Returns the y-coordinate of this point as a (truncated) integer value.- Returns:
- the integer y-coordinate of this point.
-
from
Creates and returns a new point of typePnt2d.PntInt
with the specified coordinates. See alsoPnt2d.PntInt.from(int, int)
.- Parameters:
x
- coordinatey
- coordinate- Returns:
- the new point
-
from
Creates and returns a new point of typePnt2d.PntInt
with the specified coordinates. See alsoPnt2d.PntInt.from(int[])
.- Parameters:
xy
- coordinates- Returns:
- the new point
-
from
Creates and returns a new point of typePnt2d.PntDouble
with the specified coordinates. See alsoPnt2d.PntDouble.from(double, double)
.- Parameters:
x
- coordinatey
- coordinate- Returns:
- the new point
-
from
Creates and returns a new point of typePnt2d.PntDouble
with the specified coordinates. See alsoPnt2d.PntDouble.from(double[])
.- Parameters:
xy
- coordinates- Returns:
- the new point
-
from
-
from
-
toDoubleArray
Returns this point's coordinates as a new 2-elementdouble
array.- Returns:
- the array
-
toAwtPoint2D
Returns this point's coordinates as a new AWTPoint2D.Double
point.- Returns:
- the new point
-
toVector2D
Returns this point's coordinates as a newVector2D
instance (for interfacing with Apache Commons Math).- Returns:
- a new vector
-
toRealVector
Returns this point's coordinates as a newRealVector
instance (for interfacing with Apache Commons Math).- Returns:
- a new vector
-
duplicate
Returns a copy of this point which is of the same type as the original.- Returns:
- a new instance.
-
plus
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
Returns a new point whose coordinates are the sum of this point and the specifieddouble
coordinates.- Parameters:
dx
- the x-coordinate to be addeddy
- the y-coordinate to be added- Returns:
- a new point
-
minus
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
Returns a new point whose coordinates are multiplied by the specified scalar value.- Parameters:
s
- some scalar value- Returns:
- a new point
-
minus
Returns a new point whose coordinates are the difference of this point and the given point (specified as a coordinate pair).- Parameters:
dx
- x-coordinatedy
- y-coordinate- Returns:
- a new point
-
perp
Returns a point (vector) perpendicular to this point (vector).- Returns:
- a perpendicular vector
-
dot
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
Calculates and returns the 2D pseudo cross product of this point and another point (both points are interpreted as 2D vectors). The result ofa.cross(b)
is equivalent toa.perp().dot(b)
.- Parameters:
other
- the point (vector) to be multiplied to the perpendicular vector of this vector- Returns:
- a new point (vector)
-
equals
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 totolerance
- the tolerance (see alsoTOLERANCE
).- Returns:
- true if both points match
-
distanceSq
Returns the squared L2 distance between this point and the given point.- Parameters:
other
- the other point- Returns:
- the squared distance
-
distance
Returns the L2 (Euclidean) distance between this point and the given point. This method is equivalent todistL2(Pnt2d)
.- Parameters:
other
- the other point- Returns:
- the distance
-
getDistance
Implementation required byPrimitive2d
interface.- Specified by:
getDistance
in interfacePrimitive2d
- Parameters:
other
- a 2D point- Returns:
- the minimum distance (always positive)
-
distL2
Returns the L2 (Euclidean) distance between this point and the given point. This method is equivalent todistance(Pnt2d)
.- Parameters:
other
- the other point- Returns:
- the distance
-
distL1
Returns the L1 (Manhattan) distance between this point and the given point.- Parameters:
other
- the other point- Returns:
- the distance
-
getShape
Returns a round dot (Shape
instance) for drawing this point.- Specified by:
getShape
in interfaceShapeProducer
- Parameters:
scale
- the dot radius- Returns:
- the shape
-