| 1 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 2 | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #ifdef BOOST_QVM_TEST_SINGLE_HEADER |
| 7 | # include BOOST_QVM_TEST_SINGLE_HEADER |
| 8 | #else |
| 9 | # include <boost/qvm/operations.hpp> |
| 10 | # include <boost/qvm/map_mat_mat.hpp> |
| 11 | #endif |
| 12 | |
| 13 | #include "test_qvm_matrix.hpp" |
| 14 | #include "test_qvm_quaternion.hpp" |
| 15 | #include "test_qvm_vector.hpp" |
| 16 | #include "gold.hpp" |
| 17 | |
| 18 | namespace |
| 19 | { |
| 20 | template <int Rows,int Cols> |
| 21 | void |
| 22 | test_matrix() |
| 23 | { |
| 24 | using namespace boost::qvm::sfinae; |
| 25 | test_qvm::matrix<M1,Rows,Cols> const x(42,1); |
| 26 | test_qvm::matrix<M2,Rows,Cols> const y=convert_to< test_qvm::matrix<M2,Rows,Cols> >(x); |
| 27 | BOOST_QVM_TEST_EQ(x.a,y.a); |
| 28 | } |
| 29 | |
| 30 | template <int Dim> |
| 31 | void |
| 32 | test_vector() |
| 33 | { |
| 34 | using namespace boost::qvm::sfinae; |
| 35 | test_qvm::vector<V1,Dim> const x(42,1); |
| 36 | test_qvm::vector<V2,Dim> const y=convert_to< test_qvm::vector<V2,Dim> >(x); |
| 37 | BOOST_QVM_TEST_EQ(x.a,y.a); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | test_quaternion() |
| 42 | { |
| 43 | using namespace boost::qvm; |
| 44 | test_qvm::quaternion<Q1> x(42,1); |
| 45 | normalize(a&: x); |
| 46 | { |
| 47 | test_qvm::quaternion<Q2> const y=convert_to< test_qvm::quaternion<Q2> >(a: x); |
| 48 | BOOST_QVM_TEST_EQ(x.a,y.a); |
| 49 | } |
| 50 | { |
| 51 | test_qvm::matrix<M1,3,3> const my=convert_to< test_qvm::matrix<M1,3,3> >(q: x); |
| 52 | test_qvm::quaternion<Q1> const qy=convert_to< test_qvm::quaternion<Q1> >(a: my); |
| 53 | BOOST_QVM_TEST_CLOSE(x.a,qy.a,0.00001f); |
| 54 | } |
| 55 | { |
| 56 | test_qvm::matrix<M1,4,4> const my=convert_to< test_qvm::matrix<M1,4,4> >(q: x); |
| 57 | BOOST_TEST(my.a[0][3]==0); |
| 58 | BOOST_TEST(my.a[1][3]==0); |
| 59 | BOOST_TEST(my.a[2][3]==0); |
| 60 | BOOST_TEST(my.a[3][0]==0); |
| 61 | BOOST_TEST(my.a[3][1]==0); |
| 62 | BOOST_TEST(my.a[3][2]==0); |
| 63 | BOOST_TEST(my.a[3][3]==1); |
| 64 | test_qvm::quaternion<Q1> const qy=convert_to< test_qvm::quaternion<Q1> >(a: del_row_col<3,3>(a: my)); |
| 65 | BOOST_QVM_TEST_CLOSE(x.a,qy.a,0.00001f); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | int |
| 71 | main() |
| 72 | { |
| 73 | test_matrix<1,2>(); |
| 74 | test_matrix<2,1>(); |
| 75 | test_matrix<2,2>(); |
| 76 | test_matrix<1,3>(); |
| 77 | test_matrix<3,1>(); |
| 78 | test_matrix<3,3>(); |
| 79 | test_matrix<1,4>(); |
| 80 | test_matrix<4,1>(); |
| 81 | test_matrix<4,4>(); |
| 82 | test_matrix<1,5>(); |
| 83 | test_matrix<5,1>(); |
| 84 | test_matrix<5,5>(); |
| 85 | test_quaternion(); |
| 86 | test_vector<2>(); |
| 87 | test_vector<3>(); |
| 88 | test_vector<4>(); |
| 89 | test_vector<5>(); |
| 90 | return boost::report_errors(); |
| 91 | } |
| 92 | |