예제 #1
0
def test_polygon3():
    hgen = halton([2, 3], [11, 7])
    coords = [hgen() for _ in range(20)]
    S = [point(x, y) for x, y in coords]
    S = create_xmono_polygon(S)
    P = polygon(S)
    assert P.signed_area_x2() == 3862080
예제 #2
0
def test_polygon():
    coords = [(-2, 2), (0, -1), (-5, 1), (-2, 4), (0, -4), (-4, 3), (-6, -2),
              (5, 1), (2, 2), (3, -3), (-3, -3), (3, 3), (-3, -4), (1, 4)]
    S = [point(x, y) for x, y in coords]
    S = create_test_polygon(S)
    for p in S:
        print("{},{}".format(p.x, p.y), end=' ')
    P = polygon(S)
    assert P.signed_area_x2() == 110
예제 #3
0
def test_polygon4():
    hgen = halton([3, 2], [7, 11])
    coords = [hgen() for _ in range(50)]
    S = create_test_polygon([point(x, y) for x, y in coords])
    print('<svg viewBox="0 0 2187 2048" xmlns="http://www.w3.org/2000/svg">')
    print('  <polygon points="', end=' ')
    for p in S:
        print("{},{}".format(p.x, p.y), end=' ')
    print('"')
    print('  fill="#88C0D0" stroke="black" />')
    for p in S:
        print('  <circle cx="{}" cy="{}" r="10" />'.format(p.x, p.y))
    qx, qy = hgen()
    print('  <circle cx="{}" cy="{}" r="10" fill="#BF616A" />'.format(qx, qy))
    print('</svg>')
    P = polygon(S)
    assert P.signed_area_x2() == -4449600
    assert point_in_polygon(S, point(qx, qy))
예제 #4
0
def test_RPolygon():
    coords = [(-2, 2), (0, -1), (-5, 1), (-2, 4), (0, -4), (-4, 3), (-6, -2),
              (5, 1), (2, 2), (3, -3), (-3, -4), (1, 4)]
    S, is_anticw = create_ymono_rpolygon([point(x, y) for x, y in coords])
    for p1, p2 in zip(S, S[1:] + [S[0]]):
        print("{},{} {},{}".format(p1.x, p1.y, p2.x, p1.y), end=' ')
    P = rpolygon(S)
    assert is_anticw
    assert P.signed_area() == 45
예제 #5
0
def test_RPolygon2():
    hgen = halton([3, 2], [7, 11])
    coords = [hgen() for _ in range(20)]
    S, is_anticw = create_ymono_rpolygon([point(x, y) for x, y in coords])
    for p1, p2 in zip(S, S[1:] + [S[0]]):
        print("{},{} {},{}".format(p1.x, p1.y, p2.x, p1.y), end=' ')
    P = rpolygon(S)
    assert not is_anticw
    assert P.signed_area() == -1871424
예제 #6
0
def test_RPolygon4():
    hgen = halton([3, 2], [7, 11])
    coords = [hgen() for _ in range(20)]
    S, is_anticw = create_xmono_rpolygon([point(x, y) for x, y in coords])
    p0 = S[-1]
    for p1 in S:
        print("{},{} {},{}".format(p0.x, p0.y, p1.x, p0.y), end=' ')
        p0 = p1
    P = rpolygon(S)
    assert is_anticw
    assert P.signed_area() == 2001024
예제 #7
0
def test_RPolygon5():
    hgen = halton([3, 2], [7, 11])
    coords = [hgen() for _ in range(50)]
    S = create_test_rpolygon([point(x, y) for x, y in coords])
    # for p1, p2 in zip(S, S[1:] + [S[0]]):
    #     print("{},{} {},{}".format(p1.x, p1.y, p2.x, p1.y), end=' ')
    print('<svg viewBox="0 0 2187 2048" xmlns="http://www.w3.org/2000/svg">')
    print('  <polygon points="', end=' ')
    p0 = S[-1]
    for p1 in S:
        print("{},{} {},{}".format(p0.x, p0.y, p1.x, p0.y), end=' ')
        p0 = p1
    print('"')
    print('  fill="#88C0D0" stroke="black" />')
    for p in S:
        print('  <circle cx="{}" cy="{}" r="10" />'.format(p.x, p.y))
    qx, qy = hgen()
    print('  <circle cx="{}" cy="{}" r="10" fill="#BF616A" />'.format(qx, qy))
    print('</svg>')
    P = rpolygon(S)
    assert P.signed_area() == -2176416
    assert point_in_rpolygon(S, point(qx, qy))
예제 #8
0
def test_Rectangle():
    xrng1 = interval(4, 8)
    yrng1 = interval(5, 7)
    r1 = rectangle(xrng1, yrng1)
    p = point(7, 6)
    assert r1.contains(p)