Class DiscreteTransform3


  • public class DiscreteTransform3
    extends Object
    Represents a transform. It is 3 dimensional and discrete. It will never cause aliasing.

    Rotations are performed around block centers unless the block 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 edge and face centers.

    • Field Detail

      • IDENTITY

        public static final DiscreteTransform3 IDENTITY
        Represents an identity transformation. Does nothing!
    • Method Detail

      • matrix

        public Matrix4d matrix()
        Returns the matrix representation of the transform. It is 4D to allow it to include a translation.
        Returns:
        The matrix for this transform
      • transform

        public Vector3i transform​(Vector3i vector)
        Transforms a vector using this transforms.
        Parameters:
        vector - The original vector
        Returns:
        The transformed vector
      • transform

        public Vector3i transform​(int x,
                                  int y,
                                  int z)
        Transform a vector represented as a pair of coordinates using this transform.
        Parameters:
        x - The x coordinate of the original vector
        y - The y coordinate of the original vector
        z - The z coordinate of the original vector
        Returns:
        The transformed vector
      • transformX

        public int transformX​(Vector3i vector)
        Transforms the x coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        vector - The original vector
        Returns:
        The transformed x coordinate
      • transformX

        public int transformX​(int x,
                              int y,
                              int z)
        Transforms the x coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        x - The x coordinate of the original vector
        y - The y coordinate of the original vector
        z - The z coordinate of the original vector
        Returns:
        The transformed x coordinate
      • transformY

        public int transformY​(Vector3i vector)
        Transforms the y coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        vector - The original vector
        Returns:
        The transformed y coordinate
      • transformY

        public int transformY​(int x,
                              int y,
                              int z)
        Transforms the y coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        x - The x coordinate of the original vector
        y - The y coordinate of the original vector
        z - The z coordinate of the original vector
        Returns:
        The transformed y coordinate
      • transformZ

        public int transformZ​(Vector3i vector)
        Transforms the z coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        vector - The original vector
        Returns:
        The transformed z coordinate
      • transformZ

        public int transformZ​(int x,
                              int y,
                              int z)
        Transforms the z coordinate of a vector using this transform. Only creates a new object on the first call.
        Parameters:
        x - The x coordinate of the original vector
        y - The y coordinate of the original vector
        z - The z coordinate of the original vector
        Returns:
        The transformed z coordinate
      • invert

        public DiscreteTransform3 invert()
        Inverts the transform and returns it as a new transform.
        Returns:
        The inverse of this transform
      • compose

        public DiscreteTransform3 compose​(DiscreteTransform3 that)
        Returns a transform that is the composition of this transform and the given transform. The result will apply this transformation after the given one.
        Parameters:
        that - The transform to compose with
        Returns:
        The new composed transform
      • andThen

        public DiscreteTransform3 andThen​(DiscreteTransform3 that)
        Returns a transform that is the composition of the given transform with this transform. The result will apply the given transformation after this one.
        Parameters:
        that - The transform to compose with
        Returns:
        The new composed transform
      • withTranslation

        public DiscreteTransform3 withTranslation​(Vector3i vector)
        Adds a translation to this transform and returns it as a new transform.
        Parameters:
        vector - The translation vector
        Returns:
        The translated transform as a copy
      • withTranslation

        public DiscreteTransform3 withTranslation​(int x,
                                                  int y,
                                                  int z)
        Adds a translation to this transform and returns it as a new transform.
        Parameters:
        x - The x coordinate of the translation
        y - The y coordinate of the translation
        z - The z coordinate of the translation
        Returns:
        The translated transform as a copy
      • withScale

        public DiscreteTransform3 withScale​(int a)
        Adds a scale factor to this transform and returns it as a new transform. This factor must be non-zero.
        Parameters:
        a - The scale factor
        Returns:
        The scaled transform as a copy
      • withScale

        public DiscreteTransform3 withScale​(Vector3i vector)
        Adds a scale factor for each axis to this transform and returns it as a new transform. The factors must be non-zero.
        Parameters:
        vector - The scale vector
        Returns:
        The scaled transform as a copy
      • withScale

        public DiscreteTransform3 withScale​(int x,
                                            int y,
                                            int z)
        Adds a scale factor for each axis to this transform and returns it as a new transform. The factors must be non-zero.
        Parameters:
        x - The scale factor on x
        y - The scale factor on y
        z - The scale factor on z
        Returns:
        The scaled transform as a copy
      • withRotation

        public DiscreteTransform3 withRotation​(int quarterTurns,
                                               Axis axis)
        Adds a rotation to this transform, around an axis, around the origin and returns it as a new transform. The rotation is given is quarter turns. The actual rotation is quarterTurns * 90. The rotation is around the block center, not the corner.
        Parameters:
        quarterTurns - The number of quarter turns in this rotation
        axis - The axis to rotate around
        Returns:
        The rotated transform as a copy
      • withRotation

        public DiscreteTransform3 withRotation​(int quarterTurns,
                                               Axis axis,
                                               Vector3i point,
                                               boolean blockCorner)
        Adds a a rotation to this transform, around an axis, around a given point, and returns it as a new transform. The rotation is given is quarter turns. The actual rotation is quarterTurns * 90. The block corner flag changes the point to be the block upper corner instead of the center.
        Parameters:
        quarterTurns - The number of quarter turns in this rotation
        axis - The axis to rotate around
        point - The point of rotation, as block coordinates
        blockCorner - Whether or not to use the corner of the block instead of the center
        Returns:
        The rotated transform as a copy
      • withRotation

        public DiscreteTransform3 withRotation​(int halfTurns,
                                               Axis axis,
                                               Vector3i point,
                                               boolean blockCornerX,
                                               boolean blockCornerY,
                                               boolean blockCornerZ)
        Adds a a rotation to this transform, around an axis, around a given point. The rotation is given is half turns. The actual rotation is halfTurns * 180. The block corner flags change the point to be the block corner or edge instead of the center. When all flags are false, the center is used. When only one is true the face traversed by the axis of flag is used. When two are true the edge in the direction of the remaining flag is used. When all are true the upper corner is used.
        Parameters:
        halfTurns - The number of half turns in this rotation
        axis - The axis to rotate around
        point - The point of rotation, as block coordinates
        blockCornerX - Whether or not to use the corner of the block instead of the center on the x axis
        blockCornerY - Whether or not to use the corner of the block instead of the center on the y axis
        blockCornerZ - Whether or not to use the corner of the block instead of the center on the z axis
        Returns:
        The rotated transform as a copy
      • withTransformation

        public DiscreteTransform3 withTransformation​(DiscreteTransform3 transform)
        Adds another transformation to this transformation and returns int as a new transform.
        Parameters:
        transform - The transformation to add
        Returns:
        The added transforms as a copy
      • of

        public static Optional<DiscreteTransform3> of​(Matrix4d matrix)
        Returns a new transform from the given transformation matrix, if the resulting transform would be discrete.
        Parameters:
        matrix - The matrix to use for the transform
        Returns:
        The new transform, or Optional.empty()
      • fromTranslation

        public static DiscreteTransform3 fromTranslation​(Vector3i vector)
        Returns a new transform representing a translation.
        Parameters:
        vector - The translation vector
        Returns:
        The new translation transform
      • fromTranslation

        public static DiscreteTransform3 fromTranslation​(int x,
                                                         int y,
                                                         int z)
        Returns a new transform representing a translation.
        Parameters:
        x - The x coordinate of the translation
        y - The y coordinate of the translation
        z - The z coordinate of the translation
        Returns:
        The new translation transform
      • fromScale

        public static DiscreteTransform3 fromScale​(int a)
        Returns a new transform representing a scaling. The scale factor must be non-zero.
        Parameters:
        a - The scale factor
        Returns:
        The new scale transform
      • fromScale

        public static DiscreteTransform3 fromScale​(Vector3i vector)
        Returns a new transform representing a scaling on each axis. The scale factors must be non-zero.
        Parameters:
        vector - The scale vector
        Returns:
        The new scale transform
      • fromScale

        public static DiscreteTransform3 fromScale​(int x,
                                                   int y,
                                                   int z)
        Returns a new transform representing a scaling on each axis. The scale factors must be non-zero.
        Parameters:
        x - The scale factor on x
        y - The scale factor on y
        z - The scale factor on z
        Returns:
        The new scale transform
      • fromRotation

        public static DiscreteTransform3 fromRotation​(int quarterTurns,
                                                      Axis axis)
        Returns a new transform representing a rotation around an axis around the origin. The rotation is given is quarter turns. The actual rotation is quarterTurns * 90. The rotation is around the block center, not the corner.
        Parameters:
        quarterTurns - The number of quarter turns in this rotation
        axis - The axis to rotate around
        Returns:
        The new rotation transform
      • fromRotation

        public static DiscreteTransform3 fromRotation​(int quarterTurns,
                                                      Axis axis,
                                                      Vector3i point,
                                                      boolean blockCorner)
        Returns a new transform representing a rotation around an axis, around a given point. The rotation is given is quarter turns. The actual rotation is quarterTurns * 90. The block corner flag change the point to be the block corner instead of the center.
        Parameters:
        quarterTurns - The number of quarter turns in this rotation
        axis - The axis to rotate around
        point - The point of rotation, as block coordinates
        blockCorner - Whether or not to use the corner of the block instead of the center
        Returns:
        The new rotation transform
      • fromRotation

        public static DiscreteTransform3 fromRotation​(int halfTurns,
                                                      Axis axis,
                                                      Vector3i point,
                                                      boolean blockCornerX,
                                                      boolean blockCornerY,
                                                      boolean blockCornerZ)
        Returns a new transform representing a rotation around an axis, around a given point. The rotation is given in half turns. The actual rotation is halfTurns * 180. When all flags are false, the center is used. When only one is true the face traversed by the axis of flag is used. When two are true the edge in the direction of the remaining flag is used. When all are true the upper corner is used.
        Parameters:
        halfTurns - The number of half turns in this rotation
        axis - The axis to rotate around
        point - The point of rotation, as block coordinates
        blockCornerX - Whether or not to use the corner of the block instead of the center on the x axis
        blockCornerY - Whether or not to use the corner of the block instead of the center on the y axis
        blockCornerZ - Whether or not to use the corner of the block instead of the center on the z axis
        Returns:
        The new rotation transform
      • rotationAroundCenter

        public static DiscreteTransform3 rotationAroundCenter​(int quarterTurns,
                                                              Axis axis,
                                                              Vector3i size)
        Returns a new transform representing a centered rotation of an volume of blocks. The rotation is given is quarter turns. The actual rotation is quarterTurns * 90. Volumes with differing parities on the axes can only be rotated by multiples of 180 degrees.
        Parameters:
        quarterTurns - The amount of quarter turns in this rotation
        axis - Axis for rotation
        size - The size of the volume to rotate
        Returns:
        The new rotation transform