mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 20:17:58 +07:00
two-type + - * / operators
This commit is contained in:
128
README.md
128
README.md
@@ -492,14 +492,14 @@ auto operator!(const vec<T, Size>& xs);
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(const vec<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(const vec<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(T x, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(T x, const vec<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(const vec<T, Size>& xs, const vec<U, Size>& ys);
|
||||
|
||||
// operator+=
|
||||
|
||||
@@ -511,14 +511,14 @@ vec<T, Size>& operator+=(vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(const vec<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(const vec<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(T x, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(T x, const vec<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(const vec<T, Size>& xs, const vec<U, Size>& ys);
|
||||
|
||||
// operator-=
|
||||
|
||||
@@ -530,14 +530,14 @@ vec<T, Size>& operator-=(vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(T x, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(T x, const vec<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, const vec<U, Size>& ys);
|
||||
|
||||
// operator*=
|
||||
|
||||
@@ -549,14 +549,14 @@ vec<T, Size>& operator*=(vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator/(const vec<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator/(const vec<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator/(T x, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator/(T x, const vec<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator/(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator/(const vec<T, Size>& xs, const vec<U, Size>& ys);
|
||||
|
||||
// operator/=
|
||||
|
||||
@@ -686,14 +686,14 @@ auto operator!(const mat<T, Size>& xs);
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(const mat<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(const mat<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(T x, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(T x, const mat<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator+(const mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator+(const mat<T, Size>& xs, const mat<U, Size>& ys);
|
||||
|
||||
// operator+=
|
||||
|
||||
@@ -705,14 +705,14 @@ mat<T, Size>& operator+=(mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(const mat<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(const mat<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(T x, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(T x, const mat<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator-(const mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator-(const mat<T, Size>& xs, const mat<U, Size>& ys);
|
||||
|
||||
// operator-=
|
||||
|
||||
@@ -724,17 +724,17 @@ mat<T, Size>& operator-=(mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(const mat<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(const mat<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(T x, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(T x, const mat<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(const vec<T, Size>& xs, const mat<U, Size>& ys);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator*(const mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator*(const mat<T, Size>& xs, const mat<U, Size>& ys);
|
||||
|
||||
// operator*=
|
||||
|
||||
@@ -749,11 +749,11 @@ mat<T, Size>& operator*=(mat<T, Size>& xs, const mat<T, Size>& ys);
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator/(const mat<T, Size>& xs, T y);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator/(const mat<T, Size>& xs, U y);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
auto operator/(T x, const mat<T, Size>& ys);
|
||||
template < typename T, typename U, size_t Size >
|
||||
auto operator/(T x, const mat<U, Size>& ys);
|
||||
|
||||
// operator/=
|
||||
|
||||
@@ -870,8 +870,8 @@ auto operator-(const qua<T>& xs);
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T >
|
||||
auto operator+(const qua<T>& xs, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator+(const qua<T>& xs, const qua<U>& ys);
|
||||
|
||||
// operator+=
|
||||
|
||||
@@ -880,8 +880,8 @@ qua<T>& operator+=(qua<T>& xs, const qua<T>& ys);
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T >
|
||||
auto operator-(const qua<T>& xs, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator-(const qua<T>& xs, const qua<U>& ys);
|
||||
|
||||
// operator-=
|
||||
|
||||
@@ -890,17 +890,17 @@ qua<T>& operator-=(qua<T>& xs, const qua<T>& ys);
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T >
|
||||
auto operator*(const qua<T>& xs, T y);
|
||||
template < typename T, typename U >
|
||||
auto operator*(const qua<T>& xs, U y);
|
||||
|
||||
template < typename T >
|
||||
auto operator*(T x, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator*(T x, const qua<U>& ys);
|
||||
|
||||
template < typename T >
|
||||
auto operator*(const vec<T, 3>& xs, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator*(const vec<T, 3>& xs, const qua<U>& ys);
|
||||
|
||||
template < typename T >
|
||||
auto operator*(const qua<T>& xs, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator*(const qua<T>& xs, const qua<U>& ys);
|
||||
|
||||
// operator*=
|
||||
|
||||
@@ -915,11 +915,11 @@ qua<T>& operator*=(qua<T>& xs, const qua<T>& ys);
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T >
|
||||
auto operator/(const qua<T>& xs, T y);
|
||||
template < typename T, typename U >
|
||||
auto operator/(const qua<T>& xs, U y);
|
||||
|
||||
template < typename T >
|
||||
auto operator/(T x, const qua<T>& ys);
|
||||
template < typename T, typename U >
|
||||
auto operator/(T x, const qua<U>& ys);
|
||||
|
||||
// operator/=
|
||||
|
||||
|
||||
@@ -192,19 +192,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const mat<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const mat<T, Size>& xs, U y) {
|
||||
return map_join([y](const vec<T, Size>& x){ return x + y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(T x, const mat<T, Size>& ys) {
|
||||
return map_join([x](const vec<T, Size>& y){ return x + y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(T x, const mat<U, Size>& ys) {
|
||||
return map_join([x](const vec<U, Size>& y){ return x + y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const mat<T, Size>& xs, const mat<T, Size>& ys) {
|
||||
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x + y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const mat<T, Size>& xs, const mat<U, Size>& ys) {
|
||||
return map_join([](const vec<T, Size>& x, const vec<U, Size>& y){ return x + y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator+=
|
||||
@@ -221,19 +221,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const mat<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const mat<T, Size>& xs, U y) {
|
||||
return map_join([y](const vec<T, Size>& x){ return x - y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(T x, const mat<T, Size>& ys) {
|
||||
return map_join([x](const vec<T, Size>& y){ return x - y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(T x, const mat<U, Size>& ys) {
|
||||
return map_join([x](const vec<U, Size>& y){ return x - y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const mat<T, Size>& xs, const mat<T, Size>& ys) {
|
||||
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x - y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const mat<T, Size>& xs, const mat<U, Size>& ys) {
|
||||
return map_join([](const vec<T, Size>& x, const vec<U, Size>& y){ return x - y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator-=
|
||||
@@ -250,25 +250,26 @@ namespace vmath_hpp
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const mat<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const mat<T, Size>& xs, U y) {
|
||||
return map_join([y](const vec<T, Size>& x){ return x * y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const mat<T, Size>& ys) {
|
||||
return map_join([x](const vec<T, Size>& y){ return x * y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const mat<U, Size>& ys) {
|
||||
return map_join([x](const vec<U, Size>& y){ return x * y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, const mat<T, Size>& ys) {
|
||||
return fold_join([](const vec<T, Size>& acc, T x, const vec<T, Size>& y){
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, const mat<U, Size>& ys) {
|
||||
using V = decltype(std::declval<T>() * std::declval<U>());
|
||||
return fold_join([](const vec<V, Size>& acc, T x, const vec<U, Size>& y){
|
||||
return acc + x * y;
|
||||
}, vec<T, Size>{}, xs, ys);
|
||||
}, vec<V, Size>{}, xs, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const mat<T, Size>& xs, const mat<T, Size>& ys) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const mat<T, Size>& xs, const mat<U, Size>& ys) {
|
||||
return map_join([&ys](const vec<T, Size>& x){
|
||||
return x * ys;
|
||||
}, xs);
|
||||
@@ -293,14 +294,14 @@ namespace vmath_hpp
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const mat<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const mat<T, Size>& xs, U y) {
|
||||
return map_join([y](const vec<T, Size>& x){ return x / y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const mat<T, Size>& ys) {
|
||||
return map_join([x](const vec<T, Size>& y){ return x / y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const mat<U, Size>& ys) {
|
||||
return map_join([x](const vec<U, Size>& y){ return x / y; }, ys);
|
||||
}
|
||||
|
||||
// operator/=
|
||||
|
||||
@@ -81,8 +81,8 @@ namespace vmath_hpp
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator+(const qua<T>& xs, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator+(const qua<T>& xs, const qua<U>& ys) {
|
||||
return qua(vec{xs} + vec{ys});
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ namespace vmath_hpp
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator-(const qua<T>& xs, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator-(const qua<T>& xs, const qua<U>& ys) {
|
||||
return qua(vec{xs} - vec{ys});
|
||||
}
|
||||
|
||||
@@ -109,18 +109,18 @@ namespace vmath_hpp
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator*(const qua<T>& xs, T y) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator*(const qua<T>& xs, U y) {
|
||||
return qua(vec{xs} * y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const qua<U>& ys) {
|
||||
return qua(x * vec{ys});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, 3>& xs, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, 3>& xs, const qua<U>& ys) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/
|
||||
|
||||
@@ -128,8 +128,8 @@ namespace vmath_hpp
|
||||
return xs + qv2 * ys.s + cross(ys.v, qv2);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator*(const qua<T>& xs, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator*(const qua<T>& xs, const qua<U>& ys) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/
|
||||
|
||||
@@ -157,13 +157,13 @@ namespace vmath_hpp
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator/(const qua<T>& xs, T y) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator/(const qua<T>& xs, U y) {
|
||||
return qua(vec{xs} / y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const qua<T>& ys) {
|
||||
template < typename T, typename U >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const qua<U>& ys) {
|
||||
return qua(x / vec{ys});
|
||||
}
|
||||
|
||||
|
||||
@@ -175,19 +175,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator+
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const vec<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const vec<T, Size>& xs, U y) {
|
||||
return map_join([y](T x){ return x + y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(T x, const vec<T, Size>& ys) {
|
||||
return map_join([x](T y){ return x + y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(T x, const vec<U, Size>& ys) {
|
||||
return map_join([x](U y){ return x + y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y){ return x + y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator+(const vec<T, Size>& xs, const vec<U, Size>& ys) {
|
||||
return map_join([](T x, U y){ return x + y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator+=
|
||||
@@ -204,19 +204,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator-
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const vec<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const vec<T, Size>& xs, U y) {
|
||||
return map_join([y](T x){ return x - y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(T x, const vec<T, Size>& ys) {
|
||||
return map_join([x](T y){ return x - y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(T x, const vec<U, Size>& ys) {
|
||||
return map_join([x](U y){ return x - y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y){ return x - y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator-(const vec<T, Size>& xs, const vec<U, Size>& ys) {
|
||||
return map_join([](T x, U y){ return x - y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator-=
|
||||
@@ -233,19 +233,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator*
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, U y) {
|
||||
return map_join([y](T x){ return x * y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const vec<T, Size>& ys) {
|
||||
return map_join([x](T y){ return x * y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(T x, const vec<U, Size>& ys) {
|
||||
return map_join([x](U y){ return x * y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y){ return x * y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator*(const vec<T, Size>& xs, const vec<U, Size>& ys) {
|
||||
return map_join([](T x, U y){ return x * y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator*=
|
||||
@@ -262,19 +262,19 @@ namespace vmath_hpp
|
||||
|
||||
// operator/
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const vec<T, Size>& xs, T y) {
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const vec<T, Size>& xs, U y) {
|
||||
return map_join([y](T x){ return x / y; }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const vec<T, Size>& ys) {
|
||||
return map_join([x](T y){ return x / y; }, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(T x, const vec<U, Size>& ys) {
|
||||
return map_join([x](U y){ return x / y; }, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y){ return x / y; }, xs, ys);
|
||||
template < typename T, typename U, std::size_t Size >
|
||||
[[nodiscard]] constexpr auto operator/(const vec<T, Size>& xs, const vec<U, Size>& ys) {
|
||||
return map_join([](T x, U y){ return x / y; }, xs, ys);
|
||||
}
|
||||
|
||||
// operator/=
|
||||
|
||||
@@ -163,6 +163,27 @@ TEST_CASE("vmath/mat_fun") {
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Operators2") {
|
||||
STATIC_CHECK(int2x2{} + 0.f == float2x2{});
|
||||
STATIC_CHECK(0.f + int2x2{} == float2x2{});
|
||||
STATIC_CHECK(int2x2{} + float2x2{} == float2x2{2.f});
|
||||
STATIC_CHECK(float2x2{} + int2x2{} == float2x2{2.f});
|
||||
|
||||
STATIC_CHECK(int2x2{} - 0.f == float2x2{});
|
||||
STATIC_CHECK(0.f - int2x2{} == float2x2{-1.f});
|
||||
STATIC_CHECK(int2x2{} - float2x2{} == float2x2{0.f});
|
||||
STATIC_CHECK(float2x2{} - int2x2{} == float2x2{0.f});
|
||||
|
||||
STATIC_CHECK(int2x2{} * 1.f == float2x2{});
|
||||
STATIC_CHECK(0.f * int2x2{1} == float2x2{0.f});
|
||||
STATIC_CHECK(int2{} * float2x2{} == float2{});
|
||||
STATIC_CHECK(int2x2{} * float2x2{} == float2x2{});
|
||||
STATIC_CHECK(float2x2{} * int2x2{1} == float2x2{});
|
||||
|
||||
STATIC_CHECK(int2x2{} / 1.f == float2x2{});
|
||||
STATIC_CHECK(0.f / int2x2{1,1,1,1} == float2x2{0.f});
|
||||
}
|
||||
|
||||
SUBCASE("relational functions") {
|
||||
STATIC_CHECK_FALSE(any(bool2x2(false, false, false, false)));
|
||||
STATIC_CHECK(any(bool2x2(true, false, true, false)));
|
||||
|
||||
@@ -63,6 +63,19 @@ TEST_CASE("vmath/qua_fun") {
|
||||
STATIC_CHECK(float3{1,0,0} * qfloat{0,0,0.7071067812f,0.7071067812f} == uapprox3(0.f,1.f,0.f));
|
||||
}
|
||||
|
||||
SUBCASE("Operators2") {
|
||||
STATIC_CHECK(qfloat{} + qdouble{} == qdouble{0,0,0,2});
|
||||
STATIC_CHECK(qfloat{} - qdouble{} == qdouble{0,0,0,0});
|
||||
|
||||
STATIC_CHECK(qfloat{} * 1.0 == qdouble{});
|
||||
STATIC_CHECK(1.0 * qfloat{} == qdouble{});
|
||||
STATIC_CHECK(float3{} * qdouble{} == double3{});
|
||||
STATIC_CHECK(qfloat{} * qdouble{} == qdouble{});
|
||||
|
||||
STATIC_CHECK(qfloat{} / 1.0 == qdouble{});
|
||||
STATIC_CHECK(1.0 / qfloat{1,1,1,1} == qdouble{1,1,1,1});
|
||||
}
|
||||
|
||||
SUBCASE("Common Functions") {
|
||||
{
|
||||
CHECK(all(approx(
|
||||
|
||||
@@ -133,6 +133,28 @@ TEST_CASE("vmath/vec_fun") {
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Operators2") {
|
||||
STATIC_CHECK(int2{} + 0.f == float2{});
|
||||
STATIC_CHECK(0.f + int2{} == float2{});
|
||||
STATIC_CHECK(int2{} + float2{} == float2{});
|
||||
STATIC_CHECK(float2{} + int2{} == float2{});
|
||||
|
||||
STATIC_CHECK(int2{} - 0.f == float2{});
|
||||
STATIC_CHECK(0.f - int2{} == float2{});
|
||||
STATIC_CHECK(int2{} - float2{} == float2{});
|
||||
STATIC_CHECK(float2{} - int2{} == float2{});
|
||||
|
||||
STATIC_CHECK(int2{} * 1.f == float2{});
|
||||
STATIC_CHECK(0.f * int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} * float2{1.f} == float2{});
|
||||
STATIC_CHECK(float2{} * int2{1} == float2{});
|
||||
|
||||
STATIC_CHECK(int2{} / 1.f == float2{});
|
||||
STATIC_CHECK(0.f / int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} / float2{1.f} == float2{});
|
||||
STATIC_CHECK(float2{} / int2{1} == float2{});
|
||||
}
|
||||
|
||||
SUBCASE("Angle and Trigonometric Functions") {
|
||||
STATIC_CHECK(radians(degrees(float2(12.13f))) == uapprox2(12.13f));
|
||||
STATIC_CHECK(degrees(radians(float2(12.13f))) == uapprox2(12.13f));
|
||||
|
||||
Reference in New Issue
Block a user