From 19bc1e6313e889f89e44ee8d9429c84224f41e4f Mon Sep 17 00:00:00 2001 From: frohlich Date: Fri, 27 Feb 2009 18:52:53 +0000 Subject: [PATCH] Initialize random number for the tests. Define the triangles center by the weighted sum of the vertices. Modified Files: SGGeometryTest.cxx SGTriangle.hxx --- simgear/math/SGGeometryTest.cxx | 8 ++++++-- simgear/math/SGTriangle.hxx | 8 +------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/simgear/math/SGGeometryTest.cxx b/simgear/math/SGGeometryTest.cxx index cd2383ee..432e87b6 100644 --- a/simgear/math/SGGeometryTest.cxx +++ b/simgear/math/SGGeometryTest.cxx @@ -44,6 +44,8 @@ TriangleLineIntersectionTest(void) SGTriangle tri(v0, v1, v2); + T triangleEps = 100*SGLimits::epsilon(); + // 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 (!equivalent(isectres, isectpt)) { + if (!equivalent(isectres, isectpt, triangleEps)) { 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) { - if (!equivalent(isectres, isectpt)) { + if (!equivalent(isectres, isectpt, triangleEps)) { 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; + sg_srandom(17); + if (!TriangleLineIntersectionTest()) return EXIT_FAILURE; if (!TriangleLineIntersectionTest()) diff --git a/simgear/math/SGTriangle.hxx b/simgear/math/SGTriangle.hxx index 2cba610a..bc395ab9 100644 --- a/simgear/math/SGTriangle.hxx +++ b/simgear/math/SGTriangle.hxx @@ -42,13 +42,7 @@ public: } SGVec3 getCenter() const - { - SGBox 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 getVertex(unsigned i) const -- 2.39.5