- 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 classImmutable 2D point implementation withdoublecoordinates.static classImmutable 2D point implementation withintcoordinates. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doublestatic final doubleThe default tolerance for matching coordinates (1E-6). -
Method Summary
Modifier and TypeMethodDescriptiondefault doubleCalculates and returns the 2D pseudo cross product of this point and another point (both points are interpreted as 2D vectors).default doubleReturns the L2 (Euclidean) distance between this point and the given point.default doubledistanceSq(Pnt2d other) Returns the squared L2 distance between this point and the given point.default doubleReturns the L1 (Manhattan) distance between this point and the given point.default doubleReturns the L2 (Euclidean) distance between this point and the given point.default doubleCalculates and returns the dot product of this point and another point (both points are interpreted as 2D vectors)default Pnt2dReturns a copy of this point which is of the same type as the original.default booleanTests if this point matches the given point, i.e., if both coordinate differences are zero (< than the specified tolerance).static Pnt2dfrom(double[] xy) Creates and returns a new point of typePnt2d.PntDoublewith the specified coordinates.static Pnt2dfrom(double x, double y) Creates and returns a new point of typePnt2d.PntDoublewith the specified coordinates.static Pnt2dfrom(int[] xy) Creates and returns a new point of typePnt2d.PntIntwith the specified coordinates.static Pnt2dfrom(int x, int y) Creates and returns a new point of typePnt2d.PntIntwith the specified coordinates.static Pnt2dstatic Pnt2ddefault doublegetDistance(Pnt2d other) Implementation required byPrimitive2dinterface.default ShapegetShape(double scale) Returns a round dot (Shapeinstance) for drawing this point.doublegetX()Returns the x-coordinate of this point.default intgetXint()Returns the x-coordinate of this point as a (truncated) integer value.doublegetY()Returns the y-coordinate of this point.default intgetYint()Returns the y-coordinate of this point as a (truncated) integer value.default Pnt2dminus(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 Pnt2dReturns a new point whose coordinates are the difference of this point and the given point.default Pnt2dmult(double s) Returns a new point whose coordinates are multiplied by the specified scalar value.default Pnt2dperp()Returns a point (vector) perpendicular to this point (vector).default Pnt2dplus(double dx, double dy) Returns a new point whose coordinates are the sum of this point and the specifieddoublecoordinates.default Pnt2dReturns a new point whose coordinates are the sum of this point and the given point.default Point2D.DoubleReturns this point's coordinates as a new AWTPoint2D.Doublepoint.default double[]Returns this point's coordinates as a new 2-elementdoublearray.default RealVectorReturns this point's coordinates as a newRealVectorinstance (for interfacing with Apache Commons Math).default Vector2DReturns this point's coordinates as a newVector2Dinstance (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.PntIntwith 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.PntIntwith the specified coordinates. See alsoPnt2d.PntInt.from(int[]).- Parameters:
xy- coordinates- Returns:
- the new point
-
from
Creates and returns a new point of typePnt2d.PntDoublewith 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.PntDoublewith 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-elementdoublearray.- Returns:
- the array
-
toAwtPoint2D
Returns this point's coordinates as a new AWTPoint2D.Doublepoint.- Returns:
- the new point
-
toVector2D
Returns this point's coordinates as a newVector2Dinstance (for interfacing with Apache Commons Math).- Returns:
- a new vector
-
toRealVector
Returns this point's coordinates as a newRealVectorinstance (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 specifieddoublecoordinates.- 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 byPrimitive2dinterface.- Specified by:
getDistancein 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 (Shapeinstance) for drawing this point.- Specified by:
getShapein interfaceShapeProducer- Parameters:
scale- the dot radius- Returns:
- the shape
-