19 #ifndef OST_GEOM_VEC_MAT_PREDICATES_HH
20 #define OST_GEOM_VEC_MAT_PREDICATES_HH
21 #include <boost/version.hpp>
22 #include <boost/test/unit_test.hpp>
23 #include <boost/test/floating_point_comparison.hpp>
35 boost::test_tools::predicate_result
vec_is_close(
const V& v1,
const V& v2,
39 std::string labels[]={
"x",
"y",
"z",
"w"};
41 boost::test_tools::predicate_result res(
false );
42 #if BOOST_VERSION<103400
43 boost::test_tools::close_at_tolerance<Real> close_test(tolerance);
45 boost::test_tools::close_at_tolerance<Real> close_test(boost::test_tools::percent_tolerance(tolerance));
47 for(
unsigned int i=0;i<dim;++i){
49 if(!boost::test_tools::check_is_small(v2[i],tolerance)){
51 res.message() <<
"Value for " << labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
53 }
else if (v2[i]==0.0){
54 if(!boost::test_tools::check_is_small(v1[i],tolerance)){
56 res.message() <<
"Value for "<< labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
59 if(!close_test(v1[i],v2[i])){
61 res.message() <<
"Value for " << labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
76 return vec_is_close<geom::Vec2>(v1,v2,tolerance,2);
83 return vec_is_close<geom::Vec3>(v1,v2,tolerance,3);
90 return vec_is_close<geom::Vec4>(v1,v2,tolerance,4);
94 boost::test_tools::predicate_result
mat_is_close(
const M& m1,
const M& m2,
99 boost::test_tools::predicate_result res(
false );
100 #if BOOST_VERSION<103400
101 boost::test_tools::close_at_tolerance<Real> close_test(tolerance);
103 boost::test_tools::close_at_tolerance<Real> close_test(boost::test_tools::percent_tolerance(tolerance));
105 for(
unsigned int i=0;i<dim;++i){
106 for(
unsigned int j=0;j<dim;++j){
108 if(!boost::test_tools::check_is_small(m2(i,j),tolerance)){
110 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
112 }
else if (m2(i,j)==0.0){
113 if(!boost::test_tools::check_is_small(m1(i,j),tolerance)){
115 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
118 if(!close_test(m1(i,j),m2(i,j))){
120 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
136 return mat_is_close<geom::Mat2>(m1,m2,tolerance,2);
143 return mat_is_close<geom::Mat3>(m1,m2,tolerance,3);
150 return mat_is_close<geom::Mat4>(m1,m2,tolerance,4);