]> git.mxchange.org Git - simgear.git/commitdiff
Initialize random number for the tests.
authorfrohlich <frohlich>
Fri, 27 Feb 2009 18:52:53 +0000 (18:52 +0000)
committerTim Moore <timoore@redhat.com>
Fri, 27 Feb 2009 22:34:15 +0000 (23:34 +0100)
Define the triangles center by the weighted sum of the vertices.

Modified Files:
SGGeometryTest.cxx SGTriangle.hxx

simgear/math/SGGeometryTest.cxx
simgear/math/SGTriangle.hxx

index cd2383ee954f5bfd771a64f9168c18694cc0aff6..432e87b67b6e7d48e897eddef4c0819eaf004efe 100644 (file)
@@ -44,6 +44,8 @@ TriangleLineIntersectionTest(void)
     
     SGTriangle<T> tri(v0, v1, v2);
 
     
     SGTriangle<T> tri(v0, v1, v2);
 
+    T triangleEps = 100*SGLimits<T>::epsilon();
+
     // generate random coeficients
     T u = 4*sg_random() - 2;
     T v = 4*sg_random() - 2;
     // generate random coeficients
     T u = 4*sg_random() - 2;
     T v = 4*sg_random() - 2;
@@ -59,7 +61,7 @@ TriangleLineIntersectionTest(void)
     
     if (intersects(isectres, tri, lineSegment)) {
       if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t && t <= 1) {
     
     if (intersects(isectres, tri, lineSegment)) {
       if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t && t <= 1) {
-        if (!equivalent(isectres, isectpt)) {
+        if (!equivalent(isectres, isectpt, triangleEps)) {
           std::cout << "Failed line segment intersection test #" << i
                     << ": not equivalent!\nu = "
                     << u << ", v = " << v << ", t = " << t
           std::cout << "Failed line segment intersection test #" << i
                     << ": not equivalent!\nu = "
                     << u << ", v = " << v << ", t = " << t
@@ -87,7 +89,7 @@ TriangleLineIntersectionTest(void)
     ray.set(isectpt - t*dir, dir);
     if (intersects(isectres, tri, ray)) {
       if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t) {
     ray.set(isectpt - t*dir, dir);
     if (intersects(isectres, tri, ray)) {
       if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t) {
-        if (!equivalent(isectres, isectpt)) {
+        if (!equivalent(isectres, isectpt, triangleEps)) {
           std::cout << "Failed ray intersection test #" << i
                     << ": not equivalent!\nu = "
                     << u << ", v = " << v << ", t = " << t
           std::cout << "Failed ray intersection test #" << i
                     << ": not equivalent!\nu = "
                     << u << ", v = " << v << ", t = " << t
@@ -422,6 +424,8 @@ main(void)
             << "Some of these tests can fail due to roundoff problems...\n"
             << "Dont worry if only a few of them fail..." << std::endl;
 
             << "Some of these tests can fail due to roundoff problems...\n"
             << "Dont worry if only a few of them fail..." << std::endl;
 
+  sg_srandom(17);
+
   if (!TriangleLineIntersectionTest<float>())
     return EXIT_FAILURE;
   if (!TriangleLineIntersectionTest<double>())
   if (!TriangleLineIntersectionTest<float>())
     return EXIT_FAILURE;
   if (!TriangleLineIntersectionTest<double>())
index 2cba610a582648903fbd0142892af02df85c5f78..bc395ab9cfdce4b41b0e6d4134ecf5789f505d70 100644 (file)
@@ -42,13 +42,7 @@ public:
   }
 
   SGVec3<T> getCenter() const
   }
 
   SGVec3<T> getCenter() const
-  {
-    SGBox<T> box;
-    box.expandBy(_v0);
-    box.expandBy(_v0 + _d[0]);
-    box.expandBy(_v0 + _d[1]);
-    return box.getCenter();
-  }
+  { return _v0 + T(1)/T(3)*(_d[0] + _d[1]); }
 
   // note that the index is unchecked
   SGVec3<T> getVertex(unsigned i) const
 
   // note that the index is unchecked
   SGVec3<T> getVertex(unsigned i) const