Bug fixes.

This commit is contained in:
THoehne 2024-08-26 13:08:12 +02:00
parent b1af82b806
commit 84c6b0b753
6 changed files with 41 additions and 113 deletions

View File

@ -77,8 +77,8 @@ namespace Phanes::Core::Math::Detail
{ {
v1.x = x; v1.x = x;
v1.y = y; v1.y = y;
v1.y = z; v1.z = z;
v1.y = w; v1.w = w;
} }
@ -176,12 +176,10 @@ namespace Phanes::Core::Math::Detail
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s) static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{ {
s = (T)1.0 / s; r.x = v1.x / s;
r.y = v1.y / s;
r.x = v1.x * s; r.z = v1.z / s;
r.y = v1.y * s; r.w = v1.w / s;
r.z = v1.z * s;
r.w = v1.w * s;
} }
}; };

View File

@ -553,41 +553,6 @@ namespace Phanes::Core::Math {
return (Abs(DotP(v1, v2)) == 0); return (Abs(DotP(v1, v2)) == 0);
} }
/**
* Tests if 2 vectors are parallel to each other. (Angle is close to zero.)
*
* @param(v1) Vector one
* @param(v2) Vector two
*
* @return true if parallel, false if not
*
* @note Requires v1 and v2 to be normal vectors.
*/
template<IntType T>
inline bool IsParallel(const TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
{
return ((v1.x / v2.x) == (v1.y / v2.y));
}
/**
* Tests if 2 vectors are coincident. (Are parallel and point in the same direction.)
*
* @param(v1) Vector one
* @param(v2) Vector two
*
* @return true if coincident, false if not
*
* @note Requires v1 and v2 to be normal vectors.
*/
template<IntType T>
inline bool IsCoincident(const TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
{
T tmp = v1.x / v2.x;
return (tmp == (v1.y / v2.y) && tmp > -1);
}
/** /**
* Gets outer product of to vectors. * Gets outer product of to vectors.
* *

View File

@ -547,6 +547,17 @@ namespace Phanes::Core::Math {
return v1; return v1;
} }
template<IntType T>
TIntVector3<T, false>& GetPerpendicular(TIntVector3<T, false>& v1)
{
T y = v1.y;
v1.x = 0;
v1.y = v1.z;
v1.z = -y;
return v1;
}
/** /**
* Tests whether two vectors are perpendicular. * Tests whether two vectors are perpendicular.
* *
@ -562,38 +573,6 @@ namespace Phanes::Core::Math {
return (DotP(v1, v2) == 0); return (DotP(v1, v2) == 0);
} }
/**
* Tests whether two vectors are parallel.
*
* @param(v1) Vector one
* @param(v2) Vector two
*
* @return True if parallel, false if not.
*/
template<IntType T>
inline bool IsParallel(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
{
T tmp = v1.x / v2.x;
return (tmp == (v1.y / v2.y) && tmp == (v1.z / v2.z));
}
/**
* Tests whether two vectors are coincident (Parallel and point in same direction).
*
* @param(v1) Vector one
* @param(v2) Vector two
*
* @return True if coincident, false if not.
*/
template<IntType T>
inline bool IsCoincident(const TIntVector3<T, false>& v1, const TIntVector3<T, false>& v2)
{
T tmp = v1.x / v2.x;
return (tmp == (v1.y / v2.y) && tmp == (v1.z / v2.z) && tmp > -1);
}
/** /**
* Tests if three vectors are coplanar * Tests if three vectors are coplanar
* *

View File

@ -573,6 +573,8 @@ namespace Phanes::Core::Math {
v1.y = -v1.y; v1.y = -v1.y;
v1.z = -v1.z; v1.z = -v1.z;
v1.w = -v1.w; v1.w = -v1.w;
return v1;
} }
/// <summary> /// <summary>
@ -612,6 +614,8 @@ namespace Phanes::Core::Math {
v1.y = (v1.y > 0) ? 1 : -1; v1.y = (v1.y > 0) ? 1 : -1;
v1.z = (v1.z > 0) ? 1 : -1; v1.z = (v1.z > 0) ? 1 : -1;
v1.w = (v1.w > 0) ? 1 : -1; v1.w = (v1.w > 0) ? 1 : -1;
return v1;
} }
/// <summary> /// <summary>
@ -624,33 +628,7 @@ namespace Phanes::Core::Math {
template<IntType T> template<IntType T>
inline bool IsPerpendicular(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2) inline bool IsPerpendicular(const TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
{ {
return (abs(DotP(v1, v2)) = 0); 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 } // phanes::core::math::coretypes

View File

@ -273,7 +273,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator&(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2) TIntVector4<T, S> operator&(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_and<T, S>::map(r, v1, v2); Detail::compute_ivec4_and<T, S>::map(r, v1, v2);
return r; return r;
} }
@ -281,7 +281,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator&(TIntVector4<T, S>& v1, T s) TIntVector4<T, S> operator&(TIntVector4<T, S>& v1, T s)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_and<T, S>::map(r, v1, s); Detail::compute_ivec4_and<T, S>::map(r, v1, s);
return r; return r;
} }
@ -289,7 +289,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator|(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2) TIntVector4<T, S> operator|(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_or<T, S>::map(r, v1, v2); Detail::compute_ivec4_or<T, S>::map(r, v1, v2);
return r; return r;
} }
@ -297,7 +297,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator|(TIntVector4<T, S>& v1, T s) TIntVector4<T, S> operator|(TIntVector4<T, S>& v1, T s)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_or<T, S>::map(r, v1, s); Detail::compute_ivec4_or<T, S>::map(r, v1, s);
return r; return r;
} }
@ -305,7 +305,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator^(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2) TIntVector4<T, S> operator^(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_xor<T, S>::map(r, v1, v2); Detail::compute_ivec4_xor<T, S>::map(r, v1, v2);
return r; return r;
} }
@ -313,7 +313,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator^(TIntVector4<T, S>& v1, T s) TIntVector4<T, S> operator^(TIntVector4<T, S>& v1, T s)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_xor<T, S>::map(r, v1, s); Detail::compute_ivec4_xor<T, S>::map(r, v1, s);
return r; return r;
} }
@ -321,7 +321,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator<<(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2) TIntVector4<T, S> operator<<(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_left_shift<T, S>::map(r, v1, v2); Detail::compute_ivec4_left_shift<T, S>::map(r, v1, v2);
return r; return r;
} }
@ -329,7 +329,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator<<(TIntVector4<T, S>& v1, T s) TIntVector4<T, S> operator<<(TIntVector4<T, S>& v1, T s)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_left_shift<T, S>::map(r, v1, s); Detail::compute_ivec4_left_shift<T, S>::map(r, v1, s);
return r; return r;
} }
@ -337,7 +337,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator>>(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2) TIntVector4<T, S> operator>>(TIntVector4<T, S>& v1, const TIntVector4<T, S>& v2)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_right_shift<T, S>::map(r, v1, v2); Detail::compute_ivec4_right_shift<T, S>::map(r, v1, v2);
return r; return r;
} }
@ -345,7 +345,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator>>(TIntVector4<T, S>& v1, T s) TIntVector4<T, S> operator>>(TIntVector4<T, S>& v1, T s)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_right_shift<T, S>::map(r, v1, s); Detail::compute_ivec4_right_shift<T, S>::map(r, v1, s);
return r; return r;
} }
@ -353,7 +353,7 @@ namespace Phanes::Core::Math
template<IntType T, bool S> template<IntType T, bool S>
TIntVector4<T, S> operator~(TIntVector4<T, S>& v1) TIntVector4<T, S> operator~(TIntVector4<T, S>& v1)
{ {
TVector2<T, S> r; TIntVector4<T, S> r;
Detail::compute_ivec4_bnot<T, S>::map(r, v1); Detail::compute_ivec4_bnot<T, S>::map(r, v1);
return r; return r;
} }

View File

@ -66,6 +66,14 @@ namespace Phanes::Core::Math {
typedef TIntVector3<long, false> LongVector3; typedef TIntVector3<long, false> LongVector3;
typedef TIntVector3<long, false> Vector3l; typedef TIntVector3<long, false> Vector3l;
// IntVetor4
typedef TIntVector4<int, false> IntVector4;
typedef TIntVector4<int, false> Vector4i;
typedef TIntVector4<long, false> LongVector4;
typedef TIntVector4<long, false> Vector4l;
// Vector2 // Vector2
typedef TVector2<float, false> Vector2; typedef TVector2<float, false> Vector2;