From 2c4d63d622e2423a0fa31f65031c7440cb41b914 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Mon, 29 Jan 2024 18:43:18 +0100 Subject: [PATCH] [FEAT] Add test and Tuplus object --- .PVS-Studio/State/WindowState.json | 22 +++++++ .vscode/settings.json | 5 ++ CMakeLists.txt | 12 +++- README.md | 3 + src/tuple.cpp | 65 +++++++++++++++++++ src/tuple.h | 58 +++++++++++++++++ src/vector.cpp | 24 +++++++ src/vector.h | 24 +++++++ ...itre01_tests.cpp => chapitre01_tuples.cpp} | 17 +++-- 9 files changed, 220 insertions(+), 10 deletions(-) create mode 100644 .PVS-Studio/State/WindowState.json create mode 100644 .vscode/settings.json create mode 100644 src/tuple.cpp create mode 100644 src/tuple.h create mode 100644 src/vector.cpp create mode 100644 src/vector.h rename tests/{chapitre01_tests.cpp => chapitre01_tuples.cpp} (83%) diff --git a/.PVS-Studio/State/WindowState.json b/.PVS-Studio/State/WindowState.json new file mode 100644 index 0000000..ef7ec08 --- /dev/null +++ b/.PVS-Studio/State/WindowState.json @@ -0,0 +1,22 @@ +{ + "isDataChanged": false, + "filters": { + "code": "", + "message": "", + "files": "", + "level": [ + 0, + 1, + 2, + 3 + ], + "isColumnFiltersVisible": true, + "isLevelFiltersVisible": true, + "isGroupFiltersVisible": true, + "type": [ + "General", + "Optimization" + ] + }, + "loadableProcessIds": [] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d789c03 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "Raytracer" + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 82d2fc8..d9dc441 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,23 +2,29 @@ cmake_minimum_required(VERSION 3.14) project(raytracing_challenge) # GoogleTest requires at least C++14 -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip ) + # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) enable_testing() +include_directories("${CMAKE_SOURCE_DIR}/src") + add_executable( rc_tests - tests/chapitre01_tests.cpp + + src/tuple.cpp + + tests/chapitre01_tuples.cpp ) target_link_libraries( rc_tests diff --git a/README.md b/README.md index 02aa3ed..c56b6c7 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,6 @@ ## Le Livre est ici: https://lire.amazon.fr/?asin=B07Q84TQ91&ref_=kwl_kr_iv_rec_1 + + +https://github.com/sraaphorst/raytracer-cpp/blob/b57794ce9f4ed80d782711adb9131f3e3097d4b0/CMakeLists.txt diff --git a/src/tuple.cpp b/src/tuple.cpp new file mode 100644 index 0000000..3bad547 --- /dev/null +++ b/src/tuple.cpp @@ -0,0 +1,65 @@ +/*! + * tuple.cpp + * + * Copyright (c) 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: 29/01/2024 + * + */ + +// This is an independent project of an individual developer. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com + +/* ------------------------------------------------------------------------- */ + +#include "tuple.h" + +/* ------------------------------------------------------------------------- */ + +Raytracer::Tuple::Tuple(float a_x, float a_y, float a_z, float a_w) : m_x(a_x), m_y(a_y), m_z(a_z), m_w(a_w) +{ +} + +/* ------------------------------------------------------------------------- */ + +float Raytracer::Tuple::x(void) const +{ + return m_x; +} + +/* ------------------------------------------------------------------------- */ + +float Raytracer::Tuple::y(void) const +{ + return m_y; +} + +/* ------------------------------------------------------------------------- */ + +float Raytracer::Tuple::z(void) const +{ + return m_z; +} + +/* ------------------------------------------------------------------------- */ + +float Raytracer::Tuple::w(void) const +{ + return m_w; +} diff --git a/src/tuple.h b/src/tuple.h new file mode 100644 index 0000000..af2a747 --- /dev/null +++ b/src/tuple.h @@ -0,0 +1,58 @@ +/*! + * tuple.h + * + * Copyright (c) 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: 29/01/2024 + * + */ + +#ifndef _RAYTRACER_TUPLE_H +#define _RAYTRACER_TUPLE_H + +/* ------------------------------------------------------------------------- */ + +#define kRCTuplesPoint 1.0 +#define kRCTuplesVetor 0.0 + +/* ------------------------------------------------------------------------- */ + +namespace Raytracer +{ + class Tuple + { + public: + Tuple(float x, float y, float z, float w); + + // Access + float x(void) const; + float y(void) const; + float z(void) const; + float w(void) const; + + private: + float m_x; + float m_y; + float m_z; + float m_w; + }; + +}; + +#endif /* _RAYTRACER_TUPLE_H */ diff --git a/src/vector.cpp b/src/vector.cpp new file mode 100644 index 0000000..904e767 --- /dev/null +++ b/src/vector.cpp @@ -0,0 +1,24 @@ +/*! + * vector.cpp + * + * Copyright (c) 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: 29/01/2024 + * + */ diff --git a/src/vector.h b/src/vector.h new file mode 100644 index 0000000..5e3dbd6 --- /dev/null +++ b/src/vector.h @@ -0,0 +1,24 @@ +/*! + * vector.h + * + * Copyright (c) 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: 29/01/2024 + * + */ diff --git a/tests/chapitre01_tests.cpp b/tests/chapitre01_tuples.cpp similarity index 83% rename from tests/chapitre01_tests.cpp rename to tests/chapitre01_tuples.cpp index 65f8d5e..03e8022 100644 --- a/tests/chapitre01_tests.cpp +++ b/tests/chapitre01_tuples.cpp @@ -17,7 +17,7 @@ * 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: 07/02/2021 * @@ -30,10 +30,13 @@ #include -// Demonstrate some basic assertions. -TEST(HelloTest, BasicAssertions) { - // Expect two strings not to be equal. - EXPECT_STRNE("hello", "world"); - // Expect equality. - EXPECT_EQ(7 * 6, 42); +#include "tuple.h" + +TEST(RaytracerTuple, CreateBasicTuple) +{ + Raytracer::Tuple t(4.3, -4.2, 3.1, 1.0); + EXPECT_FLOAT_EQ(t.x(), 4.3); + EXPECT_FLOAT_EQ(t.y(), -4.2); + EXPECT_FLOAT_EQ(t.z(), 3.1); + EXPECT_FLOAT_EQ(t.w(), 1.0); }