Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -15,8 +15,8 @@ using namespace std;
// NOTE the following workaround was needed on some 32 bits builds to kill extra precision of x87 registers.
// It seems that it is not needed anymore, but let's keep it here, just in case...
template<typename T> EIGEN_DONT_INLINE
void kill_extra_precision(T& /* x */) {
template <typename T>
EIGEN_DONT_INLINE void kill_extra_precision(T& /* x */) {
// This one worked but triggered a warning:
/* eigen_assert((void*)(&x) != (void*)0); */
// An alternative could be:
@@ -24,9 +24,8 @@ void kill_extra_precision(T& /* x */) {
/* x = tmp; */
}
template<typename BoxType> void alignedbox(const BoxType& box)
{
template <typename BoxType>
void alignedbox(const BoxType& box) {
/* this test covers the following files:
AlignedBox.h
*/
@@ -39,12 +38,13 @@ template<typename BoxType> void alignedbox(const BoxType& box)
VectorType p0 = VectorType::Random(dim);
VectorType p1 = VectorType::Random(dim);
while( p1 == p0 ){
p1 = VectorType::Random(dim); }
RealScalar s1 = internal::random<RealScalar>(0,1);
while (p1 == p0) {
p1 = VectorType::Random(dim);
}
RealScalar s1 = internal::random<RealScalar>(0, 1);
BoxType b0(dim);
BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
BoxType b1(VectorType::Random(dim), VectorType::Random(dim));
BoxType b2;
kill_extra_precision(b1);
@@ -53,9 +53,9 @@ template<typename BoxType> void alignedbox(const BoxType& box)
b0.extend(p0);
b0.extend(p1);
VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
VERIFY(b0.contains(p0 * s1 + (Scalar(1) - s1) * p1));
VERIFY(b0.contains(b0.center()));
VERIFY_IS_APPROX(b0.center(),(p0+p1)/Scalar(2));
VERIFY_IS_APPROX(b0.center(), (p0 + p1) / Scalar(2));
(b2 = b0).extend(b1);
VERIFY(b2.contains(b0));
@@ -71,23 +71,21 @@ template<typename BoxType> void alignedbox(const BoxType& box)
VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty());
// alignment -- make sure there is no memory alignment assertion
BoxType *bp0 = new BoxType(dim);
BoxType *bp1 = new BoxType(dim);
BoxType* bp0 = new BoxType(dim);
BoxType* bp1 = new BoxType(dim);
bp0->extend(*bp1);
delete bp0;
delete bp1;
// sampling
for( int i=0; i<10; ++i )
{
VectorType r = b0.sample();
VERIFY(b0.contains(r));
for (int i = 0; i < 10; ++i) {
VectorType r = b0.sample();
VERIFY(b0.contains(r));
}
}
template<typename BoxType> void alignedboxTranslatable(const BoxType& box)
{
template <typename BoxType>
void alignedboxTranslatable(const BoxType& box) {
typedef typename BoxType::Scalar Scalar;
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
typedef Transform<Scalar, BoxType::AmbientDimAtCompileTime, Isometry> IsometryTransform;
@@ -153,13 +151,11 @@ template<typename BoxType> void alignedboxTranslatable(const BoxType& box)
BoxType transformedC = c.transformed(IsometryTransform::Identity());
VERIFY_IS_APPROX(transformedC, c);
for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
VectorType minCorner;
VectorType maxCorner;
for (Index d = 0; d < dim; ++d)
{
minCorner[d] = internal::random<Scalar>(-10,10);
for (Index d = 0; d < dim; ++d) {
minCorner[d] = internal::random<Scalar>(-10, 10);
maxCorner[d] = minCorner[d] + internal::random<Scalar>(0, 10);
}
@@ -173,31 +169,29 @@ template<typename BoxType> void alignedboxTranslatable(const BoxType& box)
}
}
template<typename Scalar, typename Rotation>
template <typename Scalar, typename Rotation>
Rotation rotate2D(Scalar angle) {
return Rotation2D<Scalar>(angle);
}
template<typename Scalar, typename Rotation>
template <typename Scalar, typename Rotation>
Rotation rotate2DIntegral(typename NumTraits<Scalar>::NonInteger angle) {
typedef typename NumTraits<Scalar>::NonInteger NonInteger;
return Rotation2D<NonInteger>(angle).toRotationMatrix().
template cast<Scalar>();
return Rotation2D<NonInteger>(angle).toRotationMatrix().template cast<Scalar>();
}
template<typename Scalar, typename Rotation>
template <typename Scalar, typename Rotation>
Rotation rotate3DZAxis(Scalar angle) {
return AngleAxis<Scalar>(angle, Matrix<Scalar, 3, 1>(0, 0, 1));
}
template<typename Scalar, typename Rotation>
template <typename Scalar, typename Rotation>
Rotation rotate3DZAxisIntegral(typename NumTraits<Scalar>::NonInteger angle) {
typedef typename NumTraits<Scalar>::NonInteger NonInteger;
return AngleAxis<NonInteger>(angle, Matrix<NonInteger, 3, 1>(0, 0, 1)).
toRotationMatrix().template cast<Scalar>();
return AngleAxis<NonInteger>(angle, Matrix<NonInteger, 3, 1>(0, 0, 1)).toRotationMatrix().template cast<Scalar>();
}
template<typename Scalar, typename Rotation>
template <typename Scalar, typename Rotation>
Rotation rotate4DZWAxis(Scalar angle) {
Rotation result = Matrix<Scalar, 4, 4>::Identity();
result.block(0, 0, 3, 3) = rotate3DZAxis<Scalar, AngleAxisd>(angle).toRotationMatrix();
@@ -205,8 +199,7 @@ Rotation rotate4DZWAxis(Scalar angle) {
}
template <typename MatrixType>
MatrixType randomRotationMatrix()
{
MatrixType randomRotationMatrix() {
// algorithm from
// https://www.isprs-ann-photogramm-remote-sens-spatial-inf-sci.net/III-7/103/2016/isprs-annals-III-7-103-2016.pdf
const MatrixType rand = MatrixType::Random();
@@ -220,21 +213,17 @@ MatrixType randomRotationMatrix()
}
template <typename Scalar, int Dim>
Matrix<Scalar, Dim, (1<<Dim)> boxGetCorners(const Matrix<Scalar, Dim, 1>& min_, const Matrix<Scalar, Dim, 1>& max_)
{
Matrix<Scalar, Dim, (1<<Dim) > result;
for(Index i=0; i<(1<<Dim); ++i)
{
for(Index j=0; j<Dim; ++j)
result(j,i) = (i & (1<<j)) ? min_(j) : max_(j);
Matrix<Scalar, Dim, (1 << Dim)> boxGetCorners(const Matrix<Scalar, Dim, 1>& min_, const Matrix<Scalar, Dim, 1>& max_) {
Matrix<Scalar, Dim, (1 << Dim)> result;
for (Index i = 0; i < (1 << Dim); ++i) {
for (Index j = 0; j < Dim; ++j) result(j, i) = (i & (1 << j)) ? min_(j) : max_(j);
}
return result;
}
template<typename BoxType, typename Rotation> void alignedboxRotatable(
const BoxType& box,
Rotation (*rotate)(typename NumTraits<typename BoxType::Scalar>::NonInteger /*_angle*/))
{
template <typename BoxType, typename Rotation>
void alignedboxRotatable(const BoxType& box,
Rotation (*rotate)(typename NumTraits<typename BoxType::Scalar>::NonInteger /*_angle*/)) {
alignedboxTranslatable(box);
typedef typename BoxType::Scalar Scalar;
@@ -301,10 +290,9 @@ template<typename BoxType, typename Rotation> void alignedboxRotatable(
VERIFY_IS_APPROX((c.max)(), Ones + UnitX);
}
template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatable(
const BoxType& box,
Rotation (*rotate)(typename NumTraits<typename BoxType::Scalar>::NonInteger /*_angle*/))
{
template <typename BoxType, typename Rotation>
void alignedboxNonIntegralRotatable(
const BoxType& box, Rotation (*rotate)(typename NumTraits<typename BoxType::Scalar>::NonInteger /*_angle*/)) {
alignedboxRotatable(box, rotate);
typedef typename BoxType::Scalar Scalar;
@@ -328,10 +316,12 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
VectorType cornerBL = (c.min)();
VectorType cornerTR = (c.max)();
VectorType cornerBR = (c.min)(); cornerBR[0] = cornerTR[0];
VectorType cornerTL = (c.max)(); cornerTL[0] = cornerBL[0];
VectorType cornerBR = (c.min)();
cornerBR[0] = cornerTR[0];
VectorType cornerTL = (c.max)();
cornerTL[0] = cornerBL[0];
NonInteger angle = NonInteger(EIGEN_PI/3);
NonInteger angle = NonInteger(EIGEN_PI / 3);
Rotation rot = rotate(angle);
IsometryTransform tf2;
tf2.setIdentity();
@@ -352,27 +342,24 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
minCorner[1] = (min)((min)(cornerBL[1], cornerBR[1]), (min)(cornerTL[1], cornerTR[1]));
maxCorner[1] = (max)((max)(cornerBL[1], cornerBR[1]), (max)(cornerTL[1], cornerTR[1]));
for (Index d = 2; d < dim; ++d)
VERIFY_IS_APPROX(c.sizes()[d], Scalar(2));
for (Index d = 2; d < dim; ++d) VERIFY_IS_APPROX(c.sizes()[d], Scalar(2));
VERIFY_IS_APPROX((c.min)(), minCorner);
VERIFY_IS_APPROX((c.max)(), maxCorner);
VectorType minCornerValue = Ones * Scalar(-2);
VectorType maxCornerValue = Zero;
minCornerValue[0] = Scalar(Scalar(-sqrt(2*2 + 3*3)) * Scalar(cos(Scalar(atan(2.0/3.0)) - angle/2)));
minCornerValue[1] = Scalar(Scalar(-sqrt(1*1 + 2*2)) * Scalar(sin(Scalar(atan(2.0/1.0)) - angle/2)));
minCornerValue[0] = Scalar(Scalar(-sqrt(2 * 2 + 3 * 3)) * Scalar(cos(Scalar(atan(2.0 / 3.0)) - angle / 2)));
minCornerValue[1] = Scalar(Scalar(-sqrt(1 * 1 + 2 * 2)) * Scalar(sin(Scalar(atan(2.0 / 1.0)) - angle / 2)));
maxCornerValue[0] = Scalar(-sin(angle));
maxCornerValue[1] = Scalar(3 * cos(angle));
VERIFY_IS_APPROX((c.min)(), minCornerValue);
VERIFY_IS_APPROX((c.max)(), maxCornerValue);
// randomized test - translate and rotate the box and compare to a box made of transformed vertices
for (size_t i = 0; i < 10; ++i)
{
for (Index d = 0; d < dim; ++d)
{
minCorner[d] = internal::random<Scalar>(-10,10);
for (size_t i = 0; i < 10; ++i) {
for (Index d = 0; d < dim; ++d) {
minCorner[d] = internal::random<Scalar>(-10, 10);
maxCorner[d] = minCorner[d] + internal::random<Scalar>(0, 10);
}
@@ -398,11 +385,9 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
}
// randomized test - transform the box with a random affine matrix and compare to a box made of transformed vertices
for (size_t i = 0; i < 10; ++i)
{
for (Index d = 0; d < dim; ++d)
{
minCorner[d] = internal::random<Scalar>(-10,10);
for (size_t i = 0; i < 10; ++i) {
for (Index d = 0; d < dim; ++d) {
minCorner[d] = internal::random<Scalar>(-10, 10);
maxCorner[d] = minCorner[d] + internal::random<Scalar>(0, 10);
}
@@ -425,9 +410,8 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
}
}
template<typename BoxType>
void alignedboxCastTests(const BoxType& box)
{
template <typename BoxType>
void alignedboxCastTests(const BoxType& box) {
// casting
typedef typename BoxType::Scalar Scalar;
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
@@ -444,88 +428,90 @@ void alignedboxCastTests(const BoxType& box)
const int Dim = BoxType::AmbientDimAtCompileTime;
typedef typename GetDifferentType<Scalar>::type OtherScalar;
AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>();
VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0);
AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>();
VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0);
AlignedBox<OtherScalar, Dim> hp1f = b0.template cast<OtherScalar>();
VERIFY_IS_APPROX(hp1f.template cast<Scalar>(), b0);
AlignedBox<Scalar, Dim> hp1d = b0.template cast<Scalar>();
VERIFY_IS_APPROX(hp1d.template cast<Scalar>(), b0);
}
void specificTest1() {
Vector2f m;
m << -1.0f, -2.0f;
Vector2f M;
M << 1.0f, 5.0f;
void specificTest1()
{
Vector2f m; m << -1.0f, -2.0f;
Vector2f M; M << 1.0f, 5.0f;
typedef AlignedBox2f BoxType;
BoxType box(m, M);
typedef AlignedBox2f BoxType;
BoxType box( m, M );
Vector2f sides = M - m;
VERIFY_IS_APPROX(sides, box.sizes());
VERIFY_IS_APPROX(sides[1], box.sizes()[1]);
VERIFY_IS_APPROX(sides[1], box.sizes().maxCoeff());
VERIFY_IS_APPROX(sides[0], box.sizes().minCoeff());
Vector2f sides = M-m;
VERIFY_IS_APPROX(sides, box.sizes() );
VERIFY_IS_APPROX(sides[1], box.sizes()[1] );
VERIFY_IS_APPROX(sides[1], box.sizes().maxCoeff() );
VERIFY_IS_APPROX(sides[0], box.sizes().minCoeff() );
VERIFY_IS_APPROX(14.0f, box.volume());
VERIFY_IS_APPROX(53.0f, box.diagonal().squaredNorm());
VERIFY_IS_APPROX(std::sqrt(53.0f), box.diagonal().norm());
VERIFY_IS_APPROX( 14.0f, box.volume() );
VERIFY_IS_APPROX( 53.0f, box.diagonal().squaredNorm() );
VERIFY_IS_APPROX( std::sqrt( 53.0f ), box.diagonal().norm() );
VERIFY_IS_APPROX( m, box.corner( BoxType::BottomLeft ) );
VERIFY_IS_APPROX( M, box.corner( BoxType::TopRight ) );
Vector2f bottomRight; bottomRight << M[0], m[1];
Vector2f topLeft; topLeft << m[0], M[1];
VERIFY_IS_APPROX( bottomRight, box.corner( BoxType::BottomRight ) );
VERIFY_IS_APPROX( topLeft, box.corner( BoxType::TopLeft ) );
VERIFY_IS_APPROX(m, box.corner(BoxType::BottomLeft));
VERIFY_IS_APPROX(M, box.corner(BoxType::TopRight));
Vector2f bottomRight;
bottomRight << M[0], m[1];
Vector2f topLeft;
topLeft << m[0], M[1];
VERIFY_IS_APPROX(bottomRight, box.corner(BoxType::BottomRight));
VERIFY_IS_APPROX(topLeft, box.corner(BoxType::TopLeft));
}
void specificTest2() {
Vector3i m;
m << -1, -2, 0;
Vector3i M;
M << 1, 5, 3;
void specificTest2()
{
Vector3i m; m << -1, -2, 0;
Vector3i M; M << 1, 5, 3;
typedef AlignedBox3i BoxType;
BoxType box(m, M);
typedef AlignedBox3i BoxType;
BoxType box( m, M );
Vector3i sides = M - m;
VERIFY_IS_APPROX(sides, box.sizes());
VERIFY_IS_APPROX(sides[1], box.sizes()[1]);
VERIFY_IS_APPROX(sides[1], box.sizes().maxCoeff());
VERIFY_IS_APPROX(sides[0], box.sizes().minCoeff());
Vector3i sides = M-m;
VERIFY_IS_APPROX(sides, box.sizes() );
VERIFY_IS_APPROX(sides[1], box.sizes()[1] );
VERIFY_IS_APPROX(sides[1], box.sizes().maxCoeff() );
VERIFY_IS_APPROX(sides[0], box.sizes().minCoeff() );
VERIFY_IS_APPROX(42, box.volume());
VERIFY_IS_APPROX(62, box.diagonal().squaredNorm());
VERIFY_IS_APPROX( 42, box.volume() );
VERIFY_IS_APPROX( 62, box.diagonal().squaredNorm() );
VERIFY_IS_APPROX( m, box.corner( BoxType::BottomLeftFloor ) );
VERIFY_IS_APPROX( M, box.corner( BoxType::TopRightCeil ) );
Vector3i bottomRightFloor; bottomRightFloor << M[0], m[1], m[2];
Vector3i topLeftFloor; topLeftFloor << m[0], M[1], m[2];
VERIFY_IS_APPROX( bottomRightFloor, box.corner( BoxType::BottomRightFloor ) );
VERIFY_IS_APPROX( topLeftFloor, box.corner( BoxType::TopLeftFloor ) );
VERIFY_IS_APPROX(m, box.corner(BoxType::BottomLeftFloor));
VERIFY_IS_APPROX(M, box.corner(BoxType::TopRightCeil));
Vector3i bottomRightFloor;
bottomRightFloor << M[0], m[1], m[2];
Vector3i topLeftFloor;
topLeftFloor << m[0], M[1], m[2];
VERIFY_IS_APPROX(bottomRightFloor, box.corner(BoxType::BottomRightFloor));
VERIFY_IS_APPROX(topLeftFloor, box.corner(BoxType::TopLeftFloor));
}
EIGEN_DECLARE_TEST(geo_alignedbox) {
for (int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1((alignedboxNonIntegralRotatable<AlignedBox2f, Rotation2Df>(AlignedBox2f(), &rotate2D)));
CALL_SUBTEST_2(alignedboxCastTests(AlignedBox2f()));
EIGEN_DECLARE_TEST(geo_alignedbox)
{
for(int i = 0; i < g_repeat; i++)
{
CALL_SUBTEST_1( (alignedboxNonIntegralRotatable<AlignedBox2f, Rotation2Df>(AlignedBox2f(), &rotate2D)) );
CALL_SUBTEST_2( alignedboxCastTests(AlignedBox2f()) );
CALL_SUBTEST_3((alignedboxNonIntegralRotatable<AlignedBox3f, AngleAxisf>(AlignedBox3f(), &rotate3DZAxis)));
CALL_SUBTEST_4(alignedboxCastTests(AlignedBox3f()));
CALL_SUBTEST_3( (alignedboxNonIntegralRotatable<AlignedBox3f, AngleAxisf>(AlignedBox3f(), &rotate3DZAxis)) );
CALL_SUBTEST_4( alignedboxCastTests(AlignedBox3f()) );
CALL_SUBTEST_5((alignedboxNonIntegralRotatable<AlignedBox4d, Matrix4d>(AlignedBox4d(), &rotate4DZWAxis)));
CALL_SUBTEST_6(alignedboxCastTests(AlignedBox4d()));
CALL_SUBTEST_5( (alignedboxNonIntegralRotatable<AlignedBox4d, Matrix4d>(AlignedBox4d(), &rotate4DZWAxis)) );
CALL_SUBTEST_6( alignedboxCastTests(AlignedBox4d()) );
CALL_SUBTEST_7(alignedboxTranslatable(AlignedBox1d()));
CALL_SUBTEST_8(alignedboxCastTests(AlignedBox1d()));
CALL_SUBTEST_7( alignedboxTranslatable(AlignedBox1d()) );
CALL_SUBTEST_8( alignedboxCastTests(AlignedBox1d()) );
CALL_SUBTEST_9(alignedboxTranslatable(AlignedBox1i()));
CALL_SUBTEST_10((alignedboxRotatable<AlignedBox2i, Matrix2i>(AlignedBox2i(), &rotate2DIntegral<int, Matrix2i>)));
CALL_SUBTEST_11(
(alignedboxRotatable<AlignedBox3i, Matrix3i>(AlignedBox3i(), &rotate3DZAxisIntegral<int, Matrix3i>)));
CALL_SUBTEST_9( alignedboxTranslatable(AlignedBox1i()) );
CALL_SUBTEST_10( (alignedboxRotatable<AlignedBox2i, Matrix2i>(AlignedBox2i(), &rotate2DIntegral<int, Matrix2i>)) );
CALL_SUBTEST_11( (alignedboxRotatable<AlignedBox3i, Matrix3i>(AlignedBox3i(), &rotate3DZAxisIntegral<int, Matrix3i>)) );
CALL_SUBTEST_14( alignedbox(AlignedBox<double,Dynamic>(4)) );
CALL_SUBTEST_14(alignedbox(AlignedBox<double, Dynamic>(4)));
}
CALL_SUBTEST_12( specificTest1() );
CALL_SUBTEST_13( specificTest2() );
CALL_SUBTEST_12(specificTest1());
CALL_SUBTEST_13(specificTest2());
}