Beispiel #1
0
def test__ray_equal__given_two_not_equal_rays__return_false():
    assert (Ray(direction=Vector((1, 2, 3)), origin=Point(
        (3, 5, 6))) == Ray(direction=Vector((1, 2, 3)),
                           origin=Point((4, 5, 7)))) is False
    assert (Ray(direction=Vector((1, 2, 3)), origin=Point(
        (3, 5, 6))) == Ray(direction=Vector((4, 5, 7)),
                           origin=Point((3, 5, 6)))) is False
Beispiel #2
0
def test__intersect_ray_with_sphere__two_point_intersection():
    R = Ray(Point((0, 0, 2)), Vector(
        (1, 0, 0)))  #ray passing through the sphere
    S = Sphere(Point((0, 0, 0)), 3)
    val = np.sqrt(5)
    assert (_intersect_ray_with_sphere(R, S) == (Point(
        (val, 0, 2)), Point((-val, 0, 2)))) is True
Beispiel #3
0
def test__intersect_ray_with_sphere__one_point_intersection():
    R = Ray(Point((0, 0, 3)), Vector((1, 0, 0)))  #ray touching sphere surface
    S = Sphere(Point((0, 0, 0)), 3)
    assert (_intersect_ray_with_sphere(R, S) == Point((0, 0, 3))) is True
Beispiel #4
0
def test__intersect_ray_with_sphere__does_not_intersect():
    R = Ray(Point((0, 0, 4)), Vector((1, 0, 0)))  #ray outside sphere
    S = Sphere(Point((0, 0, 0)), 3)  #sphere with center at origin and radius 3
    assert (_intersect_ray_with_sphere(R, S) == "Does not intersect") is True
Beispiel #5
0
def test__ray_equal__given_two_rays_with_different_direction_and_origin_return_false(
):
    assert (Ray(Point((1, 1, 1)), Vector(
        (3, -4, 5))) == Ray(Point((0, 0, 0)), Vector((3, 4, 5)))) is False
Beispiel #6
0
def test_intersect_ray_and_sphere_with_different_origin():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector((1, 1, 1))), Sphere(Point((3, 3, 3)), 1))
            == (Point([2.42, 2.42, 2.42]), Point([3.58, 3.58, 3.58]))) is True
Beispiel #7
0
def test__vector_addition__given_two_vector__return_correct_vector():
    """The result of a vector being added to another one is a vector."""
    assert Vector((0, 1, 2)) + Vector((3, 4, 5)) == Vector((3, 5, 7))
Beispiel #8
0
def test__point_right_addition__given_vector_and_point__return_correct_point():
    """The result of a vector being added to a point is a point."""
    assert Vector((0, 1, 2)) + Point((3, 4, 5)) == Point((3, 5, 7))
Beispiel #9
0
def test__intersect_given_sphere_ray__not_intersected_two_point_d_less_than_0__return_NotImplimented(
):
    assert (_intersect_ray_with_sphere(
        Ray(direction=Vector((1, 1, 0)), origin=Point(
            (1, 1, 0))), Sphere(center=Point(
                (0, 0, 0)), radius=1))) is NotImplemented
Beispiel #10
0
def test__intersect_given_sphere_ray__intersected_two_point_d_grater_then_0():
    assert (_intersect_ray_with_sphere(
        Ray(direction=Vector((1, -1, 0)), origin=Point(
            (0, 1, 0))), Sphere(center=Point((0, 0, 0)), radius=1)) == (Point(
                (1, 0, 0)), Point((0, 1, 0)))) is True
Beispiel #11
0
def test_given_ray_vector_return_false():
    assert (_intersect(Ray((2, 0, 1), (0, -1, 0)), Vector(
        (1, 2, 3))) is False) is True
Beispiel #12
0
def test__ray_equal__given_two_equal_rays__return_true():
    assert (Ray(direction=Vector((1, 2, 3)), origin=Point(
        (3, 5, 6))) == Ray(direction=Vector((1, 2, 3)),
                           origin=Point((3, 5, 6)))) is True
Beispiel #13
0
def test_intersect_ray_and_sphere_with_different_origin_and_no_intersection():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector(
            (-1, -1, -1))), Sphere(Point(
                (4, 4, 0)), 1)) == "No Intersecction") is True
Beispiel #14
0
def test__vector_equal__given_two_equal_vectors__return_true():
    assert (Vector((1, 2, 3)) == Vector((1, 2, 3))) is True
Beispiel #15
0
def test__ray_equal__given_two_equal_rays__return_true():
    assert (Ray(Point((1,1,1)),Vector((1,2,3))) == Ray(Point((1,1,1)),Vector((1,2,3)))) is True
Beispiel #16
0
def test__vector_equal__given_two_not_equal_vectors__return_false():
    assert (Vector((1, 2, 3)) == Vector((4, 5, 6))) is False
Beispiel #17
0
def test__ray_equal__given_two_not_equal_rays__return_false():
    assert (Ray(Point((1,1,1)),Vector((1,2,3))) == Ray(Point((2,3,1)),Vector((5,7,8)))) is False
Beispiel #18
0
def test__point_subtraction__given_two_points__return_correct_vector():
    """The result of a point being subtracted from another one is a vector."""
    assert Point((0, 1, 2)) - Point((3, 4, 5)) == Vector((-3, -3, -3))
Beispiel #19
0
def test_ray_equal_given_two_equal_rays_retun_true():
    assert (Ray(Point((0, 1, 2)), Vector(
        (3, 4, 5))) == Ray(Point((0, 1, 2)), Vector((3, 4, 5)))) is True
Beispiel #20
0
def test__vector_subtraction__given_two_vectors__return_correct_vector():
    """The result of a vector being subtracted from another one is a vector."""
    assert Vector((0, 1, 2)) - Vector((3, 4, 5)) == Vector((-3, -3, -3))
Beispiel #21
0
def test_intersect_ray_and_sphere_with_same_origin():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector((1, 1, 1))), Sphere(Point(
            (0, 0, 0)), 2)) == Point([1.15, 1.15, 1.15])) is True