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 18:52:53 +00:00
committed by Tim Moore
parent 4a4e8c87b8
commit 19bc1e6313
2 changed files with 7 additions and 9 deletions

View File

@@ -44,6 +44,8 @@ TriangleLineIntersectionTest(void)
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;
@@ -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<float>())
return EXIT_FAILURE;
if (!TriangleLineIntersectionTest<double>())

View File

@@ -42,13 +42,7 @@ public:
}
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