X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGSphere.hxx;h=e4fcb096a7e576a53ca1cfe69d867cf6b695a542;hb=914d3e6a2b323cf9f186cbef2aef7865ea07b309;hp=7d6a8d3c8be5387c456b5951def92784aeb1aae7;hpb=052ce499c9a55db695e727e2ba31e1cb63b120d0;p=simgear.git diff --git a/simgear/math/SGSphere.hxx b/simgear/math/SGSphere.hxx index 7d6a8d3c..e4fcb096 100644 --- a/simgear/math/SGSphere.hxx +++ b/simgear/math/SGSphere.hxx @@ -18,11 +18,22 @@ #ifndef SGSphere_H #define SGSphere_H + template class SGSphere { public: + +#ifdef __GNUC__ +// Avoid "_center not initialized" warnings. +# pragma GCC diagnostic ignored "-Wuninitialized" +#endif + SGSphere() : - _center(0.0, 0.0, 0.0), + /* + * Do not initialize _center to save unneeded initialization time. + * Fix 'may be used uninitialized' warnings locally instead + */ +// _center(0.0, 0.0, 0.0), _radius(-1) { } SGSphere(const SGVec3& center, const T& radius) : @@ -35,6 +46,11 @@ public: _radius(sphere.getRadius()) { } +#ifdef __GNUC__ + // Restore warning settings. +# pragma GCC diagnostic warning "-Wuninitialized" +#endif + const SGVec3& getCenter() const { return _center; } void setCenter(const SGVec3& center) @@ -56,6 +72,18 @@ public: void clear() { _radius = -1; } + /// Return true if this is inside sphere + bool inside(const SGSphere& sphere) const + { + if (empty()) + return false; + if (sphere.empty()) + return false; + + T dist = sphere.getRadius() - getRadius(); + return distSqr(getCenter(), sphere.getCenter()) <= dist*dist; + } + void expandBy(const SGVec3& v) { if (empty()) {