14 concept Scalar = std::is_arithmetic_v<T>;
17 concept Vector = std::same_as<T, ImVec2> || std::same_as<T, ImVec4>;
25 template <
typename T>
struct VecSize : std::integral_constant<int, 1> {};
26 template <>
struct VecSize<ImVec2> : std::integral_constant<int, 2> {};
27 template <>
struct VecSize<ImVec4> : std::integral_constant<int, 4> {};
36 template <
typename ...P>
38 template <
typename T,
typename ...P>
43 static constexpr int value =
44 cur == 1 || cur == next ? next :
51 template <
typename ...P>
55 template <detail::VectorOrScalarMaybeCvref T>
56 [[nodiscard]]
constexpr auto&&
getElem(
int i, T&& value )
66 return ( &value.x )[i];
72 template <
typename F,
typename ...P>
requires detail::ValidOperands<P...>
77 for (
int i = 0; i < n; i++)
83 template <
typename F, detail::VectorOrScalarMaybeCvref T>
84 [[nodiscard]]
constexpr auto reduce( F&& func, T&& value )
86 if constexpr ( std::is_same_v<std::remove_cvref_t<T>, ImVec2> )
87 return func( value.x, value.y );
88 else if constexpr ( std::is_same_v<std::remove_cvref_t<T>, ImVec2> )
89 return func( func( value.x, value.y ), func( value.x, value.w ) );
97template <MR::ImGuiMath::detail::Vector A> [[nodiscard]]
constexpr A operator+(
A a ) {
return a; }
112template <MR::ImGuiMath::detail::Vector A, MR::ImGuiMath::detail::VectorOrScalar B>
constexpr A&
operator+=(
A& a,
B b ) {
return a = a + b; }
113template <MR::ImGuiMath::detail::Vector A, MR::ImGuiMath::detail::VectorOrScalar B>
constexpr A&
operator-=(
A& a,
B b ) {
return a = a - b; }
114template <MR::ImGuiMath::detail::Vector A, MR::ImGuiMath::detail::VectorOrScalar B>
constexpr A&
operator*=(
A& a,
B b ) {
return a = a * b; }
115template <MR::ImGuiMath::detail::Vector A, MR::ImGuiMath::detail::VectorOrScalar B>
constexpr A&
operator/=(
A& a,
B b ) {
return a = a / b; }
117[[nodiscard]]
constexpr bool operator==( ImVec2 a, ImVec2 b ) {
return a.x == b.x && a.y == b.y; }
118[[nodiscard]]
constexpr bool operator==( ImVec4 a, ImVec4 b ) {
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; }
125 template <detail::Vector A> [[nodiscard]]
constexpr A round(
A a ) {
return (
applyElementwise)( [](
auto x ){
return std::round( x ); }, a ); }
126 template <detail::Vector A> [[nodiscard]]
constexpr A floor(
A a ) {
return (
applyElementwise)( [](
auto x ){
return std::floor( x ); }, a ); }
127 template <detail::Vector A> [[nodiscard]]
constexpr A ceil(
A a ) {
return (
applyElementwise)( [](
auto x ){
return std::ceil( x ); }, a ); }
129 template <detail::Vector A> [[nodiscard]]
constexpr auto dot(
A a,
A b ) {
return reduce( std::plus{}, a * b ); }
131 template <detail::Vector A> [[nodiscard]]
constexpr auto lengthSq(
A a ) {
return (
dot)( a, a ); }
132 template <detail::Vector A> [[nodiscard]]
constexpr auto length(
A a ) {
return std::sqrt(
lengthSq( a ) ); }
134 template <detail::Vector A> [[nodiscard]]
constexpr A normalize(
A a ) {
auto l =
length( a );
return l ? a / l : a; }
136 [[nodiscard]]
constexpr ImVec2
rot90( ImVec2 a ) {
return ImVec2( -a.y, a.x ); }
138 template <detail::Vector A, detail::Scalar B> [[nodiscard]]
constexpr A mix(
B t,
A a,
A b ) {
return a * ( 1 - t ) + b * t; }
140 template <
typename A,
typename B>
requires detail::ValidOperands<A, B>
141 [[nodiscard]]
constexpr auto min(
A a,
B b ) {
return (
applyElementwise)( [](
auto x,
auto y ){
return x < y ? x : y; }, a, b ); }
142 template <
typename A,
typename B>
requires detail::ValidOperands<A, B>
143 [[nodiscard]]
constexpr auto max(
A a,
B b ) {
return (
applyElementwise)( [](
auto x,
auto y ){
return x > y ? x : y; }, a, b ); }
145 template <detail::Vector T,
typename A,
typename B>
requires detail::ValidOperands<T, A, B>
146 [[nodiscard]]
constexpr T
clamp( T value,
A a,
B b ) {
return (
max)( (
min)( value, b ), a ); }
153 template <
typename Derived, detail::VectorOrScalar A,
bool All>
160 template <
typename F, detail::Val
idOperands<A> B>
163 for (
int i = 0; i < detail::VecSize<A>::value; i++ )
179 template <detail::VectorOrScalar A>
184 template <detail::VectorOrScalar A>
187 template <detail::VectorOrScalar A>
192 template <detail::VectorOrScalar A>
constexpr A & operator*=(A &a, B b)
Definition MRImGuiVectorOperators.h:114
constexpr bool operator==(ImVec2 a, ImVec2 b)
Definition MRImGuiVectorOperators.h:117
constexpr A operator-(A a)
Definition MRImGuiVectorOperators.h:98
constexpr A operator+(A a)
Definition MRImGuiVectorOperators.h:97
constexpr auto operator*(A a, B b)
Definition MRImGuiVectorOperators.h:107
constexpr A & operator-=(A &a, B b)
Definition MRImGuiVectorOperators.h:113
constexpr A & operator/=(A &a, B b)
Definition MRImGuiVectorOperators.h:115
constexpr A & operator+=(A &a, B b)
Definition MRImGuiVectorOperators.h:112
constexpr auto operator/(A a, B b)
Definition MRImGuiVectorOperators.h:110
length
Definition MRObjectDimensionsEnum.h:14
Definition MRImGuiVectorOperators.h:14
Definition MRImGuiVectorOperators.h:52
Definition MRImGuiVectorOperators.h:23
Definition MRImGuiVectorOperators.h:20
Definition MRImGuiVectorOperators.h:17
Definition MRImGuiVectorOperators.h:10
constexpr auto max(A a, B b)
Definition MRImGuiVectorOperators.h:143
constexpr A mix(B t, A a, A b)
Definition MRImGuiVectorOperators.h:138
constexpr A round(A a)
Definition MRImGuiVectorOperators.h:125
constexpr A normalize(A a)
Definition MRImGuiVectorOperators.h:134
constexpr A ceil(A a)
Definition MRImGuiVectorOperators.h:127
CompareAny(A) -> CompareAny< A >
constexpr ImVec2 rot90(ImVec2 a)
Definition MRImGuiVectorOperators.h:136
constexpr T clamp(T value, A a, B b)
Definition MRImGuiVectorOperators.h:146
constexpr auto && getElem(int i, T &&value)
Definition MRImGuiVectorOperators.h:56
CompareAll(A) -> CompareAll< A >
constexpr auto applyElementwise(F &&func, P &&... params) -> typename detail::VecFromSize< detail::CommonVecSize< P... >::value >::type
Definition MRImGuiVectorOperators.h:73
constexpr auto lengthSq(A a)
Definition MRImGuiVectorOperators.h:131
constexpr auto dot(A a, A b)
Definition MRImGuiVectorOperators.h:129
constexpr auto min(A a, B b)
Definition MRImGuiVectorOperators.h:141
constexpr auto reduce(F &&func, T &&value)
Definition MRImGuiVectorOperators.h:84
constexpr A floor(A a)
Definition MRImGuiVectorOperators.h:126
Definition MRImGuiVectorOperators.h:155
constexpr bool operator>=(B other) const
Definition MRImGuiVectorOperators.h:176
constexpr bool compare(F &&func, B other) const
Definition MRImGuiVectorOperators.h:161
constexpr bool operator!=(B other) const
Definition MRImGuiVectorOperators.h:172
constexpr bool operator>(B other) const
Definition MRImGuiVectorOperators.h:174
A value
Definition MRImGuiVectorOperators.h:156
constexpr BasicVectorCompareHelper(A value)
Definition MRImGuiVectorOperators.h:158
constexpr bool operator==(B other) const
Definition MRImGuiVectorOperators.h:171
constexpr bool operator<(B other) const
Definition MRImGuiVectorOperators.h:173
constexpr bool operator<=(B other) const
Definition MRImGuiVectorOperators.h:175
Definition MRImGuiVectorOperators.h:181
Definition MRImGuiVectorOperators.h:189
Definition MRImGuiVectorOperators.h:37
ImVec2 type
Definition MRImGuiVectorOperators.h:30
ImVec4 type
Definition MRImGuiVectorOperators.h:31
Definition MRImGuiVectorOperators.h:29
Definition MRImGuiVectorOperators.h:25