def insert_arc_among_existing(self, point): arc = self.beach_line while arc is not None: intersection_point = check_if_arc_intersects(point, arc) if intersection_point is not None: second_intersection_point = check_if_arc_intersects( point, arc.next) if arc.next is not None and second_intersection_point is None: arc.next.prev = Arc(arc.point, arc, arc.next) arc.next = arc.next.prev else: arc.next = Arc(arc.point, arc) arc.next.lower_edge = arc.lower_edge arc.next.prev = Arc(point, arc, arc.next) arc.next = arc.next.prev arc = arc.next edge = Edge(intersection_point) self.voronoi.append(edge) arc.prev.lower_edge = arc.upper_edge = edge edge = Edge(intersection_point) self.voronoi.append(edge) arc.next.upper_edge = arc.lower_edge = edge self.check_circle_event(arc) self.check_circle_event(arc.prev) self.check_circle_event(arc.next) return True arc = arc.next return False
def arc_insert(self, p): if self.arc is None: self.arc = Arc(p) else: # find the current arcs at p.y i = self.arc while i is not None: flag, z = self.intersect(p, i) if flag: # new parabola intersects arc i flag, zz = self.intersect(p, i.pnext) if (i.pnext is not None) and (not flag): i.pnext.pprev = Arc(i.p, i, i.pnext) i.pnext = i.pnext.pprev else: i.pnext = Arc(i.p, i) i.pnext.s1 = i.s1 # add p between i and i.pnext i.pnext.pprev = Arc(p, i, i.pnext) i.pnext = i.pnext.pprev i = i.pnext # now i points to the new arc # add new half-edges connected to i's endpoints seg = Segment(z) self.output.append(seg) i.pprev.s1 = i.s0 = seg seg = Segment(z) self.output.append(seg) i.pnext.s0 = i.s1 = seg # check for new circle events around the new arc self.check_circle_event(i, p.x) self.check_circle_event(i.pprev, p.x) self.check_circle_event(i.pnext, p.x) return i = i.pnext # if p never intersects an arc, append it to the list i = self.arc while i.pnext is not None: i = i.pnext i.pnext = Arc(p, i) # insert new segment between p and i x = self.x0 y = (i.pnext.p.y + i.p.y) / 2.0; start = Point(x, y) seg = Segment(start) i.s1 = i.pnext.s0 = seg self.output.append(seg)
def insert_arc(self, point): if self.beach_line is None: self.beach_line = Arc(point) return if self.insert_arc_among_existing(point): return arc = self.beach_line while arc.next is not None: arc = arc.next arc.next = Arc(point, arc) x = self.LEFT y = (arc.next.point.y + arc.point.y) / 2.0 start = Point(x, y) edge = Edge(start) arc.lower_edge = arc.next.upper_edge = edge self.voronoi.append(edge)