/usr/include/vmmlib/matrix_functors.hpp is in libvmmlib-dev 1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #ifndef __VMML__MATRIX_FUNCTORS__HPP__
#define __VMML__MATRIX_FUNCTORS__HPP__
#include <vmmlib/enable_if.hpp>
#include <cstddef>
#include <functional>
namespace vmml
{
template< typename T >
struct set_to_zero_functor
{
inline void operator()( T& matrix_ ) const
{
matrix_ = static_cast< typename T::value_type >( 0.0 );
}
}; // struct set_to_zero
template< typename T >
struct set_to_identity_functor
{
inline
typename enable_if< T::ROWS == T::COLS >::type*
operator()( T& matrix_ )
{
set_to_zero_functor< T >()( matrix_ );
for( size_t index = 0; index < T::ROWS; ++index )
{
matrix_( index, index ) = static_cast< typename T::value_type >( 1.0 );
}
return 0; // for sfinae
}
}; // struct set_to_identity
// this functor compares to matrices, and also returns true/equal if
// the matrices have the same values but some rows/columns are inverted
template< typename T >
struct matrix_equals_allow_inverted_rows : std::binary_function< const T&, const T&, bool >
{
bool operator()( const T& matrix0, const T& matrix1 )
{
const size_t r = matrix0.get_number_of_rows();
bool ok = true;
for( size_t index = 0; ok && index < r; ++index )
{
if ( matrix0.get_row( index ) != matrix1.get_row( index )
&& matrix0.get_row( index ) != - matrix1.get_row( index ) )
{
ok = false;
}
}
return ok;
}
bool operator()( const T& matrix0, const T& matrix1, typename T::value_type tolerance )
{
const size_t r = matrix0.get_number_of_rows();
bool ok = true;
for( size_t index = 0; ok && index < r; ++index )
{
if (
! matrix0.get_row( index ).equals( matrix1.get_row( index ), tolerance )
&& ! matrix0.get_row( index ).equals( - matrix1.get_row( index ), tolerance )
)
{
ok = false;
}
}
return ok;
}
}; // struct matrix_equals_allow_inverted_rows
template< typename T >
struct matrix_equals_allow_inverted_columns : std::binary_function< const T&, const T&, bool >
{
bool operator()( const T& matrix0, const T& matrix1 )
{
const size_t r = matrix0.get_number_of_columns();
bool ok = true;
for( size_t index = 0; ok && index < r; ++index )
{
if ( matrix0.get_column( index ) != matrix1.get_column( index )
&& matrix0.get_column( index ) != - matrix1.get_column( index ) )
{
ok = false;
}
}
return ok;
}
bool operator()( const T& matrix0, const T& matrix1, typename T::value_type tolerance )
{
const size_t r = matrix0.get_number_of_columns();
bool ok = true;
for( size_t index = 0; ok && index < r; ++index )
{
if (
! matrix0.get_column( index ).equals( matrix1.get_column( index ), tolerance )
&& ! matrix0.get_column( index ).equals( - matrix1.get_column( index ), tolerance )
)
{
ok = false;
}
}
return ok;
}
}; // struct matrix_equals_allow_inverted_columns
} // namespace vmml
#endif
|