Beispiel #1
0
def test_same_line_is_parallel():
    line = Line(Point(0, 0), 1)
    l2 = Line(Point(1, 100), 0)
    l3 = Line(Point(2, -23), math.inf)
    assert line.is_parallel_to(line)
    assert l2.is_parallel_to(l2)
    assert l3.is_parallel_to(l3)
Beispiel #2
0
def test_create_line_seg():
    line = Line(Point(0, 0), 3 / 4)
    length = 10
    seg = line.create_line_segment_of_length(length)
    assert seg.length == length
    points = (Point(4, 3), Point(-4, -3))
    assert seg.p1 in points
    assert seg.p2 in points
Beispiel #3
0
def test_parallel_lines_are_parallel():
    line = Line(Point(0, 0), 1)
    l2 = Line(Point(1, 100), 1)
    assert line.is_parallel_to(l2)

    line.slope = math.inf
    l2.slope = math.inf
    assert line.is_parallel_to(l2)

    line.slope = 0
    l2.slope = 0
    assert line.is_parallel_to(l2)
Beispiel #4
0
def test_create_touching():
    c1 = Circle(Point(0, 0), 1)
    c2 = c1.make_circle_which_touches(0, 1)
    assert c2.radius == 1
    assert c2.point == Point(2, 0)

    c2 = c1.make_circle_which_touches(90, 1)
    assert c2.point == Point(0, 2)

    c2 = c1.make_circle_which_touches(180, 1)
    assert c2.point == Point(-2, 0)

    c2 = c1.make_circle_which_touches(270, 1)
    assert c2.point == Point(0, -2)
Beispiel #5
0
def test_rotation_about_origin():
    origin = Point(0, 0)
    point = Point(1, 1)

    assert point.rotate_about(origin, 90) == Point(-1, 1)
    assert point.rotate_about(origin, 45) == Point(0, math.sqrt(2))
    assert point.rotate_about(origin, 180) == Point(-1, -1)
Beispiel #6
0
def test_create_line_seg_vert_horr():
    line = Line(Point(0, 0), 0)
    length = 10
    seg = line.create_line_segment_of_length(length)
    assert seg.length == length
    points = (Point(5, 0), Point(-5, 0))
    assert seg.p1 in points
    assert seg.p2 in points

    line.slope = math.inf
    length = 10
    seg = line.create_line_segment_of_length(length)
    assert seg.length == length
    points = (Point(0, 5), Point(0, -5))
    assert seg.p1 in points
    assert seg.p2 in points
Beispiel #7
0
def test_make_perpendicular():
    line = Line(Point(0, 0), 0)
    perp_point = Point(0, 10)
    perp = line.create_line_perpendicular(perp_point)
    assert perp.slope == math.inf
    assert perp.p == perp_point

    line.slope = math.inf
    perp_point = Point(10, 0)
    perp = line.create_line_perpendicular(perp_point)
    assert perp.slope == 0
    assert perp.p == perp_point

    line.slope = 1
    perp_point = Point(-10, 10)
    perp = line.create_line_perpendicular(perp_point)
    assert perp.slope == -1
    assert perp.p == perp_point
def test_point_inside():
    p = Polygon([Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0)])
    assert p.point_inside(Point(5, 5))
Beispiel #9
0
def test_touching_intersection():
    c1 = Circle(Point(0, 0), 1)
    c2 = Circle(Point(2, 0), 1)
    assert c1.intersects(c2)
Beispiel #10
0
def test_simple_intersection():
    # Point of one is within the radius of another
    c1 = Circle(Point(0, 0), 2)
    c2 = Circle(Point(1, 0), 1)
    assert c1.intersects(c2)
Beispiel #11
0
def test_create_with_two_points():
    r = Rect(Point(0, 0), Point(10, 10))
    assert len(r.verts) == 4
Beispiel #12
0
def test_create_rect():
    r = Rect(Point(0, 0), width=20, height=10)
    for p in [Point(0, 0), Point(0, 10), Point(20, 10), Point(20, 0)]:
        assert p in r.verts
    r = Rect(Point(0, 0), Point(20, 10))
    for p in [Point(0, 0), Point(0, 10), Point(20, 10), Point(20, 0)]:
        assert p in r.verts
Beispiel #13
0
def test_line_length_vert():
    line = LineSeg(Point(0, 0), Point(0, 50))
    assert line.length == 50
Beispiel #14
0
def test_line_length_hor():
    line = LineSeg(Point(0, 0), Point(100, 0))
    assert line.length == 100
Beispiel #15
0
def test_half_along_is_half_y_axis():
    line = LineSeg(Point(0, 0), Point(100, 0))
    assert Point(50, 0) == line.point_along(.5)

    line = LineSeg(Point(25, 0), Point(75, 0))
    assert Point(50, 0) == line.point_along(.5)
Beispiel #16
0
def test_create_with_point_and_wh():
    assert Rect(Point(0, 0), width=10, height=10)
Beispiel #17
0
def test_create_square():
    r = Rect(Point(0, 0), width=10, height=10)
    for p in [Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0)]:
        assert p in r.verts
    r = Rect(Point(0, 0), Point(10, 10))
    for p in [Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0)]:
        assert p in r.verts
Beispiel #18
0
def test_step_too_far_is_none():
    line = LineSeg(Point(0, 0), Point(0, 50))
    assert line.step_along(51) is None
Beispiel #19
0
def test_create_fails_with_too_many_params():
    with pytest.raises(ValueError):
        Rect(Point(0, 0), Point(1, 1), 10)
Beispiel #20
0
def test_step_for_dist_is_second_point():
    p2 = Point(0, 50)
    line = LineSeg(Point(0, 0), p2)
    assert line.step_along(line.length) is p2
Beispiel #21
0
def test_outline():
    p = Polygon([Point(0, 0), Point(0, 1), Point(1, 0)])
    assert 3 == len(list(p.outline()))
Beispiel #22
0
def test_step_along():
    line = LineSeg(Point(0, 0), Point(0, 50))
    assert line.step_along(10) == Point(0, 10)
Beispiel #23
0
def test_simple_intersection2():
    c1 = Circle(Point(0, 0), 2)
    c2 = Circle(Point(3, 0), 2)
    assert c1.intersects(c2)
Beispiel #24
0
def test_three_unique_points():
    Polygon([Point(0, 0), Point(0, 1), Point(1, 0)])
Beispiel #25
0
def test_simple_creation():
    circle = Circle(Point(0, 0), 1)
Beispiel #26
0
def test_non_unique_point():
    with pytest.raises(ValueError):
        Polygon([Point(0, 0), Point(0, 1), Point(0, 0)])
Beispiel #27
0
def test_self_intersecting():
    circle = Circle(Point(0, 0), 1)
    assert circle.intersects(circle)
Beispiel #28
0
def test_float_points():
    # Should this fail? Not checking right now
    Polygon([Point(0.001, 0), Point(0, 1.1), Point(0, 0)])
def test_point_outside():
    p = Polygon([Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0)])
    assert not p.point_inside(Point(-1, -1))
Beispiel #30
0
def test_less_than_three_points():
    with pytest.raises(ValueError):
        Polygon([Point(0, 0), Point(1, 0)])