[FEAT] Update indent settings and add a clang-format file
This commit is contained in:
32
.clang-format
Normal file
32
.clang-format
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
# We'll use defaults from the LLVM style, but with 4 columns indentation.
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
# use \n instead of \r\n
|
||||
UseCRLF: true
|
||||
# spaces, not tabs!
|
||||
UseTab: Never
|
||||
---
|
||||
Language: Cpp
|
||||
Standard: c++17
|
||||
AccessModifierOffset: -4
|
||||
# Force pointers to the type for C++.
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
# Use 100 columns
|
||||
ColumnLimit: 100
|
||||
AlignConsecutiveStyle: Consecutive
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
SplitEmptyFunction: true
|
||||
BreakBeforeBraces: Allman
|
||||
SeparateDefinitionBlocks: Always
|
||||
NamespaceIndentation: All
|
||||
IndentAccessModifiers: false
|
||||
ReferenceAlignment: Right
|
||||
BreakConstructorInitializers: AfterColon
|
||||
...
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -74,5 +74,6 @@
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp"
|
||||
}
|
||||
},
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
@@ -11,6 +11,7 @@ add_library(raytracing
|
||||
src/tuple.cpp
|
||||
src/color.cpp
|
||||
src/canvas.cpp
|
||||
src/matrix.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "tuple.h"
|
||||
#include "color.h"
|
||||
#include "common.h"
|
||||
#include "matrix.h"
|
||||
#include "tuple.h"
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "common.h"
|
||||
#include "canvas.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace Raytracer;
|
||||
|
||||
@@ -46,8 +46,12 @@ Canvas::Canvas(uint16_t a_width, uint16_t a_height) : m_width(a_width), m_height
|
||||
m_pixels = std::vector<std::vector<Color>>(m_width, std::vector<Color>(m_height));
|
||||
|
||||
for (int i = 0; i < m_width; ++i)
|
||||
{
|
||||
for (int j = 0; j < m_height; ++j)
|
||||
{
|
||||
m_pixels[i][j] == Color(0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -61,6 +61,6 @@ namespace Raytracer
|
||||
uint16_t m_height;
|
||||
std::vector<std::vector<Color>> m_pixels;
|
||||
};
|
||||
};
|
||||
}; // namespace Raytracer
|
||||
|
||||
#endif // _RAYTRACER_CANVAS_H
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
#include "common.h"
|
||||
#include "color.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace Raytracer;
|
||||
|
||||
@@ -45,13 +45,15 @@ Color::Color(void) : m_red(0), m_green(0), m_blue(0)
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Color::Color(const Color &a_copy) : m_red(a_copy.m_red), m_green(a_copy.m_green), m_blue(a_copy.m_blue)
|
||||
Color::Color(const Color &a_copy) :
|
||||
m_red(a_copy.m_red), m_green(a_copy.m_green), m_blue(a_copy.m_blue)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Color::Color(double a_red, double a_green, double a_blue) : m_red(a_red), m_green(a_green), m_blue(a_blue)
|
||||
Color::Color(double a_red, double a_green, double a_blue) :
|
||||
m_red(a_red), m_green(a_green), m_blue(a_blue)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -59,7 +61,8 @@ Color::Color(double a_red, double a_green, double a_blue) : m_red(a_red), m_gree
|
||||
|
||||
bool Color::operator==(const Color &a_color) const
|
||||
{
|
||||
if (double_equal(m_red, a_color.m_red) && double_equal(m_green, a_color.m_green) && double_equal(m_blue, a_color.m_blue))
|
||||
if (double_equal(m_red, a_color.m_red) && double_equal(m_green, a_color.m_green) &&
|
||||
double_equal(m_blue, a_color.m_blue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -82,30 +85,21 @@ const Color &Color::operator=(const Color &a_color)
|
||||
|
||||
const Color Color::operator+(const Color &a_color) const
|
||||
{
|
||||
return Color(
|
||||
m_red + a_color.m_red,
|
||||
m_green + a_color.m_green,
|
||||
m_blue + a_color.m_blue);
|
||||
return Color(m_red + a_color.m_red, m_green + a_color.m_green, m_blue + a_color.m_blue);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const Color Color::operator-(const Color &a_color) const
|
||||
{
|
||||
return Color(
|
||||
m_red - a_color.m_red,
|
||||
m_green - a_color.m_green,
|
||||
m_blue - a_color.m_blue);
|
||||
return Color(m_red - a_color.m_red, m_green - a_color.m_green, m_blue - a_color.m_blue);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const Color Color::operator*(double a_scalar) const
|
||||
{
|
||||
return Color(
|
||||
m_red * a_scalar,
|
||||
m_green * a_scalar,
|
||||
m_blue * a_scalar);
|
||||
return Color(m_red * a_scalar, m_green * a_scalar, m_blue * a_scalar);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -71,6 +71,6 @@ namespace Raytracer
|
||||
double m_green;
|
||||
double m_blue;
|
||||
};
|
||||
};
|
||||
}; // namespace Raytracer
|
||||
|
||||
#endif // _RAYTRACER_COLOR_H
|
||||
|
||||
55
raytracing/src/matrix.cpp
Normal file
55
raytracing/src/matrix.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* matrix.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: 01/02/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 <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
#include "common.h"
|
||||
#include "matrix.h"
|
||||
|
||||
using namespace Raytracer;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Matrix::Matrix(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Matrix::Matrix(const Matrix &a_copy)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Matrix::Matrix(uint8_t a_nb_row, uint8_t a_nb_col)
|
||||
{
|
||||
}
|
||||
48
raytracing/src/matrix.h
Normal file
48
raytracing/src/matrix.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*!
|
||||
* matrix.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: 01/02/2024
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RAYTRACER_MATRIX_H
|
||||
#define _RAYTRACER_MATRIX_H
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
namespace Raytracer
|
||||
{
|
||||
class Matrix
|
||||
{
|
||||
public:
|
||||
Matrix(void);
|
||||
Matrix(const Matrix &a_copy);
|
||||
Matrix(uint8_t a_nb_row, uint8_t a_nb_col);
|
||||
|
||||
private:
|
||||
};
|
||||
}; // namespace Raytracer
|
||||
|
||||
#endif // _RAYTRACER_MATRIX_H
|
||||
@@ -46,13 +46,15 @@ Tuple::Tuple(void) : m_x(0.0), m_y(0.0), m_z(0.0), m_w(0.0)
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Tuple::Tuple(const Tuple &a_copy) : m_x(a_copy.m_x), m_y(a_copy.m_y), m_z(a_copy.m_z), m_w(a_copy.m_w)
|
||||
Tuple::Tuple(const Tuple &a_copy) :
|
||||
m_x(a_copy.m_x), m_y(a_copy.m_y), m_z(a_copy.m_z), m_w(a_copy.m_w)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Tuple::Tuple(double a_x, double a_y, double a_z, double a_w) : m_x(a_x), m_y(a_y), m_z(a_z), m_w(a_w)
|
||||
Tuple::Tuple(double a_x, double a_y, double a_z, double a_w) :
|
||||
m_x(a_x), m_y(a_y), m_z(a_z), m_w(a_w)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,7 +62,8 @@ Tuple::Tuple(double a_x, double a_y, double a_z, double a_w) : m_x(a_x), m_y(a_y
|
||||
|
||||
bool Tuple::operator==(const Tuple &an_other) const
|
||||
{
|
||||
if (double_equal(m_x, an_other.m_x) && double_equal(m_y, an_other.m_y) && double_equal(m_z, an_other.m_z) && double_equal(m_w, an_other.m_w))
|
||||
if (double_equal(m_x, an_other.m_x) && double_equal(m_y, an_other.m_y) &&
|
||||
double_equal(m_z, an_other.m_z) && double_equal(m_w, an_other.m_w))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -96,48 +99,28 @@ const Tuple &Tuple::operator-(void)
|
||||
|
||||
const Tuple Tuple::operator+(const Tuple &an_other) const
|
||||
{
|
||||
return Tuple(
|
||||
m_x + an_other.m_x,
|
||||
m_y + an_other.m_y,
|
||||
m_z + an_other.m_z,
|
||||
m_w + an_other.m_w
|
||||
);
|
||||
return Tuple(m_x + an_other.m_x, m_y + an_other.m_y, m_z + an_other.m_z, m_w + an_other.m_w);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const Tuple Tuple::operator-(const Tuple &an_other) const
|
||||
{
|
||||
return Tuple(
|
||||
m_x - an_other.m_x,
|
||||
m_y - an_other.m_y,
|
||||
m_z - an_other.m_z,
|
||||
m_w - an_other.m_w
|
||||
);
|
||||
return Tuple(m_x - an_other.m_x, m_y - an_other.m_y, m_z - an_other.m_z, m_w - an_other.m_w);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const Tuple Tuple::operator*(double a_scalar) const
|
||||
{
|
||||
return Tuple(
|
||||
m_x * a_scalar,
|
||||
m_y * a_scalar,
|
||||
m_z * a_scalar,
|
||||
m_w * a_scalar
|
||||
);
|
||||
return Tuple(m_x * a_scalar, m_y * a_scalar, m_z * a_scalar, m_w * a_scalar);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const Tuple Tuple::operator/(double a_scalar) const
|
||||
{
|
||||
return Tuple(
|
||||
m_x / a_scalar,
|
||||
m_y / a_scalar,
|
||||
m_z / a_scalar,
|
||||
m_w / a_scalar
|
||||
);
|
||||
return Tuple(m_x / a_scalar, m_y / a_scalar, m_z / a_scalar, m_w / a_scalar);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -248,8 +231,7 @@ bool Tuple::is_vector(void)
|
||||
|
||||
double Tuple::magnitude(void) const
|
||||
{
|
||||
return std::sqrt(
|
||||
square(m_x) + square(m_y) + square(m_z) + square(m_w));
|
||||
return std::sqrt(square(m_x) + square(m_y) + square(m_z) + square(m_w));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -258,9 +240,7 @@ Tuple Tuple::normalize(void)
|
||||
{
|
||||
double the_magnitude = magnitude();
|
||||
|
||||
return Tuple(m_x / the_magnitude,
|
||||
m_y / the_magnitude,
|
||||
m_z / the_magnitude,
|
||||
return Tuple(m_x / the_magnitude, m_y / the_magnitude, m_z / the_magnitude,
|
||||
m_w / the_magnitude);
|
||||
}
|
||||
|
||||
@@ -268,18 +248,13 @@ Tuple Tuple::normalize(void)
|
||||
|
||||
double Tuple::dot(const Tuple &a_tuple)
|
||||
{
|
||||
return m_x * a_tuple.m_x +
|
||||
m_y * a_tuple.m_y +
|
||||
m_z * a_tuple.m_z +
|
||||
m_w * a_tuple.m_w;
|
||||
return m_x * a_tuple.m_x + m_y * a_tuple.m_y + m_z * a_tuple.m_z + m_w * a_tuple.m_w;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Tuple Tuple::cross(const Tuple &a_tuple)
|
||||
{
|
||||
return Vector(
|
||||
m_y * a_tuple.m_z - m_z * a_tuple.m_y,
|
||||
m_z * a_tuple.m_x - m_x * a_tuple.m_z,
|
||||
return Vector(m_y * a_tuple.m_z - m_z * a_tuple.m_y, m_z * a_tuple.m_x - m_x * a_tuple.m_z,
|
||||
m_x * a_tuple.m_y - m_y * a_tuple.m_x);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,6 @@ namespace Raytracer
|
||||
double m_z;
|
||||
double m_w;
|
||||
};
|
||||
};
|
||||
}; // namespace Raytracer
|
||||
|
||||
#endif /* _RAYTRACER_TUPLE_H */
|
||||
|
||||
@@ -127,6 +127,5 @@ TEST_CASE("[Color] 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));
|
||||
}
|
||||
@@ -41,8 +41,12 @@ TEST_CASE("[Canvas] Creating a canvas", "[Canvas]")
|
||||
REQUIRE(c.height() == 20);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
for (int j = 0; j < 20; ++j)
|
||||
{
|
||||
REQUIRE(c.pixel_at(2, 3) == Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
0
tests/03_matrix.cpp
Normal file
0
tests/03_matrix.cpp
Normal file
@@ -11,8 +11,9 @@ add_executable(main_test
|
||||
main_test.cpp
|
||||
|
||||
01_tuples.cpp
|
||||
02_colors.cpp
|
||||
03_canvas.cpp
|
||||
02_1_colors.cpp
|
||||
02_2_canvas.cpp
|
||||
03_matrix.cpp
|
||||
)
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
||||
|
||||
Reference in New Issue
Block a user