00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026
00027 #define COMPARE_CORNER(A,B) \
00028 VERIFY_IS_EQUAL(matrix.A, matrix.B); \
00029 VERIFY_IS_EQUAL(const_matrix.A, const_matrix.B);
00030
00031 template<typename MatrixType> void corners(const MatrixType& m)
00032 {
00033 typedef typename MatrixType::Index Index;
00034 Index rows = m.rows();
00035 Index cols = m.cols();
00036
00037 Index r = internal::random<Index>(1,rows);
00038 Index c = internal::random<Index>(1,cols);
00039
00040 MatrixType matrix = MatrixType::Random(rows,cols);
00041 const MatrixType const_matrix = MatrixType::Random(rows,cols);
00042
00043 COMPARE_CORNER(topLeftCorner(r,c), block(0,0,r,c));
00044 COMPARE_CORNER(topRightCorner(r,c), block(0,cols-c,r,c));
00045 COMPARE_CORNER(bottomLeftCorner(r,c), block(rows-r,0,r,c));
00046 COMPARE_CORNER(bottomRightCorner(r,c), block(rows-r,cols-c,r,c));
00047
00048 Index sr = internal::random<Index>(1,rows) - 1;
00049 Index nr = internal::random<Index>(1,rows-sr);
00050 Index sc = internal::random<Index>(1,cols) - 1;
00051 Index nc = internal::random<Index>(1,cols-sc);
00052
00053 COMPARE_CORNER(topRows(r), block(0,0,r,cols));
00054 COMPARE_CORNER(middleRows(sr,nr), block(sr,0,nr,cols));
00055 COMPARE_CORNER(bottomRows(r), block(rows-r,0,r,cols));
00056 COMPARE_CORNER(leftCols(c), block(0,0,rows,c));
00057 COMPARE_CORNER(middleCols(sc,nc), block(0,sc,rows,nc));
00058 COMPARE_CORNER(rightCols(c), block(0,cols-c,rows,c));
00059 }
00060
00061 template<typename MatrixType, int CRows, int CCols, int SRows, int SCols> void corners_fixedsize()
00062 {
00063 MatrixType matrix = MatrixType::Random();
00064 const MatrixType const_matrix = MatrixType::Random();
00065
00066 enum {
00067 rows = MatrixType::RowsAtCompileTime,
00068 cols = MatrixType::ColsAtCompileTime,
00069 r = CRows,
00070 c = CCols,
00071 sr = SRows,
00072 sc = SCols
00073 };
00074
00075 VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template block<r,c>(0,0)));
00076 VERIFY_IS_EQUAL((matrix.template topRightCorner<r,c>()), (matrix.template block<r,c>(0,cols-c)));
00077 VERIFY_IS_EQUAL((matrix.template bottomLeftCorner<r,c>()), (matrix.template block<r,c>(rows-r,0)));
00078 VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template block<r,c>(rows-r,cols-c)));
00079
00080 VERIFY_IS_EQUAL((matrix.template topRows<r>()), (matrix.template block<r,cols>(0,0)));
00081 VERIFY_IS_EQUAL((matrix.template middleRows<r>(sr)), (matrix.template block<r,cols>(sr,0)));
00082 VERIFY_IS_EQUAL((matrix.template bottomRows<r>()), (matrix.template block<r,cols>(rows-r,0)));
00083 VERIFY_IS_EQUAL((matrix.template leftCols<c>()), (matrix.template block<rows,c>(0,0)));
00084 VERIFY_IS_EQUAL((matrix.template middleCols<c>(sc)), (matrix.template block<rows,c>(0,sc)));
00085 VERIFY_IS_EQUAL((matrix.template rightCols<c>()), (matrix.template block<rows,c>(0,cols-c)));
00086
00087 VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template block<r,c>(0,0)));
00088 VERIFY_IS_EQUAL((const_matrix.template topRightCorner<r,c>()), (const_matrix.template block<r,c>(0,cols-c)));
00089 VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,0)));
00090 VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,cols-c)));
00091
00092 VERIFY_IS_EQUAL((const_matrix.template topRows<r>()), (const_matrix.template block<r,cols>(0,0)));
00093 VERIFY_IS_EQUAL((const_matrix.template middleRows<r>(sr)), (const_matrix.template block<r,cols>(sr,0)));
00094 VERIFY_IS_EQUAL((const_matrix.template bottomRows<r>()), (const_matrix.template block<r,cols>(rows-r,0)));
00095 VERIFY_IS_EQUAL((const_matrix.template leftCols<c>()), (const_matrix.template block<rows,c>(0,0)));
00096 VERIFY_IS_EQUAL((const_matrix.template middleCols<c>(sc)), (const_matrix.template block<rows,c>(0,sc)));
00097 VERIFY_IS_EQUAL((const_matrix.template rightCols<c>()), (const_matrix.template block<rows,c>(0,cols-c)));
00098 }
00099
00100 void test_corners()
00101 {
00102 for(int i = 0; i < g_repeat; i++) {
00103 CALL_SUBTEST_1( corners(Matrix<float, 1, 1>()) );
00104 CALL_SUBTEST_2( corners(Matrix4d()) );
00105 CALL_SUBTEST_3( corners(Matrix<int,10,12>()) );
00106 CALL_SUBTEST_4( corners(MatrixXcf(5, 7)) );
00107 CALL_SUBTEST_5( corners(MatrixXf(21, 20)) );
00108
00109 CALL_SUBTEST_1(( corners_fixedsize<Matrix<float, 1, 1>, 1, 1, 0, 0>() ));
00110 CALL_SUBTEST_2(( corners_fixedsize<Matrix4d,2,2,1,1>() ));
00111 CALL_SUBTEST_3(( corners_fixedsize<Matrix<int,10,12>,4,7,5,2>() ));
00112 }
00113 }