Example #1
0
def test_object_from_equation():
    from sympy.abc import x, y, a, b
    assert Line(3*x + y + 18) == Line2D(Point2D(0, -18), Point2D(1, -21))
    assert Line(3*x + 5 * y + 1) == Line2D(Point2D(0, -1/5), Point2D(1, -4/5))
    assert Line(3*a + b + 18, x='a', y='b') == Line2D(Point2D(0, -18), Point2D(1, -21))
    assert Line(3*x + y) == Line2D(Point2D(0, 0), Point2D(1, -3))
    assert Line(x + y) == Line2D(Point2D(0, 0), Point2D(1, -1))
    raises(ValueError, lambda: Line(x))
    raises(ValueError, lambda: Line(y))
    raises(ValueError, lambda: Line(x/y))
    raises(ValueError, lambda: Line(a/b, x='a', y='b'))
    raises(ValueError, lambda: Line(y/x))
    raises(ValueError, lambda: Line(b/a, x='a', y='b'))
    raises(ValueError, lambda: Line((x + 1)**2 + y))
Example #2
0
def test_arguments():
    """Functions accepting `Point` objects in `geometry`
    should also accept tuples, lists, and generators and
    automatically convert them to points."""
    from sympy import subsets

    singles2d = ((1, 2), [1, 3], Point(1, 5))
    doubles2d = subsets(singles2d, 2)
    l2d = Line(Point2D(1, 2), Point2D(2, 3))
    singles3d = ((1, 2, 3), [1, 2, 4], Point(1, 2, 6))
    doubles3d = subsets(singles3d, 2)
    l3d = Line(Point3D(1, 2, 3), Point3D(1, 1, 2))
    singles4d = ((1, 2, 3, 4), [1, 2, 3, 5], Point(1, 2, 3, 7))
    doubles4d = subsets(singles4d, 2)
    l4d = Line(Point(1, 2, 3, 4), Point(2, 2, 2, 2))
    # test 2D
    test_single = ['contains', 'distance', 'equals', 'parallel_line', 'perpendicular_line', 'perpendicular_segment',
                   'projection', 'intersection']
    for p in doubles2d:
        Line2D(*p)
    for func in test_single:
        for p in singles2d:
            getattr(l2d, func)(p)
    # test 3D
    for p in doubles3d:
        Line3D(*p)
    for func in test_single:
        for p in singles3d:
            getattr(l3d, func)(p)
    # test 4D
    for p in doubles4d:
        Line(*p)
    for func in test_single:
        for p in singles4d:
            getattr(l4d, func)(p)
Example #3
0
def test_object_from_equation():
    from sympy.abc import x, y, a, b

    assert Line(3 * x + y + 18) == Line2D(Point2D(0, -18), Point2D(1, -21))
    assert Line(3 * x + 5 * y + 1) == Line2D(Point2D(0, Rational(-1, 5)),
                                             Point2D(1, Rational(-4, 5)))
    assert Line(3 * a + b + 18, x="a",
                y="b") == Line2D(Point2D(0, -18), Point2D(1, -21))
    assert Line(3 * x + y) == Line2D(Point2D(0, 0), Point2D(1, -3))
    assert Line(x + y) == Line2D(Point2D(0, 0), Point2D(1, -1))
    assert Line(Eq(3 * a + b, -18), x="a",
                y=b) == Line2D(Point2D(0, -18), Point2D(1, -21))
    raises(ValueError, lambda: Line(x))
    raises(ValueError, lambda: Line(y))
    raises(ValueError, lambda: Line(x / y))
    raises(ValueError, lambda: Line(a / b, x="a", y="b"))
    raises(ValueError, lambda: Line(y / x))
    raises(ValueError, lambda: Line(b / a, x="a", y="b"))
    raises(ValueError, lambda: Line((x + 1)**2 + y))