def rectangle_with_add_norm(color_name, s_lst): r1 = rectangle_with_text("add_norm_color", ["Add \\& Norm"]) r2 = rectangle_with_text(color_name, s_lst) top_left_cs, bottom_right_cs = stz.bbox(r2) cs = stz.translate_coords_vertically( stz.top_center_coords(top_left_cs, bottom_right_cs), to_add_norm_spacing) stz.translate_bbox_bottom_center_to_coords(r1, cs) c = connect_straight_vertical(r2, r1) return [r1, r2, c]
def trident_coords(e): top_left_cs, bottom_right_cs = stz.bbox(e) center_cs = stz.bottom_center_coords(top_left_cs, bottom_right_cs) left_cs = stz.translate_coords_horizontally(center_cs, -trident_alpha * width / 2.0) right_cs = stz.translate_coords_horizontally(center_cs, trident_alpha * width / 2.0) cs_lst = [left_cs, center_cs, right_cs] translated_cs_lst = [ stz.translate_coords_vertically(cs, -trident_spacing) for cs in cs_lst ] return cs_lst, translated_cs_lst
def connect_residual(e_with_addnorm, bottom_spacing, side_spacing): from_cs = stz.coords_from_bbox_with_fn(e_with_addnorm, stz.bottom_center_coords) from_cs = stz.translate_coords_vertically(from_cs, -bottom_spacing) if side_spacing < 0: to_cs = stz.coords_from_bbox_with_fn(e_with_addnorm[0], stz.left_center_coords) else: to_cs = stz.coords_from_bbox_with_fn(e_with_addnorm[0], stz.right_center_coords) cs = stz.translate_coords_horizontally(from_cs, side_spacing) return stz.open_path([from_cs, cs, [cs[0], to_cs[1]], to_cs], s_con)
def label_below(e, expr): cs_ref = stz.coords_from_bbox_with_fn(e, stz.bottom_center_coords) cs = stz.translate_coords_vertically(cs_ref, -label_spacing) return stz.latex(cs, expr)
def arrow_out(e): from_cs = stz.coords_from_bbox_with_fn(e, stz.top_center_coords) to_cs = stz.translate_coords_vertically(from_cs, arrow_length) return stz.line_segment(from_cs, to_cs, s_arr)
def arrow_in(e): to_cs = stz.coords_from_bbox_with_fn(e, stz.bottom_center_coords) from_cs = stz.translate_coords_vertically(to_cs, -arrow_length) return stz.line_segment(from_cs, to_cs, s_arr)
e1 = stz.open_path([ translated_tri_cs[1], stz.bottom_left_coords(translated_tri_cs[1], tri_cs[0]), tri_cs[0] ], s_con) e2 = stz.open_path([ translated_tri_cs[1], stz.bottom_right_coords(translated_tri_cs[1], tri_cs[2]), tri_cs[2] ], s_con) connections.extend([e1, e2]) tri_cs, translated_tri_cs = trident_coords(mha2_an) # the leftmost two from_cs = stz.coords_from_bbox_with_fn(ff1_an, stz.top_center_coords) mid_cs = stz.midway_coords(stz.bbox(bb1)[1], stz.bbox(bb2)[0]) to_cs = translated_tri_cs[0] cs = stz.translate_coords_vertically(from_cs, 1.0) e1 = stz.open_path([ from_cs, cs, [mid_cs[0], cs[1]], [mid_cs[0], to_cs[1]], translated_tri_cs[0], tri_cs[0] ], s_con) e2 = stz.open_path([ from_cs, cs, [mid_cs[0], cs[1]], [mid_cs[0], to_cs[1]], translated_tri_cs[1], tri_cs[1] ], s_con) # the rightmost one from_cs = stz.coords_from_bbox_with_fn(mmha_an, stz.top_center_coords) e3 = stz.open_path( [from_cs, translated_tri_cs[1], translated_tri_cs[2], tri_cs[2]], s_con) connections.extend([e1, e2, e3])
x_axis_length = 4.0 y_axis_length = 3.0 extra_length = 0.4 a_circle_radius = 0.08 s_fmt = fmt.arrow_heads("end") f_fmt = fmt.line_and_fill_colors('black', 'black') cs = [ stz.coords_on_circle([0, 0], pentagon_radius, 90.0 + i * (360.0 / 5)) for i in range(5) ] e = stz.closed_path(cs) origin_cs = stz.translate_coords_horizontally(cs[2], -1.0) x_end_cs = stz.translate_coords_horizontally(origin_cs, x_axis_length) y_end_cs = stz.translate_coords_vertically(origin_cs, y_axis_length) x_start_cs = stz.translate_coords_horizontally(origin_cs, -extra_length) y_start_cs = stz.translate_coords_vertically(origin_cs, -extra_length) x_label_cs = stz.translate_coords_vertically(x_end_cs, -label_spacing) y_label_cs = stz.translate_coords_horizontally(y_end_cs, -label_spacing) origin_label_cs = stz.translate_coords_diagonally(origin_cs, -label_spacing) axes = [ stz.line_segment(x_start_cs, x_end_cs, s_fmt), stz.line_segment(y_start_cs, y_end_cs, s_fmt) ] labels = [ stz.latex([cs[0][0], cs[0][1] + label_spacing], "$C$"), stz.latex([cs[1][0] - label_spacing, cs[1][1]], "$B$"), stz.latex([cs[2][0], cs[2][1] - a_circle_radius - label_spacing],