boundingbox_test.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Boundingbox unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <math.h>
  10. #include <math_helper.h>
  11. #include <ray.h>
  12. #include <transformation.h>
  13. #include <stdint.h>
  14. #include <boundingbox.h>
  15. #include <gtest/gtest.h>
  16. TEST(BoundingBoxTest, Creating_an_empty_bounding_box)
  17. {
  18. BoundingBox bb;
  19. ASSERT_TRUE(bb.isEmpty());
  20. ASSERT_EQ(bb.min, Point(INFINITY, INFINITY, INFINITY));
  21. ASSERT_EQ(bb.max, Point(-INFINITY, -INFINITY, -INFINITY));
  22. }
  23. TEST(BoundingBoxTest, Crteating_a_bounding_box_with_volume)
  24. {
  25. BoundingBox bb = BoundingBox(Point(-1, -2, -3), Point(3, 2, 1));
  26. ASSERT_FALSE(bb.isEmpty());
  27. ASSERT_EQ(bb.min, Point(-1, -2, -3));
  28. ASSERT_EQ(bb.max, Point(3, 2, 1));
  29. }
  30. TEST(BoundingBoxTest, Adding_on_bouding_to_an_empty_bounding_box)
  31. {
  32. BoundingBox bb;
  33. bb | BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
  34. ASSERT_FALSE(bb.isEmpty());
  35. ASSERT_EQ(bb.min, Point(-1, -1, -1));
  36. ASSERT_EQ(bb.max, Point(1, 1, 1));
  37. }
  38. TEST(BoundingBoxTest, Adding_boudingbox_to_another)
  39. {
  40. BoundingBox bb(Point(-1, -1, 0), Point(4, 0, 1));
  41. bb | BoundingBox(Point(-2, 0, -5), Point(4, 5, 0.5));
  42. ASSERT_FALSE(bb.isEmpty());
  43. ASSERT_EQ(bb.min, Point(-2, -1, -5));
  44. ASSERT_EQ(bb.max, Point(4, 5, 1));
  45. }
  46. TEST(BoundingBoxTest, Adding_points_to_an_empty_bounding_box)
  47. {
  48. BoundingBox bb;
  49. bb | Point(-5, 2, 0);
  50. bb | Point(7, 0, -3);
  51. ASSERT_FALSE(bb.isEmpty());
  52. ASSERT_EQ(bb.min, Point(-5, 0, -3));
  53. ASSERT_EQ(bb.max, Point(7, 2, 0));
  54. }
  55. TEST(BoundingBoxTest, A_smaller_bb_should_fit_in_a_bigger)
  56. {
  57. BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
  58. BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2));
  59. ASSERT_TRUE(bigBb.fitsIn(smallBb));
  60. }
  61. TEST(BoundingBoxTest, A_big_bb_should_not_fit_in_a_smaller)
  62. {
  63. BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
  64. BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2));
  65. ASSERT_FALSE(smallBb.fitsIn(bigBb));
  66. }