Browse Source

python: expose at least underscored Matrix[34]._translation property.

Still need to figure out a way to expose the property with the same name
as a static function, but this has to suffice for now.
pull/2/head
Vladimír Vondruš 7 years ago
parent
commit
52a0650cd2
  1. 8
      src/python/magnum/math.matrix.h
  2. 12
      src/python/magnum/test/test_math.py

8
src/python/magnum/math.matrix.h

@ -558,6 +558,10 @@ template<class T> void matrices(
static_cast<Math::Vector2<T>(Math::Matrix3<T>::*)() const>(&Math::Matrix3<T>::up),
[](Math::Matrix3<T>& self, const Math::Vector2<T>& value) { self.up() = value; },
"Up-pointing 2D vector")
.def_property("_translation", // TODO
static_cast<Math::Vector2<T>(Math::Matrix3<T>::*)() const>(&Math::Matrix3<T>::translation),
[](Math::Matrix3<T>& self, const Math::Vector2<T>& value) { self.translation() = value; },
"2D translation part of the matrix")
/* Static/member scaling(). Pybind doesn't support that natively, so
we create a scaling(*args, **kwargs) and dispatch ourselves. */
@ -688,6 +692,10 @@ template<class T> void matrices(
static_cast<Math::Vector3<T>(Math::Matrix4<T>::*)() const>(&Math::Matrix4<T>::backward),
[](Math::Matrix4<T>& self, const Math::Vector3<T>& value) { self.backward() = value; },
"Backward-pointing 3D vector")
.def_property("_translation", // TODO
static_cast<Math::Vector3<T>(Math::Matrix4<T>::*)() const>(&Math::Matrix4<T>::translation),
[](Math::Matrix4<T>& self, const Math::Vector3<T>& value) { self.translation() = value; },
"3D translation part of the matrix")
/* Static/member scaling(). Pybind doesn't support that natively, so
we create a scaling(*args, **kwargs) and dispatch ourselves. */

12
src/python/magnum/test/test_math.py

@ -649,15 +649,15 @@ class Matrix3_(unittest.TestCase):
self.assertEqual(c.scaling(), Vector2(1.0, 2.0))
def test_properties(self):
a = Matrix3.rotation(Deg(45.0))
a = Matrix3.translation(Vector2.y_axis(-5.0))@Matrix3.rotation(Deg(45.0))
self.assertEqual(a.right, Vector2(0.707107, 0.707107))
self.assertEqual(a.up, Vector2(-0.707107, 0.707107))
# TODO: a.translation
self.assertEqual(a._translation, Vector2.y_axis(-5.0)) # TODO
a.right = Vector2.x_axis(2.0)
a.up = -Vector2.y_axis()
a._translation = Vector2(0.0) # TODO
self.assertEqual(a, Matrix3.from_diagonal((2.0, -1.0, 1.0)))
# TODO: a.translation
def test_methods(self):
self.assertEqual(Matrix3.rotation(Deg(45.0)).transposed(),
@ -750,17 +750,17 @@ class Matrix4_(unittest.TestCase):
self.assertEqual(c.scaling(), Vector3(1.0, 2.0, 3.5))
def test_properties(self):
a = Matrix4.rotation_z(Deg(45.0))
a = Matrix4.translation(Vector3.y_axis(-5.0))@Matrix4.rotation_z(Deg(45.0))
self.assertEqual(a.right, Vector3(0.707107, 0.707107, 0.0))
self.assertEqual(a.up, Vector3(-0.707107, 0.707107, 0.0))
self.assertEqual(a.backward, Vector3(0.0, 0.0, 1.0))
# TODO: a.translation
self.assertEqual(a._translation, Vector3.y_axis(-5.0)) # TODO
a.right = Vector3.x_axis(3.0)
a.up = -Vector3.y_axis()
a.backward = Vector3.z_axis(2.0)
a._translation = Vector3(0.0) # TODO
self.assertEqual(a, Matrix4.from_diagonal((3.0, -1.0, 2.0, 1.0)))
# TODO: a.translation
def test_methods(self):
self.assertEqual(Matrix4.rotation_y(Deg(45.0)).transposed(),

Loading…
Cancel
Save