[FEAT] Color Finish all tests

This commit is contained in:
NADAL Jean-Baptiste
2024-01-31 11:38:36 +01:00
parent b44f8ee144
commit 033ec18577
4 changed files with 26 additions and 2 deletions

View File

@@ -109,6 +109,20 @@ const Color Color::operator*(double a_scalar) const
/* ------------------------------------------------------------------------- */
const Color Color::operator*(const Color &a_color) const
{
// Using the hadamard product.
double the_red, the_green, the_blue;
the_red = m_red * a_color.m_red;
the_green = m_green * a_color.m_green;
the_blue = m_blue * a_color.m_blue;
return Color(the_red, the_green, the_blue);
}
/* ------------------------------------------------------------------------- */
const Color &Color::operator+=(const Color &a_color)
{
m_red += a_color.m_red;

View File

@@ -42,6 +42,7 @@ namespace Raytracer
const Color operator+(const Color &a_color) const;
const Color operator-(const Color &a_color) const;
const Color operator*(double a_scalar) const;
const Color operator*(const Color &a_color) const;
const Color &operator+=(const Color &a_color);
const Color &operator-=(const Color &a_color);

View File

@@ -119,3 +119,14 @@ TEST_CASE("Multiplying a color by a scalar without modify c", "[Colors]")
REQUIRE(c * 2 == Color(0.4, 0.6, 0.8));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("Multiplying a colors", "[Colors]")
{
Color c1(1, 0.2, 0.4);
Color c2(0.9, 1, 0.1);
REQUIRE((c1 * c2) == Color(0.9, 0.2, 0.04));
}

View File

@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.14)
project(main_test)
include(CTest)
enable_testing()
set(CMAKE_CXX_STANDARD 20)