More bounding boxes
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
#include <boundingbox.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(BoundingBox, Default_boundingbox_is_not_set)
|
||||
TEST(BoundingBoxTest, Creating_an_empty_bounding_box)
|
||||
{
|
||||
BoundingBox bb;
|
||||
|
||||
@@ -31,16 +31,16 @@ TEST(BoundingBox, Default_boundingbox_is_not_set)
|
||||
ASSERT_EQ(bb.max, Point(-INFINITY, -INFINITY, -INFINITY));
|
||||
}
|
||||
|
||||
TEST(BoundingBox, Bounding_box_can_be_created_with_values)
|
||||
TEST(BoundingBoxTest, Crteating_a_bounding_box_with_volume)
|
||||
{
|
||||
BoundingBox bb = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
|
||||
BoundingBox bb = BoundingBox(Point(-1, -2, -3), Point(3, 2, 1));
|
||||
|
||||
ASSERT_FALSE(bb.isEmpty());
|
||||
ASSERT_EQ(bb.min, Point(-1, -1, -1));
|
||||
ASSERT_EQ(bb.max, Point(1, 1, 1));
|
||||
ASSERT_EQ(bb.min, Point(-1, -2, -3));
|
||||
ASSERT_EQ(bb.max, Point(3, 2, 1));
|
||||
}
|
||||
|
||||
TEST(BoundingBox, Cating_a_bb_to_an_empty_bb_reset_the_original_one)
|
||||
TEST(BoundingBoxTest, Adding_on_bouding_to_an_empty_bounding_box)
|
||||
{
|
||||
BoundingBox bb;
|
||||
|
||||
@@ -51,9 +51,9 @@ TEST(BoundingBox, Cating_a_bb_to_an_empty_bb_reset_the_original_one)
|
||||
ASSERT_EQ(bb.max, Point(1, 1, 1));
|
||||
}
|
||||
|
||||
TEST(BoundingBox, Cating_a_bb_to_another_bb_expand_the_original_one_if_needed)
|
||||
TEST(BoundingBoxTest, Adding_boudingbox_to_another)
|
||||
{
|
||||
BoundingBox bb(Point(-1, -1, -1), Point(1, 1, 1));
|
||||
BoundingBox bb(Point(-1, -1, 0), Point(4, 0, 1));
|
||||
|
||||
bb | BoundingBox(Point(-2, 0, -5), Point(4, 5, 0.5));
|
||||
|
||||
@@ -62,7 +62,19 @@ TEST(BoundingBox, Cating_a_bb_to_another_bb_expand_the_original_one_if_needed)
|
||||
ASSERT_EQ(bb.max, Point(4, 5, 1));
|
||||
}
|
||||
|
||||
TEST(BoundingBox, A_smaller_bb_should_fit_in_a_bigger)
|
||||
TEST(BoundingBoxTest, Adding_points_to_an_empty_bounding_box)
|
||||
{
|
||||
BoundingBox bb;
|
||||
|
||||
bb | Point(-5, 2, 0);
|
||||
bb | Point(7, 0, -3);
|
||||
|
||||
ASSERT_FALSE(bb.isEmpty());
|
||||
ASSERT_EQ(bb.min, Point(-5, 0, -3));
|
||||
ASSERT_EQ(bb.max, Point(7, 2, 0));
|
||||
}
|
||||
|
||||
TEST(BoundingBoxTest, A_smaller_bb_should_fit_in_a_bigger)
|
||||
{
|
||||
BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
|
||||
|
||||
@@ -71,7 +83,7 @@ TEST(BoundingBox, A_smaller_bb_should_fit_in_a_bigger)
|
||||
ASSERT_TRUE(bigBb.fitsIn(smallBb));
|
||||
}
|
||||
|
||||
TEST(BoundingBox, A_big_bb_should_not_fit_in_a_smaller)
|
||||
TEST(BoundingBoxTest, A_big_bb_should_not_fit_in_a_smaller)
|
||||
{
|
||||
BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
|
||||
|
||||
|
||||
@@ -163,8 +163,11 @@ TEST(ConeTest, An_uncut_cone_have_infinite_bounds)
|
||||
TEST(ConeTest, A_cut_cone_have_finite_bounds)
|
||||
{
|
||||
Cone t = Cone();
|
||||
t.minCap = -1;
|
||||
t.maxCap = 1;
|
||||
t.minCap = -5;
|
||||
t.maxCap = 3;
|
||||
BoundingBox res = t.getBounds();
|
||||
|
||||
ASSERT_TRUE(t.haveFiniteBounds());
|
||||
ASSERT_EQ(res.min, Point(-5, -5, -5));
|
||||
ASSERT_EQ(res.max, Point(5, 3, 5));
|
||||
}
|
||||
@@ -119,12 +119,13 @@ TEST(CubeTest, The_normal_on_the_surface_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));
|
||||
Tuple boxMin = Point(-1, -1, -1);
|
||||
Tuple boxMax = Point(1, 1, 1);
|
||||
|
||||
BoundingBox res = t.getBounds();
|
||||
|
||||
ASSERT_EQ(res.min, b.min);
|
||||
ASSERT_EQ(res.max, b.max);
|
||||
ASSERT_EQ(res.min, boxMin);
|
||||
ASSERT_EQ(res.max, boxMax);
|
||||
}
|
||||
|
||||
TEST(CubeTest, A_cube_have_finite_bounds)
|
||||
|
||||
@@ -254,8 +254,10 @@ TEST(CylinderTest, An_uncut_cylinder_have_infinite_bounds)
|
||||
TEST(CylinderTest, A_cut_cylinder_have_finite_bounds)
|
||||
{
|
||||
Cylinder t = Cylinder();
|
||||
t.minCap = -1;
|
||||
t.maxCap = 1;
|
||||
|
||||
t.minCap = -5;
|
||||
t.maxCap = 3;
|
||||
BoundingBox res = t.getBounds();
|
||||
ASSERT_TRUE(t.haveFiniteBounds());
|
||||
ASSERT_EQ(res.min, Point(-1, -5, -1));
|
||||
ASSERT_EQ(res.max, Point(1, 3, 1));
|
||||
}
|
||||
@@ -212,12 +212,13 @@ TEST(SphereTest, A_helper_for_producing_a_sphere_with_a_glassy_material)
|
||||
TEST(SphereTest, The_bounding_box_of_a_sphere)
|
||||
{
|
||||
Sphere t = Sphere();
|
||||
BoundingBox b = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
|
||||
Tuple sphereMin = Point(-1, -1, -1);
|
||||
Tuple sphereMax = Point(1, 1, 1);
|
||||
|
||||
BoundingBox res = t.getBounds();
|
||||
|
||||
ASSERT_EQ(res.min, b.min);
|
||||
ASSERT_EQ(res.max, b.max);
|
||||
ASSERT_EQ(res.min, sphereMin);
|
||||
ASSERT_EQ(res.max, sphereMax);
|
||||
}
|
||||
|
||||
TEST(SphereTest, A_sphere_have_finite_bounds)
|
||||
|
||||
@@ -88,4 +88,14 @@ TEST(TriangleTest, A_ray_strikes_a_triangle)
|
||||
|
||||
ASSERT_EQ(xs.count(), 1);
|
||||
EXPECT_EQ(xs[0].t, 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TriangleTest, A_triangle_has_a_bounding_box)
|
||||
{
|
||||
Triangle t = Triangle(Point(-3, 7, 2), Point(6, 2, -4), Point(2, -1, -1));
|
||||
|
||||
BoundingBox res = t.getBounds();
|
||||
|
||||
ASSERT_EQ(res.min, Point(-3, -1, -4));
|
||||
ASSERT_EQ(res.max, Point(6, 7, 2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user