[WIP] start chapter 10.

This commit is contained in:
NADAL Jean-Baptiste
2024-02-28 14:51:19 +01:00
parent ac84d77d14
commit 73c6e54796
6 changed files with 256 additions and 1 deletions

125
tests/10_patterns.cpp Normal file
View File

@@ -0,0 +1,125 @@
/*!
* 10_patterns.cpp
*
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 27/02/2024
*
*/
/*---------------------------------------------------------------------------*/
#include <catch.hpp>
#include "raytracing.h"
using namespace Raytracer;
/* ------------------------------------------------------------------------- */
SCENARIO("Creating a stripe pattern", "[features/patterns.feature]")
{
GIVEN("pattern <- strip_pattern(white, black)")
{
StripePattern pattern(Color::White(), Color::Black());
THEN("pattern.a = white")
{
REQUIRE(pattern.a() == Color::White());
}
AND_THEN("pattern.b = black")
{
REQUIRE(pattern.b() == Color::Black());
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A stripe pattern is constant in y", "[features/patterns.feature]")
{
GIVEN("pattern <- strip_pattern(white, black)")
{
StripePattern pattern(Color::White(), Color::Black());
THEN("stripe_at(pattern, point(0, 0, 0) = white")
{
}
AND_THEN("stripe_at(pattern, point(0, 1, 0) = white")
{
}
AND_THEN("stripe_at(pattern, point(0, 2, 0) = white")
{
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A stripe pattern is constant in z", "[features/patterns.feature]")
{
GIVEN("pattern <- strip_pattern(white, black)")
{
StripePattern pattern(Color::White(), Color::Black());
THEN("stripe_at(pattern, point(0, 0, 0) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 0)) == Color::White());
}
AND_THEN("stripe_at(pattern, point(0, 0, 1) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 1)) == Color::White());
}
AND_THEN("stripe_at(pattern, point(0, 0, 2) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 2)) == Color::White());
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A stripe pattern alternates in x", "[features/patterns.feature]")
{
GIVEN("pattern <- strip_pattern(white, black)")
{
StripePattern pattern(Color::White(), Color::Black());
THEN("stripe_at(pattern, point(0, 0, 0) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 0)) == Color::White());
}
AND_THEN("stripe_at(pattern, point(0.9, 0, 0) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(0.9, 0, 0)) == Color::White());
}
AND_THEN("stripe_at(pattern, point(1, 0, 0) = black")
{
REQUIRE(pattern.stripe_at(Tuple::Point(1, 0, 0)) == Color::Black());
}
AND_THEN("stripe_at(pattern, point(-0.1, 0, 0) = black")
{
REQUIRE(pattern.stripe_at(Tuple::Point(-0.1, 0, 0)) == Color::Black());
}
AND_THEN("stripe_at(pattern, point(-1, 0, 0) = black")
{
REQUIRE(pattern.stripe_at(Tuple::Point(-1, 0, 0)) == Color::Black());
}
AND_THEN("stripe_at(pattern, point(-1.1, 0, 0) = white")
{
REQUIRE(pattern.stripe_at(Tuple::Point(-1.1, 0, 0)) == Color::White());
}
}
}