Moved everything in namespace Leonetienne::Eule

This commit is contained in:
Leonetienne 2022-03-06 19:58:59 +01:00
parent 3c8391d9ce
commit be63652df6
19 changed files with 661 additions and 713 deletions

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Vector3.h" #include "Vector3.h"
namespace Eule namespace Leonetienne::Eule
{ {
/** Abstract class of a collider domain. /** Abstract class of a collider domain.
* Specializations describe a shape in 3d space, and provide implementations of the methods below, * Specializations describe a shape in 3d space, and provide implementations of the methods below,

View File

@ -2,14 +2,16 @@
// Pretty sure the compiler will optimize these calculations out... // Pretty sure the compiler will optimize these calculations out...
//! Pi up to 50 decimal places namespace Leonetienne::Eule {
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510; //! Pi up to 50 decimal places
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
//! Pi divided by two //! Pi divided by two
static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755; static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755;
//! Factor to convert degrees to radians //! Factor to convert degrees to radians
static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222; static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222;
//! Factor to convert radians to degrees //! Factor to convert radians to degrees
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788; static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
}

View File

@ -2,28 +2,27 @@
#include "Constants.h" #include "Constants.h"
#include <array> #include <array>
using namespace Eule; namespace Leonetienne::Eule {
int Math::Mod(const int numerator, const int denominator) int Math::Mod(const int numerator, const int denominator) {
{ if (denominator == 0)
if (denominator == 0) throw std::logic_error("Division by zero");
throw std::logic_error("Division by zero");
// Quick optimizations: // Quick optimizations:
// -> 0/n is always 0 // -> 0/n is always 0
if (numerator == 0) if (numerator == 0)
return 0; return 0;
// -> operator% works for a > 0 && b > 0 // -> operator% works for a > 0 && b > 0
if (denominator > 0 && numerator > 0) if (denominator > 0 && numerator > 0)
return numerator % denominator; return numerator % denominator;
// Else: generalized formula // Else: generalized formula
return (denominator + (numerator % denominator)) % denominator; return (denominator + (numerator % denominator)) % denominator;
} }
double Math::Oscillate(const double a, const double b, const double counter, const double speed) double Math::Oscillate(const double a, const double b, const double counter, const double speed) {
{ return (sin(counter * speed * PI - HALF_PI) * 0.5 + 0.5) * (b - a) + a;
return (sin(counter * speed * PI - HALF_PI) * 0.5 + 0.5) * (b - a) + a; }
} }

View File

@ -2,7 +2,7 @@
#include <stdexcept> #include <stdexcept>
#include <math.h> #include <math.h>
namespace Eule namespace Leonetienne::Eule
{ {
/** Math utility class containing basic functions. /** Math utility class containing basic functions.
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
#include <array> #include <array>
#include <ostream> #include <ostream>
namespace Eule namespace Leonetienne::Eule
{ {
template <class T> template <class T>
class Vector3; class Vector3;

View File

@ -10,7 +10,7 @@
#include "gcccompat.h" #include "gcccompat.h"
#endif #endif
namespace Eule { namespace Leonetienne::Eule {
Quaternion::Quaternion() Quaternion::Quaternion()
{ {

View File

@ -4,7 +4,7 @@
#include "Matrix4x4.h" #include "Matrix4x4.h"
#include <mutex> #include <mutex>
namespace Eule namespace Leonetienne::Eule
{ {
/** 3D rotation representation /** 3D rotation representation
*/ */

View File

@ -2,75 +2,68 @@
#include <array> #include <array>
#include <algorithm> #include <algorithm>
using namespace Eule; namespace Leonetienne::Eule {
// Checks if the random number generator is initialized. Does nothing if it is, initializes if it isn't. // Checks if the random number generator is initialized. Does nothing if it is, initializes if it isn't.
#define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng(); #define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng();
void Random::InitRng() void Random::InitRng() {
{ // Create truly random source (from hardware events)
// Create truly random source (from hardware events) std::random_device randomSource;
std::random_device randomSource;
// Generate enough truly random values to populate the entire state of the mersenne twister // Generate enough truly random values to populate the entire state of the mersenne twister
std::array<int, std::mt19937::state_size> seedValues; std::array<int, std::mt19937::state_size> seedValues;
std::generate_n(seedValues.data(), seedValues.size(), std::ref(randomSource)); std::generate_n(seedValues.data(), seedValues.size(), std::ref(randomSource));
std::seed_seq seedSequence(seedValues.begin(), seedValues.end()); std::seed_seq seedSequence(seedValues.begin(), seedValues.end());
// Seed the mersenne twister with these values // Seed the mersenne twister with these values
rng = std::mt19937(seedSequence); rng = std::mt19937(seedSequence);
isRngInitialized = true; isRngInitialized = true;
return; return;
} }
// Will return a random double between 0 and 1 // Will return a random double between 0 and 1
double Random::RandomFloat() double Random::RandomFloat() {
{ MAKE_SURE_RNG_IS_INITIALIZED;
MAKE_SURE_RNG_IS_INITIALIZED;
return (rng() % 694206942069ll) / 694206942069.0; return (rng() % 694206942069ll) / 694206942069.0;
} }
// Will return a random unsigned integer. // Will return a random unsigned integer.
unsigned int Random::RandomUint() unsigned int Random::RandomUint() {
{ MAKE_SURE_RNG_IS_INITIALIZED;
MAKE_SURE_RNG_IS_INITIALIZED;
return rng(); return rng();
} }
// Will return a random integer // Will return a random integer
unsigned int Random::RandomInt() unsigned int Random::RandomInt() {
{ MAKE_SURE_RNG_IS_INITIALIZED;
MAKE_SURE_RNG_IS_INITIALIZED;
// Since this is supposed to return a random value anyways, // Since this is supposed to return a random value anyways,
// we can let the random uint overflow without any problems. // we can let the random uint overflow without any problems.
return (int)rng(); return (int) rng();
} }
// Will return a random double within a range // Will return a random double within a range
// These bounds are INCLUSIVE! // These bounds are INCLUSIVE!
double Random::RandomRange(double min, double max) double Random::RandomRange(double min, double max) {
{ return (RandomFloat() * (max - min)) + min;
return (RandomFloat() * (max - min)) + min; }
}
// Will return a random integer within a range. This is faster than '(int)RandomRange(x,y)' // Will return a random integer within a range. This is faster than '(int)RandomRange(x,y)'
// These bounds are INCLUSIVE! // These bounds are INCLUSIVE!
int Random::RandomIntRange(int min, int max) int Random::RandomIntRange(int min, int max) {
{ MAKE_SURE_RNG_IS_INITIALIZED;
MAKE_SURE_RNG_IS_INITIALIZED;
return (rng() % (max + 1 - min)) + min; return (rng() % (max + 1 - min)) + min;
}
bool Random::RandomChance(const double chance) {
return RandomFloat() <= chance;
}
std::mt19937 Random::rng;
bool Random::isRngInitialized = false;
} }
bool Random::RandomChance(const double chance)
{
return RandomFloat() <= chance;
}
std::mt19937 Random::rng;
bool Random::isRngInitialized = false;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <random> #include <random>
namespace Eule namespace Leonetienne::Eule
{ {
/** Extensive random number generator /** Extensive random number generator
*/ */

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../Eule/Vector2.h" #include "../Eule/Vector2.h"
namespace Eule namespace Leonetienne::Eule
{ {
/** Trivial data structure representing a rectangle /** Trivial data structure representing a rectangle
*/ */

View File

@ -1,6 +1,6 @@
#include "TrapazoidalPrismCollider.h" #include "TrapazoidalPrismCollider.h"
using namespace Eule; using namespace Leonetienne::Eule;
TrapazoidalPrismCollider::TrapazoidalPrismCollider() TrapazoidalPrismCollider::TrapazoidalPrismCollider()
{ {

View File

@ -3,7 +3,7 @@
#include "Collider.h" #include "Collider.h"
#include <array> #include <array>
namespace Eule namespace Leonetienne::Eule
{ {
/** A collider describing a trapazoidal prism. /** A collider describing a trapazoidal prism.
* A trapazoidal prism is basically a box, but each vertex can be manipulated individually, altering * A trapazoidal prism is basically a box, but each vertex can be manipulated individually, altering

View File

@ -19,7 +19,7 @@
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus. The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
*/ */
namespace Eule { namespace Leonetienne::Eule {
template<typename T> template<typename T>
Vector2<T>::operator Vector3<T>() const Vector2<T>::operator Vector3<T>() const
@ -322,8 +322,8 @@ namespace Eule {
bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const
{ {
return return
(::Eule::Math::Similar(x, other.x, epsilon)) && (::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) (::Leonetienne::Eule::Math::Similar(y, other.y, epsilon))
; ;
} }

View File

@ -2,7 +2,7 @@
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
namespace Eule { namespace Leonetienne::Eule {
template<typename T> template<typename T>
class Vector3; class Vector3;

View File

@ -19,7 +19,7 @@
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus. The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
*/ */
namespace Eule { namespace Leonetienne::Eule {
template<typename T> template<typename T>
Vector3<T>::operator Vector2<T>() const Vector3<T>::operator Vector2<T>() const
{ {
@ -235,9 +235,9 @@ namespace Eule {
bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const
{ {
return return
(::Eule::Math::Similar(x, other.x, epsilon)) && (::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) && (::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon)) (::Leonetienne::Eule::Math::Similar(z, other.z, epsilon))
; ;
} }

View File

@ -5,7 +5,7 @@
#include <sstream> #include <sstream>
#include "Matrix4x4.h" #include "Matrix4x4.h"
namespace Eule { namespace Leonetienne::Eule {
template<typename T> template<typename T>
class Vector2; class Vector2;

View File

@ -19,7 +19,7 @@
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus. The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
*/ */
namespace Eule { namespace Leonetienne::Eule {
template<typename T> template<typename T>
Vector4<T>::operator Vector2<T>() const Vector4<T>::operator Vector2<T>() const
@ -183,10 +183,10 @@ namespace Eule {
bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const
{ {
return return
(::Eule::Math::Similar(x, other.x, epsilon)) && (::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) && (::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon)) && (::Leonetienne::Eule::Math::Similar(z, other.z, epsilon)) &&
(::Eule::Math::Similar(w, other.w, epsilon)) (::Leonetienne::Eule::Math::Similar(w, other.w, epsilon))
; ;
} }

View File

@ -5,7 +5,7 @@
#include <sstream> #include <sstream>
#include "Matrix4x4.h" #include "Matrix4x4.h"
namespace Eule namespace Leonetienne::Eule
{ {
template <typename T> class Vector2; template <typename T> class Vector2;
template <typename T> class Vector3; template <typename T> class Vector3;