2008-10-26 23:04:31 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-23 02:25:33 +08:00
|
|
|
// for linear algebra.
|
2008-10-26 23:04:31 +08:00
|
|
|
//
|
2010-06-25 05:21:58 +08:00
|
|
|
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-10-26 23:04:31 +08:00
|
|
|
//
|
2012-07-14 02:42:47 +08:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-10-26 23:04:31 +08:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include <Eigen/Geometry>
|
|
|
|
#include <Eigen/LU>
|
|
|
|
#include <Eigen/QR>
|
|
|
|
|
2010-01-20 21:55:10 +08:00
|
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2008-10-26 23:04:31 +08:00
|
|
|
template<typename BoxType> void alignedbox(const BoxType& _box)
|
|
|
|
{
|
|
|
|
/* this test covers the following files:
|
|
|
|
AlignedBox.h
|
|
|
|
*/
|
2010-06-22 00:39:24 +08:00
|
|
|
typedef typename BoxType::Index Index;
|
2008-10-26 23:04:31 +08:00
|
|
|
typedef typename BoxType::Scalar Scalar;
|
|
|
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
|
|
|
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
|
|
|
|
|
2010-06-22 00:39:24 +08:00
|
|
|
const Index dim = _box.dim();
|
|
|
|
|
2008-10-26 23:04:31 +08:00
|
|
|
VectorType p0 = VectorType::Random(dim);
|
|
|
|
VectorType p1 = VectorType::Random(dim);
|
2010-01-20 21:55:10 +08:00
|
|
|
while( p1 == p0 ){
|
|
|
|
p1 = VectorType::Random(dim); }
|
2010-10-25 22:15:22 +08:00
|
|
|
RealScalar s1 = internal::random<RealScalar>(0,1);
|
2008-10-26 23:04:31 +08:00
|
|
|
|
|
|
|
BoxType b0(dim);
|
|
|
|
BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
|
|
|
|
BoxType b2;
|
|
|
|
|
|
|
|
b0.extend(p0);
|
|
|
|
b0.extend(p1);
|
2009-01-12 23:29:51 +08:00
|
|
|
VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
|
2008-10-26 23:04:31 +08:00
|
|
|
|
|
|
|
(b2 = b0).extend(b1);
|
|
|
|
VERIFY(b2.contains(b0));
|
|
|
|
VERIFY(b2.contains(b1));
|
|
|
|
VERIFY_IS_APPROX(b2.clamp(b0), b0);
|
|
|
|
|
2010-01-20 21:55:10 +08:00
|
|
|
|
|
|
|
// alignment -- make sure there is no memory alignment assertion
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename BoxType>
|
|
|
|
void alignedboxCastTests(const BoxType& _box)
|
|
|
|
{
|
2010-06-22 00:39:24 +08:00
|
|
|
// casting
|
|
|
|
typedef typename BoxType::Index Index;
|
2010-01-20 21:55:10 +08:00
|
|
|
typedef typename BoxType::Scalar Scalar;
|
|
|
|
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
|
|
|
|
|
2010-06-22 00:39:24 +08:00
|
|
|
const Index dim = _box.dim();
|
|
|
|
|
2010-01-20 21:55:10 +08:00
|
|
|
VectorType p0 = VectorType::Random(dim);
|
|
|
|
VectorType p1 = VectorType::Random(dim);
|
|
|
|
|
|
|
|
BoxType b0(dim);
|
|
|
|
|
|
|
|
b0.extend(p0);
|
|
|
|
b0.extend(p1);
|
|
|
|
|
2008-10-26 23:04:31 +08:00
|
|
|
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);
|
2010-01-20 21:55:10 +08:00
|
|
|
}
|
2009-05-11 19:09:41 +08:00
|
|
|
|
2010-01-20 21:55:10 +08:00
|
|
|
|
|
|
|
void specificTest1()
|
|
|
|
{
|
|
|
|
Vector2f m; m << -1.0f, -2.0f;
|
|
|
|
Vector2f M; M << 1.0f, 5.0f;
|
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
typedef AlignedBox2f BoxType;
|
2010-01-20 21:55:10 +08:00
|
|
|
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() );
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( 14.0f, box.volume() );
|
|
|
|
VERIFY_IS_APPROX( 53.0f, box.diagonal().squaredNorm() );
|
2012-11-06 22:25:50 +08:00
|
|
|
VERIFY_IS_APPROX( std::sqrt( 53.0f ), box.diagonal().norm() );
|
2010-01-20 21:55:10 +08:00
|
|
|
|
|
|
|
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 ) );
|
2008-10-26 23:04:31 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 21:55:10 +08:00
|
|
|
|
|
|
|
void specificTest2()
|
|
|
|
{
|
|
|
|
Vector3i m; m << -1, -2, 0;
|
|
|
|
Vector3i M; M << 1, 5, 3;
|
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
typedef AlignedBox3i BoxType;
|
2010-01-20 21:55:10 +08:00
|
|
|
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() );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-17 17:53:05 +08:00
|
|
|
void test_geo_alignedbox()
|
2008-10-26 23:04:31 +08:00
|
|
|
{
|
2010-01-20 21:55:10 +08:00
|
|
|
for(int i = 0; i < g_repeat; i++)
|
|
|
|
{
|
2011-11-10 05:12:28 +08:00
|
|
|
CALL_SUBTEST_1( alignedbox(AlignedBox2f()) );
|
|
|
|
CALL_SUBTEST_2( alignedboxCastTests(AlignedBox2f()) );
|
2010-01-20 21:55:10 +08:00
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
CALL_SUBTEST_3( alignedbox(AlignedBox3f()) );
|
|
|
|
CALL_SUBTEST_4( alignedboxCastTests(AlignedBox3f()) );
|
2010-01-20 21:55:10 +08:00
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
CALL_SUBTEST_5( alignedbox(AlignedBox4d()) );
|
|
|
|
CALL_SUBTEST_6( alignedboxCastTests(AlignedBox4d()) );
|
2010-01-20 21:55:10 +08:00
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
CALL_SUBTEST_7( alignedbox(AlignedBox1d()) );
|
|
|
|
CALL_SUBTEST_8( alignedboxCastTests(AlignedBox1d()) );
|
2010-01-20 21:55:10 +08:00
|
|
|
|
2011-11-10 05:12:28 +08:00
|
|
|
CALL_SUBTEST_9( alignedbox(AlignedBox1i()) );
|
|
|
|
CALL_SUBTEST_10( alignedbox(AlignedBox2i()) );
|
|
|
|
CALL_SUBTEST_11( alignedbox(AlignedBox3i()) );
|
2008-10-26 23:04:31 +08:00
|
|
|
}
|
2010-01-20 21:55:10 +08:00
|
|
|
CALL_SUBTEST_12( specificTest1() );
|
|
|
|
CALL_SUBTEST_13( specificTest2() );
|
2008-10-26 23:04:31 +08:00
|
|
|
}
|