Change the Intersection to a class, and stop using memory allocation for it (and pointer)
A bit more clean (on the code side)
This commit is contained in:
@@ -17,35 +17,46 @@ TEST(IntersectTest, Creating_an_intersect_and_do_some_check)
|
||||
|
||||
ASSERT_EQ(i.count(), 0);
|
||||
|
||||
i.add(newIntersection(1.0, nullptr));
|
||||
i.add(newIntersection(4.2, nullptr));
|
||||
i.add(Intersection(1.0, nullptr));
|
||||
i.add(Intersection(4.2, nullptr));
|
||||
|
||||
ASSERT_EQ(i.count(), 2);
|
||||
|
||||
ASSERT_EQ(i[0]->t, 1.0);
|
||||
ASSERT_EQ(i[1]->t, 4.2);
|
||||
ASSERT_EQ(i[0].t, 1.0);
|
||||
ASSERT_EQ(i[1].t, 4.2);
|
||||
}
|
||||
|
||||
TEST(IntersectTest, An_intersection_encapsulate_t_and_object)
|
||||
{
|
||||
Sphere s = Sphere();
|
||||
Intersection *i = newIntersection(3.5, &s);
|
||||
Intersection i = Intersection(3.5, &s);
|
||||
|
||||
ASSERT_EQ(i->t, 3.5);
|
||||
ASSERT_EQ(i->object, (Object *)&s);
|
||||
ASSERT_EQ(i.t, 3.5);
|
||||
ASSERT_EQ(i.object, (Object *)&s);
|
||||
}
|
||||
|
||||
TEST(IntersectTest, Aggregating_intersections)
|
||||
{
|
||||
Sphere s = Sphere();
|
||||
Intersection *i1 = newIntersection(1, &s);
|
||||
Intersection *i2 = newIntersection(2, &s);
|
||||
Intersection i1 = Intersection(1, &s);
|
||||
Intersection i2 = Intersection(2, &s);
|
||||
|
||||
Intersect xs = Intersect();
|
||||
xs.add(i1);
|
||||
xs.add(i2);
|
||||
|
||||
ASSERT_EQ(xs.count(), 2);
|
||||
ASSERT_EQ(xs[0]->t, 1);
|
||||
ASSERT_EQ(xs[1]->t, 2);
|
||||
ASSERT_EQ(xs[0].t, 1);
|
||||
ASSERT_EQ(xs[1].t, 2);
|
||||
}
|
||||
|
||||
TEST(IntersectTest, Intersect_sets_the_object_on_the_intersection)
|
||||
{
|
||||
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
|
||||
Sphere s = Sphere();
|
||||
Intersect xs = s.intersect(r);
|
||||
|
||||
ASSERT_EQ(xs.count(), 2);
|
||||
ASSERT_EQ(xs[0].object, (Object *)&s);
|
||||
ASSERT_EQ(xs[1].object, (Object *)&s);
|
||||
}
|
||||
Reference in New Issue
Block a user