/** * Returns a new transform representing a translation. * * @param x The x coordinate of the translation * @param y The y coordinate of the translation * @return The new translation transform */ public static DiscreteTransform2 fromTranslation(int x, int y) { return new DiscreteTransform2(Matrix3d.createTranslation(x, y)); }
/** * Returns a transform that is the composition of the given transform with * this transform. The result will apply the given transformation after * this one. * * @param that The transform to compose with * @return The new composed transform */ public DiscreteTransform2 andThen(DiscreteTransform2 that) { return that.compose(this); }
/** * Returns a new transform representing a centered rotation of an area of * tiles. The rotation is given is quarter turns. The actual rotation is * {@code quarterTurns * 90}. Areas with differing parities on the axes can * only be rotated by multiples of 180 degrees. * * @param quarterTurns The amount of quarter turns in this rotation * @param size The size of the area to rotate * @return The new rotation transform */ public static DiscreteTransform2 rotationAroundCenter(int quarterTurns, Vector2i size) { Preconditions.checkArgument(size.getX() > 0, "The size on x must be positive"); Preconditions.checkArgument(size.getY() > 0, "The size on y must be positive"); final boolean mul180 = (quarterTurns & 1) == 0; final boolean xEven = (size.getX() & 1) == 0; final boolean yEven = (size.getY() & 1) == 0; Preconditions.checkArgument(mul180 || xEven == yEven, "The size must have the same parity on all axes for rotations that are " + "not a multiple of 180 degrees"); final Vector2i center = size.sub(1, 1).div(2); if (mul180) { return fromRotation(quarterTurns, center, xEven, yEven); } return fromRotation(quarterTurns, center, xEven); }
/** * Adds another transformation to this transformation and returns int as a * new transform. * * @param transform The transformation to add * @return The added transforms as a copy */ public DiscreteTransform2 withTransformation(DiscreteTransform2 transform) { return new DiscreteTransform2(transform.getMatrix().mul(getMatrix())); }
/** * Transform a vector represented as a pair of coordinates using this * transform. * * @param x The x coordinate of the original vector * @param y The y coordinate of the original vector * @return The transformed vector */ public Vector2i transform(int x, int y) { return new Vector2i(transformX(x, y), transformY(x, y)); }
switch (axis) { case X: { final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getZ(), size.getY())).getMatrix(); rotation3 = new Matrix4d( 1, 0, 0, 0, final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getX(), size.getZ())).getMatrix(); rotation3 = new Matrix4d( rotation2.get(0, 0), 0, rotation2.get(0, 1), rotation2.get(0, 2), final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getX(), size.getY())).getMatrix(); rotation3 = new Matrix4d( rotation2.get(0, 0), rotation2.get(0, 1), 0, rotation2.get(0, 2),
/** * Returns a new transform representing a scaling. * The scale factor must be non-zero. * * @param a The scale factor * @return The new scale transform */ public static DiscreteTransform2 fromScale(int a) { return fromScale(a, a); }
/** * Transforms the y coordinate of a vector using this transform. Only * creates a new object on the first call. * * @param vector The original vector * @return The transformed y coordinate */ public int transformY(Vector2i vector) { return transformY(vector.getX(), vector.getY()); }
/** * Transforms a vector using this transforms. * * @param vector The original vector * @return The transformed vector */ public Vector2i transform(Vector2i vector) { return transform(vector.getX(), vector.getY()); }
/** * Returns a new transform representing a translation. * * @param vector The translation vector * @return The new translation transform */ public static DiscreteTransform2 fromTranslation(Vector2i vector) { return fromTranslation(vector.getX(), vector.getY()); }
/** * Transforms the x coordinate of a vector using this transform. Only * creates a new object on the first call. * * @param vector The original vector * @return The transformed x coordinate */ public int transformX(Vector2i vector) { return transformX(vector.getX(), vector.getY()); }
/** * Transform a vector represented as a pair of coordinates using this * transform. * * @param x The x coordinate of the original vector * @param y The y coordinate of the original vector * @return The transformed vector */ public Vector2i transform(int x, int y) { return new Vector2i(transformX(x, y), transformY(x, y)); }
/** * Adds another transformation to this transformation and returns int as a * new transform. * * @param transform The transformation to add * @return The added transforms as a copy */ public DiscreteTransform2 withTransformation(DiscreteTransform2 transform) { return new DiscreteTransform2(transform.getMatrix().mul(getMatrix())); }
switch (axis) { case X: { final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getZ(), size.getY())).getMatrix(); rotation3 = new Matrix4d( 1, 0, 0, 0, final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getX(), size.getZ())).getMatrix(); rotation3 = new Matrix4d( rotation2.get(0, 0), 0, rotation2.get(0, 1), rotation2.get(0, 2), final Matrix3d rotation2 = DiscreteTransform2.rotationAroundCenter(quarterTurns, new Vector2i(size.getX(), size.getY())).getMatrix(); rotation3 = new Matrix4d( rotation2.get(0, 0), rotation2.get(0, 1), 0, rotation2.get(0, 2),
/** * Returns a new transform representing a scaling on each axis. The scale * factors must be non-zero. * * @param vector The scale vector * @return The new scale transform */ public static DiscreteTransform2 fromScale(Vector2i vector) { return fromScale(vector.getX(), vector.getY()); }
/** * Transforms the y coordinate of a vector using this transform. Only * creates a new object on the first call. * * @param vector The original vector * @return The transformed y coordinate */ public int transformY(Vector2i vector) { return transformY(vector.getX(), vector.getY()); }
/** * Transforms a vector using this transforms. * * @param vector The original vector * @return The transformed vector */ public Vector2i transform(Vector2i vector) { return transform(vector.getX(), vector.getY()); }
/** * Returns a new transform representing a translation. * * @param vector The translation vector * @return The new translation transform */ public static DiscreteTransform2 fromTranslation(Vector2i vector) { return fromTranslation(vector.getX(), vector.getY()); }
/** * Transforms the x coordinate of a vector using this transform. Only * creates a new object on the first call. * * @param vector The original vector * @return The transformed x coordinate */ public int transformX(Vector2i vector) { return transformX(vector.getX(), vector.getY()); }
/** * Adds a translation to this transform and returns it as a new transform. * * @param x The x coordinate of the translation * @param y The y coordinate of the translation * @return The translated transform as a copy */ public DiscreteTransform2 withTranslation(int x, int y) { return new DiscreteTransform2(this.matrix.translate(x, y)); }