diff --git a/raytracing/src/color.cpp b/raytracing/src/color.cpp index 674ebc4..e28186c 100644 --- a/raytracing/src/color.cpp +++ b/raytracing/src/color.cpp @@ -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; diff --git a/raytracing/src/color.h b/raytracing/src/color.h index 02ae963..6fdd40d 100644 --- a/raytracing/src/color.h +++ b/raytracing/src/color.h @@ -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); diff --git a/tests/02_colors.cpp b/tests/02_colors.cpp index 1e01e7e..da4e69e 100644 --- a/tests/02_colors.cpp +++ b/tests/02_colors.cpp @@ -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)); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1580d17..2fce1ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.14) project(main_test) -include(CTest) - enable_testing() set(CMAKE_CXX_STANDARD 20)