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
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
def test_intersect_ray_with_sphere_false(): r1 = Ray((0, 0, 0), (1, 1, 1)) s1 = Sphere((10, 10, 10), 5) d, intercepts = intersect(r1, s1) intercepts_analytical = [Point([5.0, 0.0, 0.0]), Point([-5.0, 0.0, 0.0])] d_analytical = 2 assert ((intercepts == intercepts_analytical) and (d_analytical == d)) is False
def test__intersect__ray_not_intersect_with_sphere__return_true(): r1 = Ray((100, 100, 100), (200, 200, 100)) s1 = Sphere((0, 0, 0), 5) d, intersections = intersect(r1, s1) calculated_intersections = [0] d_analytical = 0 assert ((intersections == calculated_intersections) and (d_analytical == d)) is True
def test__intersect_ray_with_sphere_return_true_1(): sph = Sphere((0, 0, 0), 2) ray = Ray((2, 0, 0), (2, 1, 0)) temp = _intersect_ray_with_sphere(ray, sph) val = 2 if np.array_equal(temp, [[2, 0, 0]]) is True: val = 1 assert (val == 1) is True
def test__intersect_ray_with_sphere_return_false_1(): sph = Sphere((0, 0, 0), 1) ray = Ray((5, 0, 0), (0, 5, 0)) val = 2 temp = _intersect_ray_with_sphere(ray, sph) if temp == 0: val = 0 assert (val == 2) is False
def test_intersect_no_intersect_ray_with_sphere_true(): r1 = Ray((100, 100, 100), (200, 200, 100)) s1 = Sphere((0, 0, 0), 5) d, intercepts = intersect(r1, s1) intercepts_analytical = [0] d_analytical = 0 assert ((intercepts == intercepts_analytical) and (d_analytical == d)) is True
def test__intersect_ray_with_sphere_return_true(): sph = Sphere((0, 0, 0), 1) ray = Ray((-1, 0, 0), (0, 0, 0)) temp = _intersect_ray_with_sphere(ray, sph) val = 1 print(temp) if np.array_equal(temp, [[1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]): val = 2 assert (val == 2) is True
def test_intersect_ray_with_triangle_true(): t = Triangle((1, 0, 0), (0, 1, 0), (0, 0, 1)) r1 = Ray((0, 0, 0), (1, 1, 1)) d, intercepts = intersect(r1, t) intercepts_analytical = Point( [0.3333333333333333, 0.3333333333333333, 0.3333333333333333]) d_analytical = 1 assert ((intercepts == intercepts_analytical) and (d_analytical == d)) is True
def test__intersect_ray_with_sphere_return_false(): sph = Sphere((0, 0, 0), 1) ray = Ray((1, 0, 0), (1, 1, 0)) val = 2 temp = _intersect_ray_with_sphere(ray, sph) print(temp) if np.array_equal(temp, [[1.0, 0.0, 0.0]]) is True: val = 1 assert (val == 2) is False
def test__intersect__ray_with_sphere__return_false(): r1 = Ray((0, 0, 0), (1, 1, 1)) s1 = Sphere((10, 10, 10), 3) d, intersections = intersect(r1, s1) calculated_intersections = [ Point([3.0, 0.0, 0.0]), Point([-3.0, 0.0, 0.0]) ] d_analytical = 2 assert ((intersections == calculated_intersections) and (d_analytical == d)) is False
def test_intersection__sphere_center_at_origin__given_ray_that_originates_inside_sphere__return_true( ): assert (intersection(Ray((-0.5, 0, 0), (1, 0, 0)), Sphere( (0, 0, 0), 1.0)) == Point([1, 0, 0]))
def test_intersection__sphere_center_at_origin__given_ray_that_intersects_at_two_points__return_true( ): assert array_equal( intersection(Ray((-2, 0, 0), (1, 0, 0)), Sphere((0, 0, 0), 1.0)), [Point([-1, 0, 0]), Point([1, 0, 0])]) is True
def test_intersection__sphere_center_at_origin__given_tangent_ray__return_true( ): assert (intersection(Ray((-3, 1, 0), (1, 0, 0)), Sphere( (0, 0, 0), 1.0)) == Point([0, 1, 0]))
def test_ray_equality_given_different_origin_direction_return_false(): assert (Ray((3, 1, 2), (1, 1, 0)) == Ray((0, 0, 2), (0, 1, 1))) is False
def test_ray_equality_given_equal_origin_direction_return_true(): assert (Ray((0, 0, 0), (1, 1, 1)) == Ray((0, 0, 0), (1, 1, 1))) is True
def test__ray__given_two_equal_rays__return_true(): r1 = Ray((1, 2, 3), (1, 1, 1)) r2 = Ray((1, 2, 3), (1, 1, 1)) assert (r1 == r2) is True
def test__sphere_equal__given_two_not_equal_sphere_center__return_false(): assert (Sphere((0, 0, 0), 5) == Ray((1, 1, 1), 5)) is False
def test_intersection__sphere_center_elsewhere__given_ray_that_intersects_at_no_points__return_true( ): assert (intersection(Ray((-2, 1.5, 0), (1, 0, 0)), Sphere((1, 1, 1), 1.0)) == None)
def test_ray_eq_same_initial_point_and_different_direction__return_False(): Ray1 = Ray([1, 1, 1], [5, 5, 5]) Ray3 = Ray([1, 1, 1], [1, 5, 1]) assert ((Ray1 == Ray3)) is False
def test_ray_eq_same_initial_point_and_same_direction__return_True(): Ray1 = Ray([1, 1, 1], [5, 5, 5]) Ray2 = Ray([1, 1, 1], [5, 5, 5]) assert (Ray1 == Ray2) is True
def test__intersect_ray_with_triangle_return_false_2(): triangle = Triangle((1, 0, 0), (-1, 0, 0), (0, 1, 0)) ray = Ray((0, 0, 1), (0, 0, 0)) val = _intersect_ray_with_triangle(ray, triangle) assert (val == 0) is False
def test__intersect_ray_with_triangle_return_true_1(): triangle = Triangle((1, 0, 0), (-1, 0, 0), (0, 1, 0)) ray = Ray((0.5, 0, 0), (0, 0.5, 0)) val = _intersect_ray_with_triangle(ray, triangle) assert (val == 2) is True
def test_intersection__sphere_center_elsewhere__given_tangent_ray__return_true( ): assert (intersection(Ray((-3, 1, 0), (1, 0, 0)), Sphere( (1, 1, 1), 1.0)) == Point([1, 1, 0]))
def test_intersection__sphere_center_elsewhere__given_ray_that_intersects_at_two_points__return_true( ): assert array_equal( intersection(Ray((-2, 1, 1), (1, 0, 0)), Sphere((1, 1, 1), 1.0)), [Point([0, 1, 1]), Point([2, 1, 1])]) is True
def test__ray_equal__given_two_not_equal_ray_origin__return_false(): assert (Ray((0, 0, 0), (1, 2, 3)) == Ray((0, 1, 0), (1, 2, 3))) is False
def test_intersection__sphere_center_elsewhere__given_ray_that_originates_inside_sphere__return_true( ): assert (intersection(Ray((1, 1, 1), (0, 0, 1)), Sphere( (1, 1, 1), 1.0)) == Point([1, 1, 2]))
def test_ray_eq_different_initial_points_and_different_directions__return_False( ): Ray1 = Ray([1, 1, 1], [5, 5, 5]) Ray4 = Ray([2, 2, 2], [1, 5, 1]) assert ((Ray1 == Ray4)) is False
def test_ray_eq_different_initial_point_and_same_direction__return_False(): Ray3 = Ray([1, 1, 1], [1, 5, 1]) Ray4 = Ray([2, 2, 2], [1, 5, 1]) assert ((Ray3 == Ray4)) is False
def test__ray__given_two_not_equal_rays__return_false(): r1 = Ray((1, 0, 0), (2, 0, 0)) r2 = Ray((1, 1, 0), (1, 2, 0)) assert (r1 == r2) is False