19 #ifndef OST_GEOM_VEC_MAT_PREDICATES_HH
20 #define OST_GEOM_VEC_MAT_PREDICATES_HH
21 #include <boost/test/unit_test.hpp>
22 #include <boost/version.hpp>
23 #if BOOST_VERSION<105900
24 #include <boost/test/floating_point_comparison.hpp>
26 #include <boost/test/tools/floating_point_comparison.hpp>
39 boost::test_tools::predicate_result
vec_is_close(
const V& v1,
const V& v2,
43 std::string labels[]={
"x",
"y",
"z",
"w"};
45 boost::test_tools::predicate_result res(
false );
46 #if BOOST_VERSION<105900
47 boost::test_tools::close_at_tolerance<Real> close_test(boost::test_tools::percent_tolerance(tolerance));
49 boost::math::fpc::close_at_tolerance<Real> close_test(boost::math::fpc::percent_tolerance(tolerance));
51 for(
unsigned int i=0;i<dim;++i){
53 if(!boost::test_tools::check_is_small(v2[i],tolerance)){
55 res.message() <<
"Value for " << labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
57 }
else if (v2[i]==0.0){
58 if(!boost::test_tools::check_is_small(v1[i],tolerance)){
60 res.message() <<
"Value for "<< labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
63 if(!close_test(v1[i],v2[i])){
65 res.message() <<
"Value for " << labels[i] <<
" differs: ( " << v1[i] <<
" != " << v2[i] <<
" ). ";
80 return vec_is_close<geom::Vec2>(v1,v2,tolerance,2);
87 return vec_is_close<geom::Vec3>(v1,v2,tolerance,3);
94 return vec_is_close<geom::Vec4>(v1,v2,tolerance,4);
98 boost::test_tools::predicate_result
mat_is_close(
const M& m1,
const M& m2,
103 boost::test_tools::predicate_result res(
false );
104 #if BOOST_VERSION<105900
105 boost::test_tools::close_at_tolerance<Real> close_test(boost::test_tools::percent_tolerance(tolerance));
107 boost::math::fpc::close_at_tolerance<Real> close_test(boost::math::fpc::percent_tolerance(tolerance));
109 for(
unsigned int i=0;i<dim;++i){
110 for(
unsigned int j=0;j<dim;++j){
112 if(!boost::test_tools::check_is_small(m2(i,j),tolerance)){
114 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
116 }
else if (m2(i,j)==0.0){
117 if(!boost::test_tools::check_is_small(m1(i,j),tolerance)){
119 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
122 if(!close_test(m1(i,j),m2(i,j))){
124 res.message() <<
"Value for (" << i <<
"," << j <<
") differs: (" << m1(i,j) <<
"!=" << m2(i,j) <<
"). ";
140 return mat_is_close<geom::Mat2>(m1,m2,tolerance,2);
147 return mat_is_close<geom::Mat3>(m1,m2,tolerance,3);
154 return mat_is_close<geom::Mat4>(m1,m2,tolerance,4);
Three dimensional vector class, using Real precision.
static const Real EPSILON
boost::test_tools::predicate_result mat_is_close(const M &m1, const M &m2, Real tolerance, unsigned int dim)
boost::test_tools::predicate_result mat2_is_close(const geom::Mat2 &m1, const geom::Mat2 &m2, Real tolerance=geom::EPSILON)
boost::test_tools::predicate_result mat4_is_close(const geom::Mat4 &m1, const geom::Mat4 &m2, Real tolerance=geom::EPSILON)
boost::test_tools::predicate_result vec_is_close(const V &v1, const V &v2, Real tolerance, unsigned int dim)
boost::test_tools::predicate_result vec3_is_close(const geom::Vec3 &v1, const geom::Vec3 &v2, Real tolerance=geom::EPSILON)
boost::test_tools::predicate_result vec2_is_close(const geom::Vec2 &v1, const geom::Vec2 &v2, Real tolerance=geom::EPSILON)
boost::test_tools::predicate_result vec4_is_close(const geom::Vec4 &v1, const geom::Vec4 &v2, Real tolerance=geom::EPSILON)
boost::test_tools::predicate_result mat3_is_close(const geom::Mat3 &m1, const geom::Mat3 &m2, Real tolerance=geom::EPSILON)