def construct_begin_edge(output: [Edge], tree: Tree, vertices: [Point], ray: Ray): vertex = ray.end leftmost = tree.leftmost z = ray.intersect(leftmost.edge) if z is None: raise ValueError("No intersections") # finding right point for construct edge with point z x, y = leftmost.edge.get_points() n = x if get_angle(ray.start, ray.end, x) < get_angle( ray.start, ray.end, y) else y partial_edge = Edge(n, z, visible=leftmost.edge.visible) new_node = Node(partial_edge) edge1, edge2 = n.edges if edge1 == leftmost.edge: edge1 = partial_edge else: edge2 = partial_edge n.edges = edge1, edge2 tree.update(old=leftmost, new=new_node, ray=ray) new_edge = Edge(z, vertex, visible=False) output.append(new_edge)
def update(tree: Tree, old: Edge, new: Edge, ray: Ray): assert_edge(ray, old) assert_edge(ray, new) old = Node(old, ray.intersect_dist(old)) new = Node(new, ray.intersect_dist(new)) tree.update(old, new, ray)