Example #1
0
    public void Solve()
    {
        if (loadedLevel != null)
        {
            graph.DestroyEdges();
            nodeManager.ResetAll();

            int numSolutionTris = loadedLevel.solution.Count;

            foreach (Int3 face in loadedLevel.solution)
            {
                int v0 = face.a;
                int v1 = face.b;
                int v2 = face.c;

                NodeController n0 = nodeManager.nodes[v0];
                NodeController n1 = nodeManager.nodes[v1];
                NodeController n2 = nodeManager.nodes[v2];


                EdgeController edge01 = edgeCreator.Create(n0, n1);
                EdgeController edge02 = edgeCreator.Create(n0, n2);
                EdgeController edge12 = edgeCreator.Create(n1, n2);

                graph.AddEdge(edge01);
                graph.AddEdge(edge02);
                graph.AddEdge(edge12);
            }
        }
    }
Example #2
0
    /// <summary>
    /// Modified the graph, creates or removes edge if valid.
    /// </summary>
    /// <param name="joinNode">New node we are using to modify</param>
    public Outcome AttemptModification(NodeController joinNode, out object outcomeData)
    {
        outcomeData = null;
        if (!creating)
        {
            return(Outcome.None);
        }

        EdgeController foundEdge;

        if (graphLogicManager.EdgeExists(startNode, joinNode, out foundEdge))
        {
            Debug.LogFormat("Removing edge between {0} and {1}", startNode.name, joinNode.name);
            List <NodeController[]> removedFaces;
            graphLogicManager.RemoveEdge(foundEdge, out removedFaces);
            counter.EdgeCountChange(-1);
            if (removedFaces.Count > 0)
            {
                outcomeData = new object[] { foundEdge, removedFaces };
                return(Outcome.RemovedEdgeAndFaces);
            }
            else
            {
                return(Outcome.RemovedEdge);
            }
        }

        if (counter.remaining <= 0)
        {
            counter.OnCreateWithNoneRemaining();
            return(Outcome.NoEdgesRemaining);
        }

        if (graphLogicManager.IsValidEdge(startNode, joinNode))
        {
            Debug.LogFormat("Creating edge between {0} and {1}", startNode.name, joinNode.name);

            EdgeController newEdge = Create(startNode, joinNode);

            // first check if this edge intersects a face directly
            bool edgeCreatesEdgeIntersection;
            edgeCreatesEdgeIntersection = graphLogicManager.AssessEdgeIntersection(newEdge);

            if (edgeCreatesEdgeIntersection)
            {
                Debug.Log("Edge invalid! Creates edge intersection.");
                Destroy(newEdge.gameObject);
                return(Outcome.IntersectingEdge);
            }

            // if it doesnt, check if it creates a face which creates an intersection
            bool edgeCreatesFaceIntersection;
            var  newFaces = graphLogicManager.CheckForNewFaces(newEdge, out edgeCreatesFaceIntersection);

            if (edgeCreatesFaceIntersection)
            {
                Debug.Log("Edge invalid! Creates face intersection.");
                Destroy(newEdge.gameObject);
                return(Outcome.IntersectingFace);
            }
            else
            {
                Debug.Log("Adding edge to graph");
                graphLogicManager.AddEdge(newEdge);
                counter.EdgeCountChange(1);
                if (newFaces.Count > 0)
                {
                    outcomeData = new object[] { newEdge, newFaces };
                    return(Outcome.CreatedEdgeAndFaces);
                }
                else
                {
                    outcomeData = newEdge;
                    return(Outcome.CreatedEdge);
                }
            }
        }
        else
        {
            return(Outcome.InvalidNodePair);
        }
    }