From af74ab96629150a399e783f3447478229dfb8bcd Mon Sep 17 00:00:00 2001 From: Tobias Schmidt <tobias.schmidt@unibas.ch> Date: Mon, 11 Jun 2012 19:11:07 +0200 Subject: [PATCH] fix for mol::Transform::SetMatrix setting the matrix now updates rotation, translation and center components and thus fixes the GetRot, GetTrans, GetCenter functions --- modules/mol/base/src/transform.cc | 10 +++++ modules/mol/base/src/transform.hh | 1 + modules/mol/base/tests/CMakeLists.txt | 1 + modules/mol/base/tests/test_transform.cc | 51 ++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 modules/mol/base/tests/test_transform.cc diff --git a/modules/mol/base/src/transform.cc b/modules/mol/base/src/transform.cc index c1ffbff6b..b1b392509 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 1ed33135e..dbbd8ace6 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 5085b0b10..c29dc6adf 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 000000000..5c950acc5 --- /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(); -- GitLab