Math/Vector[2|3]: Removed Distancef and made Distance templated
This commit is contained in:
@@ -33,8 +33,8 @@ namespace Nz
|
||||
T AbsDotProduct(const Vector2& vec) const;
|
||||
T AngleBetween(const Vector2& vec) const;
|
||||
|
||||
T Distance(const Vector2& vec) const;
|
||||
float Distancef(const Vector2& vec) const;
|
||||
template<typename U = T>
|
||||
U Distance(const Vector2& vec) const;
|
||||
T DotProduct(const Vector2& vec) const;
|
||||
|
||||
T GetLength() const;
|
||||
@@ -92,6 +92,7 @@ namespace Nz
|
||||
bool operator>(const Vector2& vec) const;
|
||||
bool operator>=(const Vector2& vec) const;
|
||||
|
||||
template<typename U = T> static U Distance(const Vector2& vec1, const Vector2& vec2);
|
||||
static T DotProduct(const Vector2& vec1, const Vector2& vec2);
|
||||
static Vector2 Lerp(const Vector2& from, const Vector2& to, T interpolation);
|
||||
static Vector2 Normalize(const Vector2& vec);
|
||||
|
||||
@@ -124,22 +124,10 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T Vector2<T>::Distance(const Vector2& vec) const
|
||||
template<typename U>
|
||||
U Vector2<T>::Distance(const Vector2& vec) const
|
||||
{
|
||||
return std::sqrt(SquaredDistance(vec));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the distance between two vectors
|
||||
* \return The metric distance in float between two vectors with euclidean norm
|
||||
*
|
||||
* \param vec The other vector to measure the distance with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
float Vector2<T>::Distancef(const Vector2& vec) const
|
||||
{
|
||||
return std::sqrt(static_cast<float>(SquaredDistance(vec)));
|
||||
return static_cast<U>(std::sqrt(SquaredDistance(vec)));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -835,6 +823,24 @@ namespace Nz
|
||||
return !operator<(vec);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Measure the distance between two points
|
||||
* Shorthand for vec1.Distance(vec2)
|
||||
*
|
||||
* param vec1 the first point
|
||||
* param vec2 the second point
|
||||
*
|
||||
* \return The distance between the two vectors
|
||||
*
|
||||
* \see SquaredDistance
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
U Vector2<T>::Distance(const Vector2& vec1, const Vector2& vec2)
|
||||
{
|
||||
return vec1.Distance<U>(vec2);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the dot (scalar) product with two vectors
|
||||
* \return The value of the dot product
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace Nz
|
||||
|
||||
Vector3 CrossProduct(const Vector3& vec) const;
|
||||
|
||||
T Distance(const Vector3& vec) const;
|
||||
float Distancef(const Vector3& vec) const;
|
||||
template<typename U = T>
|
||||
U Distance(const Vector3& vec) const;
|
||||
T DotProduct(const Vector3& vec) const;
|
||||
|
||||
T GetLength() const;
|
||||
@@ -106,8 +106,7 @@ namespace Nz
|
||||
static Vector3 Backward();
|
||||
static Vector3 CrossProduct(const Vector3& vec1, const Vector3& vec2);
|
||||
static T DotProduct(const Vector3& vec1, const Vector3& vec2);
|
||||
static T Distance(const Vector3& vec1, const Vector3& vec2);
|
||||
static float Distancef(const Vector3& vec1, const Vector3& vec2);
|
||||
template<typename U = T> static U Distance(const Vector3& vec1, const Vector3& vec2);
|
||||
static Vector3 Down();
|
||||
static Vector3 Forward();
|
||||
static Vector3 Left();
|
||||
|
||||
@@ -162,21 +162,10 @@ namespace Nz
|
||||
* \see SquaredDistance
|
||||
*/
|
||||
template<typename T>
|
||||
T Vector3<T>::Distance(const Vector3& vec) const
|
||||
template<typename U>
|
||||
U Vector3<T>::Distance(const Vector3& vec) const
|
||||
{
|
||||
return std::sqrt(SquaredDistance(vec));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates the distance between two vectors
|
||||
* \return The metric distance in float between two vectors with euclidean norm
|
||||
*
|
||||
* \param vec The other vector to measure the distance with
|
||||
*/
|
||||
template<typename T>
|
||||
float Vector3<T>::Distancef(const Vector3& vec) const
|
||||
{
|
||||
return std::sqrt(static_cast<float>(SquaredDistance(vec)));
|
||||
return static_cast<U>(std::sqrt(SquaredDistance(vec)));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1014,26 +1003,10 @@ namespace Nz
|
||||
* \see SquaredDistance
|
||||
*/
|
||||
template<typename T>
|
||||
T Vector3<T>::Distance(const Vector3& vec1, const Vector3& vec2)
|
||||
template<typename U>
|
||||
U Vector3<T>::Distance(const Vector3& vec1, const Vector3& vec2)
|
||||
{
|
||||
return vec1.Distance(vec2);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Measure the distance between two points as a float
|
||||
* Shorthand for vec1.Distancef(vec2)
|
||||
*
|
||||
* param vec1 the first point
|
||||
* param vec2 the second point
|
||||
*
|
||||
* \return The distance between the two vectors as a float
|
||||
*
|
||||
* \see SquaredDistancef
|
||||
*/
|
||||
template<typename T>
|
||||
float Vector3<T>::Distancef(const Vector3& vec1, const Vector3& vec2)
|
||||
{
|
||||
return vec1.Distancef(vec2);
|
||||
return vec1.Distance<U>(vec2);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user