From 89861582677a1808f92fe87e66bbb9fd100ce4e9 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/BoundingSphere.cpp | 20 +++++++++++++------- GeoLib/BoundingSphere.h | 8 +++++--- 2 files changed, 18 insertions(+), 10 deletions(-) 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