public class DiscreteTransform2 extends Object
Rotations are performed around tile centers unless the tile corner flags are set to true. To prevent aliasing, quarter turn rotations are only legal on block centers or corners. Half turns can be performed additionally on line centers.
Modifier and Type | Field and Description |
---|---|
static DiscreteTransform2 |
IDENTITY
Represents an identity transformation.
|
Modifier and Type | Method and Description |
---|---|
DiscreteTransform2 |
andThen(DiscreteTransform2 that)
Returns a transform that is the composition of the given transform with
this transform.
|
DiscreteTransform2 |
compose(DiscreteTransform2 that)
Returns a transform that is the composition of this transform and the
given transform.
|
static DiscreteTransform2 |
fromRotation(int quarterTurns)
Returns a new transform representing a rotation in the xy plane around
the origin.
|
static DiscreteTransform2 |
fromRotation(int quarterTurns,
com.flowpowered.math.vector.Vector2i point,
boolean tileCorner)
Returns a new transform representing a rotation in the xy plane, around a
given point.
|
static DiscreteTransform2 |
fromRotation(int halfTurns,
com.flowpowered.math.vector.Vector2i point,
boolean tileCornerX,
boolean tileCornerY)
Returns a new transform representing a rotation in the xy plane, around a
given point.
|
static DiscreteTransform2 |
fromScale(int a)
Returns a new transform representing a scaling.
|
static DiscreteTransform2 |
fromScale(int x,
int y)
Returns a new transform representing a scaling on each axis.
|
static DiscreteTransform2 |
fromScale(com.flowpowered.math.vector.Vector2i vector)
Returns a new transform representing a scaling on each axis.
|
static DiscreteTransform2 |
fromTranslation(int x,
int y)
Returns a new transform representing a translation.
|
static DiscreteTransform2 |
fromTranslation(com.flowpowered.math.vector.Vector2i vector)
Returns a new transform representing a translation.
|
com.flowpowered.math.matrix.Matrix3d |
getMatrix()
Returns the matrix representation of the transform.
|
DiscreteTransform2 |
invert()
Inverts the transform and returns it as a new transform.
|
static Optional<DiscreteTransform2> |
of(com.flowpowered.math.matrix.Matrix3d matrix)
Returns a new transform from the given transformation matrix, if the
resulting transform would be discrete.
|
static DiscreteTransform2 |
rotationAroundCenter(int quarterTurns,
com.flowpowered.math.vector.Vector2i size)
Returns a new transform representing a centered rotation of an area of
tiles.
|
com.flowpowered.math.vector.Vector2i |
transform(int x,
int y)
Transform a vector represented as a pair of coordinates using this
transform.
|
com.flowpowered.math.vector.Vector2i |
transform(com.flowpowered.math.vector.Vector2i vector)
Transforms a vector using this transforms.
|
int |
transformX(int x,
int y)
Transforms the x coordinate of a vector using this transform.
|
int |
transformX(com.flowpowered.math.vector.Vector2i vector)
Transforms the x coordinate of a vector using this transform.
|
int |
transformY(int x,
int y)
Transforms the y coordinate of a vector using this transform.
|
int |
transformY(com.flowpowered.math.vector.Vector2i vector)
Transforms the y coordinate of a vector using this transform.
|
DiscreteTransform2 |
withRotation(int quarterTurns)
Adds a rotation to this transform, in the xy plane, around the origin and
returns it as a new transform.
|
DiscreteTransform2 |
withRotation(int quarterTurns,
com.flowpowered.math.vector.Vector2i point,
boolean tileCorner)
Adds a a rotation to this transform, in the xy plane, around a given
point, and returns it as a new transform.
|
DiscreteTransform2 |
withRotation(int halfTurns,
com.flowpowered.math.vector.Vector2i point,
boolean tileCornerX,
boolean tileCornerY)
Adds a a rotation to this transform, in the xy plane, around a given
point, and returns it as a new transform.
|
DiscreteTransform2 |
withScale(int a)
Adds a scale factor to this transform and returns it as a new transform.
|
DiscreteTransform2 |
withScale(int x,
int y)
Adds a scale factor for each axis to this transform and returns it as a
new transform.
|
DiscreteTransform2 |
withScale(com.flowpowered.math.vector.Vector2i vector)
Adds a scale factor for each axis to this transform and returns it as a
new transform.
|
DiscreteTransform2 |
withTransformation(DiscreteTransform2 transform)
Adds another transformation to this transformation and returns int as a
new transform.
|
DiscreteTransform2 |
withTranslation(int x,
int y)
Adds a translation to this transform and returns it as a new transform.
|
DiscreteTransform2 |
withTranslation(com.flowpowered.math.vector.Vector2i vector)
Adds a translation to this transform and returns it as a new transform.
|
public static final DiscreteTransform2 IDENTITY
public com.flowpowered.math.matrix.Matrix3d getMatrix()
public com.flowpowered.math.vector.Vector2i transform(com.flowpowered.math.vector.Vector2i vector)
vector
- The original vectorpublic com.flowpowered.math.vector.Vector2i transform(int x, int y)
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorpublic int transformX(com.flowpowered.math.vector.Vector2i vector)
vector
- The original vectorpublic int transformX(int x, int y)
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorpublic int transformY(com.flowpowered.math.vector.Vector2i vector)
vector
- The original vectorpublic int transformY(int x, int y)
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorpublic DiscreteTransform2 invert()
public DiscreteTransform2 compose(DiscreteTransform2 that)
that
- The transform to compose withpublic DiscreteTransform2 andThen(DiscreteTransform2 that)
that
- The transform to compose withpublic DiscreteTransform2 withTranslation(com.flowpowered.math.vector.Vector2i vector)
vector
- The translation vectorpublic DiscreteTransform2 withTranslation(int x, int y)
x
- The x coordinate of the translationy
- The y coordinate of the translationpublic DiscreteTransform2 withScale(int a)
a
- The scale factorpublic DiscreteTransform2 withScale(com.flowpowered.math.vector.Vector2i vector)
vector
- The scale vectorpublic DiscreteTransform2 withScale(int x, int y)
x
- The scale factor on xy
- The scale factor on ypublic DiscreteTransform2 withRotation(int quarterTurns)
quarterTurns * 90
. The rotation is around
the block center, not the corner.quarterTurns
- The number of quarter turns in this rotationpublic DiscreteTransform2 withRotation(int quarterTurns, com.flowpowered.math.vector.Vector2i point, boolean tileCorner)
quarterTurns * 90
. The tile
corner flag changes the point to be the tile upper corner instead of the
center.quarterTurns
- The number of quarter turns in this rotationpoint
- The point of rotation, as tile coordinatestileCorner
- Whether or not to use the corner of the tile instead of
the centerpublic DiscreteTransform2 withRotation(int halfTurns, com.flowpowered.math.vector.Vector2i point, boolean tileCornerX, boolean tileCornerY)
halfTurns * 180
. The tile corner
flags change the point to be the tile corner or edge instead of the
center. When both flags are false, the center is used. When only one is
true the edge on the opposite axis to the flag is used. When both are
true the upper corner is used.halfTurns
- The number of half turns in this rotationpoint
- The point of rotation, as tile coordinatestileCornerX
- Whether or not to use the corner of the tile instead
of the center on the x axistileCornerY
- Whether or not to use the corner of the tile instead
of the center on the y axispublic DiscreteTransform2 withTransformation(DiscreteTransform2 transform)
transform
- The transformation to addpublic static Optional<DiscreteTransform2> of(com.flowpowered.math.matrix.Matrix3d matrix)
matrix
- The matrix to use for the transformOptional.empty()
public static DiscreteTransform2 fromTranslation(com.flowpowered.math.vector.Vector2i vector)
vector
- The translation vectorpublic static DiscreteTransform2 fromTranslation(int x, int y)
x
- The x coordinate of the translationy
- The y coordinate of the translationpublic static DiscreteTransform2 fromScale(int a)
a
- The scale factorpublic static DiscreteTransform2 fromScale(com.flowpowered.math.vector.Vector2i vector)
vector
- The scale vectorpublic static DiscreteTransform2 fromScale(int x, int y)
x
- The scale factor on xy
- The scale factor on ypublic static DiscreteTransform2 fromRotation(int quarterTurns)
quarterTurns * 90
. The rotation is around the block center,
not the corner.quarterTurns
- The number of quarter turns in this rotationpublic static DiscreteTransform2 fromRotation(int quarterTurns, com.flowpowered.math.vector.Vector2i point, boolean tileCorner)
quarterTurns * 90
. The tile corner flag change the point to be
the tile corner instead of the center.quarterTurns
- The number of quarter turns in this rotationpoint
- The point of rotation, as tile coordinatestileCorner
- Whether or not to use the corner of the tile instead of
the centerpublic static DiscreteTransform2 fromRotation(int halfTurns, com.flowpowered.math.vector.Vector2i point, boolean tileCornerX, boolean tileCornerY)
halfTurns * 180
. The tile corner flags change the point to be the
tile corner or edge instead of the center. When both flags are false, the
center is used. When only one is true the edge on the opposite axis to
the flag is used. When both are true the upper corner is used.halfTurns
- The number of half turns in this rotationpoint
- The point of rotation, as tile coordinatestileCornerX
- Whether or not to use the corner of the tile instead
of the center on the x axistileCornerY
- Whether or not to use the corner of the tile instead
of the center on the y axispublic static DiscreteTransform2 rotationAroundCenter(int quarterTurns, com.flowpowered.math.vector.Vector2i size)
quarterTurns * 90
. Areas with differing parities on the axes can
only be rotated by multiples of 180 degrees.quarterTurns
- The amount of quarter turns in this rotationsize
- The size of the area to rotate