summary refs log tree commit diff
path: root/src/GFX/Util
AgeCommit message (Expand)Author
2023-08-06Create separate Player entity and add bad collision systemMel
2023-07-123D CloudsMel
2023-07-11Create MeshBuilder utility for comfy mesh buildingMel
#n29'>29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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;
}

}