Continue working on bounding boxes.
This commit is contained in:
@@ -127,8 +127,12 @@ BoundingBox Cone::getBounds()
|
||||
{
|
||||
BoundingBox ret;
|
||||
|
||||
ret.min = this->objectToWorld(Point(-1, this->minCap, -1));
|
||||
ret.max = this->objectToWorld(Point(1, this->maxCap, 1));
|
||||
double a = fabs(this->minCap);
|
||||
double b = fabs(this->maxCap);
|
||||
double limit = (a < b)?a:b;
|
||||
|
||||
ret.min = this->objectToWorld(Point(-limit, this->minCap, -limit));
|
||||
ret.max = this->objectToWorld(Point(limit, this->maxCap, limit));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -115,3 +115,14 @@ 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);
|
||||
}
|
||||
@@ -221,3 +221,15 @@ 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -208,3 +208,14 @@ TEST(SphereTest, A_helper_for_producing_a_sphere_with_a_glassy_material)
|
||||
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);
|
||||
}
|
||||
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user