Class Boundary2DScanner.Step
- Enclosing class:
Boundary2DScanner
The step of scanning the boundary: moving from one boundary segment to the next boundary segment.
See definition of the "boundary" and "boundary segment" terms in comments to Boundary2DScanner
class.
In fact, this class is an enumeration: there are only 12 immutable instances of this class (all they are created while initialization). Namely:
- 4 straight movements: one of
pixelCenterDX()
,pixelCenterDY()
is ±1, another is 0,newSide()
==oldSide()
; - 4 diagonal movements:
pixelCenterDX()
==±1,pixelCenterDY()
==±1,oldSide()
andnewSide()
is a pair of adjacent pixel sides; - 4 kinds of movement around the same pixel (rotations), from one pixel side to next pixel side:
here
pixelCenterDX()
==0,pixelCenterDY()
==0,oldSide()
andnewSide()
is a pair of adjacent pixel sides.
So, you can compare instances of this class by == operator, as well as enumeration instances.
You can also identify instances of this class with help of a unique code, returned by code()
method.
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
Equal to StrictMath.sqrt(2.0): the distance between pixel centers for diagonal steps.static final double
Equal to 0.5 * StrictMath.sqrt(2.0): the distance between segment centers for diagonal steps and movements around the same pixel.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.X_MINUS
,newSide()
=Side.Y_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.X_PLUS
,newSide()
=Side.Y_PLUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.Y_MINUS
,newSide()
=Side.X_PLUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.Y_PLUS
,newSide()
=Side.X_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= 0,oldSide()
=Side.Y_PLUS
,newSide()
=Side.Y_PLUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= −1,oldSide()
=Side.X_MINUS
,newSide()
=Side.Y_PLUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= +1,oldSide()
=Side.Y_PLUS
,newSide()
=Side.X_PLUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= 0,oldSide()
=Side.Y_MINUS
,newSide()
=Side.Y_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= −1,oldSide()
=Side.Y_MINUS
,newSide()
=Side.X_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= +1,oldSide()
=Side.X_PLUS
,newSide()
=Side.Y_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= −1,oldSide()
=Side.X_MINUS
,newSide()
=Side.X_MINUS
.static final int
Result ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= +1,oldSide()
=Side.X_PLUS
,newSide()
=Side.X_PLUS
. -
Method Summary
Modifier and TypeMethodDescriptionint
code()
Returns integer unique code from 0 to 11, identifying this step.double
Returns the distance between the centers of the previous and current pixel; equal to StrictMath.hypot(pixelCenterDX()
,pixelCenterDY()
).double
Returns the distance between the centers of the previous and current boundary segments.int
ReturnspixelVertexX()
+0.5.int
ReturnspixelVertexY()
+0.5.boolean
Returns true ifpixelCenterDX()
!=0 &&pixelCenterDY()
!=0 (diagonal kind of movement).boolean
Returns true ifpixelCenterDX()
is ±1 andpixelCenterDY()
is 0.boolean
Returns true ifpixelCenterDX()
==0 &&pixelCenterDY()
==0 (rotation kind of movement).boolean
Returns true if one ofpixelCenterDX()
andpixelCenterDY()
values is ±1, but another is 0 (straight kind of movement).boolean
Returns true ifpixelCenterDY()
is ±1 andpixelCenterDX()
is 0.newSide()
Returns the new (current) pixel side.oldSide()
Returns the previous pixel side.int
Returns change of x-coordinate of the pixel center, performed by this step.int
Returns change of y-coordinate of the pixel center, performed by this step.double
Returns x-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the center of the new (current) pixel is at the origin of coordinates.double
Returns y-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the center of the new (current) pixel is at the origin of coordinates.double
Returns change of x-coordinate of the center of the current boundary segment, performed by this step.double
Returns change of y-coordinate of the center of the current boundary segment, performed by this step.toString()
Returns a brief string description of this object.
-
Field Details
-
Y_MINUS_CODE
public static final int Y_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= −1,oldSide()
=Side.X_MINUS
,newSide()
=Side.X_MINUS
. It is shown below:↑ ↑ - See Also:
-
X_PLUS_CODE
public static final int X_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= 0,oldSide()
=Side.Y_MINUS
,newSide()
=Side.Y_MINUS
. It is shown below:→ → - See Also:
-
Y_PLUS_CODE
public static final int Y_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= +1,oldSide()
=Side.X_PLUS
,newSide()
=Side.X_PLUS
. It is shown below:↓ ↓ - See Also:
-
X_MINUS_CODE
public static final int X_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= 0,oldSide()
=Side.Y_PLUS
,newSide()
=Side.Y_PLUS
. It is shown below:← ← - See Also:
-
X_MINUS_Y_MINUS_CODE
public static final int X_MINUS_Y_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= −1,oldSide()
=Side.X_MINUS
,newSide()
=Side.Y_PLUS
. It is shown below:← ↑ - See Also:
-
X_PLUS_Y_MINUS_CODE
public static final int X_PLUS_Y_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= −1,oldSide()
=Side.Y_MINUS
,newSide()
=Side.X_MINUS
. It is shown below:↑ → - See Also:
-
X_PLUS_Y_PLUS_CODE
public static final int X_PLUS_Y_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= +1,pixelCenterDY()
= +1,oldSide()
=Side.X_PLUS
,newSide()
=Side.Y_MINUS
. It is shown below:↓ → - See Also:
-
X_MINUS_Y_PLUS_CODE
public static final int X_MINUS_Y_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= −1,pixelCenterDY()
= +1,oldSide()
=Side.Y_PLUS
,newSide()
=Side.X_PLUS
. It is shown below:← ↓ - See Also:
-
ROTATION_X_MINUS_TO_Y_MINUS_CODE
public static final int ROTATION_X_MINUS_TO_Y_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.X_MINUS
,newSide()
=Side.Y_MINUS
. It is shown below:→ ↑ - See Also:
-
ROTATION_Y_MINUS_TO_X_PLUS_CODE
public static final int ROTATION_Y_MINUS_TO_X_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.Y_MINUS
,newSide()
=Side.X_PLUS
. It is shown below:→ ↓ - See Also:
-
ROTATION_X_PLUS_TO_Y_PLUS_CODE
public static final int ROTATION_X_PLUS_TO_Y_PLUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.X_PLUS
,newSide()
=Side.Y_PLUS
. It is shown below:↓ ← - See Also:
-
ROTATION_Y_PLUS_TO_X_MINUS_CODE
public static final int ROTATION_Y_PLUS_TO_X_MINUS_CODEResult ofcode()
method for the following scanning step:pixelCenterDX()
= 0,pixelCenterDY()
= 0,oldSide()
=Side.Y_PLUS
,newSide()
=Side.X_MINUS
. It is shown below:↑ ← - See Also:
-
DIAGONAL_LENGTH
public static final double DIAGONAL_LENGTHEqual to StrictMath.sqrt(2.0): the distance between pixel centers for diagonal steps. SeedistanceBetweenPixelCenters()
. -
HALF_DIAGONAL_LENGTH
public static final double HALF_DIAGONAL_LENGTHEqual to 0.5 * StrictMath.sqrt(2.0): the distance between segment centers for diagonal steps and movements around the same pixel.
-
-
Method Details
-
code
public int code()Returns integer unique code from 0 to 11, identifying this step. Works very quickly (this method just returns an internal field).This method returns one of the following constants:
Y_PLUS_CODE
,X_PLUS_CODE
,Y_MINUS_CODE
,X_MINUS_CODE
,X_MINUS_Y_MINUS_CODE
,X_PLUS_Y_MINUS_CODE
,X_PLUS_Y_PLUS_CODE
,X_MINUS_Y_PLUS_CODE
,ROTATION_X_MINUS_TO_Y_MINUS_CODE
,ROTATION_Y_MINUS_TO_X_PLUS_CODE
,ROTATION_X_PLUS_TO_Y_PLUS_CODE
,ROTATION_Y_PLUS_TO_X_MINUS_CODE
.
You can use this value for maximally efficient switching, depending on the step kind, using Java switch operator.
- Returns:
- integer unique code of this step (0..11).
-
pixelCenterDX
public int pixelCenterDX()Returns change of x-coordinate of the pixel center, performed by this step. Can be −1, 0, 1. In other word, returns the increment of thecurrent position
along x-axis. Works very quickly (this method just returns an internal field).- Returns:
- change of x-coordinate of the center of the current pixel.
- See Also:
-
pixelCenterDY
public int pixelCenterDY()Returns change of y-coordinate of the pixel center, performed by this step. Can be −1, 0, 1. In other word, returns the increment of thecurrent position
along y-axis. Works very quickly (this method just returns an internal field).- Returns:
- change of y-coordinate of the center of the current pixel.
- See Also:
-
segmentCenterDX
public double segmentCenterDX()Returns change of x-coordinate of the center of the current boundary segment, performed by this step. Can be 0.0, ±0.5, ±1.0. Works very quickly (this method just returns an internal field).- Returns:
- change of x-coordinate of the center of the current boundary segment.
- See Also:
-
segmentCenterDY
public double segmentCenterDY()Returns change of y-coordinate of the center of the current boundary segment, performed by this step. Can be 0.0, ±0.5, ±1.0. Works very quickly (this method just returns an internal field).- Returns:
- change of y-coordinate of the center of the current boundary segment.
- See Also:
-
pixelVertexX
public double pixelVertexX()Returns x-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the center of the new (current) pixel is at the origin of coordinates. Works very quickly (this method just returns an internal field).- Returns:
- x-coordinate of the vertex of the new (current) pixel, lying between previous and current segments of the boundary.
-
pixelVertexY
public double pixelVertexY()Returns y-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the center of the new (current) pixel is at the origin of coordinates. Works very quickly (this method just returns an internal field).- Returns:
- y-coordinate of the vertex of the new (current) pixel, lying between previous and current segments of the boundary.
-
increasedPixelVertexX
public int increasedPixelVertexX()ReturnspixelVertexX()
+0.5. It is always an integer value 0 or 1. Works very quickly (this method just returns an internal field).In other words, returns x-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the left up corner of the new (current) pixel is at the origin of coordinates.
- Returns:
- 0.5 + x-coordinate of the vertex of the new (current) pixel, lying between previous and current segments of the boundary.
-
increasedPixelVertexY
public int increasedPixelVertexY()ReturnspixelVertexY()
+0.5. It is always an integer value 0 or 1. Works very quickly (this method just returns an internal field).In other words, returns y-coordinate of the vertex of the new (current) pixel, which is common for the current and previous segments (pixel sides), on the assumption that the left up corner of the new (current) pixel is at the origin of coordinates.
- Returns:
- 0.5 + y-coordinate of the vertex of the new (current) pixel, lying between previous and current segments of the boundary.
-
isRotation
public boolean isRotation()Returns true ifpixelCenterDX()
==0 &&pixelCenterDY()
==0 (rotation kind of movement). Works very quickly (this method just returns an internal field).- Returns:
- true if
pixelCenterDX()
==0 &&pixelCenterDY()
==0.
-
isHorizontal
public boolean isHorizontal()Returns true ifpixelCenterDX()
is ±1 andpixelCenterDY()
is 0. Works very quickly (this method just returns an internal field).- Returns:
- true if
pixelCenterDX()
!=0 &&pixelCenterDY()
==0.
-
isVertical
public boolean isVertical()Returns true ifpixelCenterDY()
is ±1 andpixelCenterDX()
is 0. Works very quickly (this method just returns an internal field).- Returns:
- true if
pixelCenterDX()
==0 &&pixelCenterDY()
!=0.
-
isStraight
public boolean isStraight()Returns true if one ofpixelCenterDX()
andpixelCenterDY()
values is ±1, but another is 0 (straight kind of movement). Works very quickly (this method just returns an internal field).- Returns:
- true if
isHorizontal()
||isVertical()
.
-
isDiagonal
public boolean isDiagonal()Returns true ifpixelCenterDX()
!=0 &&pixelCenterDY()
!=0 (diagonal kind of movement). Works very quickly (this method just returns an internal field).- Returns:
- true if
pixelCenterDX()
!=0 &&pixelCenterDY()
!=0.
-
distanceBetweenPixelCenters
public double distanceBetweenPixelCenters()Returns the distance between the centers of the previous and current pixel; equal to StrictMath.hypot(pixelCenterDX()
,pixelCenterDY()
). In other words, returns 0 ifisRotation()
, 1 for straight steps andDIAGONAL_LENGTH
=√2 for diagonal steps. Works very quickly (this method just returns an internal field).- Returns:
- the distance between the centers of the previous and current pixe.
-
distanceBetweenSegmentCenters
public double distanceBetweenSegmentCenters()Returns the distance between the centers of the previous and current boundary segments. In other words, returns 1 for straight steps andHALF_DIAGONAL_LENGTH
=0.5*√2 for diagonal steps and for movements around the same pixel. Works very quickly (this method just returns an internal field).- Returns:
- the distance between the centers of the previous and current boundary segments.
-
oldSide
Returns the previous pixel side.- Returns:
- the previous pixel side.
-
newSide
Returns the new (current) pixel side.- Returns:
- the new (current) pixel side.
-
toString
Returns a brief string description of this object.The result of this method may depend on implementation.
-