]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/bvh/bvhtest.cxx
hla: Provide a directly property based api for property data element.
[simgear.git] / simgear / scene / bvh / bvhtest.cxx
index 797299cb7f05a1ca2b3f47f32045c7bf38d847f6..0f01e7f002888eb274a477bf5afec73ee3966203 100644 (file)
@@ -33,6 +33,7 @@
 #include "BVHBoundingBoxVisitor.hxx"
 #include "BVHSubTreeCollector.hxx"
 #include "BVHLineSegmentVisitor.hxx"
+#include "BVHNearestPointVisitor.hxx"
 
 using namespace simgear;
 
@@ -109,10 +110,33 @@ testLineIntersections()
     return true;
 }
 
+bool
+testNearestPoint()
+{
+    SGVec3f v1(-1, -1, 0);
+    SGVec3f v2(1, -1, 0);
+    SGVec3f v3(-1, 1, 0);
+    SGSharedPtr<BVHNode> node = buildSingleTriangle(v1, v2, v3);
+
+    SGSphered sphere(SGVec3d(0, 0, -1), 2);
+    {
+      BVHNearestPointVisitor nearestPointVisitor(sphere, 0);
+        node->accept(nearestPointVisitor);
+        if (nearestPointVisitor.empty())
+            return false;
+        if (!equivalent(nearestPointVisitor.getPoint(), SGVec3d(0, 0, 0)))
+            return false;
+    }
+
+    return true;
+}
+
 int
 main(int argc, char** argv)
 {
     if (!testLineIntersections())
         return EXIT_FAILURE;
+    if (!testNearestPoint())
+        return EXIT_FAILURE;
     return EXIT_SUCCESS;
 }