plane_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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, xs);
  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, xs);
  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, xs);
  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, xs);
  53. ASSERT_EQ(xs.count(), 1);
  54. ASSERT_EQ(xs[0].t, 1);
  55. ASSERT_EQ(xs[0].object, &p);
  56. }
  57. TEST(PlaneTest, The_bounding_box_of_a_plane)
  58. {
  59. Plane t = Plane();
  60. BoundingBox res = t.getBounds();
  61. ASSERT_FALSE(res.min.isRepresentable());
  62. ASSERT_FALSE(res.max.isRepresentable());
  63. }
  64. TEST(PlaneTest, A_plane_have_infinite__bounds)
  65. {
  66. Plane t = Plane();
  67. ASSERT_FALSE(t.haveFiniteBounds());
  68. }