diff options
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/Math/Common.hpp | 4 | ||||
| -rw-r--r-- | src/Math/Functions.hpp | 46 | ||||
| -rw-r--r-- | src/Math/Mod.hpp | 12 | ||||
| -rw-r--r-- | src/Math/Rotation.hpp | 2 | ||||
| -rw-r--r-- | src/Math/Sigmoid.hpp | 13 | ||||
| -rw-r--r-- | src/Math/Trig.hpp | 17 | ||||
| -rw-r--r-- | src/Math/Vector.hpp | 3 | ||||
| -rw-r--r-- | src/World/Generation/Generator.cpp | 2 | ||||
| -rw-r--r-- | src/World/Position.hpp | 3 |
10 files changed, 54 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a411020..5227274 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ add_executable(meowcraft src/Math/Rotation.hpp src/GFX/Shading/Uniform.cpp src/GFX/Shading/Uniform.hpp src/GFX/Mouse.cpp src/GFX/Mouse.hpp - src/Math/Trig.hpp src/GFX/Texture.cpp src/GFX/Texture.hpp src/Assets.cpp src/Assets.hpp src/GFX/Image/RawImage.cpp src/GFX/Image/RawImage.hpp @@ -43,7 +42,6 @@ add_executable(meowcraft src/Math/Perlin.cpp src/Compute/Queue.hpp src/Math/Constants.hpp - src/Math/Sigmoid.hpp src/World/Generation/ChunkMeshing.cpp src/World/Generation/ChunkMeshing.hpp src/Math/Tensor.hpp src/World/Generation/Decoration.cpp src/World/Generation/Decoration.hpp @@ -58,12 +56,12 @@ add_executable(meowcraft src/World/ChunkRegistry.cpp src/World/ChunkRegistry.hpp src/World/Position.hpp src/World/ChunkDimensions.hpp - src/Math/Mod.hpp src/Transform.cpp src/Transform.hpp src/Entities/Player.cpp src/Entities/Player.hpp src/Common/FlexArray.hpp src/Math/Ray.hpp src/Common/Lambda.hpp + src/Math/Functions.hpp ) target_link_libraries(meowcraft glfw GLEW::GLEW) diff --git a/src/Math/Common.hpp b/src/Math/Common.hpp index cf5a2c7..6e4d8f3 100644 --- a/src/Math/Common.hpp +++ b/src/Math/Common.hpp @@ -2,8 +2,8 @@ #include "../Common/Sizes.hpp" +#include "Functions.hpp" #include "Vector.hpp" #include "Matrix.hpp" #include "Rotation.hpp" -#include "Trig.hpp" -#include "Constants.hpp" \ No newline at end of file +#include "Constants.hpp" diff --git a/src/Math/Functions.hpp b/src/Math/Functions.hpp new file mode 100644 index 0000000..fd99c6d --- /dev/null +++ b/src/Math/Functions.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include <cmath> +#include "Constants.hpp" + +namespace Math { + +// I. Trigonometric functions. + +template<typename T> +T radians(T degrees) { + return degrees * PI / 180.0f; +} + +template<typename T> +T degrees(T radians) { + return radians * 180.0f / PI; +} + +// II. Mathematical functions. + +template <typename T> +T sigmoid(T x) { + return 1 / (1 + std::pow(E, -x)); +} + +// Returns the least nonnegative remainder of a % b. +// Euclidian definition of modulo. +template <typename A, typename B> +auto mod(A a, B b) -> decltype(a % b) { + return (a % b + b) % b; +} + +template <typename T, typename R = T> +R sign(T x) { + return x < 0 ? -1 : 1; +} + +// III. Utility functions. + +template <typename T> +Bool floats_equal(T a, T b, Real epsilon = 0.0001f) { + return std::abs(a - b) < epsilon; +} + +} \ No newline at end of file diff --git a/src/Math/Mod.hpp b/src/Math/Mod.hpp deleted file mode 100644 index d686ad9..0000000 --- a/src/Math/Mod.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace Math { - -// Returns the least nonnegative remainder of a % b. -// Euclidian definition of modulo. -template <typename A, typename B> -auto mod(A a, B b) -> decltype(a % b) { - return (a % b + b) % b; -} - -} \ No newline at end of file diff --git a/src/Math/Rotation.hpp b/src/Math/Rotation.hpp index d5bc023..d12ac29 100644 --- a/src/Math/Rotation.hpp +++ b/src/Math/Rotation.hpp @@ -1,7 +1,7 @@ #pragma once #include <cmath> -#include "Trig.hpp" +#include "Functions.hpp" #include "Vector.hpp" struct Rotation { diff --git a/src/Math/Sigmoid.hpp b/src/Math/Sigmoid.hpp deleted file mode 100644 index f2fa009..0000000 --- a/src/Math/Sigmoid.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include <cmath> -#include "Constants.hpp" - -namespace Math { - -template <typename T> -T sigmoid(T x) { - return 1 / (1 + std::pow(E, -x)); -} - -} diff --git a/src/Math/Trig.hpp b/src/Math/Trig.hpp deleted file mode 100644 index 00489a9..0000000 --- a/src/Math/Trig.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Constants.hpp" - -namespace Math { - -template<typename T> -T radians(T degrees) { - return degrees * PI / 180.0f; -} - -template<typename T> -T degrees(T radians) { - return radians * 180.0f / PI; -} - -} \ No newline at end of file diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp index a31afec..4506f0b 100644 --- a/src/Math/Vector.hpp +++ b/src/Math/Vector.hpp @@ -1,8 +1,9 @@ #pragma once -#include "../Common/Sizes.hpp" #include <sstream> #include <cmath> +#include "../Common/Sizes.hpp" +#include "Functions.hpp" template <uint S, typename T = Real> struct Vector { diff --git a/src/World/Generation/Generator.cpp b/src/World/Generation/Generator.cpp index 79c10b6..ec124cc 100644 --- a/src/World/Generation/Generator.cpp +++ b/src/World/Generation/Generator.cpp @@ -1,6 +1,6 @@ #include "Generator.hpp" +#include "../../Math/Common.hpp" #include "../../Math/Interpolation.hpp" -#include "../../Math/Sigmoid.hpp" namespace MC::World::Generation { diff --git a/src/World/Position.hpp b/src/World/Position.hpp index 91ec306..c18d8ed 100644 --- a/src/World/Position.hpp +++ b/src/World/Position.hpp @@ -2,8 +2,7 @@ #include "array" #include "ChunkDimensions.hpp" -#include "../Math/Mod.hpp" -#include "../Math/Random.hpp" +#include "../Math/Common.hpp" #include "../Math/Vector.hpp" namespace MC::Position { |
