[FEAT] Update cyclinder

This commit is contained in:
NADAL Jean-Baptiste
2024-03-19 18:42:19 +01:00
parent d34ad6a60b
commit 38107165a7
5 changed files with 180 additions and 39 deletions

View File

@@ -185,9 +185,9 @@ SCENARIO("The default minimum and maximum for a cylinder", "[features/cylinders.
Cylinder cyl;
THEN("cym.minimum = -infinity")
{
REQUIRE(cyl.minimum() == std::numeric_limits<double>::infinity());
REQUIRE(cyl.minimum() == -std::numeric_limits<double>::infinity());
}
AND_THEN("cym.maximum = -infinity")
AND_THEN("cym.maximum = infinity")
{
REQUIRE(cyl.maximum() == std::numeric_limits<double>::infinity());
}
@@ -245,3 +245,71 @@ SCENARIO("Intersecting a constrained cylinder", "[features/cylinders.feature]")
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The default closed value for a cylinder", "[features/cylinders.feature]")
{
GIVEN("cyl <- cylinder()")
{
Cylinder cyl;
THEN("cyl.closed = false")
{
REQUIRE(cyl.closed() == false);
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Intersecting the caps of a closed cylinder", "[features/cylinders.feature]")
{
// | | point | direction | count |
// | 1 | point(0, 3, 0) | vector(0, -1, 0) | 2 |
// | 2 | point(0, 3, -2) | vector(0, -1, 2) | 2 |
// | 3 | point(0, 4, -2) | vector(0, -1, 1) | 2 | # corner case
// | 4 | point(0, 0, -2) | vector(0, 1, 2) | 2 |
// | 5 | point(0, -1, -2) | vector(0, 1, 1) | 2 | # corner case
CylinderTestConstrained the_test[] = {
{Tuple::Point(0, 3, 0), Tuple::Vector(0, -1, 0), 2},
{Tuple::Point(0, 3, -2), Tuple::Vector(0, -1, 2), 2},
{Tuple::Point(0, 4, -2), Tuple::Vector(0, -1, 1), 2},
{Tuple::Point(0, 0, -2), Tuple::Vector(0, 1, 2), 2},
{Tuple::Point(0, -1, -2), Tuple::Vector(0, 1, 1), 2}
};
GIVEN("cyl <- cylinder()")
{
Cylinder cyl;
AND_GIVEN("cyl.minimum <- 1")
{
cyl.set_minimum(1);
AND_GIVEN("cyl.maximum <- 2")
{
cyl.set_maximum(2);
AND_GIVEN("cyl.closed <- true")
{
cyl.set_closed(true);
AND_GIVEN("direction <- normalize(<direction>)")
{
AND_GIVEN("r <- ray(<point>, direction)")
{
WHEN("xs <- local_intersect(cyl,r)")
{
for (int i = 0; i < 5; i++)
{
Tuple direction = the_test[i].direction.normalize();
Ray r(the_test[i].point, direction);
Intersections xs = cyl.local_intersect(r);
THEN("xs.count = <count>")
{
REQUIRE(xs.count() == the_test[i].count);
}
}
}
}
}
}
}
}
}
}