예제 #1
0
def test_degenerate_xy_of_cases():
    vert = Line.ByPoints(P2(1, 1), P2(1, -1))

    assert vert.f_of_x(1) is None
    assert vert.f_of_x(-100) is None
    assert vert.f_of_y(-1) == pytest.approx(1)
    assert vert.f_of_y(1) == pytest.approx(1)
    assert vert.f_of_y(-100) == pytest.approx(1)
    assert vert.f_of_y(100) == pytest.approx(1)

    horz = Line.ByPoints(P2(-1, 0), P2(1, 0))

    assert horz.f_of_x(-1) == pytest.approx(0)
    assert horz.f_of_x(1) == pytest.approx(0)
    assert horz.f_of_x(-100) == pytest.approx(0)
    assert horz.f_of_x(100) == pytest.approx(0)

    assert horz.f_of_y(-1) is None
    assert horz.f_of_y(1) is None
    assert horz.f_of_y(-100) is None
    assert horz.f_of_y(100) is None
예제 #2
0
def test_does_intersect_line_line_segment():
    line = Line(1, 0, 0)
    x_ls = LineSegment(P2(-1, 0), P2(1, 0))
    p_ls = LineSegment(P2(-1, -1), P2(-1, 1))

    assert does_intersect(line, x_ls)
    assert does_intersect(x_ls, line)

    assert not does_intersect(line, p_ls)
    assert not does_intersect(p_ls, line)

    with pytest.raises(ValueError):
        does_intersect(line, LineSegment(P2(0, 0), P2(0, 1)))
예제 #3
0
def test_translate():
    line = Line(2, 1, 2)
    assert line.f_of_x(0) == pytest.approx(2)
    assert line.f_of_y(0) == pytest.approx(1)

    translated = line.translate(V2(1, 1))
    assert translated.f_of_x(0) == pytest.approx(3)
    assert translated.f_of_y(0) == pytest.approx(2)

    horz = Line.ByPoints(P2(-1, 10), P2(1, 10))
    assert horz.f_of_x(0) == pytest.approx(10)

    translated = horz.translate(V2(1, 1))
    assert translated.f_of_x(0) == pytest.approx(11)

    vert = Line.ByPoints(P2(10, -1), P2(10, 1))
    assert vert.f_of_y(0) == pytest.approx(10)

    translated = vert.translate(V2(1, 1))
    assert translated.f_of_y(0) == pytest.approx(11)
예제 #4
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)
예제 #5
0
def test_line_line_segment_degenerate():
    l1 = Line(1, 1, 0)

    with pytest.raises(ValueError):
        intersect(l1, LineSegment(P2(0, 0), P2(-10, 10)))
예제 #6
0
def test_xy_of():
    l = Line(-1, 1, 0)

    assert l.f_of_x(1) == pytest.approx(1)
    assert l.f_of_x(-1) == pytest.approx(-1)
    assert l.f_of_y(1) == pytest.approx(1)
    assert l.f_of_y(-1) == pytest.approx(-1)

    assert l.f_of_x(25) == pytest.approx(25)
    assert l.f_of_x(-25) == pytest.approx(-25)
    assert l.f_of_y(25) == pytest.approx(25)
    assert l.f_of_y(-25) == pytest.approx(-25)

    l = Line(1, 1, 0)

    assert l.f_of_x(1) == pytest.approx(-1)
    assert l.f_of_x(-1) == pytest.approx(1)
    assert l.f_of_y(1) == pytest.approx(-1)
    assert l.f_of_y(-1) == pytest.approx(1)

    assert l.f_of_x(25) == pytest.approx(-25)
    assert l.f_of_x(-25) == pytest.approx(25)
    assert l.f_of_y(25) == pytest.approx(-25)
    assert l.f_of_y(-25) == pytest.approx(25)
예제 #7
0
def test_line_points():

    line = Line(1, -1, 0)

    assert P2(25, 25) == line.point(x=25)
    assert P2(25, 25) == line.point(y=25)