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
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface imagingbook.common.geometry.basic.Pnt2d
Pnt2d.PntDouble, Pnt2d.PntInt
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal int
The (immutable) x-coordinate of this pointfinal int
The (immutable) y-coordinate of this pointstatic final Pnt2d.PntInt
Singleton point instance with zero coordinates.Fields inherited from interface imagingbook.common.geometry.basic.Pnt2d
DefaultDotRadius, TOLERANCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
distanceSq
(Pnt2d.PntInt other) Returns the squared L2 distance between this point and the given point.int
Returns the L1 (Manhattan) distance between this point and the given point.Returns a copy of this point which is of the same type as the original.boolean
static Pnt2d.PntInt
from
(int[] xy) Returns a newPnt2d.PntInt
instance.static Pnt2d.PntInt
from
(int x, int y) Returns a newPnt2d.PntInt
instance.static Pnt2d.PntInt
Returns a newPnt2d.PntInt
from a givenPnt2d
instance.static Pnt2d.PntInt
from
(Pnt2d.PntInt p) Returns a newPnt2d.PntInt
instance from a given point.static Pnt2d.PntInt
Returns a newPnt2d.PntDouble
instance with the same coordinates as the given AWTPoint
.double
getX()
Returns the x-coordinate of this point.int
getXint()
Returns the x-coordinate of this point as a (truncated) integer value.double
getY()
Returns the y-coordinate of this point.int
getYint()
Returns the y-coordinate of this point as a (truncated) integer value.int
hashCode()
minus
(int dx, int dy) Returns a new point whose coordinates are the difference of this point and the given point.plus
(int[] dxy) plus
(int dx, int dy) Returns a new point whose coordinates are the sum of this point and the given point.plus
(Pnt2d.PntInt p) Returns this point's coordinates as a new AWTPoint
point.int[]
Returns this point's coordinates as a new 2-elementint
array.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface imagingbook.common.geometry.basic.Pnt2d
cross, distance, distanceSq, distL1, distL2, dot, equals, getDistance, getShape, minus, mult, perp, plus, toAwtPoint2D, toDoubleArray, toRealVector, toVector2D
Methods inherited from interface imagingbook.common.geometry.shape.ShapeProducer
getShape, getShapes, getShapes
-
Field Details
-
ZERO
Singleton point instance with zero coordinates. -
x
The (immutable) x-coordinate of this point -
y
The (immutable) y-coordinate of this point
-
-
Constructor Details
-
PntInt
Constructor.- Parameters:
x
- x-coordinatey
- 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. -
from
Returns a newPnt2d.PntInt
instance from a given point.- Parameters:
p
- the original point- Returns:
- the new point
-
from
Returns a newPnt2d.PntInt
instance.- Parameters:
x
- x-coordinate valuey
- y-coordinate value- Returns:
- the new point
-
from
Returns a newPnt2d.PntInt
instance.- Parameters:
xy
- x/y-coordinates- Returns:
- the new point
-
from
Returns a newPnt2d.PntInt
from a givenPnt2d
instance. This only works if the argument is of typePnt2d.PntInt
, otherwise an exception is thrown.- Parameters:
p
- a point of typePnt2d.PntInt
- Returns:
- the new point
-
from
Returns a newPnt2d.PntDouble
instance with the same coordinates as the given AWTPoint
.- Parameters:
p
- the original AWT point- Returns:
- the new point
-
getX
Description copied from interface:Pnt2d
Returns the x-coordinate of this point. -
getY
Description copied from interface:Pnt2d
Returns the y-coordinate of this point. -
getXint
Description copied from interface:Pnt2d
Returns the x-coordinate of this point as a (truncated) integer value. -
getYint
Description copied from interface:Pnt2d
Returns the y-coordinate of this point as a (truncated) integer value. -
plus
-
plus
-
plus
-
plus
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. -
minus
-
minus
-
minus
Description copied from interface:Pnt2d
Returns a new point whose coordinates are the difference of this point and the given point. -
distL1
Returns the L1 (Manhattan) distance between this point and the given point.- Parameters:
p
- the other point- Returns:
- the distance
-
distanceSq
Returns the squared L2 distance between this point and the given point.- Parameters:
other
- the other point- Returns:
- the squared distance
-
equals
-
toString
-
hashCode
-
toIntArray
Returns this point's coordinates as a new 2-elementint
array.- Returns:
- the array
-
toAwtPoint
Returns this point's coordinates as a new AWTPoint
point.- Returns:
- the new point
-