plane_test.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Plane unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <ray.h>
  10. #include <shape.h>
  11. #include <plane.h>
  12. #include <material.h>
  13. #include <transformation.h>
  14. #include <gtest/gtest.h>
  15. TEST(PlaneTest, The_normal_of_a_plane_is_constant_everywhere)
  16. {
  17. Plane p = Plane();
  18. Tuple n1 = p.normalAt(Point(0, 0, 0));
  19. Tuple n2 = p.normalAt(Point(10, 0, -10));
  20. Tuple n3 = p.normalAt(Point(-5, 0, 0150));
  21. ASSERT_EQ(n1, Vector(0, 1, 0));
  22. ASSERT_EQ(n2, Vector(0, 1, 0));
  23. ASSERT_EQ(n3, Vector(0, 1, 0));
  24. }
  25. TEST(PlaneTest, Intersect_with_a_ray_parallel_to_the_plane)
  26. {
  27. Plane p = Plane();
  28. Ray r = Ray(Point(0, 10, 0), Vector(0, 0, 1));
  29. Intersect xs = p.intersect(r);
  30. ASSERT_EQ(xs.count(), 0);
  31. }
  32. TEST(PlaneTest, Intersect_with_a_coplanar_ray)
  33. {
  34. Plane p = Plane();
  35. Ray r = Ray(Point(0, 0, 0), Vector(0, 0, 1));
  36. Intersect xs = p.intersect(r);
  37. ASSERT_EQ(xs.count(), 0);
  38. }
  39. TEST(PlaneTest, A_ray_intersecting_a_plane_from_above)
  40. {
  41. Plane p = Plane();
  42. Ray r = Ray(Point(0, 1, 0), Vector(0, -1, 0));
  43. Intersect xs = p.intersect(r);
  44. ASSERT_EQ(xs.count(), 1);
  45. ASSERT_EQ(xs[0].t, 1);
  46. ASSERT_EQ(xs[0].object, &p);
  47. }
  48. TEST(PlaneTest, A_ray_intersecting_a_plane_from_below)
  49. {
  50. Plane p = Plane();
  51. Ray r = Ray(Point(0, -1, 0), Vector(0, 1, 0));
  52. Intersect xs = p.intersect(r);
  53. ASSERT_EQ(xs.count(), 1);
  54. ASSERT_EQ(xs[0].t, 1);
  55. ASSERT_EQ(xs[0].object, &p);
  56. }