]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGSphere.hxx
math: Add integer valued vector types.
[simgear.git] / simgear / math / SGSphere.hxx
index 7d8b3ab1b0d50dfbb2c7d1eb365fde3b0f8be046..e4fcb096a7e576a53ca1cfe69d867cf6b695a542 100644 (file)
 #ifndef SGSphere_H
 #define SGSphere_H
 
+
 template<typename T>
 class SGSphere {
 public:
+
+#ifdef __GNUC__
+// Avoid "_center not initialized" warnings.
+#   pragma GCC diagnostic ignored "-Wuninitialized"
+#endif
+
   SGSphere() :
+     /*
+      * 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<T>& center, const T& radius) :
@@ -34,6 +46,11 @@ public:
     _radius(sphere.getRadius())
   { }
 
+#ifdef __GNUC__
+  // Restore warning settings.
+#   pragma GCC diagnostic warning "-Wuninitialized"
+#endif
+
   const SGVec3<T>& getCenter() const
   { return _center; }
   void setCenter(const SGVec3<T>& center)
@@ -55,6 +72,18 @@ public:
   void clear()
   { _radius = -1; }
 
+  /// Return true if this is inside sphere
+  bool inside(const SGSphere<T>& 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<T>& v)
   {
     if (empty()) {