[FEAT] Add Plane Chapter 09 is done

This commit is contained in:
2024-02-27 23:29:44 +01:00
parent 86e31e76eb
commit 32689ab4cc
20 changed files with 399 additions and 68 deletions

View File

@@ -244,3 +244,142 @@ SCENARIO("Computing the normal on a transformed shape", "[features/shapes.featur
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The normal of a plane is constant everywhere", "[features/planes.feature]")
{
GIVEN("p <- plane()")
{
Plane p;
WHEN("n1 <- local_normal_at(p, point(0, 0, 0)))")
{
Tuple n1 = p.local_normal_at(Tuple::Point(0, 0, 0));
AND_WHEN("n2 <- local_normal_at(p, point(10, 0, 0)))")
{
Tuple n2 = p.local_normal_at(Tuple::Point(10, 0, 0));
AND_WHEN("n3 <- local_normal_at(p, point(-5, 0, 150)))")
{
Tuple n3 = p.local_normal_at(Tuple::Point(-5, 0, 150));
THEN("n1 = vector(0, 1, 0)")
{
REQUIRE(n1 == Tuple::Vector(0, 1, 0));
}
AND_THEN("n2 = vector(0, 1, 0)")
{
REQUIRE(n1 == Tuple::Vector(0, 1, 0));
}
AND_THEN("n3 = vector(0, 1, 0)")
{
REQUIRE(n1 == Tuple::Vector(0, 1, 0));
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Intersect with a ray parallel to the plane", "[features/planes.feature]")
{
GIVEN("p <- plane()")
{
Plane p;
AND_GIVEN("r <- ray(point(0, 10, 0), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 10, 0), Tuple::Vector(0, 0, 1));
WHEN("xs <-local_intersect(p, r)")
{
Intersections xs = p.local_intersect(r);
THEN("xs is empty")
{
REQUIRE(xs.count() == 0);
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Intersect with a coplanar ray", "[features/planes.feature]")
{
GIVEN("p <- plane()")
{
Plane p;
AND_GIVEN("r <- ray(point(0, 0, 0), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
WHEN("xs <-local_intersect(p, r)")
{
Intersections xs = p.local_intersect(r);
THEN("xs is empty")
{
REQUIRE(xs.count() == 0);
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A ray Intersecting a plane from above", "[features/planes.feature]")
{
GIVEN("p <- plane()")
{
Plane p;
AND_GIVEN("r <- ray(point(0, 1, 0), vector(0, -1, 0))")
{
Ray r(Tuple::Point(0, 1, 0), Tuple::Vector(0, -1, 0));
WHEN("xs <-local_intersect(p, r)")
{
Intersections xs = p.local_intersect(r);
THEN("xs.count = 1")
{
REQUIRE(xs.count() == 1);
}
AND_THEN("xs[0].t = 1")
{
REQUIRE(xs[0].distance_t() == 1);
}
AND_THEN("xs[0].object = p")
{
REQUIRE(xs[0].object() == p);
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A ray Intersecting a plane from below", "[features/planes.feature]")
{
GIVEN("p <- plane()")
{
Plane p;
AND_GIVEN("r <- ray(point(0, -1, 0), vector(0, 1, 0))")
{
Ray r(Tuple::Point(0, -1, 0), Tuple::Vector(0, 1, 0));
WHEN("xs <-local_intersect(p, r)")
{
Intersections xs = p.local_intersect(r);
THEN("xs.count = 1")
{
REQUIRE(xs.count() == 1);
}
AND_THEN("xs[0].t = 1")
{
REQUIRE(xs[0].distance_t() == 1);
}
AND_THEN("xs[0].object = p")
{
REQUIRE(xs[0].object() == p);
}
}
}
}
}