SIMD improvement.
This commit is contained in:
parent
668a01491a
commit
84ef3a680a
@ -2,6 +2,8 @@
|
||||
|
||||
#include "Core/public/Math/Boilerplate.h"
|
||||
|
||||
#include "../IntVector3.hpp"
|
||||
|
||||
namespace Phanes::Core::Math::Detail
|
||||
{
|
||||
template<IntType T, bool S>
|
||||
@ -56,31 +58,46 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct construct_ivec3<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
v1.x = v2.x;
|
||||
v1.y = v2.y;
|
||||
v1.z = v2.z;
|
||||
v1.w = (T)0;
|
||||
}
|
||||
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
v1.x = s;
|
||||
v1.y = s;
|
||||
v1.z = s;
|
||||
v1.w = (T)0;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T x, T y)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, T x, T y, T z)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
v1.y = z;
|
||||
v1.w = (T)0;
|
||||
}
|
||||
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const T* comp)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const T* comp)
|
||||
{
|
||||
v1.x = comp[0];
|
||||
v1.y = comp[1];
|
||||
v1.z = comp[2];
|
||||
v1.w = (T)0;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2, const T s)
|
||||
{
|
||||
v1.x = v2.x;
|
||||
v1.y = v2.y;
|
||||
v1.z = s;
|
||||
v1.w = (T)0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -88,16 +105,18 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct compute_ivec3_add<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x + v2.x;
|
||||
r.y = v1.y + v2.y;
|
||||
r.z = v1.z + v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x + s;
|
||||
r.y = v1.y + s;
|
||||
r.z = v1.z + s;
|
||||
}
|
||||
};
|
||||
|
||||
@ -105,16 +124,18 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct compute_ivec3_sub<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x - v2.x;
|
||||
r.y = v1.y - v2.y;
|
||||
r.z = v1.z - v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x - s;
|
||||
r.y = v1.y - s;
|
||||
r.z = v1.z - s;
|
||||
}
|
||||
};
|
||||
|
||||
@ -122,16 +143,18 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct compute_ivec3_mul<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x * v2.x;
|
||||
r.y = v1.y * v2.y;
|
||||
r.z = v1.z * v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x * s;
|
||||
r.y = v1.y * s;
|
||||
r.z = v1.z * s;
|
||||
}
|
||||
};
|
||||
|
||||
@ -139,74 +162,82 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct compute_ivec3_div<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x / v2.x;
|
||||
r.y = v1.y / v2.y;
|
||||
r.z = v1.z / v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
s = (T)1.0 / s;
|
||||
|
||||
r.x = v1.x * s;
|
||||
r.y = v1.y * s;
|
||||
r.z = v1.z * s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_mod<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x % v2.x;
|
||||
r.y = v1.y % v2.y;
|
||||
r.z = v1.z % v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x % s;
|
||||
r.y = v1.y % s;
|
||||
r.z = v1.z % s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_eq<T, false>
|
||||
{
|
||||
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr bool map(const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
|
||||
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC);
|
||||
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC &&
|
||||
Phanes::Core::Math::Abs(v1.z - v2.z) < P_FLT_INAC);
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_ieq<T, false>
|
||||
{
|
||||
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr bool map(const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
|
||||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
|
||||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC ||
|
||||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_inc<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
|
||||
{
|
||||
r.x = v1.x + 1;
|
||||
r.y = v1.y + 1;
|
||||
r.z = v1.z + 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_dec<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
|
||||
{
|
||||
r.x = v1.x - 1;
|
||||
r.y = v1.y - 1;
|
||||
r.z = v1.z - 1;
|
||||
}
|
||||
};
|
||||
|
||||
@ -214,66 +245,101 @@ namespace Phanes::Core::Math::Detail
|
||||
template<IntType T>
|
||||
struct compute_ivec3_and<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x & v2.x;
|
||||
r.y = v1.y & v2.y;
|
||||
r.z = v1.z & v2.y;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x & s;
|
||||
r.y = v1.y & s;
|
||||
r.z = v1.z & s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_or<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x | v2.x;
|
||||
r.y = v1.y | v2.y;
|
||||
r.z = v1.z | v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x | s;
|
||||
r.y = v1.y | s;
|
||||
r.z = v1.z | s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_xor<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x ^ v2.x;
|
||||
r.y = v1.y ^ v2.y;
|
||||
r.z = v1.z ^ v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x ^ s;
|
||||
r.y = v1.y ^ s;
|
||||
r.z = v1.z ^ s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_left_shift<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x << v2.x;
|
||||
r.y = v1.y << v2.y;
|
||||
r.z = v1.z << v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x << s;
|
||||
r.y = v1.y << s;
|
||||
r.z = v1.z << s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_right_shift<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, const Phanes::Core::Math::TIntVector3<T, false>& v2)
|
||||
{
|
||||
r.x = v1.x >> v2.x;
|
||||
r.y = v1.y >> v2.y;
|
||||
r.z = v1.z >> v2.z;
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1, T s)
|
||||
{
|
||||
r.x = v1.x >> s;
|
||||
r.y = v1.y >> s;
|
||||
r.z = v1.z >> s;
|
||||
}
|
||||
};
|
||||
|
||||
template<IntType T>
|
||||
struct compute_ivec3_bnot<T, false>
|
||||
{
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector3<T, false>& r, const Phanes::Core::Math::TIntVector3<T, false>& v1)
|
||||
{
|
||||
r.x = ~v1.x;
|
||||
r.y = ~v1.y;
|
||||
r.z = ~v1.z;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -89,6 +89,14 @@ namespace Phanes::Core::Math::Detail
|
||||
v1.z = comp[2];
|
||||
v1.w = comp[3];
|
||||
}
|
||||
|
||||
static constexpr void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector2<int, true>& v1, const Phanes::Core::Math::TIntVector2<int, true>& v2)
|
||||
{
|
||||
r.x = v1.x;
|
||||
r.y = v1.y;
|
||||
r.x = v2.x;
|
||||
r.y = v2.y;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -362,12 +362,10 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T, bool A>
|
||||
FORCEINLINE TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
inline TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
FORCEINLINE TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, T s);
|
||||
|
||||
|
||||
inline TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator& (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
@ -430,10 +428,13 @@ namespace Phanes::Core::Math {
|
||||
template<IntType T, bool A>
|
||||
bool operator!= (const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
|
||||
|
||||
// ============================================== //
|
||||
// TIntVector2 static function implementation //
|
||||
// ============================================== //
|
||||
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T, false> MaxV(TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
|
||||
{
|
||||
@ -470,24 +471,6 @@ namespace Phanes::Core::Math {
|
||||
return v1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component wise multiplication of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T, false> ScaleV(TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies one Vector two another
|
||||
*
|
||||
@ -581,7 +564,7 @@ namespace Phanes::Core::Math {
|
||||
template<IntType T>
|
||||
inline bool IsCoincident(const TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) > 1);
|
||||
return (DotP(v1, v2) = 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,10 +47,7 @@ namespace Phanes::Core::Math {
|
||||
* Copy constructor
|
||||
*/
|
||||
|
||||
TIntVector3(const TIntVector3<T>& v)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
TIntVector3(const TIntVector3<T, A>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from xyz components.
|
||||
@ -60,7 +57,13 @@ namespace Phanes::Core::Math {
|
||||
* @param(z) Z component
|
||||
*/
|
||||
|
||||
TIntVector3(const T x, const T y, const T z) : x(x), y(y), z(z) {};
|
||||
TIntVector3(const T x, const T y, const T z);
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast s into all components.
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
TIntVector3(const T s);
|
||||
|
||||
/**
|
||||
* Construct Vector from two component array.
|
||||
@ -68,24 +71,9 @@ namespace Phanes::Core::Math {
|
||||
* @param(comp) Array of components
|
||||
*/
|
||||
|
||||
TIntVector3(const T* comp)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
TIntVector3(const T* comp);
|
||||
|
||||
/**
|
||||
* Constructs a vector pointing from start to end.
|
||||
*
|
||||
* @param(start) Startingpoint
|
||||
* @param(end) Endpoint
|
||||
*/
|
||||
|
||||
TIntVector3(const TIntPoint3<T>& start, const TIntPoint3<T>& end)
|
||||
{
|
||||
this->x = end.x - start.x;
|
||||
this->y = end.y - start.y;
|
||||
this->z = end.z - start.z;
|
||||
}
|
||||
TIntVector3(const TIntVector2<T, A>& v1, const T s)
|
||||
|
||||
};
|
||||
|
||||
@ -102,15 +90,8 @@ namespace Phanes::Core::Math {
|
||||
* @param(s) scalar to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator+= (TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x += s;
|
||||
v1.y += s;
|
||||
v1.z += s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator+= (TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of 3D vector to 3D vector
|
||||
@ -119,15 +100,8 @@ namespace Phanes::Core::Math {
|
||||
* @param(v2) vector to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator+= (TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x += v2.x;
|
||||
v1.y += v2.y;
|
||||
v1.z += v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator+= (TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of scalar of 3D vector
|
||||
@ -136,15 +110,8 @@ namespace Phanes::Core::Math {
|
||||
* @param(s) scalar to substract
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator-= (TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x -= s;
|
||||
v1.y -= s;
|
||||
v1.z -= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator-= (TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of 3D vector to 3D vector
|
||||
@ -153,15 +120,8 @@ namespace Phanes::Core::Math {
|
||||
* @param(v2) vector to substract with
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator-= (TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x -= v2.x;
|
||||
v1.y -= v2.y;
|
||||
v1.z -= v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator-= (TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Dot product between two 3D Vectors
|
||||
@ -170,15 +130,8 @@ namespace Phanes::Core::Math {
|
||||
* @param(s) scalar
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator*= (TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
v1.z *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator*= (TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Division of vector by scalar
|
||||
@ -187,34 +140,45 @@ namespace Phanes::Core::Math {
|
||||
* @param(s) scalar
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator/= (TIntVector3<T>& v1, T s)
|
||||
{
|
||||
float _1_s = 1.0f / s;
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator/= (TIntVector3<T, A>& v1, T s);
|
||||
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
v1.z *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector2<T, A> operator%= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Stores remainder of division with scalar
|
||||
*
|
||||
* @param(v1) vector one
|
||||
* @param(s) scalar
|
||||
*/
|
||||
template<IntType T, bool A>
|
||||
TIntVector2<T, A> operator%= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator%= (TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x %= s;
|
||||
v1.y %= s;
|
||||
v1.z %= s;
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator&= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator&= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator|= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator|= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator^= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator^= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator<<= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator<<= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator>>= (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator>>= (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise multiplication of 3D Vectors with scalar
|
||||
@ -225,11 +189,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator* (const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x * s, v1.y * s, v1.z * s);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator* (const TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise multiplication of 3D Vectors with scalar
|
||||
@ -240,11 +201,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Solution vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
FORCEINLINE TIntVector3<T> operator* (T s, const TIntVector3<T>& v1)
|
||||
{
|
||||
return v1 * s;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
FORCEINLINE TIntVector3<T, A> operator* (T s, const TIntVector3<T, A>& v1) { return v1 / s; };
|
||||
|
||||
/**
|
||||
* Division by scalar
|
||||
@ -255,33 +213,51 @@ namespace Phanes::Core::Math {
|
||||
* @return Solution vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator/ (const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
float _1_s = 1.0f / s;
|
||||
return TIntVector3<T>(v1.x * s, v1.y * s, v1.z * s);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector3<T, A> operator/ (const TIntVector3<T, A>& v1, T s);
|
||||
|
||||
template<IntType T>
|
||||
FORCEINLINE TIntVector3<T> operator/ (T s, const TIntVector3<T>& v1)
|
||||
{
|
||||
return v1 / s;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
FORCEINLINE TIntVector3<T, A> operator/ (T s, const TIntVector3<T, A>& v1) { return v1 / s; };
|
||||
|
||||
/**
|
||||
* Stores remainder of division by scalar
|
||||
*
|
||||
* @param(s) scalar
|
||||
* @param(v2) vector
|
||||
*
|
||||
* @return Solution vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator% (T s, const TIntVector3<T>& v1)
|
||||
{
|
||||
return TIntVector3<T>(v1.x % s, v1.y % s, v1.z % s);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator% (const TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator& (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator& (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator| (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator| (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator^ (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator^ (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator<< (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator<< (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator>> (TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator>> (TIntVector2<T, A>& v1, T s);
|
||||
|
||||
template<IntType T, bool A>
|
||||
inline TIntVector2<T, A> operator~ (TIntVector2<T, A>& v1);
|
||||
|
||||
/**
|
||||
* Dot product between two 3D Vectors
|
||||
@ -292,11 +268,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Dot product of Vectors
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T operator* (const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator* (const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of scalar to 3D vector
|
||||
@ -307,11 +280,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator+ (const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x + s.v1.y + s, v1.z + s);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+ (const TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of 3D vector to 3D vector
|
||||
@ -322,11 +292,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator+ (const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+ (const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of scalar of 3D vector
|
||||
@ -337,11 +304,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x - s.v1.y - s, v1.z - s);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator- (const TIntVector3<T, A>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of scalar of 3D vector
|
||||
@ -352,27 +316,8 @@ namespace Phanes::Core::Math {
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negates vector
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (TIntVector3<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator- (const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Tests two 3D vectors for equality.
|
||||
@ -387,11 +332,8 @@ namespace Phanes::Core::Math {
|
||||
* @note Uses [MACRO]P_FLT_INAC
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool operator== (const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline bool operator== (const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
/**
|
||||
* Tests two 3D vectors for inequality.
|
||||
@ -402,11 +344,8 @@ namespace Phanes::Core::Math {
|
||||
* @return True if inequal, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool operator!= (const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC);
|
||||
}
|
||||
template<IntType T, bool A>
|
||||
inline bool operator!= (const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2);
|
||||
|
||||
|
||||
// ============================================== //
|
||||
@ -423,7 +362,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T DotP(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
T DotP(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
@ -439,7 +378,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool Equals(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold = P_FLT_INAC)
|
||||
inline bool Equals(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2, T threshold = P_FLT_INAC)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold);
|
||||
}
|
||||
@ -454,7 +393,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> CrossPV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> CrossPV(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
float x = v1.x;
|
||||
float y = v1.y;
|
||||
@ -477,7 +416,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> MaxV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> MaxV(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
|
||||
@ -496,7 +435,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> MinV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> MinV(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
|
||||
@ -514,7 +453,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> NegateV(TIntVector3<T>& v1)
|
||||
TIntVector3<T, false> NegateV(TIntVector3<T, false>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
@ -533,7 +472,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> ScaleV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> ScaleV(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
@ -550,7 +489,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Set(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> Set(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
v1 = v2;
|
||||
|
||||
@ -567,7 +506,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Set(TIntVector3<T>& v1, T x, T y, T z)
|
||||
TIntVector3<T, false> Set(TIntVector3<T, false>& v1, T x, T y, T z)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
@ -583,7 +522,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> SignVectorV(TIntVector3<T>& v1)
|
||||
TIntVector3<T, false> SignVectorV(TIntVector3<T, false>& v1)
|
||||
{
|
||||
v1.x = (v1.x >= 0) ? 1 : -1;
|
||||
v1.y = (v1.y >= 0) ? 1 : -1;
|
||||
@ -604,7 +543,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T ScalarTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
T ScalarTriple(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2, const TIntVector3<T, false>& v3)
|
||||
{
|
||||
return CrossP(v1, v2) * v3;
|
||||
}
|
||||
@ -620,7 +559,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> VectorTripleV(TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
TIntVector3<T, false> VectorTripleV(TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2, const TIntVector3<T, false>& v3)
|
||||
{
|
||||
CrossPV(CrossPV(v1, v2), v3);
|
||||
|
||||
@ -637,7 +576,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsPerpendicular(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
inline bool IsPerpendicular(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) == 0);
|
||||
}
|
||||
@ -652,7 +591,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsParallel(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
inline bool IsParallel(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) == 1);
|
||||
}
|
||||
@ -667,7 +606,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsCoincident(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
inline bool IsCoincident(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) == 1);
|
||||
}
|
||||
@ -683,7 +622,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsCoplanar(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
inline bool IsCoplanar(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2, const TIntVector3<T, false>& v3)
|
||||
{
|
||||
return (ScalarTriple(v1, v2, v3) == 0);
|
||||
}
|
||||
@ -703,9 +642,9 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> CrossP(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> CrossP(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.y * v2.z) - (v1.z * v2.y),
|
||||
return TIntVector3<T, false>((v1.y * v2.z) - (v1.z * v2.y),
|
||||
(v1.z * v2.x) - (v1.x * v2.z),
|
||||
(v1.x * v2.y) - (v1.y * v2.x));
|
||||
}
|
||||
@ -720,9 +659,9 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Max(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> Max(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.x > v2.x) ? v1.x : v2.x,
|
||||
return TIntVector3<T, false>((v1.x > v2.x) ? v1.x : v2.x,
|
||||
(v1.y > v2.y) ? v1.y : v2.y,
|
||||
(v1.z > v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
@ -737,9 +676,9 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Min(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> Min(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.x < v2.x) ? v1.x : v2.x,
|
||||
return TIntVector3<T, false>((v1.x < v2.x) ? v1.x : v2.x,
|
||||
(v1.y < v2.y) ? v1.y : v2.y,
|
||||
(v1.z < v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
@ -753,9 +692,9 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Negate(const TIntVector3<T>& v1)
|
||||
TIntVector3<T, false> Negate(const TIntVector3<T, false>& v1)
|
||||
{
|
||||
return TIntVector3<T>(-v1.x, -v1.y, -v1.z);
|
||||
return TIntVector3<T, false>(-v1.x, -v1.y, -v1.z);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -768,9 +707,9 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Scale(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
TIntVector3<T, false> Scale(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
return TIntVector3<T, false>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -784,7 +723,7 @@ namespace Phanes::Core::Math {
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> VectorTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
TIntVector3<T, false> VectorTriple(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2, const TIntVector3<T, false>& v3)
|
||||
{
|
||||
return CrossP(CrossP(v1, v2), v3);
|
||||
}
|
||||
|
409
Engine/Source/Runtime/Core/public/Math/IntVector3.inl
Normal file
409
Engine/Source/Runtime/Core/public/Math/IntVector3.inl
Normal file
@ -0,0 +1,409 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/public/Math/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/Detail/IntVector3Decl.inl"
|
||||
#include "Core/public/Math/SIMD/SIMDIntrinsics.h"
|
||||
|
||||
#include "Core/public/Math/SIMD/PhanesSIMDTypes.h"
|
||||
|
||||
#include "IntVector3.hpp"
|
||||
|
||||
namespace Phanes::Core::Math
|
||||
{
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>::TIntVector3(const TIntVector3<T, A>& v)
|
||||
{
|
||||
Detail::construct_ivec3<T, SIMD::use_simd<T, 3, A>::value>::map(*this, v);
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>::TIntVector3(const T _x, const T _y, const T _z)
|
||||
{
|
||||
Detail::construct_ivec3<T, SIMD::use_simd<T, 3, A>::value>::map(*this, _x, _y, _z, _w);
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>::TIntVector3(const T s)
|
||||
{
|
||||
Detail::construct_ivec3<T, SIMD::use_simd<T, 3, A>::value>::map(*this, s);
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>::TIntVector3(const T* comp)
|
||||
{
|
||||
Detail::construct_ivec3<T, SIMD::use_simd<T, 3, A>::value>::map(*this, comp);
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>::TIntVector3(const TIntVector2<T, A>& v1, const T s)
|
||||
{
|
||||
Detail::construct_ivec3<T, SIMD::use_simd<T, 3, A>::value>::map(*this, v1, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_add<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_add<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator-=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_sub<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator-=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_sub<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator*=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_mul<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator*=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_mul<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator/=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_div<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator/=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_div<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator%=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_mod<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator%=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_mod<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_add<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator+(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_add<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator-(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_sub<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator-(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_sub<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator*(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_mul<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator*(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_mul<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator/(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_div<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator/(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_div<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator%(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_mod<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator%(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TIntVector3<T, A> r;
|
||||
Detail::compute_ivec3_mod<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Bitwise operators
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator&=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_and<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator&=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_and<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator|=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_or<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator|=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_or<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator^=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_xor<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator^=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_xor<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator<<=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_left_shift<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator<<=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_left_shift<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator>>=(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
Detail::compute_ivec3_right_shift<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, v2);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator>>=(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
Detail::compute_ivec3_right_shift<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v1, s);
|
||||
return v1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator&(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_and<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator&(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_and<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator|(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_or<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator|(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_or<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator^(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_xor<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator^(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_xor<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator<<(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_left_shift<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator<<(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_left_shift<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator>>(TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_right_shift<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, v2);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator>>(TIntVector3<T, A>& v1, T s)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_right_shift<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A> operator~(TIntVector3<T, A>& v1)
|
||||
{
|
||||
TVector2<T, A> r;
|
||||
Detail::compute_ivec3_bnot<T, SIMD::use_simd<T, 3, A>::value>::map(r, v1);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Comparision
|
||||
|
||||
template<IntType T, bool A>
|
||||
bool operator==(const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
return Detail::compute_ivec3_eq<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v2);
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
bool operator!=(const TIntVector3<T, A>& v1, const TIntVector3<T, A>& v2)
|
||||
{
|
||||
return Detail::compute_ivec3_ieq<T, SIMD::use_simd<T, 3, A>::value>::map(v1, v2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Inc- / Decrement
|
||||
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>& operator++(TIntVector3<T, A>& v1)
|
||||
{
|
||||
Detail::compute_ivec3_inc<T, SIMD::use_simd<T, 3, A>::value>::map(v1);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>& operator--(TIntVector3<T, A>& v1)
|
||||
{
|
||||
Detail::compute_ivec3_inc<T, SIMD::use_simd<T, 3, A>::value>::map(v1);
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>& operator++(TIntVector3<T, A>& v1, int)
|
||||
{
|
||||
return ++v1;
|
||||
}
|
||||
|
||||
template<IntType T, bool A>
|
||||
TIntVector3<T, A>& operator--(TIntVector3<T, A>& v1, int)
|
||||
{
|
||||
return --v1;
|
||||
}
|
||||
}
|
@ -435,8 +435,226 @@ namespace Phanes::Core::Math {
|
||||
|
||||
|
||||
|
||||
|
||||
// ========================= //
|
||||
// TIntVector4 functions //
|
||||
// ========================= //
|
||||
|
||||
template<IntType T>
|
||||
void Set(TIntVector4<T, false>& v1, TIntVector4<T, false>& v2)
|
||||
{
|
||||
v1.x = v2.x;
|
||||
v1.y = v2.y;
|
||||
v1.z = v2.z;
|
||||
v1.w = v2.w;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the dot product between two vectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector one</param>
|
||||
/// <param name="v2">Vector two</param>
|
||||
/// <returns>Dot product between vectors.</returns>
|
||||
template<IntType T>
|
||||
T DotP(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets componentwise max of both vectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector one</param>
|
||||
/// <param name="v2">Vector two</param>
|
||||
/// <returns>Vector with componentwise max of both vectors.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> Max(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return TIntVector4<T, false>(
|
||||
(v1.x > v2.x) ? v1.x : v2.x,
|
||||
(v1.y > v2.y) ? v1.y : v2.y,
|
||||
(v1.z > v2.z) ? v1.z : v2.z,
|
||||
(v1.w > v2.w) ? v1.w : v2.w
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets componentwise max of both vectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector one</param>
|
||||
/// <param name="v2">Vector two</param>
|
||||
/// <returns>Copy of v1.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> MaxV(TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
v1.x = (v1.x > v2.x) ? v1.x : v2.x;
|
||||
v1.y = (v1.y > v2.y) ? v1.y : v2.y;
|
||||
v1.z = (v1.z > v2.z) ? v1.z : v2.z;
|
||||
v1.w = (v1.w > v2.w) ? v1.w : v2.w;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets componentwise min of both vectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector one</param>
|
||||
/// <param name="v2">Vector two</param>
|
||||
/// <returns>Vector with componentwise max of both vectors.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> Min(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return TIntVector4<T, false>(
|
||||
(v1.x < v2.x) ? v1.x : v2.x,
|
||||
(v1.y < v2.y) ? v1.y : v2.y,
|
||||
(v1.z < v2.z) ? v1.z : v2.z,
|
||||
(v1.w < v2.w) ? v1.w : v2.w
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets componentwise min of both vectors.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector one</param>
|
||||
/// <param name="v2">Vector two</param>
|
||||
/// <returns>Copy of v1.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> MinV(TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
v1.x = (v1.x < v2.x) ? v1.x : v2.x;
|
||||
v1.y = (v1.y < v2.y) ? v1.y : v2.y;
|
||||
v1.z = (v1.z < v2.z) ? v1.z : v2.z;
|
||||
v1.w = (v1.w < v2.w) ? v1.w : v2.w;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inverses vector.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector</param>
|
||||
/// <returns>Inverted vector</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> Negate(const TIntVector4<T, false>& v1)
|
||||
{
|
||||
return TIntVector4<T, false>(
|
||||
-v1.x,
|
||||
-v1.y,
|
||||
-v1.z,
|
||||
-v1.w
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inverses vector.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <param name="v1">Vector</param>
|
||||
/// <returns>Copy of v1.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> NegateV(TIntVector4<T, false>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
v1.w = -v1.w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get signs of components.
|
||||
/// <para>
|
||||
/// + -> +1
|
||||
/// </para>
|
||||
/// x -> -1
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <typeparam name="A">Vector is aligned?</typeparam>
|
||||
/// <returns>Vector with signs of components.</returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> SignVector(TIntVector4<T, false>& v1)
|
||||
{
|
||||
return TIntVector4<T, false>(
|
||||
(v1.x > 0) ? 1 : -1,
|
||||
(v1.y > 0) ? 1 : -1,
|
||||
(v1.z > 0) ? 1 : -1,
|
||||
(v1.w > 0) ? 1 : -1,
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get signs of components.
|
||||
/// <param>
|
||||
/// + -> +1
|
||||
/// </param>
|
||||
/// x -> -1
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <returns></returns>
|
||||
template<IntType T>
|
||||
TIntVector4<T, false> SignVectorV(TIntVector4<T, false>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) ? 1 : -1;
|
||||
v1.y = (v1.y > 0) ? 1 : -1;
|
||||
v1.z = (v1.z > 0) ? 1 : -1;
|
||||
v1.w = (v1.w > 0) ? 1 : -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if two vectors are perpendicular.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <param name="v1"></param>
|
||||
/// <param name="v2"></param>
|
||||
/// <returns>True if perpendicular.</returns>
|
||||
template<IntType T>
|
||||
inline bool IsPerpendicular(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) = 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if two vectors are parallel.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of vector</typeparam>
|
||||
/// <param name="v1"></param>
|
||||
/// <param name="v2"></param>
|
||||
/// <returns>True if parralel.</returns>
|
||||
template<IntType T>
|
||||
inline bool IsParallel(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) = 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if two vectors are parallel.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="v1"></param>
|
||||
/// <param name="v2"></param>
|
||||
/// <returns></returns>
|
||||
template<IntType T>
|
||||
inline bool IsCoincident(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) = 1);
|
||||
}
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
|
||||
#endif // !INTVECTOR3_H
|
||||
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
#include "Core/public/Math/SIMD/PhanesSIMDTypes.h"
|
||||
|
||||
#include "IntVector4.hpp"
|
||||
|
||||
namespace Phanes::Core::Math
|
||||
{
|
||||
template<IntType T, bool A>
|
||||
|
@ -137,6 +137,7 @@ namespace Phanes::Core::Math::Detail
|
||||
v1.w = s[3];
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -524,6 +524,11 @@ namespace Phanes::Core::Math::Detail
|
||||
{
|
||||
v1.comp = _mm_loadu_epi32(comp);
|
||||
}
|
||||
|
||||
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector2<int, true>& v1, const Phanes::Core::Math::TIntVector2<int, true>& v2)
|
||||
{
|
||||
r.comp = _mm_setr_epi32(v1.x, v1.y, v2.x, v2.y);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
|
Loading…
x
Reference in New Issue
Block a user