LkEngine 0.1.2
 
Loading...
Searching...
No Matches
MathLibrary.h
1#pragma once
2
3#include <random>
4#include <limits>
5#include <type_traits>
6
7#include "Math.h" /* FIXME: Temporary include until refactor is done. */
8
9namespace LkEngine {
10
11 enum class EAngleUnit
12 {
13 Degree,
14 Radian,
15 };
16
17 namespace Enum
18 {
19 static constexpr const char* ToString(const EAngleUnit AngleUnit)
20 {
21 switch (AngleUnit)
22 {
23 case EAngleUnit::Degree: return "Degree";
24 case EAngleUnit::Radian: return "Radian";
25 }
26
27 LK_CORE_VERIFY(false, "Enum::ToString(const EAngleUnit) failed with value: {}", static_cast<int>(AngleUnit));
28 return nullptr;
29 }
30 }
31
32}
33
34namespace LkEngine::Math {
35
36 template <typename T>
37 static T GenerateRandomNumber()
38 {
39 static_assert(std::is_integral<T>::value, "T must be an integral type");
40 constexpr T Min = std::numeric_limits<T>::min();
41 constexpr T Max = std::numeric_limits<T>::max();
42 LK_CORE_ASSERT(Min <= Max, "Minimum value has to be less than or equal to maximum, min: {}, max: {}", Min, Max);
43
44 thread_local static std::mt19937 Generator(std::random_device{}());
45 thread_local static std::uniform_int_distribution<typename std::make_unsigned<T>::type> Distribution;
46
47 /* Update the distribution range before generating a number. */
48 return static_cast<T>(Distribution(Generator,
49 typename std::uniform_int_distribution<typename std::make_unsigned<T>::type>::param_type{
50 static_cast<typename std::make_unsigned<T>::type>(Min),
51 static_cast<typename std::make_unsigned<T>::type>(Max)
52 }));
53 }
54
55}
56
Mathematics used by the engine.
Definition Asset.h:11