]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGIntersect.hxx
Lots of (mostly) doxygen fixes/cleanup.
[simgear.git] / simgear / math / SGIntersect.hxx
index aea3bb3ea9dab89d54be518787baae5253267437..46bdb427d0e027c388be42a3997858eeed1ec4ac 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef SGIntersect_HXX
 #define SGIntersect_HXX
 
+#include <algorithm>
+
 template<typename T>
 inline bool
 intersects(const SGSphere<T>& s1, const SGSphere<T>& s2)
@@ -38,25 +40,11 @@ intersects(const SGBox<T1>& box, const SGSphere<T2>& sphere)
 {
   if (sphere.empty())
     return false;
-  // Is more or less trivially included in the next tests
-  // if (box.empty())
-  //   return false;
-
-  if (sphere.getCenter().x() < box.getMin().x() - sphere.getRadius())
-    return false;
-  if (sphere.getCenter().y() < box.getMin().y() - sphere.getRadius())
-    return false;
-  if (sphere.getCenter().z() < box.getMin().z() - sphere.getRadius())
+  if (box.empty())
     return false;
 
-  if (box.getMax().x() + sphere.getRadius() < sphere.getCenter().x())
-    return false;
-  if (box.getMax().y() + sphere.getRadius() < sphere.getCenter().y())
-    return false;
-  if (box.getMax().z() + sphere.getRadius() < sphere.getCenter().z())
-    return false;
-
-  return true;
+  SGVec3<T1> closest = box.getClosestPoint(sphere.getCenter());
+  return distSqr(closest, SGVec3<T1>(sphere.getCenter())) <= sphere.getRadius2();
 }
 // make it symmetric
 template<typename T1, typename T2>
@@ -265,11 +253,11 @@ intersects(SGVec3<T>& dst, const SGLineSegment<T>& lineSegment, const SGPlane<T>
 
   // The negative numerator for the \alpha expression
   T num = plane.getPositiveDist();
-  num -= dot(plane.getNormal(), lineSegment.getOrigin());
+  num -= dot(plane.getNormal(), lineSegment.getStart());
   
   // If the numerator is zero, we have the lines origin included in the plane
   if (fabs(num) <= SGLimits<T>::min()) {
-    dst = lineSegment.getOrigin();
+    dst = lineSegment.getStart();
     return true;
   }
 
@@ -291,7 +279,7 @@ intersects(SGVec3<T>& dst, const SGLineSegment<T>& lineSegment, const SGPlane<T>
   if (1 < alpha)
     return false;
 
-  dst = lineSegment.getOrigin() + alpha*lineSegment.getDirection();
+  dst = lineSegment.getStart() + alpha*lineSegment.getDirection();
   return true;
 }
 // make it symmetric
@@ -572,6 +560,7 @@ closestPoint(const SGTriangle<T>& tri, const SGVec3<T>& p)
   T u = b*e - c*d;
   T v = b*d - a*e;
 
+/*
   // Regions
   // \2|
   //  \|
@@ -579,6 +568,7 @@ closestPoint(const SGTriangle<T>& tri, const SGVec3<T>& p)
   // 3 |0\ 1
   //----------
   // 4 | 5 \ 6
+*/
 
   if (u + v <= det) {
     if (u < 0) {
@@ -766,6 +756,7 @@ intersects(const SGTriangle<T>& tri, const SGSphere<T2>& sphere)
   T u = b*e - c*d;
   T v = b*d - a*e;
 
+/*
   // Regions
   // \2|
   //  \|
@@ -773,6 +764,7 @@ intersects(const SGTriangle<T>& tri, const SGSphere<T2>& sphere)
   // 3 |0\ 1
   //----------
   // 4 | 5 \ 6
+*/
 
   if (u + v <= det) {
     if (u < 0) {