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;
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
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
<< "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>())
}
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