#include #include #include "rays.h" #include "planes.h" #include "intersections_shapes.h" #include "runner.h" #include "matrices.h" #include "transformations.h" static bool planes_test_0(const char ** scenario) { *scenario = "The normal of a plane is constant everywhere"; struct tuple n1 = plane_normal_at(point(0.0f, 0.0f, 0.0f)); struct tuple n2 = plane_normal_at(point(10.0f, 0.0f, -10.0f)); struct tuple n3 = plane_normal_at(point(-5.0f, 0.0f, 150.0f)); return tuple_equal(n1, vector(0.0f, 1.0f, 0.0f)) && tuple_equal(n2, vector(0.0f, 1.0f, 0.0f)) && tuple_equal(n3, vector(0.0f, 1.0f, 0.0f)); } static bool planes_test_1(const char ** scenario) { *scenario = "Intersect with a ray parallel to the plane"; struct shape p = plane(); struct ray r = ray(point(0.0f, 10.0f, 0.0f), vector(0.0f, 0.0f, 1.0f)); struct intersections xs; xs.count = 0; plane_intersect(&p, r, &xs); return xs.count == 0; } static bool planes_test_2(const char ** scenario) { *scenario = "Intersect with a coplanar ray"; struct shape p = plane(); struct ray r = ray(point(0.0f, 0.0f, 0.0f), vector(0.0f, 0.0f, 1.0f)); struct intersections xs; xs.count = 0; plane_intersect(&p, r, &xs); return xs.count == 0; } static bool planes_test_3(const char ** scenario) { *scenario = "A ray intersecting a plane from above"; struct shape p = plane(); struct ray r = ray(point(0.0f, 1.0f, 0.0f), vector(0.0f, -1.0f, 0.0f)); struct intersections xs; xs.count = 0; plane_intersect(&p, r, &xs); return xs.count == 1 && float_equal(xs.i[0].t, 1.0f) && xs.i[0].object == &p; } static bool planes_test_4(const char ** scenario) { *scenario = "A ray intersecting a plane from below"; struct shape p = plane(); struct ray r = ray(point(0.0f, -1.0f, 0.0f), vector(0.0f, 1.0f, 1.0f)); struct intersections xs; xs.count = 0; plane_intersect(&p, r, &xs); return xs.count == 1 && float_equal(xs.i[0].t, 1.0f) && xs.i[0].object == &p; } test_t planes_tests[] = { planes_test_0, planes_test_1, planes_test_2, planes_test_3, planes_test_4, }; RUNNER(planes_tests);