Continue working on bounding boxes.

This commit is contained in:
Godzil
2020-02-25 09:20:38 +00:00
parent 3011544e8f
commit 831a096281
6 changed files with 71 additions and 7 deletions

View File

@@ -114,4 +114,15 @@ TEST(CubeTest, The_normal_on_the_surface_of_a_cube)
{
ASSERT_EQ(c.normalAt(HitPoints[i]), ExpectedNormals[i]);
}
}
TEST(Cube, The_bounding_box_of_a_cube)
{
Cube t = Cube();
BoundingBox b = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
BoundingBox res = t.getBounds();
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}

View File

@@ -220,4 +220,16 @@ TEST(CylinderTest, The_normal_on_a_cylinder_end_cap)
{
ASSERT_EQ(cyl.normalAt(HitPointss[idx]), Normals[idx]);
}
}
TEST(CylinderTest, The_bounding_box_of_an_uncut_cylinder)
{
Cylinder t = Cylinder();
BoundingBox b = BoundingBox(Point(-1, -10000, -1), Point(1, 10000, 1));
t.minCap = -10000;
t.maxCap = 10000;
BoundingBox res = t.getBounds();
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}

View File

@@ -106,7 +106,7 @@ TEST(ShapeTest, A_shape_has_a_parent_attribute)
ASSERT_EQ(s.parent, nullptr);
}
TEST(TestShape, Converting_a_point_from_world_to_object_space)
TEST(ShapeTest, Converting_a_point_from_world_to_object_space)
{
Group g1 = Group();
g1.setTransform(rotationY(M_PI / 2));
@@ -122,7 +122,7 @@ TEST(TestShape, Converting_a_point_from_world_to_object_space)
ASSERT_EQ(p, Point(0, 0, -1));
}
TEST(TestShape, Converting_a_normal_form_object_to_world_space)
TEST(ShapeTest, Converting_a_normal_form_object_to_world_space)
{
Group g1 = Group();
g1.setTransform(rotationY(M_PI / 2));
@@ -144,7 +144,7 @@ TEST(TestShape, Converting_a_normal_form_object_to_world_space)
}
TEST(TestShape, Finding_the_normal_on_a_child_object)
TEST(ShapeTest, Finding_the_normal_on_a_child_object)
{
Group g1 = Group();
g1.setTransform(rotationY(M_PI / 2));
@@ -165,7 +165,7 @@ TEST(TestShape, Finding_the_normal_on_a_child_object)
set_equal_precision(FLT_EPSILON);
}
TEST(TestShape, Test_the_bouding_box_of_the_test_shape)
TEST(ShapeTest, Test_the_bouding_box_of_the_test_shape)
{
TestShape t = TestShape();
BoundingBox b = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
@@ -175,3 +175,29 @@ TEST(TestShape, Test_the_bouding_box_of_the_test_shape)
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}
TEST(ShapeTest, Test_the_bouding_box_of_the_scaled_shape)
{
TestShape t = TestShape();
t.setTransform(scaling(3, 3, 3));
BoundingBox b = BoundingBox(Point(-3, -3, -3), Point(3, 3, 3));
BoundingBox res = t.getBounds();
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}
TEST(ShapeTest, Test_the_bouding_box_of_the_translated_shape)
{
TestShape t = TestShape();
t.setTransform(translation(10, 0, 0));
BoundingBox b = BoundingBox(Point(9, -1, -1), Point(11, 1, 1));
BoundingBox res = t.getBounds();
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}

View File

@@ -207,4 +207,15 @@ TEST(SphereTest, A_helper_for_producing_a_sphere_with_a_glassy_material)
ASSERT_EQ(s.transformMatrix, Matrix4().identity());
ASSERT_EQ(s.material.transparency, 1.0);
ASSERT_EQ(s.material.refractiveIndex, 1.5);
}
TEST(SphereTest, The_bounding_box_of_a_sphere)
{
Sphere t = Sphere();
BoundingBox b = BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
BoundingBox res = t.getBounds();
ASSERT_EQ(res.min, b.min);
ASSERT_EQ(res.max, b.max);
}

View File

@@ -119,7 +119,7 @@ int main()
/* ----------------------------- */
/* Set the camera */
Camera camera = Camera(400, 200, deg_to_rad(90));
Camera camera = Camera(1280, 900, deg_to_rad(90));
camera.setTransform(viewTransform(Point(-2, 2.5, -3.5),
Point(2, 0, 3),
Vector(0, 1, 0)));