public void SimpleShapeShouldReturn0WhenNoConnections()
        {
            AdjacencyMap   adjacencyMap = new AdjacencyMap();
            AdjacencyShape result       = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.O);
        }
        public void SimpleShapeShouldReturnLWhenHasTwoAdjacentOrthogonalConnections()
        {
            AdjacencyMap adjacencyMapNorthEast = new AdjacencyMap();

            adjacencyMapNorthEast.SetConnection(Direction.North, existingConnection);
            adjacencyMapNorthEast.SetConnection(Direction.East, existingConnection);
            AdjacencyMap adjacencyMapSouthEast = new AdjacencyMap();

            adjacencyMapSouthEast.SetConnection(Direction.South, existingConnection);
            adjacencyMapSouthEast.SetConnection(Direction.East, existingConnection);
            AdjacencyMap adjacencyMapSouthWest = new AdjacencyMap();

            adjacencyMapSouthWest.SetConnection(Direction.South, existingConnection);
            adjacencyMapSouthWest.SetConnection(Direction.West, existingConnection);
            AdjacencyMap adjacencyMapNorthWest = new AdjacencyMap();

            adjacencyMapNorthWest.SetConnection(Direction.North, existingConnection);
            adjacencyMapNorthWest.SetConnection(Direction.West, existingConnection);

            AdjacencyShape resultNorthEast = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthEast);
            AdjacencyShape resultSouthEast = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapSouthEast);
            AdjacencyShape resultSouthWest = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapSouthWest);
            AdjacencyShape resultNorthWest = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthWest);

            Assert.IsTrue(resultNorthEast == AdjacencyShape.L);
            Assert.IsTrue(resultSouthEast == AdjacencyShape.L);
            Assert.IsTrue(resultSouthWest == AdjacencyShape.L);
            Assert.IsTrue(resultNorthWest == AdjacencyShape.L);
        }
        public void SimpleShapeShouldReturn0WhenHasOnlyDiagonalConnections()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.NorthEast, existingConnection);
            adjacencyMap.SetConnection(Direction.SouthWest, existingConnection);

            AdjacencyShape result = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.O);
        }
        public void SimpleShapeShouldReturnTWhenHasThreeOrthogonalConnections()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.North, existingConnection);
            adjacencyMap.SetConnection(Direction.East, existingConnection);
            adjacencyMap.SetConnection(Direction.South, existingConnection);

            AdjacencyShape result = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.T);
        }
示例#5
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap)
        {
            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            AdjacencyShape shape = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            switch (shape)
            {
            case AdjacencyShape.O:
                mesh = o;
                break;

            case AdjacencyShape.U:
                mesh     = u;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection());
                break;

            case AdjacencyShape.I:
                mesh     = i;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East);
                break;

            case AdjacencyShape.L:
                mesh     = l;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections());
                break;

            case AdjacencyShape.T:
                mesh     = t;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.X:
                mesh = x;
                break;

            default:
                Debug.LogError($"Received unexpected shape from simple shape resolver: {shape}");
                mesh = o;
                break;
            }

            return(new MeshDirectionInfo {
                Mesh = mesh, Rotation = rotation
            });
        }
        public void SimpleShapeShouldReturnIWhenHasTwoOppositeOrthogonalConnections()
        {
            AdjacencyMap adjacencyMapNorthSouth = new AdjacencyMap();

            adjacencyMapNorthSouth.SetConnection(Direction.North, existingConnection);
            adjacencyMapNorthSouth.SetConnection(Direction.South, existingConnection);
            AdjacencyMap adjacencyMapEastWest = new AdjacencyMap();

            adjacencyMapEastWest.SetConnection(Direction.East, existingConnection);
            adjacencyMapEastWest.SetConnection(Direction.West, existingConnection);

            AdjacencyShape resultNorthSouth = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthSouth);
            AdjacencyShape resultEastWest   = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapEastWest);

            Assert.IsTrue(resultNorthSouth == AdjacencyShape.I);
            Assert.IsTrue(resultEastWest == AdjacencyShape.I);
        }
        public void SimpleShapeShouldReturnUWhenSingleOrthogonalConnection()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.North, existingConnection);
            AdjacencyShape resultN = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            adjacencyMap.SetConnection(Direction.North, missingConnection);
            adjacencyMap.SetConnection(Direction.East, existingConnection);
            AdjacencyShape resultE = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            adjacencyMap.SetConnection(Direction.East, missingConnection);
            adjacencyMap.SetConnection(Direction.South, existingConnection);
            AdjacencyShape resultS = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            adjacencyMap.SetConnection(Direction.South, missingConnection);
            adjacencyMap.SetConnection(Direction.West, existingConnection);
            AdjacencyShape resultW = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            Assert.IsTrue(resultN == AdjacencyShape.U);
            Assert.IsTrue(resultE == AdjacencyShape.U);
            Assert.IsTrue(resultS == AdjacencyShape.U);
            Assert.IsTrue(resultW == AdjacencyShape.U);
        }