public void FloatRotationsKeepDecimals() { Vector2 coord1 = new Vector2(39.4f, 12.2f); Assert.AreEqual(TileTransformer.RotateCoord(coord1), new Vector2(39.4f, 12.2f)); Assert.AreEqual(TileTransformer.InverseRotateCoord(coord1), new Vector2(39.4f, 12.2f)); OrientationManager.SetOrientation(Orientation.West); Assert.AreEqual(TileTransformer.RotateCoord(coord1), new Vector2(12.2f, -39.4f)); Assert.AreEqual(TileTransformer.InverseRotateCoord(coord1), new Vector2(-12.2f, 39.4f)); }
public void RegularRotationBehaviour() { Vector2Int coord = new Vector2Int(34, -21); OrientationManager.SetOrientation(Orientation.East); Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(21, 34)); OrientationManager.SetOrientation(Orientation.West); Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(-21, -34)); OrientationManager.SetOrientation(Orientation.South); Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(-34, 21)); }
public void NorthRotationIsIdentity() { OrientationManager.SetOrientation(Orientation.North); Vector2Int coord1 = new Vector2Int(73, 12); Vector2Int coord2 = new Vector2Int(-89, 22); Vector2Int coord3 = new Vector2Int(10, -4); Assert.AreEqual(coord1, TileTransformer.RotateCoord(coord1)); Assert.AreEqual(coord2, TileTransformer.RotateCoord(coord2)); Assert.AreEqual(coord3, TileTransformer.RotateCoord(coord3)); Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(coord1)); Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(coord2)); Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(coord3)); }
public void CoordToWorldRotates() { OrientationManager.SetOrientation(Orientation.North); Vector2Int originalCoord = new Vector2Int(77, 23); Vector2 originalWorld = TileTransformer.CoordToWorld(originalCoord); OrientationManager.SetOrientation(Orientation.East); Vector2Int eastCoord = TileTransformer.RotateCoord(originalCoord); Vector2 eastWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord); OrientationManager.SetOrientation(Orientation.West); Vector2Int westCoord = TileTransformer.RotateCoord(originalCoord); Vector2 westWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord); OrientationManager.SetOrientation(Orientation.South); Vector2Int southCoord = TileTransformer.RotateCoord(originalCoord); Vector2 southWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord); OrientationManager.SetOrientation(Orientation.North); Assert.AreEqual(TileTransformer.CoordToWorld(eastCoord), eastWorldFromOriginal); Assert.AreEqual(TileTransformer.CoordToWorld(westCoord), westWorldFromOriginal); Assert.AreEqual(TileTransformer.CoordToWorld(southCoord), southWorldFromOriginal); }
public void TileRotationIsInvertible() { Vector2Int coord1 = new Vector2Int(13, 32); Vector2Int coord2 = new Vector2Int(-42, 78); Vector2Int coord3 = new Vector2Int(-81, -70); // North OrientationManager.SetOrientation(Orientation.North); Vector2Int rotated1 = TileTransformer.RotateCoord(coord1); Vector2Int rotated2 = TileTransformer.RotateCoord(coord2); Vector2Int rotated3 = TileTransformer.RotateCoord(coord3); Vector2Int inverseRotated1 = TileTransformer.InverseRotateCoord(coord1); Vector2Int inverseRotated2 = TileTransformer.InverseRotateCoord(coord2); Vector2Int inverseRotated3 = TileTransformer.InverseRotateCoord(coord3); Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1)); Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2)); Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3)); Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1)); Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2)); Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3)); // East OrientationManager.SetOrientation(Orientation.East); rotated1 = TileTransformer.RotateCoord(coord1); rotated2 = TileTransformer.RotateCoord(coord2); rotated3 = TileTransformer.RotateCoord(coord3); inverseRotated1 = TileTransformer.InverseRotateCoord(coord1); inverseRotated2 = TileTransformer.InverseRotateCoord(coord2); inverseRotated3 = TileTransformer.InverseRotateCoord(coord3); Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1)); Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2)); Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3)); Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1)); Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2)); Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3)); // West OrientationManager.SetOrientation(Orientation.West); rotated1 = TileTransformer.RotateCoord(coord1); rotated2 = TileTransformer.RotateCoord(coord2); rotated3 = TileTransformer.RotateCoord(coord3); inverseRotated1 = TileTransformer.InverseRotateCoord(coord1); inverseRotated2 = TileTransformer.InverseRotateCoord(coord2); inverseRotated3 = TileTransformer.InverseRotateCoord(coord3); Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1)); Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2)); Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3)); Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1)); Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2)); Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3)); // South OrientationManager.SetOrientation(Orientation.South); rotated1 = TileTransformer.RotateCoord(coord1); rotated2 = TileTransformer.RotateCoord(coord2); rotated3 = TileTransformer.RotateCoord(coord3); inverseRotated1 = TileTransformer.InverseRotateCoord(coord1); inverseRotated2 = TileTransformer.InverseRotateCoord(coord2); inverseRotated3 = TileTransformer.InverseRotateCoord(coord3); Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1)); Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2)); Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3)); Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1)); Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2)); Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3)); }
public static int FloorOrder(int x, int y, FloorSubLayer layer) { Vector2Int rotatedCoords = TileTransformer.RotateCoord(new Vector2Int(x, y)); return(((rotatedCoords.x + rotatedCoords.y) * 10) + (int)layer); }
public static int TileOrder(int x, int y, TileSubLayer layer) { Vector2Int rotatedCoords = TileTransformer.RotateCoord(new Vector2Int(x, y)); return((rotatedCoords.x + rotatedCoords.y) * 20 + ((int)layer * 2)); }