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_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_triangle_given_triangles_equal_true(): t1 = Triangle((10, 0, 0), (0, 10, 0), (0, 0, 10)) t2 = Triangle((10, 0, 0), (0, 10, 0), (0, 0, 10)) assert (t1 == t2) is True
def test_triangle_init_function_point_list(): t1 = Triangle(Point((0, 10, 0)), Point((10, 0, 0)), Point((0, 0, 10))) t2 = Triangle((0, 10, 0), (10, 0, 0), (0, 0, 10)) assert (t1 == t2) is True
# inputs for ray and sphere intersecting at 1 point x0 = Ray((0, 10, 0), (0, -1, 0)) y0 = Sphere((5, 0, 0), 5) def test_intersect_ray_and_sphere_return_true(): assert (intersect(x0, y0) == _intersect_ray_with_sphere(x0, y0)) is True def test_intersect_sphere_and_ray_return_true(): assert (intersect(y0, x0) == _intersect_ray_with_sphere(x0, y0)) is True # input for intersecting ray and triangle r0 = Ray((5, 2, 5), (0, 0, -1)) t0 = Triangle((0, 0, 0), (10, 0, 0), (5, 10, 0)) def test_intersect_ray_and_triangle_return_true(): assert (intersect(r0, t0) == _intersect_ray_with_triangle(r0, t0)) is True def test_intersect_triangle_and_ray_return_true(): assert (intersect(t0, r0) == _intersect_ray_with_triangle(r0, t0)) is True def test_intersect_sphere_and_triangle_return_false(): assert intersect(y0, t0) is False # _intersect_ray_with_sphere
from pygeo.objects import Point, Vector, Ray, Sphere, Triangle from pygeo.intersect import intersect """To check if the installation of the package is done and all packages are running""" r1 = Ray((0, 0, 0), (10, 0, 0)) s1 = Sphere((0, 0, 0), 5) d, intercepts = intersect(r1, s1) print('The ', r1, 'intersects ', s1, 'at', intercepts) t = Triangle((1, 0, 0), (0, 1, 0), (0, 0, 1)) r1 = Ray((0, 0, 0), (1, 1, 1)) d, intercepts = intersect(r1, t) print('The ', r1, 'intersects ', t, 'at', intercepts)
def test_triangle_equal_given_two_non_equal_triangles_return_false(): assert (Triangle((1, 0, 0), (0, 1, 0), (0, 0, 1)) == Triangle( (1, 0, 0), (0, 1, 1), (0, 1, 0))) is False
def test_triangle_equal_given_two_equal_triangles_return_true(): assert (Triangle((1, 0, 0), (0, 1, 0), (0, 0, 1)) == Triangle( (1, 0, 0), (0, 0, 1), (0, 1, 0))) is True
def test_given_ray_triangle_no_intersection_return_false(): assert (_intersect_ray_with_triangle( Ray((0, 0, 0), (1, 1, 0)), Triangle( ((1, 1, 0), (3, 1, 0), (2, 0, 1)))) == Point((0, 0, 1))) is True
def test_given_ray_triangle_return_intersection_point(): assert (_intersect_ray_with_triangle( Ray((5, 2, 5), (0, 0, -1)), Triangle( ((0, 0, 0), (10, 0, 0), (5, 10, 0)))) == Point( (0.4, 0.2, 5))) is True