コード例 #1
0
def test_continue_straight_lines():
    # Line ACD is joined to create line AD.

    #   01234
    # 0   A
    # 1   |
    # 2 B-C
    # 3   |\
    # 4   D E
    a = (2, 0)
    b = (0, 2)
    c = (2, 2)
    d = (2, 4)
    e = (4, 4)
    graph = {
        a: {c},
        b: {c},
        c: {a, b, d, e},
        d: {c},
        e: {c},
    }
    continue_straight_lines(graph)
    assert_equal(
        graph,
        {
            a: {d}, d: {a},
            b: {c},
            c: {b, e},
            e: {c},
        }
    )
コード例 #2
0
def draw_polygons(polygons):
    p = canoepaddle.Pen()
    p.fill_mode('#eee')
    for poly in polygons:
        p.move_to(poly[-1])
        for point in poly:
            p.line_to(point)
    return p.paper


if __name__ == '__main__':
    polygons = gen_polygons()

    graph = polygons_to_graph(polygons)
    merge_corners_onto_borders(graph)
    continue_straight_lines(graph)

    paper = canoepaddle.Paper()
    paper.merge(draw_polygons(polygons))
    paper.merge(draw_graph(graph))

    bounds = paper.bounds()
    bounds.left -= 2
    bounds.right += 2
    bounds.bottom -= 2
    bounds.top += 2
    paper.override_bounds(bounds)

    print(paper.format_svg(2))