Example #1
0
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 get_config_tree(config_str):
    config_tokens = config_str.split()

    if "nil" not in config_tokens:
        config_str += " " + " ".join(["nil"] * len(config_tokens))

    tree = Tree()
    tree.parse(config_str, int)
    # convert from 1-indexed to zero-indexed
    tree = tree.dfs(lambda x: x - 1)

    return tree
def get_config_tree(config_str):
    config_tokens = config_str.split()

    if 'nil' not in config_tokens:
        config_str += ' ' + ' '.join(['nil'] * len(config_tokens))

    tree = Tree()
    tree.parse(config_str, int)
    # convert from 1-indexed to zero-indexed
    tree = tree.dfs(lambda x: x - 1)

    return tree
Example #4
0
def init_tree(edges, ray) -> Tree:
    nodes = []
    for edge in edges:
        assert_edge(ray, edge)
        dist = ray.start.dist(ray.intersect(edge))
        nodes.append(Node(edge, dist))

    return Tree(nodes)
Example #5
0
#!/usr/bin/env python

from tree_ import Tree
from sys import argv

assert (len(argv) == 2)

t = Tree()

# method 2
t.parse(argv[1], str, 2)
print t.to_string()

# method 1
t.parse(argv[1], str)
print t.to_string()
Example #6
0
def insert(tree: Tree, edge: Edge, ray: Ray):
    assert_edge(ray, edge)
    node = Node(edge, ray.intersect_dist(edge))
    tree.insert(node, ray)
Example #7
0
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)
Example #8
0
#!/usr/bin/env python

from tree_ import Tree
from sys import argv

assert(len(argv) == 2)

t = Tree()

# method 2
t.parse(argv[1], str, 2)
print t.to_string()

# method 1
t.parse(argv[1], str)
print t.to_string()