From 8a0a451a589e9895c107883df6a9b5a7acc322e5 Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Tue, 2 Sep 2014 10:44:19 +0200
Subject: [PATCH] renamed distance method, changed initialisation list, fixed
 issue with volume calculation

---
 GeoLib/AnalyticalGeometry.cpp |  2 +-
 GeoLib/BoundingSphere.cpp     | 20 +++++++++++++-------
 GeoLib/BoundingSphere.h       |  8 +++++---
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp
index 3b9bccae479..c38b98e3fa2 100644
--- a/GeoLib/AnalyticalGeometry.cpp
+++ b/GeoLib/AnalyticalGeometry.cpp
@@ -255,7 +255,7 @@ double calcTetrahedronVolume(const double* x1, const double* x2, const double* x
 	const MathLib::Vector3 ab(x1, x2);
 	const MathLib::Vector3 ac(x1, x3);
 	const MathLib::Vector3 ad(x1, x4);
-	return GeoLib::scalarTriple(ab, ac, ad) / 6.0;
+	return std::abs(GeoLib::scalarTriple(ac, ad, ab)) / 6.0;
 }
 
 // NewellPlane from book Real-Time Collision detection p. 494
diff --git a/GeoLib/BoundingSphere.cpp b/GeoLib/BoundingSphere.cpp
index 3ee19d7ef28..57f92a70408 100644
--- a/GeoLib/BoundingSphere.cpp
+++ b/GeoLib/BoundingSphere.cpp
@@ -22,27 +22,33 @@
 namespace GeoLib {
 
 BoundingSphere::BoundingSphere()
-: _center(std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()), _radius(-1)
+: _radius(-1), _center(std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max())
 {	
 }
 
 BoundingSphere::BoundingSphere(BoundingSphere const& sphere)
-: _center(sphere.getCenter()), _radius(sphere.getRadius())
+: _radius(sphere.getRadius()), _center(sphere.getCenter())
 {
 }
 
+BoundingSphere::BoundingSphere(BoundingSphere const&& sphere)
+: _radius(sphere.getRadius()), _center(sphere.getCenter())
+{
+}
+
+
 BoundingSphere::BoundingSphere(GeoLib::Point const& p)
-: _center(p), _radius(std::numeric_limits<double>::epsilon())
+: _radius(std::numeric_limits<double>::epsilon()), _center(p)
 {
 }
 
 BoundingSphere::BoundingSphere(GeoLib::Point const& p, double radius)
-: _center(p), _radius(radius)
+: _radius(radius), _center(p)
 {
 }
 
 BoundingSphere::BoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q)
-: _center(p), _radius(std::numeric_limits<double>::epsilon())
+: _radius(std::numeric_limits<double>::epsilon()), _center(p)
 {
     MathLib::Vector3 const a(p, q);
 
@@ -164,7 +170,7 @@ BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sp
     for(std::size_t i=0; i<length; ++i)
     {
         // current point is located outside of sphere
-        if (sphere.sqrPointDist(*sphere_points[start_idx+i]) > 0)
+        if (sphere.pointDistanceSquared(*sphere_points[start_idx+i]) > 0)
         {
             if (i>start_idx)
             {
@@ -178,7 +184,7 @@ BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sp
     return sphere;
 }
 
-double BoundingSphere::sqrPointDist(GeoLib::Point const& pnt) const
+double BoundingSphere::pointDistanceSquared(GeoLib::Point const& pnt) const
 {
     return MathLib::sqrDist(_center.getCoords(), pnt.getCoords())-(_radius*_radius);
 }
diff --git a/GeoLib/BoundingSphere.h b/GeoLib/BoundingSphere.h
index 4ab3b4b22c6..1ec2d467d30 100644
--- a/GeoLib/BoundingSphere.h
+++ b/GeoLib/BoundingSphere.h
@@ -31,6 +31,8 @@ public:
     BoundingSphere();
     /// Copy constructor
     BoundingSphere(BoundingSphere const& sphere);
+    /// Move constructor
+    BoundingSphere(BoundingSphere const&& sphere);
     /// Point-Sphere
     BoundingSphere(GeoLib::Point const& p);
     /// Constructor using center and radius
@@ -51,10 +53,10 @@ public:
     /// Returns the radius of the sphere
     double getRadius() const {return _radius; }
 
-    /// Returns the squared distance of a point from the sphere (for points within the sphere distance is negative)
-    double sqrPointDist(GeoLib::Point const& pnt) const;
+    /// Returns the squared euclidean distance of a point from the sphere (for points within the sphere distance is negative)
+    double pointDistanceSquared(GeoLib::Point const& pnt) const;
 
-    /// Creates n_points random points located on the surface of the sphere (useful for visualisation)
+    /// Creates n_points random points located on the surface of the bounding sphere (useful for visualisation)
     std::vector<GeoLib::Point*>* getRandomSpherePoints(std::size_t n_points) const;
 
 private:
-- 
GitLab