Skip to content
Snippets Groups Projects
Commit 5a58c032 authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

fixed missing geom vec/mat py data wrapper

parent b2e54770
No related branches found
No related tags found
No related merge requests found
......@@ -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)
;
}
......@@ -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)
;
}
......@@ -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)
;
}
......@@ -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>())
......
......@@ -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);
......
......@@ -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)
;
}
......@@ -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
......
#------------------------------------------------------------------------------
# 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()
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
#------------------------------------------------------------------------------
# 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment