summary refs log tree commit diff
path: root/src/Math
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-07 23:05:14 +0200
committerMel <einebeere@gmail.com>2023-07-07 23:14:59 +0200
commit129f2e421e16bd008cdca8713cc91f67d103d94e (patch)
treea4d3e1005c57591b44fd57be4c1b00441512e36d /src/Math
parentf1fc192ddc4c739fa8b4b376c759b7d3218a34eb (diff)
downloadmeowcraft-129f2e421e16bd008cdca8713cc91f67d103d94e.tar.zst
meowcraft-129f2e421e16bd008cdca8713cc91f67d103d94e.zip
Fix minor quality issues
Diffstat (limited to 'src/Math')
-rw-r--r--src/Math/Grid.hpp3
-rw-r--r--src/Math/Interpolation.cpp3
-rw-r--r--src/Math/Interpolation.hpp3
-rw-r--r--src/Math/MVP.cpp2
-rw-r--r--src/Math/Matrix.hpp14
-rw-r--r--src/Math/Perlin.cpp2
-rw-r--r--src/Math/Random.cpp2
-rw-r--r--src/Math/Rotation.hpp9
-rw-r--r--src/Math/Trig.hpp2
-rw-r--r--src/Math/Vector.hpp10
10 files changed, 23 insertions, 27 deletions
diff --git a/src/Math/Grid.hpp b/src/Math/Grid.hpp
index 1c1a7ca..e9907a0 100644
--- a/src/Math/Grid.hpp
+++ b/src/Math/Grid.hpp
@@ -1,7 +1,6 @@
 #pragma once
 
-#include "Common.hpp"
-#include "Matrix.hpp"
+#include "Vector.hpp"
 
 namespace Math {
 
diff --git a/src/Math/Interpolation.cpp b/src/Math/Interpolation.cpp
index a1e6b69..d5b2564 100644
--- a/src/Math/Interpolation.cpp
+++ b/src/Math/Interpolation.cpp
@@ -1,5 +1,4 @@
 #include "Interpolation.hpp"
-#include <functional>
 #include "Common.hpp"
 
 namespace Math {
@@ -15,7 +14,7 @@ float bilinear_interpolation(Matrix<2, 2> val, GridCellBoundaries cell, Vector<2
     return linear_interpolation({r1, r2}, cell.y1, cell.y2, pos.y());
 }
 
-float trilinear_interpolation(Matrix<2, 2> val_front, Matrix<2, 2> val_back, CubeCellBoundaries cell, Vector<3> pos) {
+float trilinear_interpolation(Matrix<2, 2> val_front, Matrix<2, 2> val_back, const CubeCellBoundaries& cell, Vector<3> pos) {
     auto r1 = bilinear_interpolation(val_front, cell.grid_cell(), {pos.x(), pos.y()});
     auto r2 = bilinear_interpolation(val_back, cell.grid_cell(), {pos.x(), pos.y()});
 
diff --git a/src/Math/Interpolation.hpp b/src/Math/Interpolation.hpp
index 9eaf604..eaaa67d 100644
--- a/src/Math/Interpolation.hpp
+++ b/src/Math/Interpolation.hpp
@@ -1,6 +1,5 @@
 #pragma once
 
-#include <functional>
 #include "Common.hpp"
 #include "Grid.hpp"
 
@@ -8,6 +7,6 @@ namespace Math {
 
 float linear_interpolation(Vector<2> val, float left, float right, float pos);
 float bilinear_interpolation(Matrix<2, 2> val, GridCellBoundaries cell, Vector<2> pos);
-float trilinear_interpolation(Matrix<2, 2> val_front, Matrix<2, 2> val_back, CubeCellBoundaries cell, Vector<3> pos);
+float trilinear_interpolation(Matrix<2, 2> val_front, Matrix<2, 2> val_back, const CubeCellBoundaries& cell, Vector<3> pos);
 
 }
\ No newline at end of file
diff --git a/src/Math/MVP.cpp b/src/Math/MVP.cpp
index dd5b5e7..de771d3 100644
--- a/src/Math/MVP.cpp
+++ b/src/Math/MVP.cpp
@@ -19,7 +19,7 @@ Matrix<4, 4> view(Vector<3> position, Rotation angles) {
 }
 
 Matrix<4, 4> perspective_projection(float aspect, float fov, float near, float far) {
-    auto fov_radians = Math::radians(fov);
+    auto fov_radians = radians(fov);
 
     float x_scale = 1.0f / (tan(fov_radians / 2.0f) * aspect);
     float y_scale = 1.0f / tan(fov_radians / 2.0f);
diff --git a/src/Math/Matrix.hpp b/src/Math/Matrix.hpp
index d467f72..56663e0 100644
--- a/src/Math/Matrix.hpp
+++ b/src/Math/Matrix.hpp
@@ -7,18 +7,18 @@
 
 template <size_t R, size_t C, typename T = float>
 struct Matrix {
-    Matrix() : elements{} {};
+    Matrix() : elements{} {}
 
     explicit Matrix(const T scalar) {
         std::fill(elements, elements + R * C, scalar);
-    };
+    }
 
-    template<typename ...Args, typename std::enable_if_t<sizeof...(Args) == R * C, int> = 0>
-    Matrix(Args... args): elements{ args... } {};
+    template<typename ...Args, std::enable_if_t<sizeof...(Args) == R * C, int> = 0>
+    Matrix(Args... args): elements{ args... } {}
 
     explicit Matrix(const T values[R * C]) {
         std::copy(values, values + R * C, elements);
-    };
+    }
 
     static Matrix<R, R, T> identity() {
         Matrix<R, R, T> result{};
@@ -68,7 +68,7 @@ struct Matrix {
     }
 
     Vector<C, T> row(size_t index) const {
-        return { &elements[index * C] };
+        return Vector<C, T>{ &elements[index * C] };
     }
 
     Vector<R, T> col(size_t index) const {
@@ -124,7 +124,7 @@ struct Matrix {
     Vector<R, T> operator*(const Vector<R, T> vector) const {
         Matrix<R, 1, T> matrix(vector.elements);
         matrix = this->operator*(matrix);
-        return { matrix.elements };
+        return Vector<R, T>{ matrix.elements };
     }
 
     const T& operator()(const size_t x, const size_t y) const {
diff --git a/src/Math/Perlin.cpp b/src/Math/Perlin.cpp
index e0982cb..5614bb6 100644
--- a/src/Math/Perlin.cpp
+++ b/src/Math/Perlin.cpp
@@ -9,7 +9,7 @@ float ease(float t) {
 }
 
 uint8_t hash(uint8_t x) {
-    auto rot = (x * 5) % 8;
+    auto rot = x * 5 % 8;
     return x << rot | x >> (8 - rot);
 }
 
diff --git a/src/Math/Random.cpp b/src/Math/Random.cpp
index e35cda7..aa0ff55 100644
--- a/src/Math/Random.cpp
+++ b/src/Math/Random.cpp
@@ -18,7 +18,7 @@ float to_float(uint8_t u) {
 }
 
 uint8_t hash(uint8_t x) {
-    auto o = ((x ^ 0xAA) * 5);
+    auto o = (x ^ 0xAA) * 5;
     auto rot = o % 8;
     return o << rot | o >> (8 - rot);
 }
diff --git a/src/Math/Rotation.hpp b/src/Math/Rotation.hpp
index 0c5c606..a3420ed 100644
--- a/src/Math/Rotation.hpp
+++ b/src/Math/Rotation.hpp
@@ -4,16 +4,15 @@
 #include "Vector.hpp"
 
 struct Rotation {
-public:
-    Rotation() : vector{} {};
+    Rotation() = default;
 
-    Rotation(Vector<3> vector) : vector{ wrap(vector) } {};
+    Rotation(Vector<3> vector) : vector{ wrap(vector) } {}
 
-    Rotation(float angles[3]) : Rotation(angles[0], angles[1], angles[2]) {};
+    explicit Rotation(float angles[3]) : Rotation(angles[0], angles[1], angles[2]) {}
 
     Rotation(float pitch, float yaw, float roll) {
         vector = wrap({pitch, yaw, roll });
-    };
+    }
 
     Rotation operator+(Rotation other) const {
         return wrap(vector + other.vector);
diff --git a/src/Math/Trig.hpp b/src/Math/Trig.hpp
index 2a415f5..00489a9 100644
--- a/src/Math/Trig.hpp
+++ b/src/Math/Trig.hpp
@@ -6,7 +6,7 @@ namespace Math {
 
 template<typename T>
 T radians(T degrees) {
-    return (degrees * PI) / 180.0f;
+    return degrees * PI / 180.0f;
 }
 
 template<typename T>
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp
index 54207f0..2d87c4b 100644
--- a/src/Math/Vector.hpp
+++ b/src/Math/Vector.hpp
@@ -7,18 +7,18 @@
 
 template <size_t S, typename T = float>
 struct Vector {
-    Vector(): elements{} {};
+    Vector(): elements{} {}
 
     template<typename ...Args, std::enable_if_t<sizeof...(Args) == S, int> = 0>
-    Vector(Args... args) : elements{ args... } {};
+    Vector(Args... args) : elements{ args... } {}
 
-    Vector(const T values[S]) {
+    explicit Vector(const T values[S]) {
         std::copy(values, values + S, elements);
-    };
+    }
 
     explicit Vector(const T scalar) {
         std::fill(elements, elements + S, scalar);
-    };
+    }
 
     Vector(const Vector<S - 1, T> vector, const T scalar) {
         std::copy(vector.elements, vector.elements + S - 1, elements);