예제 #1
0
def test_circle_circle():
    # functionality tested in test_r2_circle

    circle1 = Circle(100, P2(0, 0))
    circle2 = Circle(100, P2(100, 100))

    assert {P2(0.0, 100.0), P2(100.0, 0.0)} == intersect(circle1, circle2)
예제 #2
0
def test_offset_circle_contains():
    circle = Circle(100, P2(2, 2))
    assert circle.contains(P2(0, 0))
    assert not circle.contains(P2(-99, 0))

    assert P2(0, 0) in circle
    assert P2(-99, 0) not in circle
예제 #3
0
def test_create_degenerate():

    with pytest.raises(ValueError):
        Circle(0)

    with pytest.raises(ValueError):
        Circle(-10)
예제 #4
0
def test_does_intersect_circle_circle():

    c1 = Circle(100)
    c2 = Circle(100, P2(500, 500))
    assert not does_intersect(c1, c2)
    assert not does_intersect(c1, Circle(50))

    assert does_intersect(c1, Circle(100, P2(10, 10)))
예제 #5
0
def test_circle_contains():
    circle = Circle(100)

    assert circle.contains(P2(-100, 0))
    assert circle.contains(P2(100, 0))
    assert circle.contains(P2(0, 100))
    assert circle.contains(P2(0, -100))

    assert not circle.contains(P2(150, 0))
    assert not circle.contains(P2(0, 150))

    with pytest.raises(TypeError):
        circle.contains(None)

    with pytest.raises(TypeError):
        circle.contains(V2(0, 0))
예제 #6
0
def test_circle_create():

    circle = Circle(100)

    assert circle.radius == 100
    assert circle.center == P2(0, 0)

    circle = Circle(100, P2(100, 100))

    assert circle.radius == 100
    assert circle.center == P2(100, 100)

    with pytest.raises(TypeError):
        Circle(100, V2(100, 100))

    with pytest.raises(TypeError):
        Circle(None)
예제 #7
0
def test_on_perimeter():
    circle = Circle(100)

    assert not circle.on_circumference(P2(0, 0))

    assert circle.on_circumference(P2(100, 0))
    assert circle.on_circumference(P2(0, 100))

    circle = Circle(100, P2(1, 1))
    assert not circle.on_circumference(P2(0, 0))
    assert circle.on_circumference(P2(1, -99))
    assert circle.on_circumference(P2(-99, 1))
    assert circle.on_circumference(P2(101, 1))
    assert circle.on_circumference(P2(1, 101))
예제 #8
0
def test_line_circle():
    circle = Circle(100, P2(1, 1))
    x = Line(1, 0, 1)

    points = intersect(x, circle)
    assert {P2(1.0, 101.0), P2(1.0, -99.0)} == points

    points = intersect(circle, x)
    assert {P2(1.0, 101.0), P2(1.0, -99.0)} == points

    tangent_circle = Circle(1, P2(2, 0))
    assert {P2(1.0, 0.0)} == intersect(tangent_circle, x)
    assert {P2(1.0, 0.0)} == intersect(x, tangent_circle)

    horz = Line(0, 1, 1)
    assert {P2(-99.0, 1.0), P2(101, 1.0)} == intersect(horz, circle)
    assert {P2(-99.0, 1.0), P2(101, 1.0)} == intersect(circle, horz)

    far_line = Line(1, 0, 200)
    assert set() == intersect(far_line, circle)
    assert set() == intersect(circle, far_line)
예제 #9
0
def test_line_segment_circle():
    circle = Circle(100, P2(1, 0))
    x = LineSegment(P2(1, -1000), P2(1, 1000))

    points = intersect(x, circle)
    assert {P2(1.0, 100.0), P2(1.0, -100.0)} == points

    points = intersect(circle, x)
    assert {P2(1.0, 100.0), P2(1.0, -100.0)} == points

    x2 = LineSegment(P2(1, -1000), P2(1, 0))
    assert {P2(1.0, -100.0)} == intersect(circle, x2)

    assert {P2(1.0, -100.0)} == intersect(x2, circle)
예제 #10
0
def test_does_intersect_circle_line_segment():
    circle = Circle(100)

    ls_right = LineSegment(P2(50, 0), P2(150, 0))
    assert does_intersect(circle, ls_right)
    assert does_intersect(ls_right, circle)

    ls_left = LineSegment(P2(-50, -50), P2(-100, -100))
    assert does_intersect(circle, ls_left)
    assert does_intersect(ls_left, circle)

    ls_inside = LineSegment(P2(-25, -25), P2(25, 25))
    assert not does_intersect(circle, ls_inside)
    assert not does_intersect(ls_inside, circle)

    ls_outside = LineSegment(P2(0, 175), P2(175, 0))
    assert not does_intersect(circle, ls_outside)
    assert not does_intersect(ls_outside, circle)
예제 #11
0
def test_does_intersect_line_circle():
    circle = Circle(99, P2(100, 100))

    assert not does_intersect(circle, Line(1, 1, 0))
    assert not does_intersect(Line(1, 1, 0), circle)

    assert does_intersect(circle, Line(1, -1, 0))
    assert does_intersect(Line(1, -1, 0), circle)

    assert does_intersect(circle, Line(1, 0, 100))
    assert does_intersect(Line(1, 0, 100), circle)

    assert does_intersect(circle, Line(0, 1, 100))
    assert does_intersect(Line(0, 1, 100), circle)

    assert not does_intersect(circle, Line(1, 0, 0))
    assert not does_intersect(Line(1, 0, 0), circle)

    assert does_intersect(circle, Line(1, 0, 1))
    assert does_intersect(Line(1, 0, 1), circle)
예제 #12
0
def test_circle_properties():
    circle = Circle(100)

    assert circle.diameter == 200
    assert circle.circumference == pytest.approx(math.pi * 200)
    assert circle.area == pytest.approx(math.pi * 100**2)