Ejemplo n.º 1
0
    public List <GraphEdge> Triangulate(float x_low_bound, float x_high_bound, float y_low_bound, float y_high_bound)
    {
        tris = InitTris(x_low_bound, x_high_bound, y_low_bound, y_high_bound);

        GraphNode[] dummy_verts = tris.GetVertices();
        foreach (GraphNode node in nodes)
        {
            AddNode(node, dummy_verts);
        }

        List <Triangle> tri_list = tris.AsList();

        List <GraphEdge> edges = new List <GraphEdge>();

        foreach (Triangle tri in tri_list)
        {
            if (!TriangleContains(tri, tris.GetVertices()))
            {
                float       area     = tri.Area() / 3;
                GraphNode[] vertices = tri.GetVertices();
                vertices[0].Voronoi += area;
                vertices[1].Voronoi += area;
                vertices[2].Voronoi += area;

                GraphEdge edge = vertices[0].AddEdgeFromNode(vertices[1]);
                edges.Add(edge);
                vertices[1].AddEdge(edge);

                edge = vertices[0].AddEdgeFromNode(vertices[2]);
                edges.Add(edge);
                vertices[2].AddEdge(edge);

                edge = vertices[1].AddEdgeFromNode(vertices[2]);
                edges.Add(edge);
                vertices[2].AddEdge(edge);
            }
        }
        return(edges);
    }
Ejemplo n.º 2
0
    protected List <TriangleTree> FlipEdge(TriangleTree tri, TriangleTree adj)
    {
        List <GraphNode> shared_verts   = new List <GraphNode>();
        List <GraphNode> separate_verts = new List <GraphNode>();

        separate_verts.AddRange(tri.GetVertices());

        foreach (GraphNode vertex_a in adj.GetVertices())
        {
            bool separate = true;
            foreach (GraphNode vertex_b in separate_verts)
            {
                if (vertex_a.X == vertex_b.X && vertex_a.Y == vertex_b.Y)
                {
                    separate_verts.Remove(vertex_b);
                    shared_verts.Add(vertex_b);
                    separate = false;
                    break;
                }
            }
            if (separate)
            {
                separate_verts.Add(vertex_a);
            }
        }

        List <TriangleTree> new_tris = new List <TriangleTree>();

        new_tris.Add(new TriangleTree(new Triangle(separate_verts[0], separate_verts[1], shared_verts[0])));
        new_tris.Add(new TriangleTree(new Triangle(separate_verts[0], separate_verts[1], shared_verts[1])));

        // TODO: Bugfix!! Sometimes, very rarely, shared_verts[1] doesn't exist????????

        tri.GetChildren().AddRange(new_tris);
        adj.GetChildren().AddRange(new_tris);

        return(new_tris);
    }