LeviLamina
Loading...
Searching...
No Matches
FloatN.h
1#pragma once
2
3#include <cstddef>
4
5#include "ll/api/base/Macro.h"
6
7#include "mc/math/vector/base/Field.h"
8#include "mc/math/vector/base/VectorBase.h"
9
10namespace ll::math {
11template <typename T, typename... Components>
12class LL_EBO FloatN : public Field<T, Components...>, public FloatNTag {
13public:
14 using first_type = Field<T, Components...>::first_type;
15
16 [[nodiscard]] constexpr T normalize() const noexcept {
17 return *(static_cast<T const*>(this)) / static_cast<first_type>(this->length());
18 }
19
20 [[nodiscard]] constexpr double angle(T const& b) const noexcept { return acos(normalize().dot(b.normalize())); }
21
22 [[nodiscard]] constexpr T cross(T const& b) const noexcept
23 requires(FloatN::size() == 3)
24 {
25 return {
26 static_cast<T const*>(this)->template get<first_type, 1>() * b.template get<first_type, 2>()
27 - static_cast<T const*>(this)->template get<first_type, 2>() * b.template get<first_type, 1>(),
28 static_cast<T const*>(this)->template get<first_type, 2>() * b.template get<first_type, 0>()
29 - static_cast<T const*>(this)->template get<first_type, 0>() * b.template get<first_type, 2>(),
30 static_cast<T const*>(this)->template get<first_type, 0>() * b.template get<first_type, 1>()
31 - static_cast<T const*>(this)->template get<first_type, 1>() * b.template get<first_type, 0>()
32 };
33 }
34};
35
36template <IsFloatN T>
37[[nodiscard]] constexpr T lerp(T const& a, T const& b, T const& x) noexcept {
38 T tmp;
39 T::forEachComponent([&]<typename axis_type, size_t iter> {
40 tmp.template get<axis_type, iter>() = std::lerp(
41 a.template get<axis_type, iter>(),
42 b.template get<axis_type, iter>(),
43 x.template get<axis_type, iter>()
44 );
45 });
46 return tmp;
47}
48
49LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, acos)
50LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, asin)
51LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, atan)
52LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, acosh)
53LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, asinh)
54LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, atanh)
55LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, ceil)
56LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, cos)
57LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, cosh)
58LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, exp)
59LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, fabs)
60LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, floor)
61LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, log)
62LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, log2)
63LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, log10)
64LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, round)
65LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, sin)
66LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, sinh)
67LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, sqrt)
68LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, tan)
69LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, tanh)
70
71// LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, atan2)
72// LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, fmod)
73// LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, modf)
74// LL_VEC_GEN_BASIC_MATH_FUNC_FLOAT(IsFloatN, pow)
75
76
77template <IsFloatN T>
78[[nodiscard]] constexpr T atan2(T const& a, T const& b) noexcept {
79 T tmp;
80 T::forEachComponent([&]<typename axis_type, size_t iter> {
81 tmp.template get<axis_type, iter>() =
82 std::atan2(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
83 });
84 return tmp;
85}
86
87template <IsFloatN T>
88[[nodiscard]] constexpr T fmod(T const& a, T const& b) noexcept {
89 T tmp;
90 T::forEachComponent([&]<typename axis_type, size_t iter> {
91 tmp.template get<axis_type, iter>() =
92 std::fmod(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
93 });
94 return tmp;
95}
96
97template <IsFloatN T>
98[[nodiscard]] constexpr T modf(T const& a, T const& b) noexcept {
99 T tmp;
100 T::forEachComponent([&]<typename axis_type, size_t iter> {
101 tmp.template get<axis_type, iter>() =
102 std::modf(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
103 });
104 return tmp;
105}
106
107template <IsFloatN T>
108[[nodiscard]] constexpr T pow(T const& a, T const& b) noexcept {
109 T tmp;
110 T::forEachComponent([&]<typename axis_type, size_t iter> {
111 tmp.template get<axis_type, iter>() =
112 std::pow(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
113 });
114 return tmp;
115}
116} // namespace ll::math
Definition FloatN.h:12
Definition Field.h:19
Definition VectorBase.h:42