PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
normalization.h
1#pragma once
2
3#include "pixelbullet/math/validation.h"
4
5#include <glm/glm.hpp>
6
7#include <concepts>
8
9namespace pixelbullet::math
10{
11template <glm::length_t Length, std::floating_point T, glm::qualifier Qualifier>
12[[nodiscard]] inline glm::vec<Length, T, Qualifier>
13normalized_or(const glm::vec<Length, T, Qualifier>& value, const glm::vec<Length, T, Qualifier>& fallback, const T minimum_length) noexcept
14{
15 const T length = glm::length(value);
16 const T effective_minimum_length = minimum_length > T{ 0 } ? minimum_length : T{ 0 };
17 return is_finite(length) && length > effective_minimum_length ? value / length : fallback;
18}
19} // namespace pixelbullet::math