diff --git a/modules/mol/base/src/transform.cc b/modules/mol/base/src/transform.cc index c1ffbff6b8a34bf6016d01fba72deeba8a2f4fdb..b1b39250906bce36119817f04a1dbb3045bcd7c8 100644 --- a/modules/mol/base/src/transform.cc +++ b/modules/mol/base/src/transform.cc @@ -49,6 +49,7 @@ void Transform::SetMatrix(const Mat4& m) { tm_=m; ttm_ = Transpose(tm_); + update_components(); } Mat4 Transform::GetTransposedMatrix() const @@ -196,6 +197,15 @@ void Transform::update_tm() ttm_ = Transpose(tm_); } +void Transform::update_components() +{ + rot_ = tm_.ExtractRotation(); + cen_ = tm_.ExtractTranslation(); + trans_[0] = tm_(3,0); + trans_[1] = tm_(3,1); + trans_[2] = tm_(3,2); +} + #if(OST_INFO_ENABLED) Transform TransformFromInfo(const info::InfoGroup& group) { diff --git a/modules/mol/base/src/transform.hh b/modules/mol/base/src/transform.hh index 1ed33135e1ca1287f0e2c9debc151aeacca069cc..dbbd8ace687830ab319e549a615855fef4b08cb8 100644 --- a/modules/mol/base/src/transform.hh +++ b/modules/mol/base/src/transform.hh @@ -82,6 +82,7 @@ private: geom::Mat4 ttm_; void update_tm(); + void update_components(); }; #if(OST_INFO_ENABLED) diff --git a/modules/mol/base/tests/CMakeLists.txt b/modules/mol/base/tests/CMakeLists.txt index 5085b0b10b257fab18361001a1cb7a55b796769d..c29dc6adfe3d5ec1bbe2e85a5a587940b35848c2 100644 --- a/modules/mol/base/tests/CMakeLists.txt +++ b/modules/mol/base/tests/CMakeLists.txt @@ -10,6 +10,7 @@ set(OST_MOL_BASE_UNIT_TESTS test_query.cc test_surface.cc test_residue.cc + test_transform.cc test_view.cc test_view_op.cc tests.cc diff --git a/modules/mol/base/tests/test_transform.cc b/modules/mol/base/tests/test_transform.cc new file mode 100644 index 0000000000000000000000000000000000000000..5c950acc5a170448290be09dde71d76fad5e8e66 --- /dev/null +++ b/modules/mol/base/tests/test_transform.cc @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// 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 +//------------------------------------------------------------------------------ +/* + Authors: Tobias Schmidt + */ + #define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> +#include <boost/test/auto_unit_test.hpp> +#include <ost/mol/mol.hh> +#include <ost/mol/transform.hh> +#include <ost/geom/geom.hh> + +using namespace ost; +using namespace ost::mol; + +BOOST_AUTO_TEST_SUITE( mol_base ); + +BOOST_AUTO_TEST_CASE(test_transform) +{ + Transform tf; + + BOOST_CHECK_EQUAL(tf.GetMatrix(), geom::Mat4()); + BOOST_CHECK_EQUAL(tf.GetRot(), geom::Mat3()); + BOOST_CHECK_EQUAL(tf.GetTrans(), geom::Vec3()); + BOOST_CHECK_EQUAL(tf.GetCenter(), geom::Vec3()); + + geom::Mat4 mat = geom::Mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); + tf.SetMatrix(mat); + BOOST_CHECK_EQUAL(tf.GetMatrix(), mat); + BOOST_CHECK_EQUAL(tf.GetRot(), geom::Mat3(1,2,3,5,6,7,9,10,11)); + BOOST_CHECK_EQUAL(tf.GetCenter(), geom::Vec3(4,8,12)); + BOOST_CHECK_EQUAL(tf.GetTrans(), geom::Vec3(13,14,15)); +} + +BOOST_AUTO_TEST_SUITE_END();