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
#include "Vector3.h"
namespace Eule
namespace Leonetienne::Eule
{
/** Abstract class of a collider domain.
* 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...
//! Pi up to 50 decimal places
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
namespace Leonetienne::Eule {
//! Pi up to 50 decimal places
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
//! Pi divided by two
static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755;
//! Pi divided by two
static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755;
//! Factor to convert degrees to radians
static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222;
//! Factor to convert degrees to radians
static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222;
//! Factor to convert radians to degrees
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
//! Factor to convert radians to degrees
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
}

View File

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

View File

@ -2,7 +2,7 @@
#include <stdexcept>
#include <math.h>
namespace Eule
namespace Leonetienne::Eule
{
/** 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 <ostream>
namespace Eule
namespace Leonetienne::Eule
{
template <class T>
class Vector3;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
#include "Collider.h"
#include <array>
namespace Eule
namespace Leonetienne::Eule
{
/** A collider describing a trapazoidal prism.
* 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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector2<T>::operator Vector3<T>() const
@ -322,8 +322,8 @@ namespace Eule {
bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon))
;
}

View File

@ -2,7 +2,7 @@
#include <cstdlib>
#include <sstream>
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector3<T>::operator Vector2<T>() const
{
@ -235,9 +235,9 @@ namespace Eule {
bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon))
;
}

View File

@ -5,7 +5,7 @@
#include <sstream>
#include "Matrix4x4.h"
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector4<T>::operator Vector2<T>() const
@ -183,10 +183,10 @@ namespace Eule {
bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon)) &&
(::Eule::Math::Similar(w, other.w, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(w, other.w, epsilon))
;
}

View File

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