Exemplo n.º 1
0
def draw_ticks_ftree(T_in, B_in, context, v2_in, v_to_location):
    """
    Increased barb radius.
    """
    eps = 1e-8
    T = set(T_in)
    B = dict(B_in)
    v2 = dict(v2_in)
    # break the branches according to valuation signs of v2
    FtreeAux.break_branches_by_vertex_sign(T, B, v2, eps)
    # add the new locations for internal vertices
    v_to_x = dict((v, x) for v, (x, y) in v_to_location.items())
    v_to_y = dict((v, y) for v, (x, y) in v_to_location.items())
    FtreeAux.harmonically_interpolate(T, B, v_to_x)
    FtreeAux.harmonically_interpolate(T, B, v_to_y)
    vertices = Ftree.T_to_order(T)
    v_to_location = dict((v, (v_to_x[v], v_to_y[v])) for v in vertices)
    # draw the ticks
    v_to_neighbors = Ftree.T_to_v_to_neighbors(T)
    for v, location in v_to_location.items():
        x, y = location
        neighbors = v_to_neighbors[v]
        if abs(v2[v]) > eps:
            continue
        if len(neighbors) == 2:
            barb_radius_cm = 0.1
            va, vb = neighbors
            ax, ay = v_to_location[va]
            bx, by = v_to_location[vb]
            theta = math.atan2(by - ay, bx - ax)
            barbx1 = x + barb_radius_cm * math.cos(theta + math.pi/2)
            barby1 = y + barb_radius_cm * math.sin(theta + math.pi/2)
            barbx2 = x + barb_radius_cm * math.cos(theta - math.pi/2)
            barby2 = y + barb_radius_cm * math.sin(theta - math.pi/2)
            context.draw_dark_line(barbx1, barby1, barbx2, barby2)
        elif len(neighbors) > 2:
            if max(abs(v2[n]) for n in neighbors) < eps:
                continue
            context.draw_dark_dot(x, y)
Exemplo n.º 2
0
def draw_ticks_ftree(T_in, B_in, context, v2_in, v_to_location):
    """
    Increased barb radius.
    """
    eps = 1e-8
    T = set(T_in)
    B = dict(B_in)
    v2 = dict(v2_in)
    # break the branches according to valuation signs of v2
    FtreeAux.break_branches_by_vertex_sign(T, B, v2, eps)
    # add the new locations for internal vertices
    v_to_x = dict((v, x) for v, (x, y) in v_to_location.items())
    v_to_y = dict((v, y) for v, (x, y) in v_to_location.items())
    FtreeAux.harmonically_interpolate(T, B, v_to_x)
    FtreeAux.harmonically_interpolate(T, B, v_to_y)
    vertices = Ftree.T_to_order(T)
    v_to_location = dict((v, (v_to_x[v], v_to_y[v])) for v in vertices)
    # draw the ticks
    v_to_neighbors = Ftree.T_to_v_to_neighbors(T)
    for v, location in v_to_location.items():
        x, y = location
        neighbors = v_to_neighbors[v]
        if abs(v2[v]) > eps:
            continue
        if len(neighbors) == 2:
            barb_radius_cm = 0.1
            va, vb = neighbors
            ax, ay = v_to_location[va]
            bx, by = v_to_location[vb]
            theta = math.atan2(by - ay, bx - ax)
            barbx1 = x + barb_radius_cm * math.cos(theta + math.pi / 2)
            barby1 = y + barb_radius_cm * math.sin(theta + math.pi / 2)
            barbx2 = x + barb_radius_cm * math.cos(theta - math.pi / 2)
            barby2 = y + barb_radius_cm * math.sin(theta - math.pi / 2)
            context.draw_dark_line(barbx1, barby1, barbx2, barby2)
        elif len(neighbors) > 2:
            if max(abs(v2[n]) for n in neighbors) < eps:
                continue
            context.draw_dark_dot(x, y)