2
// Copyright (C) 1997 - 2007, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* \brief Unit tests for SqMatrix2D
23
* \author Chris Foster [ chris42f (at) gmail (dot) com ]
26
#include <aqsis/math/matrix2d.h>
28
#ifndef AQSIS_SYSTEM_WIN32
29
#define BOOST_TEST_DYN_LINK
30
#endif //AQSIS_SYSTEM_WIN32
32
#include <boost/test/auto_unit_test.hpp>
33
#include <boost/test/floating_point_comparison.hpp>
35
static const TqFloat closeEps = 1e-5f;
37
BOOST_AUTO_TEST_CASE(SqMatrix2D_inv_test)
39
Aqsis::SqMatrix2D A(1,2,3,4);
40
Aqsis::SqMatrix2D Ainv = A.inv();
41
Aqsis::SqMatrix2D I = A*Ainv;
42
BOOST_CHECK_CLOSE(I.a, 1.0f, closeEps);
43
BOOST_CHECK_SMALL(I.b, closeEps);
44
BOOST_CHECK_SMALL(I.c, closeEps);
45
BOOST_CHECK_CLOSE(I.d, 1.0f, closeEps);
48
BOOST_AUTO_TEST_CASE(SqMatrix2D_eigenvalue_test)
52
Aqsis::SqMatrix2D A(1);
54
BOOST_CHECK_CLOSE(l1, 1.0f, closeEps);
55
BOOST_CHECK_CLOSE(l2, 1.0f, closeEps);
57
A = Aqsis::SqMatrix2D(1,2);
59
BOOST_CHECK_CLOSE(l1, 2.0f, closeEps);
60
BOOST_CHECK_CLOSE(l2, 1.0f, closeEps);
62
A = Aqsis::SqMatrix2D(1,1, 1,2);
64
BOOST_CHECK_CLOSE(l1, TqFloat((3+std::sqrt(5.0f))/2), closeEps);
65
BOOST_CHECK_CLOSE(l2, TqFloat((3-std::sqrt(5.0f))/2), closeEps);
68
BOOST_AUTO_TEST_CASE(SqMatrix2D_orthogDiagonalize_test)
72
Aqsis::SqMatrix2D A = Aqsis::SqMatrix2D(1,2);
74
Aqsis::SqMatrix2D R = A.orthogDiagonalize(l1,l2);
75
Aqsis::SqMatrix2D D = R.transpose()*A*R;
76
BOOST_CHECK_CLOSE(D.a, l1, closeEps);
77
BOOST_CHECK_CLOSE(D.d, l2, closeEps);
78
BOOST_CHECK_SMALL(D.b, closeEps);
79
BOOST_CHECK_SMALL(D.c, closeEps);
84
Aqsis::SqMatrix2D A(1,1, 1,2);
86
Aqsis::SqMatrix2D R = A.orthogDiagonalize(l1,l2);
87
Aqsis::SqMatrix2D D = R.transpose()*A*R;
88
BOOST_CHECK_CLOSE(D.a, TqFloat((3+std::sqrt(5.0f))/2), closeEps);
89
BOOST_CHECK_CLOSE(D.d, TqFloat((3-std::sqrt(5.0f))/2), closeEps);
90
BOOST_CHECK_SMALL(D.b, closeEps);
91
BOOST_CHECK_SMALL(D.c, closeEps);