Beispiel #1
0
    protected TriangleTree GetContainingTriangle(GraphNode node)
    {
        TriangleTree tri_within        = tris;
        bool         outside_triangles = true;

        while (!tri_within.IsLeaf())
        {
            foreach (TriangleTree sub_tri in tri_within.GetChildren())
            {
                if (sub_tri.IsInTriangle(node))
                {
                    tri_within        = sub_tri;
                    outside_triangles = false;
                    break;
                }
            }
            if (outside_triangles)
            {
                return(null);
            }
            outside_triangles = true;
        }

        return(tri_within);
    }
Beispiel #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);
    }