mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-14 20:31:25 +07:00
qua +,-,+=,-= operators
This commit is contained in:
@@ -165,6 +165,48 @@ namespace vmath_hpp::detail
|
|||||||
|
|
||||||
namespace vmath_hpp
|
namespace vmath_hpp
|
||||||
{
|
{
|
||||||
|
// +operator
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
[[nodiscard]] constexpr qua<T> operator+(const qua<T>& xs) {
|
||||||
|
return xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -operator
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs) {
|
||||||
|
return map_join([](T x){ return -x; }, xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator+
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
[[nodiscard]] constexpr qua<T> operator+(const qua<T>& xs, const qua<T>& ys) {
|
||||||
|
return map_join([](T x, T y){ return x + y; }, xs, ys);
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator+=
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
constexpr qua<T>& operator+=(qua<T>& xs, const qua<T>& ys) {
|
||||||
|
return (xs = (xs + ys));
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator-
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs, const qua<T>& ys) {
|
||||||
|
return map_join([](T x, T y){ return x - y; }, xs, ys);
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator-=
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
constexpr qua<T>& operator-=(qua<T>& xs, const qua<T>& ys) {
|
||||||
|
return (xs = (xs - ys));
|
||||||
|
}
|
||||||
|
|
||||||
// operator==
|
// operator==
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
|
|||||||
@@ -39,4 +39,24 @@ TEST_CASE("vmath/qua_fun") {
|
|||||||
return acc + x;
|
return acc + x;
|
||||||
}, qua{1,2,3,4}) == 10);
|
}, qua{1,2,3,4}) == 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUBCASE("Operators") {
|
||||||
|
STATIC_REQUIRE(+qua(1,-2,3,-4) == qua(1,-2,3,-4));
|
||||||
|
STATIC_REQUIRE(-qua(1,-2,3,-4) == qua(-1,2,-3,4));
|
||||||
|
|
||||||
|
STATIC_REQUIRE(qua(1,2,3,4) + qua(3,4,5,6) == qua(4,6,8,10));
|
||||||
|
STATIC_REQUIRE(qua(1,2,3,4) - qua(3,5,7,9) == qua(-2,-3,-4,-5));
|
||||||
|
|
||||||
|
{
|
||||||
|
qua v{1,2,3,4};
|
||||||
|
REQUIRE(&v == &(v += qua{3,4,5,6}));
|
||||||
|
REQUIRE(v == qua{4,6,8,10});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
qua v{1,2,3,4};
|
||||||
|
REQUIRE(&v == &(v -= qua{3,4,5,6}));
|
||||||
|
REQUIRE(v == qua{-2,-2,-2,-2});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user