From 2ea4abdce78b79060a44318e5899f181e4039c83 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 25 Feb 2020 18:03:12 +0000 Subject: [PATCH] Boundingboxes should be ready. Next step (later) would be to properly use them other than group to lower the number of intersection calculation per ray. --- source/include/boundingbox.h | 89 +++++++++++++++++++++++++++++++++++- source/include/cone.h | 1 + source/include/cylinder.h | 1 + source/include/group.h | 10 +++- source/include/plane.h | 1 + source/include/shape.h | 4 +- source/include/tuple.h | 4 ++ source/math_helper.cpp | 3 ++ source/shapes/cone.cpp | 5 +- source/shapes/cylinder.cpp | 3 ++ source/shapes/group.cpp | 89 ++++++++++++++++++++++++++---------- source/shapes/plane.cpp | 3 ++ source/tuple.cpp | 24 ++++++++++ tests/CMakeLists.txt | 3 +- tests/boundingbox_test.cpp | 81 ++++++++++++++++++++++++++++++++ tests/cone_test.cpp | 38 +++++++++++++++ tests/cube_test.cpp | 9 +++- tests/cylinder_test.cpp | 28 +++++++++++- tests/group_test.cpp | 20 +++++++- tests/plane_test.cpp | 17 +++++++ tests/sphere_test.cpp | 7 +++ 21 files changed, 406 insertions(+), 34 deletions(-) create mode 100644 tests/boundingbox_test.cpp diff --git a/source/include/boundingbox.h b/source/include/boundingbox.h index 12d5061..161bd0d 100644 --- a/source/include/boundingbox.h +++ b/source/include/boundingbox.h @@ -11,11 +11,96 @@ struct BoundingBox { +private: + bool isReset; + +public: Tuple min; Tuple max; - BoundingBox() : min(-0, -0, -0), max(0, 0, 0) { }; - BoundingBox(Tuple min, Tuple max) : min(min), max(max) { }; + BoundingBox() : min(INFINITY, INFINITY, INFINITY, 1.0), max(-INFINITY, -INFINITY, -INFINITY, 1.0), isReset(true) { }; + BoundingBox(Tuple min, Tuple max) : min(min), max(max), isReset(false) { }; + + void operator|(const BoundingBox &b) { + isReset = false; + + if (this->min.x > b.min.x) { this->min.x = b.min.x; } + if (this->min.y > b.min.y) { this->min.y = b.min.y; } + if (this->min.z > b.min.z) { this->min.z = b.min.z; } + + if (this->max.x < b.max.x) { this->max.x = b.max.x; } + if (this->max.y < b.max.y) { this->max.y = b.max.y; } + if (this->max.z < b.max.z) { this->max.z = b.max.z; } + } + + bool haveFiniteBounds() { return this->min.isRepresentable() && this->max.isRepresentable(); }; + + bool fitsIn(const BoundingBox &other) { + bool fits = true; + + if (this->min.x > other.min.x) { fits = false; } + if (this->min.y > other.min.y) { fits = false; } + if (this->min.z > other.min.z) { fits = false; } + + if (this->max.x < other.max.x) { fits = false; } + if (this->max.y < other.max.y) { fits = false; } + if (this->max.z < other.max.z) { fits = false; } + + return fits; + } + + void checkAxis(double axeOrigin, double axeDirection, double xMin, double xMax, double *axeMin, double *axeMax) + { + double tMinNumerator = (xMin - axeOrigin); + double tMaxNumerator = (xMax - axeOrigin); + + if (fabs(axeDirection) >= getEpsilon()) + { + *axeMin = tMinNumerator / axeDirection; + *axeMax = tMaxNumerator / axeDirection; + } + else + { + *axeMin = tMinNumerator * INFINITY; + *axeMax = tMaxNumerator * INFINITY; + } + + if (*axeMin > *axeMax) + { + double swap = *axeMax; + *axeMax = *axeMin; + *axeMin = swap; + } + } + + void reset() + { + this->isReset = true; + min.x = min.y = min.z = INFINITY; + max.x = max.y = max.z = -INFINITY; + } + + bool isEmpty() { return this->isReset; }; + + bool intesectMe(Ray r) { + + double xtMin, xtMax, ytMin, ytMax, ztMin, ztMax; + double tMin, tMax; + + this->checkAxis(r.origin.x, r.direction.x, this->min.x, this->max.x, &xtMin, &xtMax); + this->checkAxis(r.origin.y, r.direction.y, this->min.y, this->max.y, &ytMin, &ytMax); + this->checkAxis(r.origin.z, r.direction.z, this->min.z, this->max.z, &ztMin, &ztMax); + + tMin = max3(xtMin, ytMin, ztMin); + tMax = min3(xtMax, ytMax, ztMax); + + if (tMin <= tMax) + { + return true; + } + return false; + } + }; #endif //DORAYME_BOUNDINGBOX_H diff --git a/source/include/cone.h b/source/include/cone.h index b26397c..9772ba2 100644 --- a/source/include/cone.h +++ b/source/include/cone.h @@ -29,6 +29,7 @@ public: Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) {}; BoundingBox getBounds(); + bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; }; #endif /* DORAYME_CONE_H */ diff --git a/source/include/cylinder.h b/source/include/cylinder.h index 46c1825..e911be9 100644 --- a/source/include/cylinder.h +++ b/source/include/cylinder.h @@ -30,6 +30,7 @@ public: Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CYLINDER) {}; BoundingBox getBounds(); + bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; }; #endif //DORAYME_CYLINDER_H diff --git a/source/include/group.h b/source/include/group.h index b905773..f4bd471 100644 --- a/source/include/group.h +++ b/source/include/group.h @@ -11,6 +11,8 @@ #include +/* TODO: Add a way to force(?) material from group to be applied on childs */ + class Group : public Shape { private: @@ -18,11 +20,15 @@ private: Shape* *objectList; uint32_t objectCount; + uint32_t allocatedUnboxableObjectCount; + Shape* *unboxableObjectList; + uint32_t unboxableObjectCount; + protected: Intersect localIntersect(Ray r); Tuple localNormalAt(Tuple point); - + BoundingBox bounds; public: bool isEmpty(); @@ -34,6 +40,8 @@ public: BoundingBox getBounds(); + void updateBoundingBox(); + Group(); }; diff --git a/source/include/plane.h b/source/include/plane.h index 6ef85ba..c2debbb 100644 --- a/source/include/plane.h +++ b/source/include/plane.h @@ -18,6 +18,7 @@ private: public: Plane() : Shape(SHAPE_PLANE) { }; BoundingBox getBounds(); + bool haveFiniteBounds() { return false; }; }; #endif //DORAYME_PLANE_H diff --git a/source/include/shape.h b/source/include/shape.h index 616c909..cd5b0bb 100644 --- a/source/include/shape.h +++ b/source/include/shape.h @@ -53,10 +53,12 @@ public: Shape(ShapeType = SHAPE_NONE); virtual Intersect intersect(Ray r); + virtual Intersect intersectOOB(Ray r) { return this->intersect(r); }; Tuple normalAt(Tuple point); - /* Bouding box points are always world value */ + /* Bounding box points are always world value */ virtual BoundingBox getBounds(); + virtual bool haveFiniteBounds() { return true; }; void updateTransform(); Tuple worldToObject(Tuple point) { return this->inverseTransform * point; }; diff --git a/source/include/tuple.h b/source/include/tuple.h index 2b0cbce..303378d 100644 --- a/source/include/tuple.h +++ b/source/include/tuple.h @@ -40,6 +40,10 @@ public: Tuple operator/(const double &b) const { return Tuple(this->x / b, this->y / b, this->z / b, this->w / b); }; + void fixPoint(); + void fixVector(); + bool isRepresentable(); + void set(double nX, double nY, double nZ) { this->x = nX; this->y = nY; this->z = nZ; }; double magnitude(); Tuple normalise(); diff --git a/source/math_helper.cpp b/source/math_helper.cpp index 6d2f7c4..522f5f0 100644 --- a/source/math_helper.cpp +++ b/source/math_helper.cpp @@ -25,6 +25,9 @@ double getEpsilon() bool double_equal(double a, double b) { + if (isinf(a) && isinf(b)) + return true; + return fabs(a - b) < current_precision; } diff --git a/source/shapes/cone.cpp b/source/shapes/cone.cpp index 5d22394..9843a2d 100644 --- a/source/shapes/cone.cpp +++ b/source/shapes/cone.cpp @@ -129,10 +129,13 @@ BoundingBox Cone::getBounds() double a = fabs(this->minCap); double b = fabs(this->maxCap); - double limit = (a < b)?a:b; + double limit = (a > b)?a:b; ret.min = this->objectToWorld(Point(-limit, this->minCap, -limit)); ret.max = this->objectToWorld(Point(limit, this->maxCap, limit)); + ret.min.fixPoint(); + ret.max.fixPoint(); + return ret; } \ No newline at end of file diff --git a/source/shapes/cylinder.cpp b/source/shapes/cylinder.cpp index bb70463..e7735d6 100644 --- a/source/shapes/cylinder.cpp +++ b/source/shapes/cylinder.cpp @@ -115,5 +115,8 @@ BoundingBox Cylinder::getBounds() ret.min = this->objectToWorld(Point(-1, this->minCap, -1)); ret.max = this->objectToWorld(Point(1, this->maxCap, 1)); + ret.min.fixPoint(); + ret.max.fixPoint(); + return ret; } \ No newline at end of file diff --git a/source/shapes/group.cpp b/source/shapes/group.cpp index 11b377f..81c92f3 100644 --- a/source/shapes/group.cpp +++ b/source/shapes/group.cpp @@ -19,6 +19,11 @@ Group::Group() : Shape(SHAPE_GROUP) this->allocatedObjectCount = MIN_ALLOC; this->objectList = (Shape **)calloc(sizeof(Shape *), MIN_ALLOC); this->objectCount = 0; + + this->allocatedUnboxableObjectCount = MIN_ALLOC; + this->unboxableObjectList = (Shape **)calloc(sizeof(Shape *), MIN_ALLOC); + this->unboxableObjectCount = 0; + } Intersect Group::intersect(Ray r) @@ -27,9 +32,28 @@ Intersect Group::intersect(Ray r) int i, j; if (this->objectCount > 0) { - for(i = 0; i < this->objectCount; i++) + if (this->bounds.intesectMe(r)) { - Intersect xs = this->objectList[i]->intersect(r); + for (i = 0 ; i < this->objectCount ; i++) + { + Intersect xs = this->objectList[i]->intersect(r); + if (xs.count() > 0) + { + for (j = 0 ; j < xs.count() ; j++) + { + ret.add(xs[j]); + } + } + } + } + } + + /* We are force to do them all the time */ + if (this->unboxableObjectCount > 0) + { + for(i = 0; i < this->unboxableObjectCount; i++) + { + Intersect xs = this->unboxableObjectList[i]->intersect(r); if (xs.count() > 0) { for(j = 0; j < xs.count(); j++) @@ -39,7 +63,6 @@ Intersect Group::intersect(Ray r) } } } - return ret; } @@ -53,48 +76,64 @@ Tuple Group::localNormalAt(Tuple point) return Vector(1, 0, 0); } +/* ONLY INSERT SHAPES THAT ARE NOT GOING TO CHANGE ELSE..! */ void Group::addObject(Shape *s) { - if ((this->objectCount + 1) > this->allocatedObjectCount) + if (s->haveFiniteBounds()) { - this->allocatedObjectCount *= 2; - this->objectList = (Shape **)realloc(this->objectList, sizeof(Shape **) * this->allocatedObjectCount); + if ((this->objectCount + 1) > this->allocatedObjectCount) + { + this->allocatedObjectCount *= 2; + this->objectList = (Shape **)realloc(this->objectList, sizeof(Shape **) * this->allocatedObjectCount); + } + + s->parent = this; + s->updateTransform(); + + this->objectList[this->objectCount++] = s; + + this->bounds | s->getBounds(); + } + else + { + if ((this->unboxableObjectCount + 1) > this->allocatedUnboxableObjectCount) + { + this->allocatedUnboxableObjectCount *= 2; + this->unboxableObjectList = (Shape **)realloc(this->unboxableObjectList, sizeof(Shape **) * this->allocatedUnboxableObjectCount); + } - s->parent = this; - s->updateTransform(); + s->parent = this; + s->updateTransform(); - this->objectList[this->objectCount++] = s; + this->unboxableObjectList[this->unboxableObjectCount++] = s; + } } bool Group::isEmpty() { - return (this->objectCount == 0); + return (this->objectCount == 0) && (this->unboxableObjectCount == 0); } BoundingBox Group::getBounds() { - BoundingBox ret; + if (this->bounds.isEmpty()) { this->updateBoundingBox(); } + return this->bounds; +} +void Group::updateBoundingBox() +{ + this->bounds.reset(); if (this->objectCount > 0) { - ret.min = Point(INFINITY, INFINITY, INFINITY); - ret.max = Point(-INFINITY, -INFINITY, -INFINITY); - int i; for(i = 0; i < this->objectCount; i++) { - BoundingBox obj = this->objectList[i]->getBounds(); - - if (ret.min.x > obj.min.x) { ret.min.x = obj.min.x; } - if (ret.min.y > obj.min.y) { ret.min.y = obj.min.y; } - if (ret.min.z > obj.min.z) { ret.min.z = obj.min.z; } - - if (ret.max.x < obj.max.x) { ret.max.x = obj.max.x; } - if (ret.max.y < obj.max.y) { ret.max.y = obj.max.y; } - if (ret.max.z < obj.max.z) { ret.max.z = obj.max.z; } + if (!this->objectList[i]->haveFiniteBounds()) + { + BoundingBox objB = this->objectList[i]->getBounds(); + this->bounds | objB; + } } } - - return ret; } \ No newline at end of file diff --git a/source/shapes/plane.cpp b/source/shapes/plane.cpp index 7a47044..26518ca 100644 --- a/source/shapes/plane.cpp +++ b/source/shapes/plane.cpp @@ -42,5 +42,8 @@ BoundingBox Plane::getBounds() ret.min = this->objectToWorld(Point(-INFINITY, 0-getEpsilon(), -INFINITY)); ret.max = this->objectToWorld(Point(INFINITY, 0+getEpsilon(), INFINITY)); + ret.min.fixPoint(); + ret.max.fixPoint(); + return ret; } \ No newline at end of file diff --git a/source/tuple.cpp b/source/tuple.cpp index fb5aba2..9249e34 100644 --- a/source/tuple.cpp +++ b/source/tuple.cpp @@ -43,4 +43,28 @@ Tuple Tuple::cross(const Tuple &b) const Tuple Tuple::reflect(const Tuple &normal) { return *this - normal * 2 * this->dot(normal); +} + +void Tuple::fixPoint() +{ + if (isnan(this->x) || isnan(this->y) || isnan(this->z)) + { + /* w is probably broken, so fix it */ + this->w = 1; + } +} + +void Tuple::fixVector() +{ + + if (isnan(this->x) || isnan(this->y) || isnan(this->z)) + { + /* w is probably broken, so fix it */ + this->w = 0; + } +} + +bool Tuple::isRepresentable() +{ + return !(isnan(this->x) || isnan(this->y) || isnan(this->z)); } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2586846..9298ad8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,8 @@ find_package(Threads REQUIRED) set(TESTS_SRC math_test.cpp tuple_test.cpp colour_test.cpp canvas_test.cpp matrix_test.cpp transformation_test.cpp ray_test.cpp intersect_test.cpp sphere_test.cpp light_test.cpp material_test.cpp world_test.cpp camera_test.cpp - shape_test.cpp plane_test.cpp pattern_test.cpp cube_test.cpp cylinder_test.cpp cone_test.cpp group_test.cpp) + shape_test.cpp plane_test.cpp pattern_test.cpp cube_test.cpp cylinder_test.cpp cone_test.cpp group_test.cpp + boundingbox_test.cpp) add_executable(testMyRays) target_include_directories(testMyRays PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) diff --git a/tests/boundingbox_test.cpp b/tests/boundingbox_test.cpp new file mode 100644 index 0000000..9b32ca9 --- /dev/null +++ b/tests/boundingbox_test.cpp @@ -0,0 +1,81 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * Boundingbox unit tests + * + * Created by Manoël Trapier + * Copyright (c) 2020 986-Studio. + * + */ +/* + * DoRayMe - a quick and dirty Raytracer + * Camera unit tests + * + * Created by Manoël Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#include +#include +#include +#include +#include +#include +#include + +TEST(BoundingBox, Default_boundingbox_is_not_set) +{ + BoundingBox bb; + + ASSERT_TRUE(bb.isEmpty()); + ASSERT_EQ(bb.min, Point(INFINITY, INFINITY, INFINITY)); + ASSERT_EQ(bb.max, Point(-INFINITY, -INFINITY, -INFINITY)); +} + +TEST(BoundingBox, Bounding_box_can_be_created_with_values) +{ + BoundingBox bb = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1)); + + ASSERT_FALSE(bb.isEmpty()); + ASSERT_EQ(bb.min, Point(-1, -1, -1)); + ASSERT_EQ(bb.max, Point(1, 1, 1)); +} + +TEST(BoundingBox, Cating_a_bb_to_an_empty_bb_reset_the_original_one) +{ + BoundingBox bb; + + bb | BoundingBox(Point(-1, -1, -1), Point(1, 1, 1)); + + ASSERT_FALSE(bb.isEmpty()); + ASSERT_EQ(bb.min, Point(-1, -1, -1)); + ASSERT_EQ(bb.max, Point(1, 1, 1)); +} + +TEST(BoundingBox, Cating_a_bb_to_another_bb_expand_the_original_one_if_needed) +{ + BoundingBox bb(Point(-1, -1, -1), Point(1, 1, 1)); + + bb | BoundingBox(Point(-2, 0, -5), Point(4, 5, 0.5)); + + ASSERT_FALSE(bb.isEmpty()); + ASSERT_EQ(bb.min, Point(-2, -1, -5)); + ASSERT_EQ(bb.max, Point(4, 5, 1)); +} + +TEST(BoundingBox, A_smaller_bb_should_fit_in_a_bigger) +{ + BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10)); + + BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2)); + + ASSERT_TRUE(bigBb.fitsIn(smallBb)); +} + +TEST(BoundingBox, A_big_bb_should_not_fit_in_a_smaller) +{ + BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10)); + + BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2)); + + ASSERT_FALSE(smallBb.fitsIn(bigBb)); +} diff --git a/tests/cone_test.cpp b/tests/cone_test.cpp index ed37f3c..9855cd6 100644 --- a/tests/cone_test.cpp +++ b/tests/cone_test.cpp @@ -130,3 +130,41 @@ TEST(ConeTest, Computing_the_normal_vector_on_a_cone) ASSERT_EQ(cone.doLocalNormalAt(HitPointss[i]), Normals[i]); } } + +TEST(ConeTest, The_bounding_box_of_a_cut_cone) +{ + Cone t = Cone(); + BoundingBox b = BoundingBox(Point(-8, -5, -8), Point(8, 8, 8)); + t.minCap = -5; + t.maxCap = 8; + BoundingBox res = t.getBounds(); + + ASSERT_EQ(res.min, b.min); + ASSERT_EQ(res.max, b.max); +} + +TEST(ConeTest, The_bounding_box_of_a_uncut_cone) +{ + /* This one is tricky. Infinite size don't cope well with transformations */ + Cone t = Cone(); + BoundingBox res = t.getBounds(); + + ASSERT_FALSE(res.min.isRepresentable()); + ASSERT_FALSE(res.max.isRepresentable()); +} + +TEST(ConeTest, An_uncut_cone_have_infinite_bounds) +{ + Cone t = Cone(); + + ASSERT_FALSE(t.haveFiniteBounds()); +} + +TEST(ConeTest, A_cut_cone_have_finite_bounds) +{ + Cone t = Cone(); + t.minCap = -1; + t.maxCap = 1; + + ASSERT_TRUE(t.haveFiniteBounds()); +} \ No newline at end of file diff --git a/tests/cube_test.cpp b/tests/cube_test.cpp index 24ccf6b..6b2a735 100644 --- a/tests/cube_test.cpp +++ b/tests/cube_test.cpp @@ -116,7 +116,7 @@ TEST(CubeTest, The_normal_on_the_surface_of_a_cube) } } -TEST(Cube, The_bounding_box_of_a_cube) +TEST(CubeTest, The_bounding_box_of_a_cube) { Cube t = Cube(); BoundingBox b = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1)); @@ -125,4 +125,11 @@ TEST(Cube, The_bounding_box_of_a_cube) ASSERT_EQ(res.min, b.min); ASSERT_EQ(res.max, b.max); +} + +TEST(CubeTest, A_cube_have_finite_bounds) +{ + Cube t = Cube(); + + ASSERT_TRUE(t.haveFiniteBounds()); } \ No newline at end of file diff --git a/tests/cylinder_test.cpp b/tests/cylinder_test.cpp index d38c2a8..9b4bc39 100644 --- a/tests/cylinder_test.cpp +++ b/tests/cylinder_test.cpp @@ -222,7 +222,7 @@ TEST(CylinderTest, The_normal_on_a_cylinder_end_cap) } } -TEST(CylinderTest, The_bounding_box_of_an_uncut_cylinder) +TEST(CylinderTest, The_bounding_box_of_a_cut_cylinder) { Cylinder t = Cylinder(); BoundingBox b = BoundingBox(Point(-1, -10000, -1), Point(1, 10000, 1)); @@ -232,4 +232,30 @@ TEST(CylinderTest, The_bounding_box_of_an_uncut_cylinder) ASSERT_EQ(res.min, b.min); ASSERT_EQ(res.max, b.max); +} + +TEST(CylinderTest, The_bounding_box_of_a_uncut_cylinder) +{ + /* This one is tricky. Infinite size don't cope well with transformations */ + Cylinder t = Cylinder(); + BoundingBox res = t.getBounds(); + + ASSERT_FALSE(res.min.isRepresentable()); + ASSERT_FALSE(res.max.isRepresentable()); +} + +TEST(CylinderTest, An_uncut_cylinder_have_infinite_bounds) +{ + Cylinder t = Cylinder(); + + ASSERT_FALSE(t.haveFiniteBounds()); +} + +TEST(CylinderTest, A_cut_cylinder_have_finite_bounds) +{ + Cylinder t = Cylinder(); + t.minCap = -1; + t.maxCap = 1; + + ASSERT_TRUE(t.haveFiniteBounds()); } \ No newline at end of file diff --git a/tests/group_test.cpp b/tests/group_test.cpp index bf8fa3b..0a817b6 100644 --- a/tests/group_test.cpp +++ b/tests/group_test.cpp @@ -66,7 +66,7 @@ TEST(GroupTest, Intersecting_a_ray_with_an_nonempty_group) EXPECT_EQ(xs[3].object, &s1); } -TEST(GroupTest, Intersecting_a_transformer_group) +TEST(GroupTest, Intersecting_a_transformed_group) { Group g = Group(); Sphere s = Sphere(); @@ -79,4 +79,22 @@ TEST(GroupTest, Intersecting_a_transformer_group) Ray r = Ray(Point(10, 0, -50), Vector(0, 0, 1)); Intersect xs = g.intersect(r); ASSERT_EQ(xs.count(), 2); +} + +TEST(GroupTest, Group_bounding_box) +{ + Group g = Group(); + Sphere s = Sphere(); + + g.setTransform(scaling(2, 2, 2)); + s.setTransform(translation(5, 0, 0)); + + g.addObject(&s); + + BoundingBox b = BoundingBox(Point(8, -2, -2), Point(12, 2, 2)); + + BoundingBox res = g.getBounds(); + + ASSERT_EQ(res.min, b.min); + ASSERT_EQ(res.max, b.max); } \ No newline at end of file diff --git a/tests/plane_test.cpp b/tests/plane_test.cpp index be06593..36aee8a 100644 --- a/tests/plane_test.cpp +++ b/tests/plane_test.cpp @@ -68,4 +68,21 @@ TEST(PlaneTest, A_ray_intersecting_a_plane_from_below) ASSERT_EQ(xs.count(), 1); ASSERT_EQ(xs[0].t, 1); ASSERT_EQ(xs[0].object, &p); +} + +TEST(PlaneTest, The_bounding_box_of_a_plane) +{ + Plane t = Plane(); + BoundingBox b = BoundingBox(Point(-8, -5, -8), Point(8, 8, 8)); + BoundingBox res = t.getBounds(); + + ASSERT_FALSE(res.min.isRepresentable()); + ASSERT_FALSE(res.max.isRepresentable()); +} + +TEST(PlaneTest, A_plane_have_infinite__bounds) +{ + Plane t = Plane(); + + ASSERT_FALSE(t.haveFiniteBounds()); } \ No newline at end of file diff --git a/tests/sphere_test.cpp b/tests/sphere_test.cpp index 11260ff..7918d17 100644 --- a/tests/sphere_test.cpp +++ b/tests/sphere_test.cpp @@ -218,4 +218,11 @@ TEST(SphereTest, The_bounding_box_of_a_sphere) ASSERT_EQ(res.min, b.min); ASSERT_EQ(res.max, b.max); +} + +TEST(SphereTest, A_sphere_have_finite_bounds) +{ + Sphere t = Sphere(); + + ASSERT_TRUE(t.haveFiniteBounds()); } \ No newline at end of file