Skip to main content

utils.ixx File

Misc math utility functions. More...

Included Headers

#include <cmath> #include <numbers> #include <type_traits>

Namespaces Index

namespacehelios
namespacemath

Description

Misc math utility functions.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cmath>
8#include <numbers>
9#include <type_traits>
10
11export module helios.math.utils;
12
13export namespace helios::math {
14
24 constexpr float EPSILON_LENGTH = 1e-6f;
25
32 constexpr float radians(const float angle) noexcept {
33 return angle * static_cast<float>(std::numbers::pi)/180.0f;
34 }
35
42 constexpr float degrees(const float radians) noexcept {
43 return radians * 180.0f/static_cast<float>(std::numbers::pi);
44 }
45
57 constexpr float shortestAngle(const float from, const float to) noexcept {
58
59 const float x = to - from;
60
61 // consteval required for MSVC since constexpr
62 // for std::floor only works on Mac
63 if consteval {
64 const float y = (x + 180.0f) / 360.0f;
65 const auto yi = static_cast<long long>(y);
66 const float floored = static_cast<float>(y >= 0.0f ? yi : yi - 1);
67 return x - 360.0f * floored;
68 }
69
70 return x - 360.0f * std::floor((x + 180.0f) / 360.0f);
71 }
72
73
74}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.