mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 14:11:28 +07:00
two-type dot and cross functions
This commit is contained in:
@@ -305,10 +305,11 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
||||
constexpr dot(T x, T y) noexcept {
|
||||
return x * y;
|
||||
template < typename T, typename U
|
||||
, typename V = decltype(std::declval<T>() * std::declval<U>()) >
|
||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<V>, V>
|
||||
constexpr dot(T x, U y) noexcept {
|
||||
return { x * y };
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
|
||||
@@ -249,8 +249,11 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr T dot(const qua<T>& xs, const qua<T>& ys) {
|
||||
template < typename T, typename U
|
||||
, typename V = decltype(dot(
|
||||
std::declval<vec<T, 4>>(),
|
||||
std::declval<vec<U, 4>>())) >
|
||||
[[nodiscard]] constexpr V dot(const qua<T>& xs, const qua<U>& ys) {
|
||||
return dot(vec{xs}, vec{ys});
|
||||
}
|
||||
|
||||
|
||||
@@ -775,11 +775,12 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] constexpr T dot(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return fold_join([](T acc, T x, T y){
|
||||
template < typename T, typename U, std::size_t Size
|
||||
, typename V = decltype(std::declval<T>() * std::declval<U>()) >
|
||||
[[nodiscard]] constexpr V dot(const vec<T, Size>& xs, const vec<U, Size>& ys) {
|
||||
return fold_join([](V acc, T x, U y){
|
||||
return acc + (x * y);
|
||||
}, T{0}, xs, ys);
|
||||
}, V{0}, xs, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
@@ -812,13 +813,15 @@ namespace vmath_hpp
|
||||
return length2(ys - xs);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr T cross(const vec<T, 2>& xs, const vec<T, 2>& ys) {
|
||||
return xs.x * ys.y - xs.y * ys.x;
|
||||
template < typename T, typename U
|
||||
, typename V = decltype(std::declval<T>() * std::declval<U>()) >
|
||||
[[nodiscard]] constexpr V cross(const vec<T, 2>& xs, const vec<U, 2>& ys) {
|
||||
return { xs.x * ys.y - xs.y * ys.x };
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr vec<T, 3> cross(const vec<T, 3>& xs, const vec<T, 3>& ys) {
|
||||
template < typename T, typename U
|
||||
, typename V = decltype(std::declval<T>() * std::declval<U>()) >
|
||||
[[nodiscard]] constexpr vec<V, 3> cross(const vec<T, 3>& xs, const vec<U, 3>& ys) {
|
||||
return {
|
||||
xs.y * ys.z - xs.z * ys.y,
|
||||
xs.z * ys.x - xs.x * ys.z,
|
||||
|
||||
Reference in New Issue
Block a user