Example #1
0
        public void When_FindFloorFacesOfSimpleCube_Expect_TwoBottomFaces(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int> floorFaces = ComponentGraphGenerator.GetFloorFaces(simpleCube);

            Assert.AreEqual(2, floorFaces.Count);
            Assert.Contains(6, floorFaces);
            Assert.Contains(7, floorFaces);
        }
Example #2
0
        public void When_GetShellVerticesOfSimpleCube_Expect_FloorSideVertices(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int>       floorFaces        = ComponentGraphGenerator.GetFloorFaces(simpleCube);
            LinkedList <int> floorSideVertices = ComponentGraphGenerator.GetShellVertices(simpleCube, floorFaces);

            Assert.AreEqual(4, floorSideVertices.Count);
            Assert.Contains(1, floorSideVertices);
            Assert.Contains(3, floorSideVertices);
            Assert.Contains(0, floorSideVertices);
            Assert.Contains(5, floorSideVertices);
        }
Example #3
0
        public void When_SplitLinkedListOfSimpleCube_Expect_LongSideVertices(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int>       floorFaces        = ComponentGraphGenerator.GetFloorFaces(simpleCube);
            LinkedList <int> floorSideVertices = ComponentGraphGenerator.GetShellVertices(simpleCube, floorFaces);

            (LinkedList <int>, LinkedList <int>)sides = ComponentGraphGenerator.SplitLinkedList(simpleCube, floorSideVertices);

            Assert.AreEqual(2, sides.Item1.Count);
            Assert.AreEqual(2, sides.Item2.Count);
            Assert.Contains(0, sides.Item1);
            Assert.Contains(1, sides.Item1);
            Assert.Contains(3, sides.Item2);
            Assert.Contains(5, sides.Item2);
        }
Example #4
0
    public void DrawStructure(DrawStructure choices, Structure structure, Vect3 structureMiddlePoint)
    {
        GameObject structureObject = new GameObject("Structure");

        for (int componentIndex = 0; componentIndex < structure.components.Count; componentIndex++)
        {
            GameObject componentObject = new GameObject(string.Format("Component {0}", componentIndex));
            componentObject.transform.parent = structureObject.transform;
            Nodegraph_Generator.Component component = structure.components[componentIndex];

            // To prepare color
            List <int>       floorFaces = ComponentGraphGenerator.GetFloorFaces(component);
            LinkedList <int> linkedList = ComponentGraphGenerator.GetShellVertices(component, floorFaces);
            (LinkedList <int>, LinkedList <int>)sidePair = ComponentGraphGenerator.SplitLinkedList(component, linkedList);

            if (choices.drawVertices)
            {
                GameObject verticesObject = new GameObject(string.Format("Component {0}, Vertices", componentIndex));
                verticesObject.transform.parent = componentObject.transform;
                for (int vertexIndex = 0; vertexIndex < component.vertices.Count; vertexIndex++)
                {
                    Vertex     vertex         = component.GetVertex(vertexIndex);
                    Vect3      vertexPosition = Utilities.GetScaledTransletedVect3(vertex.coordinate, structureMiddlePoint, scalingFactor);
                    GameObject vertexObject   = Utilities.DrawObject(vertexPrefab, vertexPosition, verticesObject);
                    vertexObject.name = string.Format("Vertex {0}", vertexIndex);
                    if (choices.colorFloor)
                    {
                        if (sidePair.Item1.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.blue);
                        }
                        else if (sidePair.Item2.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.red);
                        }
                    }
                }
            }

            if (choices.drawFaces)
            {
                var        drawnVertexPairs = new List <(int, int)>();
                var        drawnFaceSides   = new List <GameObject>();
                GameObject faces            = new GameObject(string.Format("Component {0}, Faces", componentIndex));
                faces.transform.parent = componentObject.transform;
                for (int faceIndex = 0; faceIndex < component.faces.Count; faceIndex++)
                {
                    Face face            = component.GetFace(faceIndex);
                    var  faceMiddlepoint = new Vect3();
                    for (int i = 0; i < face.vertexIndices.Length; i++)
                    {
                        int    firstVertexIndex = face.vertexIndices[i];
                        Vertex firstVertex      = component.GetVertex(firstVertexIndex);
                        faceMiddlepoint += firstVertex.coordinate;
                        for (int j = i + 1; j < face.vertexIndices.Length; j++)
                        {
                            int secondVertexIndex = face.vertexIndices[j];
                            if (!(drawnVertexPairs.Contains((firstVertexIndex, secondVertexIndex)) ||
                                  drawnVertexPairs.Contains((secondVertexIndex, firstVertexIndex))))
                            {
                                Vertex secondVertex = component.GetVertex(secondVertexIndex);
                                Vect3  startPos     = Utilities.GetScaledTransletedVect3(firstVertex.coordinate,
                                                                                         structureMiddlePoint, scalingFactor);
                                Vect3 endPos = Utilities.GetScaledTransletedVect3(secondVertex.coordinate,
                                                                                  structureMiddlePoint, scalingFactor);
                                GameObject faceSideObject = Utilities.DrawLine(startPos, endPos, faces);
                                faceSideObject.name = string.Format("Faceside to Face {0}", faceIndex);
                                Utilities.ColorObject(faceSideObject,
                                                      (choices.colorFloor && floorFaces.Contains(faceIndex)) ? Color.green : Color.black);
                                drawnVertexPairs.Add((secondVertexIndex, firstVertexIndex));
                                drawnFaceSides.Add(faceSideObject);
                            }
                            else
                            {
                                GameObject faceSideObject = drawnFaceSides[drawnVertexPairs.FindIndex(a =>
                                                                                                      (a.Item1 == firstVertexIndex && a.Item2 == secondVertexIndex) || (a.Item1 == secondVertexIndex && a.Item2 == firstVertexIndex))];
                                if (choices.colorFloor && floorFaces.Contains(faceIndex))
                                {
                                    Utilities.ColorObject(faceSideObject, Color.green);
                                }
                                faceSideObject.name += ", " + faceIndex;
                            }
                        }
                    }
Example #5
0
        public void When_FindFloorOfSimpleCube_Expect_TwoFaces(Structure structure)
        {
            Component simpleCube = structure.components[0];

            Assert.AreEqual(2, ComponentGraphGenerator.GetFloorFaces(simpleCube).Count);
        }