[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

@@ -234,7 +234,7 @@ SCENARIO("An intersection encapsulates t and object", "[features/intersections.f
Sphere s;
WHEN("intersection(3.5,s)")
{
Intersection i(3.5, s);
Intersection i(3.5, &s);
THEN("i.t = 3.5")
{
@@ -257,7 +257,7 @@ SCENARIO("An intersection could be affected", "[features/intersections.feature]"
Sphere s;
AND_GIVEN("i1 <- intersection(3.5,s) and i2 <- intersection()")
{
Intersection i1(3.5, s);
Intersection i1(3.5, &s);
Intersection i2;
WHEN("i2 <- i1")
@@ -286,8 +286,8 @@ SCENARIO("Intersection could be compared", "[features/intersections.feature]")
Sphere s;
AND_GIVEN("i1 <- intersection(3,s) and i2 <- intersection(4,s)")
{
Intersection i1(3.0, s);
Intersection i2(4.0, s);
Intersection i1(3.0, &s);
Intersection i2(4.0, &s);
THEN("i2 > i1")
{
@@ -326,10 +326,10 @@ SCENARIO("Aggregating intersections", "[features/intersections.feature]")
Sphere s;
AND_GIVEN("i1 <- intersection(1,s)")
{
Intersection i1(1, s);
Intersection i1(1, &s);
AND_GIVEN("i2 <- intersection(2,s)")
{
Intersection i2(2, s);
Intersection i2(2, &s);
WHEN("xs <- intersections(i1,i2)")
{
Intersections xs = Intersections({i1, i2});
@@ -361,7 +361,7 @@ SCENARIO("Operations with intersections", "[features/intersections.feature]")
AND_GIVEN("s <- sphere()")
{
Sphere s;
Intersection i1(1, s);
Intersection i1(1, &s);
AND_GIVEN("xs2 <- intersections({i1})")
{
Intersections xs2({i1});
@@ -423,10 +423,10 @@ SCENARIO("The hit, when all intersections have positive t", "[features/intersect
Sphere s;
AND_GIVEN("i1 <- intersection(1,s)")
{
Intersection i1(1, s);
Intersection i1(1, &s);
AND_GIVEN("i2 <- intersection(2,s)")
{
Intersection i2(2, s);
Intersection i2(2, &s);
AND_GIVEN("xs <- intersections(i1,i2)")
{
Intersections xs = Intersections({i2, i1});
@@ -453,10 +453,10 @@ SCENARIO("The hit, when some intersections have negative t", "[features/intersec
Sphere s;
AND_GIVEN("i1 <- intersection(-1,s)")
{
Intersection i1(-1, s);
Intersection i1(-1, &s);
AND_GIVEN("i2 <- intersection(2,s)")
{
Intersection i2(1, s);
Intersection i2(1, &s);
AND_GIVEN("xs <- intersections(i1,i2)")
{
Intersections xs = Intersections({i2, i1});
@@ -483,10 +483,10 @@ SCENARIO("The hit, when all intersections have negative t", "[features/intersect
Sphere s;
AND_GIVEN("i1 <- intersection(-2,s)")
{
Intersection i1(-2, s);
Intersection i1(-2, &s);
AND_GIVEN("i2 <- intersection(-1,s)")
{
Intersection i2(-1, s);
Intersection i2(-1, &s);
AND_GIVEN("xs <- intersections(i1,i2)")
{
Intersections xs = Intersections({i1, i2});
@@ -514,16 +514,16 @@ SCENARIO("The hit is always the lowest nonnegative intersection", "[features/int
Sphere s;
AND_GIVEN("i1 <- intersection(5,s)")
{
Intersection i1(5, s);
Intersection i1(5, &s);
AND_GIVEN("i2 <- intersection(7,s)")
{
Intersection i2(7, s);
Intersection i2(7, &s);
AND_GIVEN("i3 <- intersection(-3,s)")
{
Intersection i3(-3, s);
Intersection i3(-3, &s);
AND_GIVEN("i4 <- intersection(2,s)")
{
Intersection i4(2, s);
Intersection i4(2, &s);
AND_GIVEN("xs <- intersections(i1, i2, i3, i4)")
{
Intersections xs = Intersections({i1, i2, i3, i4});

View File

@@ -143,7 +143,7 @@ SCENARIO("Precompute the state of an intersection", "[features/intersections.fea
Sphere shape;
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, shape);
Intersection i(4, &shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
@@ -185,7 +185,7 @@ SCENARIO("The hit, when an intersection occurs on the outside", "[features/inter
Sphere shape;
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, shape);
Intersection i(4, &shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
@@ -211,7 +211,7 @@ SCENARIO("The hit, when an intersection occurs on the inside", "[features/inters
Sphere shape;
AND_GIVEN("i <- intersection(1, shape)")
{
Intersection i(1, shape);
Intersection i(1, &shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
@@ -252,7 +252,7 @@ SCENARIO("Shading an intersection", "[features/world.feature]")
Shape *shape = w.objects(0);
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, *shape);
Intersection i(4, shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
@@ -289,7 +289,7 @@ SCENARIO("Shading an intersection from the inside", "[features/world.feature]")
Shape *shape = w.objects(1);
AND_GIVEN("i <- intersection(0.5, shape)")
{
Intersection i(0.5, *shape);
Intersection i(0.5, shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);

View File

@@ -164,7 +164,7 @@ SCENARIO("shade_hit() is given an intersection in the shadow", "[features/world.
Ray r(Tuple::Point(0, 0, 5), Tuple::Vector(0, 0, 1));
AND_GIVEN("i <- intersection(4, s2)")
{
Intersection i(4, *s2);
Intersection i(4, s2);
WHEN("comps <- prepare_computatons(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
@@ -200,7 +200,7 @@ SCENARIO("The hit should offset the point", "[features/intersections.feature]")
shape.set_transform(Matrix::translation(0, 0, 1));
AND_GIVEN("i <- intersection(5, shape)")
{
Intersection i(5, shape);
Intersection i(5, &shape);
WHEN("comps <- prepare_computatons(i,r)")
{
IntersectionData comps = i.prepare_computations(r);

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);
}
}
}
}
}