/*! * 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 #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()); } } }