Added functions to dump the current tree in graphviz format and to print the beachline.
Added functions to dump the current tree in graphviz format and to print the beachline.

file:a/voronoi.py -> file:b/voronoi.py
--- a/voronoi.py
+++ b/voronoi.py
@@ -236,16 +236,48 @@
             else:
                 self.parent.set_right(self.left)
 
-    def dump_tree(self):
+    def dump_tree(self,path):
+        fh=open(path,'w')
+
+        fh.write('digraph G {\n')
+        name='root'
+        self.dump_node(fh,name)
+        fh.write('}\n')
+        fh.close()
+
+    def dump_node(self,fh,name):
         if self.is_leaf():
-            print self,self.parabola.point
-        else:
-            print self,self.left,self.right
-        if self.right!=None:
-            self.right.dump_tree()
-        if self.left!=None:
-            self.left.dump_tree()      
+            label='%s\\n(%.1f,%.1f)'%(self,self.parabola.point[0],self.parabola.point[1])
+            fh.write('\t%s [label="%s"];\n'%(name,label))
+        else:
+            label='%s\\np (%.1f,%.1f)\\nd (%.1f,%.1f)'%(self,self.edge.start[0],self.edge.start[1],self.edge.direction[0],self.edge.direction[1])
+            fh.write('\t%s [label="%s"];\n'%(name,label))
+
+            self.left.dump_node(fh,name+'l')
+            self.right.dump_node(fh,name+'r')
+
+            fh.write('\t%s -> %s;\n'%(name,name+'l'));
+            fh.write('\t%s -> %s;\n'%(name,name+'r'));
             
+    def dump_beachline(self,ypp):
+        if self.is_leaf():
+            return str(self.parabola.point)
+        else:
+            str1=self.left.dump_beachline(ypp)
+            str2=self.right.dump_beachline(ypp)
+
+            r1=1/(self.edge.lp[1]-ypp)
+            r2=1/(self.edge.rp[1]-ypp)
+            a=r1-r2
+            b=2*(self.edge.rp[0]*r2-self.edge.lp[0]*r1)
+            c=r1*(self.edge.lp[0]**2+self.edge.lp[1]**2-ypp**2)-r2*(self.edge.rp[0]**2+self.edge.rp[1]**2-ypp**2)
+            
+            x1=(-b-sqrt(b**2-4*a*c))/(2*a)
+            x2=(-b+sqrt(b**2-4*a*c))/(2*a)
+            
+            x=x1
+
+            return '%s |%f| %s'%(str1,x,str2)
 
 class Voronoi:
     def __init__(self,points,width,height):