Fixed circle_check on intersection when start is None. Also find_leaf works when there is only one intersection.
Fixed circle_check on intersection when start is None. Also find_leaf works when there is only one intersection.

file:a/voronoi.py -> file:b/voronoi.py
--- a/voronoi.py
+++ b/voronoi.py
@@ -155,17 +155,26 @@
         if self.is_leaf():
             return self
 
-        r1=1/(self.edge.lp[1]-point[1])
-        r2=1/(self.edge.rp[1]-point[1])
-        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-point[1]**2)-r2*(self.edge.rp[0]**2+self.edge.rp[1]**2-point[1]**2)
-
-        x1=(-b-sqrt(b**2-4*a*c))/(2*a)
-        x2=(-b+sqrt(b**2-4*a*c))/(2*a)
-
-        x=x1
-
+        x=None
+
+        if self.edge.lp[1]==self.edge.rp[1]:
+            b=2*(self.edge.rp[0]-self.edge.lp[0])
+            c=(self.edge.lp[0]**2+self.edge.lp[1]**2-self.edge.rp[0]**2-self.edge.rp[1]**2)
+            x=(self.edge.lp[0]+self.edge.rp[0])/2
+        elif self.edge.lp[1]!=self.edge.rp[1]:
+            r1=1/(self.edge.lp[1]-point[1])
+            r2=1/(self.edge.rp[1]-point[1])
+            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-point[1]**2)-r2*(self.edge.rp[0]**2+self.edge.rp[1]**2-point[1]**2)
+            
+            x1=(-b-sqrt(b**2-4*a*c))/(2*a)
+            x2=(-b+sqrt(b**2-4*a*c))/(2*a)
+
+            x=x1
+
+        if x==None:
+            print 'WARNING: Unhandled case ',self.edge.rp[1],self.edge.lp[1],point[1]
         if point[0]<x:
             return self.left.find_leaf(point)
         else:
@@ -339,6 +348,7 @@
             del leaf.circle_event
 
         self.insert_parabola(leaf,par)
+#        self.root.dump_tree('add_parabola_%s.dot'%str(point))
 
     def insert_parabola(self,node,parabola):
         if parabola.point[1]!=node.parabola.point[1]:
@@ -398,8 +408,11 @@
         edge_to_end2=circle_node.first_right_parent().edge
         t,s=edge_to_end1.intersects_with(edge_to_end2)
         
-#        print 't,s',t,s
-        if t<0 or s<0:
+        print 't,s',t,s
+        if (t<0 and edge_to_end1.start!=None) or (s<0 and edge_to_end2.start!=None):
+            return
+
+        if t==s and t==0:
             return
 
         center=edge_to_end1.value(t)
@@ -446,6 +459,8 @@
 
         self.circle_check(prev_parabola_node)
         self.circle_check(next_parabola_node)
+
+#        self.root.dump_tree('remove_parabola_%s.dot'%str(parabola_node))
 
     def finish_edges(self):
         edges=[]