PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
validation.h
1#pragma once
2
3#include <glm/glm.hpp>
4#include <glm/gtc/quaternion.hpp>
5
6#include <cmath>
7#include <concepts>
8
9namespace pixelbullet::math
10{
11template <std::floating_point T>
12[[nodiscard]] inline bool is_finite(const T value) noexcept
13{
14 return std::isfinite(value);
15}
16
17template <glm::length_t Length, std::floating_point T, glm::qualifier Qualifier>
18[[nodiscard]] inline bool is_finite(const glm::vec<Length, T, Qualifier>& value) noexcept
19{
20 for (glm::length_t index = 0; index < Length; ++index)
21 {
22 if (!is_finite(value[index]))
23 {
24 return false;
25 }
26 }
27
28 return true;
29}
30
31template <std::floating_point T, glm::qualifier Qualifier>
32[[nodiscard]] inline bool is_finite(const glm::qua<T, Qualifier>& value) noexcept
33{
34 return is_finite(value.x) && is_finite(value.y) && is_finite(value.z) && is_finite(value.w);
35}
36
37template <glm::length_t Columns, glm::length_t Rows, std::floating_point T, glm::qualifier Qualifier>
38[[nodiscard]] inline bool is_finite(const glm::mat<Columns, Rows, T, Qualifier>& value) noexcept
39{
40 for (glm::length_t column = 0; column < Columns; ++column)
41 {
42 if (!is_finite(value[column]))
43 {
44 return false;
45 }
46 }
47
48 return true;
49}
50} // namespace pixelbullet::math