aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/geo_hyperplane.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2014-01-11 20:04:36 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2014-01-11 20:04:36 +0100
commite15cb9f4f83e67096f8f2443afadebba9efab0b4 (patch)
tree48a6fb71e0e0dbe953db16e51825ae7d8f0d867a /test/geo_hyperplane.cpp
parent92190a1cafc3a8613e1200cd4ed81dbc509a93bd (diff)
Make geo_hyperplane unit test more stable (bug #539)
Diffstat (limited to 'test/geo_hyperplane.cpp')
-rw-r--r--test/geo_hyperplane.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/test/geo_hyperplane.cpp b/test/geo_hyperplane.cpp
index f26fc1329..befd7d483 100644
--- a/test/geo_hyperplane.cpp
+++ b/test/geo_hyperplane.cpp
@@ -18,10 +18,12 @@ template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
/* this test covers the following files:
Hyperplane.h
*/
+ using std::abs;
typedef typename HyperplaneType::Index Index;
const Index dim = _plane.dim();
enum { Options = HyperplaneType::Options };
typedef typename HyperplaneType::Scalar Scalar;
+ typedef typename HyperplaneType::RealScalar RealScalar;
typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime, 1> VectorType;
typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime,
HyperplaneType::AmbientDimAtCompileTime> MatrixType;
@@ -42,7 +44,10 @@ template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
VERIFY_IS_APPROX( n1.dot(n1), Scalar(1) );
VERIFY_IS_MUCH_SMALLER_THAN( pl0.absDistance(p0), Scalar(1) );
- VERIFY_IS_APPROX( pl1.signedDistance(p1 + n1 * s0), s0 );
+ if(numext::abs2(s0)>RealScalar(1e-6))
+ VERIFY_IS_APPROX( pl1.signedDistance(p1 + n1 * s0), s0);
+ else
+ VERIFY_IS_MUCH_SMALLER_THAN( abs(pl1.signedDistance(p1 + n1 * s0) - s0), Scalar(1) );
VERIFY_IS_MUCH_SMALLER_THAN( pl1.signedDistance(pl1.projection(p0)), Scalar(1) );
VERIFY_IS_MUCH_SMALLER_THAN( pl1.absDistance(p1 + pl1.normal().unitOrthogonal() * s1), Scalar(1) );
@@ -52,6 +57,8 @@ template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
MatrixType rot = MatrixType::Random(dim,dim).householderQr().householderQ();
DiagonalMatrix<Scalar,HyperplaneType::AmbientDimAtCompileTime> scaling(VectorType::Random());
Translation<Scalar,HyperplaneType::AmbientDimAtCompileTime> translation(VectorType::Random());
+
+ while(scaling.diagonal().cwiseAbs().minCoeff()<RealScalar(1e-4)) scaling.diagonal() = VectorType::Random();
pl2 = pl1;
VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot).absDistance(rot * p1), Scalar(1) );
@@ -61,7 +68,7 @@ template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*scaling).absDistance((rot*scaling) * p1), Scalar(1) );
pl2 = pl1;
VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*scaling*translation)
- .absDistance((rot*scaling*translation) * p1), Scalar(1) );
+ .absDistance((rot*scaling*translation) * p1), Scalar(1) );
pl2 = pl1;
VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*translation,Isometry)
.absDistance((rot*translation) * p1), Scalar(1) );
@@ -104,12 +111,15 @@ template<typename Scalar> void lines()
Vector result = line_u.intersection(line_v);
// the lines should intersect at the point we called "center"
- VERIFY_IS_APPROX(result, center);
+ if(abs(a-1) > 1e-2 && abs(v.normalized().dot(u.normalized()))<0.9)
+ VERIFY_IS_APPROX(result, center);
// check conversions between two types of lines
PLine pl(line_u); // gcc 3.3 will commit suicide if we don't name this variable
- CoeffsType converted_coeffs = HLine(pl).coeffs();
- converted_coeffs *= (line_u.coeffs()[0])/(converted_coeffs[0]);
+ HLine line_u2(pl);
+ CoeffsType converted_coeffs = line_u2.coeffs();
+ if(line_u2.normal().dot(line_u.normal())<0.)
+ converted_coeffs = -line_u2.coeffs();
VERIFY(line_u.coeffs().isApprox(converted_coeffs));
}
}