diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index a769ec0a8..37e543e63 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -44,7 +44,7 @@ NzSphere::NzSphere(const NzSphere& sphere) template bool NzSphere::Contains(T X, T Y, T Z) const { - return Distance(X, Y, Z) < F(0.0); + return SquaredDistance(X, Y, Z) <= radius*radius; } /* template @@ -62,7 +62,7 @@ template T NzSphere::Distance(T X, T Y, T Z) const { NzVector3 distance(X-x, Y-y, Z-z); - return distance.GetLength() - radius; + return distance.GetLength(); } template @@ -74,10 +74,10 @@ T NzSphere::Distance(const NzVector3& point) const template NzSphere& NzSphere::ExtendTo(T X, T Y, T Z) { - T distance = Distance(X, Y, Z); + T distance = SquaredDistance(X, Y, Z); - if (distance > F(0.0)) - radius += distance; + if (distance > radius*radius) + radius = std::sqrt(distance); return *this; } @@ -122,7 +122,7 @@ bool NzSphere::Intersect(const NzBox& box) const template bool NzSphere::Intersect(const NzSphere& sphere) const { - return Distance(sphere.x, sphere.y, sphere.z) <= sphere.radius; + return SquaredDistance(sphere.x, sphere.y, sphere.z) - radius*radius <= sphere.radius*sphere.radius; } template @@ -210,7 +210,7 @@ template T NzSphere::SquaredDistance(T X, T Y, T Z) const { NzVector3 distance(X-x, Y-y, Z-z); - return distance.SquaredLength() - radius*radius; + return distance.SquaredLength(); } template