Math/Plane: Rename Distance method to SignedDistance
This commit is contained in:
@@ -151,7 +151,7 @@ namespace Nz
|
||||
Vector3<T> projectedExtents = extents * plane.normal.GetAbs();
|
||||
float radius = projectedExtents.x + projectedExtents.y + projectedExtents.z;
|
||||
|
||||
float distance = plane.Distance(center);
|
||||
float distance = plane.SignedDistance(center);
|
||||
if (distance < T(-radius))
|
||||
return false;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ namespace Nz
|
||||
{
|
||||
for (const auto& plane : m_planes)
|
||||
{
|
||||
if (plane.Distance(sphere.GetPosition()) < -sphere.radius)
|
||||
if (plane.SignedDistance(sphere.GetPosition()) < -sphere.radius)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace Nz
|
||||
{
|
||||
for (const auto& plane : m_planes)
|
||||
{
|
||||
if (plane.Distance(point) < T(0.0))
|
||||
if (plane.SignedDistance(point) < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace Nz
|
||||
std::size_t j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (plane.Distance(points[j]) > T(0.0))
|
||||
if (plane.SignedDistance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace Nz
|
||||
Vector3<T> projectedExtents = extents * plane.normal.GetAbs();
|
||||
float radius = projectedExtents.x + projectedExtents.y + projectedExtents.z;
|
||||
|
||||
float distance = plane.Distance(center);
|
||||
float distance = plane.SignedDistance(center);
|
||||
|
||||
if (distance < T(-radius))
|
||||
return IntersectionSide::Outside;
|
||||
@@ -358,7 +358,7 @@ namespace Nz
|
||||
|
||||
for (const auto& plane : m_planes)
|
||||
{
|
||||
T distance = plane.Distance(sphere.GetPosition());
|
||||
T distance = plane.SignedDistance(sphere.GetPosition());
|
||||
if (distance < -sphere.radius)
|
||||
return IntersectionSide::Outside;
|
||||
else if (distance < sphere.radius)
|
||||
@@ -385,7 +385,7 @@ namespace Nz
|
||||
std::size_t j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (plane.Distance(points[j]) > T(0.0))
|
||||
if (plane.SignedDistance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,10 @@ namespace Nz
|
||||
|
||||
constexpr bool ApproxEqual(const Plane& plane, T maxDifference = std::numeric_limits<T>::epsilon()) const;
|
||||
|
||||
constexpr T Distance(T x, T y, T z) const;
|
||||
constexpr T Distance(const Vector3<T>& point) const;
|
||||
|
||||
Plane& Normalize(T* length = nullptr);
|
||||
|
||||
constexpr T SignedDistance(const Vector3<T>& point) const;
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
constexpr Plane& operator=(const Plane& other) = default;
|
||||
|
||||
@@ -113,22 +113,17 @@ namespace Nz
|
||||
return NumberEquals(distance, plane.distance, maxDifference);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the distance from the plane to the point
|
||||
* \return Distance to the point
|
||||
*
|
||||
* \param x X position of the point
|
||||
* \param y Y position of the point
|
||||
* \param z Z position of the point
|
||||
*
|
||||
* \remark If T is negative, it means that the point is in the opposite direction of the normal
|
||||
*
|
||||
* \see Distance
|
||||
*/
|
||||
template<typename T>
|
||||
constexpr T Plane<T>::Distance(T x, T y, T z) const
|
||||
Plane<T>& Plane<T>::Normalize(T* length)
|
||||
{
|
||||
return Distance(Vector3<T>(x, y, z));
|
||||
T normalLength = normal.GetLength();
|
||||
normal /= normalLength;
|
||||
distance /= normalLength;
|
||||
|
||||
if (length)
|
||||
*length = normalLength;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -142,24 +137,11 @@ namespace Nz
|
||||
* \see Distance
|
||||
*/
|
||||
template<typename T>
|
||||
constexpr T Plane<T>::Distance(const Vector3<T>& point) const
|
||||
constexpr T Plane<T>::SignedDistance(const Vector3<T>& point) const
|
||||
{
|
||||
return normal.DotProduct(point) + distance; // ax + by + cz + d = 0.
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Plane<T>& Plane<T>::Normalize(T* length)
|
||||
{
|
||||
T normalLength = normal.GetLength();
|
||||
normal /= normalLength;
|
||||
distance /= normalLength;
|
||||
|
||||
if (length)
|
||||
*length = normalLength;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gives a string representation
|
||||
* \return A string representation of the object: "Plane(Normal: Vector3(x, y, z); Distance: w)"
|
||||
|
||||
Reference in New Issue
Block a user