Initialize random number for the tests.

Define the triangles center by the weighted sum of the vertices.

Modified Files:
	SGGeometryTest.cxx SGTriangle.hxx
This commit is contained in:
frohlich
2009-02-27 23:34:15 +01:00
committed by Tim Moore
parent 4a4e8c87b8
commit 19bc1e6313
2 changed files with 7 additions and 9 deletions
+6 -2
View 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 // generate random coeficients
T u = 4*sg_random() - 2; T u = 4*sg_random() - 2;
T v = 4*sg_random() - 2; T v = 4*sg_random() - 2;
@@ -59,7 +61,7 @@ TriangleLineIntersectionTest(void)
if (intersects(isectres, tri, lineSegment)) { if (intersects(isectres, tri, lineSegment)) {
if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t && t <= 1) { 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 std::cout << "Failed line segment intersection test #" << i
<< ": not equivalent!\nu = " << ": not equivalent!\nu = "
<< u << ", v = " << v << ", t = " << t << u << ", v = " << v << ", t = " << t
@@ -87,7 +89,7 @@ TriangleLineIntersectionTest(void)
ray.set(isectpt - t*dir, dir); ray.set(isectpt - t*dir, dir);
if (intersects(isectres, tri, ray)) { if (intersects(isectres, tri, ray)) {
if (0 <= u && 0 <= v && u+v <= 1 && 0 <= t) { 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 std::cout << "Failed ray intersection test #" << i
<< ": not equivalent!\nu = " << ": not equivalent!\nu = "
<< u << ", v = " << v << ", t = " << t << u << ", v = " << v << ", t = " << t
@@ -422,6 +424,8 @@ main(void)
<< "Some of these tests can fail due to roundoff problems...\n" << "Some of these tests can fail due to roundoff problems...\n"
<< "Dont worry if only a few of them fail..." << std::endl; << "Dont worry if only a few of them fail..." << std::endl;
sg_srandom(17);
if (!TriangleLineIntersectionTest<float>()) if (!TriangleLineIntersectionTest<float>())
return EXIT_FAILURE; return EXIT_FAILURE;
if (!TriangleLineIntersectionTest<double>()) if (!TriangleLineIntersectionTest<double>())
+1 -7
View File
@@ -42,13 +42,7 @@ public:
} }
SGVec3<T> getCenter() const SGVec3<T> getCenter() const
{ { return _v0 + T(1)/T(3)*(_d[0] + _d[1]); }
SGBox<T> box;
box.expandBy(_v0);
box.expandBy(_v0 + _d[0]);
box.expandBy(_v0 + _d[1]);
return box.getCenter();
}
// note that the index is unchecked // note that the index is unchecked
SGVec3<T> getVertex(unsigned i) const SGVec3<T> getVertex(unsigned i) const