6#include "ll/api/base/Macro.h"
8#include "mc/math/vector/base/VectorBase.h"
16template <
typename T,
typename... Components>
19 using first_type =
typename VectorBase<T, Components...>::first_type;
21 constexpr T& operator+=(T
const& b)
noexcept
24 CommutativeGroup::forEachComponent([&]<
typename axis_type,
size_t iter> {
25 static_cast<T*
>(
this)->
template get<axis_type, iter>() += b.template get<axis_type, iter>();
27 return static_cast<T&
>(*(
static_cast<T*
>(
this)));
30 constexpr T& operator-=(T
const& b)
noexcept
33 CommutativeGroup::forEachComponent([&]<
typename axis_type,
size_t iter> {
34 static_cast<T*
>(
this)->
template get<axis_type, iter>() -= b.template get<axis_type, iter>();
36 return static_cast<T&
>(*(
static_cast<T*
>(
this)));
39 [[nodiscard]]
constexpr T operator+(T
const& b)
const noexcept
42 T tmp = *(
static_cast<T const*
>(
this));
47 [[nodiscard]]
constexpr T operator-(T
const& b)
const noexcept
50 T tmp = *(
static_cast<T const*
>(
this));
54 template <std::convertible_to<first_type> V>
55 constexpr T& operator+=(V
const& b)
noexcept {
56 CommutativeGroup::forEachComponent([&]<
typename axis_type,
size_t iter> {
57 static_cast<T*
>(
this)->
template get<first_type, iter>() +=
static_cast<first_type
>(b);
59 return static_cast<T&
>(*(
static_cast<T*
>(
this)));
63 template <std::convertible_to<first_type> V>
64 constexpr T& operator-=(V
const& b)
noexcept {
65 CommutativeGroup::forEachComponent([&]<
typename axis_type,
size_t iter> {
66 static_cast<T*
>(
this)->
template get<first_type, iter>() -=
static_cast<first_type
>(b);
68 return static_cast<T&
>(*(
static_cast<T*
>(
this)));
71 template <std::convertible_to<first_type> V>
72 [[nodiscard]]
constexpr T operator+(V
const& b)
const noexcept {
73 T tmp = *(
static_cast<T const*
>(
this));
74 tmp +=
static_cast<first_type
>(b);
78 template <std::convertible_to<first_type> V>
79 [[nodiscard]]
constexpr T operator-(V
const& b)
const noexcept {
80 T tmp = *(
static_cast<T const*
>(
this));
81 tmp -=
static_cast<first_type
>(b);
85 [[nodiscard]]
constexpr T add(T
const& b)
const noexcept
88 return *(
static_cast<T const*
>(
this)) + b;
91 [[nodiscard]]
constexpr T sub(T
const& b)
const noexcept
94 return *(
static_cast<T const*
>(
this)) - b;
97 template <std::convertible_to<first_type> V>
98 [[nodiscard]]
constexpr T add(V
const& b)
const noexcept {
99 return *(
static_cast<T const*
>(
this)) +
static_cast<first_type
>(b);
102 template <std::convertible_to<first_type> V>
103 [[nodiscard]]
constexpr T sub(V
const& b)
const noexcept {
104 return *(
static_cast<T const*
>(
this)) -
static_cast<first_type
>(b);
108template <IsCommutativeGroup T, std::convertible_to<
typename T::first_type> V>
109[[nodiscard]]
constexpr auto operator+(V
const& v, T
const& t)
noexcept {
110 return T{
static_cast<typename T::first_type
>(v)} + t;
113template <IsCommutativeGroup T, std::convertible_to<
typename T::first_type> V>
114[[nodiscard]]
constexpr auto operator-(V
const& v, T
const& t)
noexcept {
115 return T{
static_cast<typename T::first_type
>(v)} - t;
118template <IsCommutativeGroup T>
119[[nodiscard]]
constexpr T min(T
const& a, T
const& b)
noexcept {
121 T::forEachComponent([&]<
typename axis_type,
size_t iter> {
122 if constexpr (std::is_base_of_v<CommutativeGroupTag, axis_type>) {
123 tmp.template get<axis_type, iter>() =
124 min<axis_type>(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
126 tmp.template get<axis_type, iter>() =
127 std::min<axis_type>(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
133template <IsCommutativeGroup T>
134[[nodiscard]]
constexpr T max(T
const& a, T
const& b)
noexcept {
136 T::forEachComponent([&]<
typename axis_type,
size_t iter> {
137 if constexpr (std::is_base_of_v<CommutativeGroupTag, axis_type>) {
138 tmp.template get<axis_type, iter>() =
139 max<axis_type>(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
141 tmp.template get<axis_type, iter>() =
142 std::max<axis_type>(a.template get<axis_type, iter>(), b.template get<axis_type, iter>());
Definition CommutativeGroup.h:14
Definition CommutativeGroup.h:11
Definition CommutativeGroup.h:17
Definition VectorBase.h:51