mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-12 09:23:12 +08:00
Make geo_hyperplane unit test more stable (bug #539)
This commit is contained in:
parent
92190a1caf
commit
e15cb9f4f8
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user