Ejemplo n.º 1
0
def test_merge_corners_onto_borders():
    #   01234567
    # 0 A-B-C
    # 1   |
    # 2   D
    a = (0, 0)
    b = (2, 0)
    c = (4, 0)
    d = (2, 2)
    graph = {a: {c}, c: {a}, b: {d}, d: {b}}
    merge_corners_onto_borders(graph)
    assert_equal(graph, {a: {b}, b: {a, c, d}, c: {b}, d: {b}})

    #   01234567
    # 0 A-B-C-D
    # 1   | |
    # 2   E F
    a = (0, 0)
    b = (2, 0)
    c = (4, 0)
    d = (6, 0)
    e = (2, 2)
    f = (4, 2)
    graph = {a: {d}, d: {a}, b: {e}, e: {b}, c: {f}, f: {c}}
    merge_corners_onto_borders(graph)
    assert_equal(graph, {a: {b}, b: {a, c, e}, c: {b, d, f}, d: {c}, e: {b}, f: {c}})
Ejemplo n.º 2
0
def test_disjoint():
    # this test will be stuck in an infinite loop
    poly1 = [(8, -16), (8, 0), (0, 0), (0, -8)]
    poly2 = [(-12, 36), (0, 36), (0, 48), (-12, 48)]
    poly3 = [(-12, 12), (0, 12), (0, -8), (-12, 4)]
    polys = [poly1, poly2, poly3]
    graph = polygons_to_graph(polys)
    merge_corners_onto_borders(graph)
Ejemplo n.º 3
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))