void FinishEdge(BeachNode node)
    {
        if (node.GetType() == typeof(BeachArc))
        {
            return;
        }
        BeachEdge n = (BeachEdge)node;
        float     mx;

        if (n.edge.direction.x > 0)
        {
            mx = Mathf.Max(width, n.edge.start.pos.x + 10);
        }
        else
        {
            mx = Mathf.Max(0, n.edge.start.pos.x - 10);
        }

        Vertex end = new Vertex(new Vector2(mx, mx * n.edge.f + n.edge.g));

        n.edge.end = end;
        diagram.vertices.Add(end);
        diagram.edges.Add(n.edge);

        FinishEdge(n.left);
        FinishEdge(n.right);
    }
        public static BeachArc GetRightChild(BeachNode n)
        {
            if (n == null)
            {
                return(null);
            }
            BeachNode child = n.right;

            while (child.GetType() != typeof(BeachArc))
            {
                child = child.left;
            }
            return((BeachArc)child);
        }
 string PrintNode(BeachNode n)
 {
     if (n.GetType() == typeof(BeachArc))
     {
         return(((BeachArc)n).site.name + " ");
     }
     else
     {
         BeachEdge edgeNode = (BeachEdge)n;
         string    left     = PrintNode(n.left);
         string    right    = PrintNode(n.right);
         float     x        = GetXOfEdge(edgeNode, sweep);
         float     y        = edgeNode.edge.f * x + edgeNode.edge.g;
         return(left + "[" + x.ToString("0.0") + ", " + y.ToString("0.0") + "] " + right);
     }
 }
    List <Vector2> GetBreaks(BeachNode n)
    {
        if (n.GetType() == typeof(BeachArc))
        {
            return(new List <Vector2>());
        }
        BeachEdge      edgeNode = (BeachEdge)n;
        List <Vector2> left     = GetBreaks(n.left);
        float          x        = GetXOfEdge(edgeNode, sweep);
        float          y        = edgeNode.edge.f * x + edgeNode.edge.g;

        left.Add(new Vector2(x, y));
        List <Vector2> right = GetBreaks(n.right);

        left.AddRange(right);
        return(left);
    }
    public BeachArc GetParabolaByX(float x)
    {
        BeachNode par = root;
        float     cur = 0;

        while (par.GetType() != typeof(BeachArc))
        {
            cur = GetXOfEdge((BeachEdge)par, sweep);
            if (cur > x)
            {
                par = par.left;
            }
            else
            {
                par = par.right;
            }
        }
        return((BeachArc)par);
    }