diff --git a/test/test_object.c b/test/test_object.c index 2a1d7e0..53afdc0 100644 --- a/test/test_object.c +++ b/test/test_object.c @@ -5,18 +5,49 @@ * Eryn Wells */ +#include + #include + #include "object.h" #include "test_suites.h" +void check_sphere_intersection(Object *sphere, Ray ray, int expected_nints); + + START_TEST(test_sphere_does_intersect) { + // Create a sphere at the origin of radius 1. + Object *sphere = object_init(ObjectTypeSphere); + object_sphere_set_radius(sphere, 1.0); + Vector3 loc, dir; + Ray ray; + + loc = vector_init(0, 0, -5); + dir = vector_init(0, 0, 1); + ray = ray_init(loc, dir); + check_sphere_intersection(sphere, ray, 2); + + loc = vector_init(0, -5, 0); + dir = vector_init( } END_TEST +void +check_sphere_intersection(Object *sphere, Ray ray, int expected_nints) +{ + float *t; + int nints = object_does_intersect(sphere, ray, &t); + ck_assert(nints == expected_nints); + if (nints > 0) { + free(t); + } +} + + Suite * test_object_create_suite() {