mal-math
C++20 mathematics library.
All Classes Namespaces Files Functions Variables Typedefs Concepts
rvec3.inl
Go to the documentation of this file.
1#pragma once
2#include "rvec3.hpp"
3namespace mal_math::_detail
4{
5 template <Primitive T>
6 constexpr void rvec<3, T>::reset() noexcept
7 {
8 x = y = z = 0;
9 }
10
11 template <Primitive T>
12 [[nodiscard]] constexpr rvec<3, T> const &rvec<3, T>::operator+() const noexcept
13 {
14 return *this;
15 }
16 template <Primitive T>
17 [[nodiscard]] constexpr vec<3, T> rvec<3, T>::operator-() const noexcept
18 {
19 return vec<3, T>(-x, -y, -z);
20 }
21
22 template <Primitive T>
23 template <Primitive U>
24 constexpr rvec<3, T> &rvec<3, T>::operator+=(U const value) noexcept
25 {
26 x = static_cast<T>(x + value);
27 y = static_cast<T>(y + value);
28 z = static_cast<T>(z + value);
29 return *this;
30 }
31 template <Primitive T>
32 template <Primitive U>
33 constexpr rvec<3, T> &rvec<3, T>::operator-=(U const value) noexcept
34 {
35 x = static_cast<T>(x - value);
36 y = static_cast<T>(y - value);
37 z = static_cast<T>(z - value);
38 return *this;
39 }
40 template <Primitive T>
41 template <Primitive U>
42 constexpr rvec<3, T> &rvec<3, T>::operator*=(U const value) noexcept
43 {
44 x = static_cast<T>(x * value);
45 y = static_cast<T>(y * value);
46 z = static_cast<T>(z * value);
47 return *this;
48 }
49 template <Primitive T>
50 template <Primitive U>
51 constexpr rvec<3, T> &rvec<3, T>::operator/=(U const value) noexcept
52 {
53 x = static_cast<T>(x / value);
54 y = static_cast<T>(y / value);
55 z = static_cast<T>(z / value);
56 return *this;
57 }
58 template <Primitive T>
59 template <Primitive U>
60 constexpr rvec<3, T> &rvec<3, T>::operator%=(U const value) noexcept
61 {
62 x = static_cast<T>(x % value);
63 y = static_cast<T>(y % value);
64 z = static_cast<T>(z % value);
65 return *this;
66 }
67
68 template <Primitive T>
69 template <AnyVec U>
70 constexpr rvec<3, T> &rvec<3, T>::operator+=(U const &other) noexcept requires(size == U::size)
71 {
72 x = static_cast<T>(x + other.x);
73 y = static_cast<T>(y + other.y);
74 z = static_cast<T>(z + other.z);
75 return *this;
76 }
77 template <Primitive T>
78 template <AnyVec U>
79 constexpr rvec<3, T> &rvec<3, T>::operator-=(U const &other) noexcept requires(size == U::size)
80 {
81 x = static_cast<T>(x - other.x);
82 y = static_cast<T>(y - other.y);
83 z = static_cast<T>(z - other.z);
84 return *this;
85 }
86 template <Primitive T>
87 template <AnyVec U>
88 constexpr rvec<3, T> &rvec<3, T>::operator*=(U const &other) noexcept requires(size == U::size)
89 {
90 x = static_cast<T>(x * other.x);
91 y = static_cast<T>(y * other.y);
92 z = static_cast<T>(z * other.z);
93 return *this;
94 }
95 template <Primitive T>
96 template <AnyVec U>
97 constexpr rvec<3, T> &rvec<3, T>::operator/=(U const &other) noexcept requires(size == U::size)
98 {
99 x = static_cast<T>(x / other.x);
100 y = static_cast<T>(y / other.y);
101 z = static_cast<T>(z / other.z);
102 return *this;
103 }
104
105 template <Primitive T>
106 template <AnyVec U>
107 constexpr rvec<3, T> &rvec<3, T>::operator%=(U const &other) noexcept requires(size == U::size)
108 {
109 x = static_cast<T>(x % other.x);
110 y = static_cast<T>(y % other.y);
111 z = static_cast<T>(z % other.z);
112 return *this;
113 }
114 template <Primitive T>
115 [[nodiscard]] constexpr T &rvec<3, T>::operator[](size_t i)
116 {
117 assert(i < size);
118 return data[i];
119 }
120 template <Primitive T>
121 [[nodiscard]] constexpr T const &rvec<3, T>::operator[](size_t i) const
122 {
123 assert(i < size);
124 return data[i];
125 }
126
127 template <Primitive T>
128 template <size_t n>
129 [[nodiscard]] constexpr rvec<n, T> rvec<3, T>::as_rvec() noexcept requires(n >= 2 && n <= size)
130 {
131 return rvec<n, T>{*this};
132 }
133
134 template <Primitive T>
135 template <size_t n, Primitive U>
136 [[nodiscard]] constexpr vec<n, std::remove_const_t<U>> rvec<3, T>::as_vec() const noexcept requires(n >= 2 && n <= size)
137 {
139 for (size_t i = 0; i < n; i++)
140 {
141 rv.data[i] = static_cast<U>(data[i]);
142 }
143 return rv;
144 }
145
146 template <Primitive T>
147 template <size_t n>
148 [[nodiscard]] constexpr rvec<n, const T> rvec<3, T>::as_crvec() const noexcept requires(n >= 2 && n <= size)
149 {
150 return rvec<n, const T>{*this};
151 }
152} // namespace mal_math
Provides the implementation of a 3D reference vector.
Internal detail definition of a reference vector with fixed size L and type T
Definition of the mathematical vector with fixed size L and type T
Definition vecn.hpp:22
std::array< T, size > data
The underlying data of the vector.
Definition vecn.hpp:101