diff --git a/modules/geom/pymod/export_mat2.cc b/modules/geom/pymod/export_mat2.cc index fa1e382c9c62b7bc7ef789303d41cc88bcca6316..8905a47466622acc71b60f69ad1210dd11a06cba 100644 --- a/modules/geom/pymod/export_mat2.cc +++ b/modules/geom/pymod/export_mat2.cc @@ -33,6 +33,16 @@ String mat2_repr(const geom::Mat2& m) { << m(1,0) << ", " << m(1,1) << ")"; return ss.str(); } + +list mat2_data(const geom::Mat2& m) +{ + list nrvo; + for(size_t k=0;k<4;++k) { + nrvo.append(m.Data()[k]); + } + return nrvo; +} + void export_Mat2() { using namespace geom; @@ -54,5 +64,6 @@ void export_Mat2() .def(self_ns::str(self)) .def("__getitem__",Mat2_getitem) .def("__setitem__",Mat2_setitem) + .add_property("data",mat2_data) ; } diff --git a/modules/geom/pymod/export_mat3.cc b/modules/geom/pymod/export_mat3.cc index 4d86381a4db04b747f6834f6e56d5b3890c0de3c..bf92d2e4e5c11f34ad692953f913902237206c4d 100644 --- a/modules/geom/pymod/export_mat3.cc +++ b/modules/geom/pymod/export_mat3.cc @@ -63,6 +63,14 @@ String mat3_repr(const geom::Mat3& m) return ss.str(); } +list mat3_data(const geom::Mat3& m) +{ + list nrvo; + for(size_t k=0;k<9;++k) { + nrvo.append(m.Data()[k]); + } + return nrvo; +} void export_Mat3() { @@ -88,6 +96,7 @@ void export_Mat3() .def("__setitem__",Mat3_setitem) .def("__setitem__",Mat3_setslice) .def("GetCol", &Mat3::GetCol) - .def("GetRow", &Mat3::GetRow) + .def("GetRow", &Mat3::GetRow) + .add_property("data",mat3_data) ; } diff --git a/modules/geom/pymod/export_mat4.cc b/modules/geom/pymod/export_mat4.cc index 7a5805dc6c45305fcebc5742428065d9d49f2afe..3bb555b2cfe0783346c0cf3de9a3c1626dc7fa36 100644 --- a/modules/geom/pymod/export_mat4.cc +++ b/modules/geom/pymod/export_mat4.cc @@ -85,6 +85,14 @@ String mat4_repr(const geom::Mat4& m) { return ss.str(); } +list mat4_data(const geom::Mat4& m) +{ + list nrvo; + for(size_t k=0;k<16;++k) { + nrvo.append(m.Data()[k]); + } + return nrvo; +} void export_Mat4() { @@ -115,5 +123,6 @@ void export_Mat4() .def("PasteRotation",&Mat4::PasteRotation) .def("ExtractTranslation",&Mat4::ExtractTranslation) .def("PasteTranslation",&Mat4::PasteTranslation) + .add_property("data",mat4_data) ; } diff --git a/modules/geom/pymod/export_vec2.cc b/modules/geom/pymod/export_vec2.cc index eec194418d780663aab9ecfe8e09388067c7f28f..456d26db370fdad9e364cfaa9d98fa74a4dd28d1 100644 --- a/modules/geom/pymod/export_vec2.cc +++ b/modules/geom/pymod/export_vec2.cc @@ -35,6 +35,15 @@ String vec2_repr(const geom::Vec2& v) return ss.str(); } +list vec2_data(const geom::Vec2& v) +{ + list nrvo; + for(size_t k=0;k<2;++k) { + nrvo.append(v.Data()[k]); + } + return nrvo; +} + void export_Vec2() { using namespace geom; @@ -66,6 +75,7 @@ void export_Vec2() .def("GetY", &Vec2::GetY) .add_property("x", &Vec2::GetX, &Vec2::SetX) .add_property("y", &Vec2::GetY, &Vec2::SetY) + .add_property("data",vec2_data) ; class_<Vec2List>("Vec2List", init<>()) .def(vector_indexing_suite<Vec2List>()) diff --git a/modules/geom/pymod/export_vec3.cc b/modules/geom/pymod/export_vec3.cc index 623671de519d14f73d7843115a5d5b18e74c8da8..6ac28a6147e726f25d229da3ad100472ad349600 100644 --- a/modules/geom/pymod/export_vec3.cc +++ b/modules/geom/pymod/export_vec3.cc @@ -38,6 +38,15 @@ String vec3_repr(const geom::Vec3& v) return ss.str(); } +list vec3_data(const geom::Vec3& v) +{ + list nrvo; + for(size_t k=0;k<3;++k) { + nrvo.append(v.Data()[k]); + } + return nrvo; +} + void export_Vec3() { using namespace geom; @@ -71,6 +80,7 @@ void export_Vec3() .add_property("x", &Vec3::GetX, &Vec3::SetX) .add_property("y", &Vec3::GetY, &Vec3::SetY) .add_property("z", &Vec3::GetZ, &Vec3::SetZ) + .add_property("data",vec3_data) ; def("Normalize", &NormalizeV3); diff --git a/modules/geom/pymod/export_vec4.cc b/modules/geom/pymod/export_vec4.cc index bb3d80f90cc62205ec40e6fd22a736d05c0b1d20..4ebe1bbd108c95db0709622f544b9d79ee285c55 100644 --- a/modules/geom/pymod/export_vec4.cc +++ b/modules/geom/pymod/export_vec4.cc @@ -34,6 +34,15 @@ String vec4_repr(const geom::Vec4& v) return ss.str(); } +list vec4_data(const geom::Vec4& v) +{ + list nrvo; + for(size_t k=0;k<4;++k) { + nrvo.append(v.Data()[k]); + } + return nrvo; +} + void export_Vec4() { using namespace geom; @@ -61,6 +70,11 @@ void export_Vec4() .def(self_ns::str(self)) .def("__getitem__",Vec4_getitem) .def("__setitem__",Vec4_setitem) + .add_property("x", &Vec4::GetX, &Vec4::SetX) + .add_property("y", &Vec4::GetY, &Vec4::SetY) + .add_property("z", &Vec4::GetZ, &Vec4::SetZ) + .add_property("w", &Vec4::GetW, &Vec4::SetW) + .add_property("data",vec4_data) ; } diff --git a/modules/geom/tests/CMakeLists.txt b/modules/geom/tests/CMakeLists.txt index 7a7dace6b3ed006ba13997889693a4b3910949f8..42d7f4c43b393411b5c7edeaecec9bc1e8bc2ca4 100644 --- a/modules/geom/tests/CMakeLists.txt +++ b/modules/geom/tests/CMakeLists.txt @@ -11,7 +11,7 @@ set(GEOM_UNITTESTS test_vec3.cc test_vec4.cc tests.cc - test_repr.py + test_geom.py ) ost_unittest(MODULE geom diff --git a/modules/geom/tests/test_geom.py b/modules/geom/tests/test_geom.py new file mode 100644 index 0000000000000000000000000000000000000000..e25081bf1f0f305cf7928bd897566ade46c9c9e3 --- /dev/null +++ b/modules/geom/tests/test_geom.py @@ -0,0 +1,84 @@ +#------------------------------------------------------------------------------ +# 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 +#------------------------------------------------------------------------------ + +import unittest +if __name__== '__main__': + import sys + sys.path.insert(0,"../../../stage/lib64/openstructure/") + sys.path.insert(0,"../../../stage/lib/openstructure/") + +import ost +import ost.geom as geom + +class TestGeom(unittest.TestCase): + def runTest(self): + self.test_repr() + self.test_data() + + def test_repr(self): + v=geom.Vec2(1,2) + v2=eval(repr(v)) + self.assertTrue(geom.Equal(v, v2)) + + v=geom.Vec3(1,2,3) + v2=eval(repr(v)) + self.assertTrue(geom.Equal(v, v2)) + + v=geom.Vec4(1,2,3,4) + v2=eval(repr(v)) + self.assertTrue(geom.Equal(v, v2)) + + m=geom.Mat2(1,2,3,4) + m2=eval(repr(m)) + self.assertTrue(geom.Equal(m, m2)) + + m=geom.Mat3(1,2,3,4,5,6,7,8,9) + m2=eval(repr(m)) + self.assertTrue(geom.Equal(m, m2)) + + m=geom.Mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) + m2=eval(repr(m)) + self.assertTrue(geom.Equal(m, m2)) + + def test_data(self): + self.assertEqual(geom.Vec2(1,2).data,[1,2]) + self.assertEqual(geom.Vec3(1,2,3).data,[1,2,3]) + self.assertEqual(geom.Vec4(1,2,3,4).data,[1,2,3,4]) + self.assertEqual(geom.Mat2(1,2, + 3,4).data, + [1,2, + 3,4]) + self.assertEqual(geom.Mat3(1,2,3, + 4,5,6, + 7,8,9).data, + [1,2,3, + 4,5,6, + 7,8,9]) + self.assertEqual(geom.Mat4(1,2,3,4, + 5,6,7,8, + 9,10,11,12, + 13,14,15,16).data, + [1,2,3,4, + 5,6,7,8, + 9,10,11,12, + 13,14,15,16]) + +if __name__== '__main__': + unittest.main() + diff --git a/modules/geom/tests/test_repr.py b/modules/geom/tests/test_repr.py deleted file mode 100644 index e69358f20f783c7f8b731de7f13deb569105a0fa..0000000000000000000000000000000000000000 --- a/modules/geom/tests/test_repr.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest -from ost import geom - -class TestRepr(unittest.TestCase): - def testReprVec2(self): - v=geom.Vec2(1,2) - v2=eval(repr(v)) - assert geom.Equal(v, v2) - - def testReprVec3(self): - v=geom.Vec3(1,2,3) - v2=eval(repr(v)) - assert geom.Equal(v, v2) - - def testReprVec4(self): - v=geom.Vec4(1,2,3,4) - v2=eval(repr(v)) - assert geom.Equal(v, v2) - - def testReprMat2(self): - m=geom.Mat2(1,2,3,4) - m2=eval(repr(m)) - assert geom.Equal(m, m2) - - def testReprMat3(self): - m=geom.Mat3(1,2,3,4,5,6,7,8,9) - m2=eval(repr(m)) - assert geom.Equal(m, m2) - - def testReprMat4(self): - m=geom.Mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) - m2=eval(repr(m)) - assert geom.Equal(m, m2) - -if __name__ == "__main__": - try: - unittest.main() - except Exception, e: - print e \ No newline at end of file diff --git a/modules/gfx/tests/test_gfx.py b/modules/gfx/tests/test_gfx.py index 362535b28229333910947f350269ef41bcdf5e82..25c0df13baf0c092f363714c8a1101997100d95f 100644 --- a/modules/gfx/tests/test_gfx.py +++ b/modules/gfx/tests/test_gfx.py @@ -1,3 +1,22 @@ +#------------------------------------------------------------------------------ +# 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 +#------------------------------------------------------------------------------ + import unittest if __name__== '__main__': import sys