From 52a0650cd2e075d0e250b52da017986f57a054a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 1 Jun 2019 13:14:25 +0200 Subject: [PATCH] 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. --- src/python/magnum/math.matrix.h | 8 ++++++++ src/python/magnum/test/test_math.py | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/python/magnum/math.matrix.h b/src/python/magnum/math.matrix.h index 3db3324..f8b4ae1 100644 --- a/src/python/magnum/math.matrix.h +++ b/src/python/magnum/math.matrix.h @@ -558,6 +558,10 @@ template void matrices( static_cast(Math::Matrix3::*)() const>(&Math::Matrix3::up), [](Math::Matrix3& self, const Math::Vector2& value) { self.up() = value; }, "Up-pointing 2D vector") + .def_property("_translation", // TODO + static_cast(Math::Matrix3::*)() const>(&Math::Matrix3::translation), + [](Math::Matrix3& self, const Math::Vector2& 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 void matrices( static_cast(Math::Matrix4::*)() const>(&Math::Matrix4::backward), [](Math::Matrix4& self, const Math::Vector3& value) { self.backward() = value; }, "Backward-pointing 3D vector") + .def_property("_translation", // TODO + static_cast(Math::Matrix4::*)() const>(&Math::Matrix4::translation), + [](Math::Matrix4& self, const Math::Vector3& 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. */ diff --git a/src/python/magnum/test/test_math.py b/src/python/magnum/test/test_math.py index 5232816..d672b3a 100644 --- a/src/python/magnum/test/test_math.py +++ b/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(),