From 5a58c0327b919ebce0a3d28bde29f2a2def97dd0 Mon Sep 17 00:00:00 2001
From: Ansgar Philippsen <ansgar.philippsen@gmail.com>
Date: Wed, 10 Aug 2011 20:15:00 -0400
Subject: [PATCH] fixed missing geom vec/mat py data wrapper

---
 modules/geom/pymod/export_mat2.cc | 11 ++++
 modules/geom/pymod/export_mat3.cc | 11 +++-
 modules/geom/pymod/export_mat4.cc |  9 ++++
 modules/geom/pymod/export_vec2.cc | 10 ++++
 modules/geom/pymod/export_vec3.cc | 10 ++++
 modules/geom/pymod/export_vec4.cc | 14 ++++++
 modules/geom/tests/CMakeLists.txt |  2 +-
 modules/geom/tests/test_geom.py   | 84 +++++++++++++++++++++++++++++++
 modules/geom/tests/test_repr.py   | 39 --------------
 modules/gfx/tests/test_gfx.py     | 19 +++++++
 10 files changed, 168 insertions(+), 41 deletions(-)
 create mode 100644 modules/geom/tests/test_geom.py
 delete mode 100644 modules/geom/tests/test_repr.py

diff --git a/modules/geom/pymod/export_mat2.cc b/modules/geom/pymod/export_mat2.cc
index fa1e382c9..8905a4746 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 4d86381a4..bf92d2e4e 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 7a5805dc6..3bb555b2c 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 eec194418..456d26db3 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 623671de5..6ac28a614 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 bb3d80f90..4ebe1bbd1 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 7a7dace6b..42d7f4c43 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 000000000..e25081bf1
--- /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 e69358f20..000000000
--- 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 362535b28..25c0df13b 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
-- 
GitLab