6#include <unordered_map>
32template <
typename T>
inline T *
ptr(T &obj) {
return &obj; }
41template <
typename T>
inline T *
ptr(T *obj) {
return obj; }
53template <
typename T>
constexpr T
lerp(
const T &a,
const T &b,
const double &c) {
54 return a * (1.0 - c) + c * b;
57template <
typename T>
inline bool fuzzyEqual(
const T &a,
const T &b,
double eps = 1e-6) {
58 return (
fabs(a - b) < eps *
fabs(a));
63 return std::find(vec.
begin(), vec.
end(), elem) != vec.
end();
65template <
typename T>
inline void eraseFromVector(
const T &elem, std::deque<T> &vec) {
66 vec.erase(std::remove(vec.begin(), vec.end(), elem), vec.end());
82 std::stringstream ss(s);
84 while (std::getline(ss, st, delim)) res.
push_back(st);
97inline std::array<double, 3>
hsvToRgb(
double h,
double s,
double v) {
98 if (s <= 0.0)
return {{v, v, v}};
99 double hh =
fmod(h, 1.0);
101 unsigned int i =
static_cast<unsigned int>(hh);
102 double ff = hh -
static_cast<double>(i);
103 double p = v * (1.0 - s);
104 double q = v * (1.0 - (s * ff));
105 double t = v * (1.0 - (s * (1.0 - ff)));
125template <
typename T>
inline constexpr T
constpow(
const T base,
unsigned const exponent) {
126 return (exponent == 0) ? 1 : (base *
constpow(base, exponent - 1));
129template <
typename T>
constexpr size_t eToUI(
const T &t) {
130 return static_cast<size_t>(t);
134 return r * 2.0 *
sqrt(m * k);
141template <
typename T,
typename U>
struct hash<pair<T, U>> {
143 return hash<T>()(x.first) ^ hash<U>()(x.second);
general purpose 3D vector/point class.
A simple vector class template.
void erase(iterator position)
Removes the element at the specified position.
void push_back(const T &value)
Adds an element to the end of the vector.
iterator begin()
Returns an iterator to the first element.
iterator end()
Returns an iterator to the last element.
this file contains various miscellanious utility functions & helpers *
constexpr T lerp(const T &a, const T &b, const double &c)
linear interpolation
constexpr size_t eToUI(const T &t)
bool isInVector(const T &elem, const std::vector< T > &vec)
T * ptr(T &obj)
returns a pointer (transforms reference into pointer)
bool fuzzyEqual(const T &a, const T &b, double eps=1e-6)
void eraseFromVector(const T &elem, std::deque< T > &vec)
double dampingFromRatio(const double r, const double m, const double k)
std::vector< std::string > splitStr(const std::string &s, char delim)
String spliting.
constexpr T constpow(const T base, unsigned const exponent)
std::array< double, 3 > hsvToRgb(double h, double s, double v)
transform hsv color space to rgb
Provides common mathematical functions and vector operations.
double sqrt(double x)
Computes the square root of a number.
double fabs(double x)
Computes the absolute value of a floating-point number.
double fmod(double x, double y)
Computes the remainder of the division of two numbers.
size_t operator()(const pair< T, U > &x) const