boundingbox_test.cpp 2.0 KB

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