From 84ebd6043c80f014f28e2d5942e020138d633193 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 31 Jul 2013 14:18:27 +0200 Subject: [PATCH] Sphere::Distance now returns distance between center and point No more negative distances Former-commit-id: 1688b82e88621e20312b6b28090ed63941b3e02a --- include/Nazara/Math/Sphere.inl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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