diff --git a/modules/geom/src/CMakeLists.txt b/modules/geom/src/CMakeLists.txt index b4720797290e3e0ad37c94f578593bb5ff03cb67..deb888dfd1e82838dae181e8d2a59cbbc8e2fd5b 100644 --- a/modules/geom/src/CMakeLists.txt +++ b/modules/geom/src/CMakeLists.txt @@ -23,6 +23,7 @@ composite_op.hh composite2_op.hh composite3_op.hh aligned_cuboid.hh +vec_mat_predicates.hh quat.hh point_cloud.hh diff --git a/modules/geom/src/vec_mat_predicates.hh b/modules/geom/src/vec_mat_predicates.hh new file mode 100644 index 0000000000000000000000000000000000000000..5827c60cc81b1266288794ff284fa9519cac3645 --- /dev/null +++ b/modules/geom/src/vec_mat_predicates.hh @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_GEOM_VEC_MAT_PREDICATES_HH +#define OST_GEOM_VEC_MAT_PREDICATES_HH + +#include <boost/test/unit_test.hpp> +#include <ost/geom/geom.hh> + + +/* + This file contains several predicates to check for equality of vectors and + matrices. Usage: + + BOOST_CHECK(vec2_is_close(geom::Vec2(1,2), geom::Vec2(1, 2))); + */ + +template<class V> +boost::test_tools::predicate_result vec_is_close(const V& v1, const V& v2, + Real tolerance, + unsigned int dim) +{ + std::string labels[]={"x","y","z","w"}; + bool flag=true; + boost::test_tools::predicate_result res( false ); + boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(tolerance)); + for(unsigned int i=0;i<dim;++i){ + if(v1[i]==0.0){ + if(!boost::test_tools::check_is_small(v2[i],tolerance)){ + flag=false; + res.message() << "Value for " << labels[i] << " differs: ( " << v1[i] << " != " << v2[i] << " ). "; + } + }else if (v2[i]==0.0){ + if(!boost::test_tools::check_is_small(v1[i],tolerance)){ + flag=false; + res.message() << "Value for "<< labels[i] << " differs: ( " << v1[i] << " != " << v2[i] << " ). "; + } + }else{ + if(!close_test(v1[i],v2[i])){ + flag=false; + res.message() << "Value for " << labels[i] << " differs: ( " << v1[i] << " != " << v2[i] << " ). "; + } + } + } + if(flag){ + return true; + }else{ + return res; + } +} + +boost::test_tools::predicate_result vec2_is_close(const geom::Vec2& v1, + const geom::Vec2& v2, + Real tolerance=geom::EPSILON) +{ + return vec_is_close<geom::Vec2>(v1,v2,tolerance,2); +} + +boost::test_tools::predicate_result vec3_is_close(const geom::Vec3& v1, + const geom::Vec3& v2, + Real tolerance=geom::EPSILON) +{ + return vec_is_close<geom::Vec3>(v1,v2,tolerance,3); +} + +boost::test_tools::predicate_result vec4_is_close(const geom::Vec4& v1, + const geom::Vec4& v2, + Real tolerance=geom::EPSILON) +{ + return vec_is_close<geom::Vec4>(v1,v2,tolerance,4); +} + +template<class M> +boost::test_tools::predicate_result mat_is_close(const M& m1, const M& m2, + Real tolerance, + unsigned int dim) +{ + bool flag=true; + boost::test_tools::predicate_result res( false ); + boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(tolerance)); + for(unsigned int i=0;i<dim;++i){ + for(unsigned int j=0;j<dim;++j){ + if(m1(i,j)==0.0){ + if(!boost::test_tools::check_is_small(m2(i,j),tolerance)){ + flag=false; + res.message() << "Value for (" << i << "," << j << ") differs: (" << m1(i,j) << "!=" << m2(i,j) << "). "; + } + }else if (m2(i,j)==0.0){ + if(!boost::test_tools::check_is_small(m1(i,j),tolerance)){ + flag=false; + res.message() << "Value for (" << i << "," << j << ") differs: (" << m1(i,j) << "!=" << m2(i,j) << "). "; + } + }else{ + if(!close_test(m1(i,j),m2(i,j))){ + flag=false; + res.message() << "Value for (" << i << "," << j << ") differs: (" << m1(i,j) << "!=" << m2(i,j) << "). "; + } + } + } + } + if(flag){ + return true; + }else{ + return res; + } +} + +boost::test_tools::predicate_result mat2_is_close(const geom::Mat2& m1, + const geom::Mat2& m2, + Real tolerance=geom::EPSILON) +{ + return mat_is_close<geom::Mat2>(m1,m2,tolerance,2); +} + +boost::test_tools::predicate_result mat3_is_close(const geom::Mat3& m1, + const geom::Mat3& m2, + Real tolerance=geom::EPSILON) +{ + return mat_is_close<geom::Mat3>(m1,m2,tolerance,3); +} + +boost::test_tools::predicate_result mat4_is_close(const geom::Mat4& m1, + const geom::Mat4& m2, + Real tolerance=geom::EPSILON) +{ + return mat_is_close<geom::Mat4>(m1,m2,tolerance,4); +} + +#endif diff --git a/modules/mol/base/tests/test_entity.cc b/modules/mol/base/tests/test_entity.cc index 646b75f74e2b3f4b1e892cb4a6033cca5f2e5db1..1bf5a2bba8550420786b9e19db640d0170869c7d 100644 --- a/modules/mol/base/tests/test_entity.cc +++ b/modules/mol/base/tests/test_entity.cc @@ -20,6 +20,7 @@ * Authors: Marco Biasini, Juergen Haas */ +#include <ost/geom/vec_mat_predicates.hh> #include <ost/mol/chem_class.hh> #include <ost/mol/mol.hh> #include <cmath> @@ -27,20 +28,13 @@ #include <boost/test/unit_test.hpp> #define CHECK_TRANSFORMED_ATOM_POSITION(ATOM,TARGET) \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetPos()[0]-TARGET[0])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetPos()[1]-TARGET[1])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetPos()[2]-TARGET[2])),0.000001); + BOOST_CHECK(vec3_is_close(ATOM.GetPos(), TARGET)) #define CHECK_ORIGINAL_ATOM_POSITION(ATOM,TARGET) \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetOriginalPos()[0]-TARGET[0])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetOriginalPos()[1]-TARGET[1])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetOriginalPos()[2]-TARGET[2])),0.000001); + BOOST_CHECK(vec3_is_close(ATOM.GetOriginalPos(), TARGET)) #define CHECK_ALTERNATE_ATOM_POSITION(ATOM,TARGET,GROUP) \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetAltPos(GROUP)[0]-TARGET[0])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetAltPos(GROUP)[1]-TARGET[1])),0.000001); \ - BOOST_CHECK_SMALL(static_cast<double>(std::fabs(ATOM.GetAltPos(GROUP)[2]-TARGET[2])),0.000001); - + BOOST_CHECK(vec3_is_close(ATOM.GetAltPos(GROUP), TARGET)) using namespace ost; using namespace ost::mol; diff --git a/modules/mol/base/tests/test_residue.cc b/modules/mol/base/tests/test_residue.cc index 3451f6f5bfc001e7bc23aa4458c602dbb8bf3ff1..351723b1caf714d002ad4d6ed0c70fa59abb6c00 100644 --- a/modules/mol/base/tests/test_residue.cc +++ b/modules/mol/base/tests/test_residue.cc @@ -48,7 +48,6 @@ BOOST_AUTO_TEST_CASE(test_in_sequence) BOOST_AUTO_TEST_CASE(test_res_index_bzdng227) { - std::cout << "HERE" << std::endl; EntityHandle eh=CreateEntity(); XCSEditor e=eh.EditXCS(); ChainHandle ch1=e.InsertChain("A");