39#ifndef RTYPE_VECBASE_HPP_
40 #define RTYPE_VECBASE_HPP_
59 template <Numeric T, std::
size_t N>
61 using RealT = std::conditional_t<std::is_integral_v<T>, double, T>;
63 template <
typename Self>
66 const std::remove_cvref_t<Self> &other)
noexcept
69 template <
typename Self>
72 const std::remove_cvref_t<Self> &other)
noexcept
75 template <
typename Self>
79 template <
typename Self>
81 constexpr auto length(
this const Self &self)
noexcept ->
RealT;
83 template <
typename Self>
85 constexpr auto normalize(
this Self &self)
noexcept -> Self &
86 requires std::floating_point<T>;
88 template <
typename Self>
90 constexpr auto normalized(
this const Self &self)
noexcept
91 -> std::remove_cvref_t<Self>
92 requires std::floating_point<T>;
94 template <
typename Self>
96 constexpr auto dot(
this const Self &self,
97 const std::remove_cvref_t<Self> &other)
noexcept
100 template <
typename Self>
103 const std::remove_cvref_t<Self> &other)
noexcept
104 -> std::remove_cvref_t<Self>
105 requires std::floating_point<T>;
111 template <
typename Self>
113 const std::remove_cvref_t<Self> &other)
noexcept;
115 template <
typename Self>
117 const std::remove_cvref_t<Self> &other)
noexcept;
119 template <
typename Self>
121 const std::remove_cvref_t<Self> &other)
noexcept;
123 template <
typename Self>
125 const std::remove_cvref_t<Self> &other)
noexcept;
131 template <
typename Self>
132 constexpr auto &
operator+=(
this Self &self, T scalar)
noexcept;
134 template <
typename Self>
135 constexpr auto &
operator-=(
this Self &self, T scalar)
noexcept;
137 template <
typename Self>
138 constexpr auto &
operator*=(
this Self &self, T scalar)
noexcept;
140 template <
typename Self>
141 constexpr auto &
operator/=(
this Self &self, T scalar)
noexcept;
147 template <
typename ConcreteVec>
150 const ConcreteVec &rhs)
noexcept
152 requires std::derived_from<ConcreteVec, VecBase>
158 template <
typename ConcreteVec>
161 const ConcreteVec &rhs)
noexcept
163 requires std::derived_from<ConcreteVec, VecBase>
169 template <
typename ConcreteVec>
172 const ConcreteVec &rhs)
noexcept
174 requires std::derived_from<ConcreteVec, VecBase>
180 template <
typename ConcreteVec>
183 const ConcreteVec &rhs)
noexcept
185 requires std::derived_from<ConcreteVec, VecBase>
195 template <
typename ConcreteVec>
197 friend constexpr auto operator+(ConcreteVec lhs, T scalar)
noexcept
199 requires std::derived_from<ConcreteVec, VecBase>
205 template <
typename ConcreteVec>
207 friend constexpr auto operator-(ConcreteVec lhs, T scalar)
noexcept
209 requires std::derived_from<ConcreteVec, VecBase>
215 template <
typename ConcreteVec>
217 friend constexpr auto operator*(ConcreteVec lhs, T scalar)
noexcept
219 requires std::derived_from<ConcreteVec, VecBase>
225 template <
typename ConcreteVec>
227 friend constexpr auto operator/(ConcreteVec lhs, T scalar)
noexcept
229 requires std::derived_from<ConcreteVec, VecBase>
239 template <
typename ConcreteVec>
241 friend constexpr auto operator+(T scalar, ConcreteVec rhs)
noexcept
243 requires std::derived_from<ConcreteVec, VecBase>
249 template <
typename ConcreteVec>
251 friend constexpr auto operator*(T scalar, ConcreteVec rhs)
noexcept
253 requires std::derived_from<ConcreteVec, VecBase>
259 template <
typename ConcreteVec>
261 friend constexpr auto operator-(T scalar, ConcreteVec rhs)
noexcept
263 requires std::derived_from<ConcreteVec, VecBase>
265 for (std::size_t i = 0; i < N; ++i)
266 rhs[i] = scalar - rhs[i];
270 template <
typename ConcreteVec>
273 const ConcreteVec &rhs)
noexcept
275 requires std::derived_from<ConcreteVec, VecBase>
278 for (std::size_t i = 0; i < N; ++i)
279 result[i] = scalar / rhs[i];
287 template <
typename ConcreteVec>
289 friend constexpr auto operator-(ConcreteVec lhs)
noexcept
291 requires std::derived_from<ConcreteVec, VecBase>
293 for (std::size_t i = 0; i < N; ++i)
302 template <
typename ConcreteVec>
304 const ConcreteVec &v)
305 requires std::derived_from<ConcreteVec, VecBase>
308 for (std::size_t i = 0; i < N - 1; ++i)
Definition of the Numeric concept.
CRTP base class for vectors.
constexpr auto dot(this const Self &self, const std::remove_cvref_t< Self > &other) noexcept -> T
constexpr auto & operator/=(this Self &self, const std::remove_cvref_t< Self > &other) noexcept
friend constexpr auto operator+(ConcreteVec lhs, const ConcreteVec &rhs) noexcept -> ConcreteVec
constexpr auto & operator-=(this Self &self, T scalar) noexcept
constexpr auto length(this const Self &self) noexcept -> RealT
friend constexpr auto operator+(T scalar, ConcreteVec rhs) noexcept -> ConcreteVec
friend constexpr auto operator*(ConcreteVec lhs, T scalar) noexcept -> ConcreteVec
constexpr auto & operator-=(this Self &self, const std::remove_cvref_t< Self > &other) noexcept
constexpr auto & operator+=(this Self &self, const std::remove_cvref_t< Self > &other) noexcept
friend constexpr auto operator/(ConcreteVec lhs, T scalar) noexcept -> ConcreteVec
friend std::ostream & operator<<(std::ostream &os, const ConcreteVec &v)
friend constexpr auto operator+(ConcreteVec lhs, T scalar) noexcept -> ConcreteVec
constexpr auto & operator*=(this Self &self, T scalar) noexcept
friend constexpr auto operator-(ConcreteVec lhs, const ConcreteVec &rhs) noexcept -> ConcreteVec
constexpr auto project(this const Self &self, const std::remove_cvref_t< Self > &other) noexcept -> std::remove_cvref_t< Self >
constexpr auto & operator+=(this Self &self, T scalar) noexcept
friend constexpr auto operator-(ConcreteVec lhs) noexcept -> ConcreteVec
friend constexpr auto operator/(T scalar, const ConcreteVec &rhs) noexcept -> ConcreteVec
std::conditional_t< std::is_integral_v< T >, double, T > RealT
constexpr auto & operator/=(this Self &self, T scalar) noexcept
constexpr auto distance(this const Self &self, const std::remove_cvref_t< Self > &other) noexcept -> RealT
friend constexpr auto operator-(T scalar, ConcreteVec rhs) noexcept -> ConcreteVec
constexpr auto squaredDistance(this const Self &self, const std::remove_cvref_t< Self > &other) noexcept -> T
constexpr auto & operator*=(this Self &self, const std::remove_cvref_t< Self > &other) noexcept
constexpr auto normalize(this Self &self) noexcept -> Self &
friend constexpr auto operator-(ConcreteVec lhs, T scalar) noexcept -> ConcreteVec
friend constexpr auto operator/(ConcreteVec lhs, const ConcreteVec &rhs) noexcept -> ConcreteVec
friend constexpr auto operator*(ConcreteVec lhs, const ConcreteVec &rhs) noexcept -> ConcreteVec
friend constexpr auto operator*(T scalar, ConcreteVec rhs) noexcept -> ConcreteVec
constexpr auto normalized(this const Self &self) noexcept -> std::remove_cvref_t< Self >
constexpr auto squaredLength(this const Self &self) noexcept -> T