/** * 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); }
/** * 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); }