diff --git a/doc/python/magnum.math.rst b/doc/python/magnum.math.rst index bf76350e..449b4e34 100644 --- a/doc/python/magnum.math.rst +++ b/doc/python/magnum.math.rst @@ -192,6 +192,9 @@ - All vector and matrix classes implement :py:`len()`, which is used instead of e.g. :dox:`Math::Vector::Size`. Works on both classes and instances. + - :dox:`Math::Matrix3::from()` / :dox:`Math::Matrix4::from()` are named + :ref:`Matrix3.from_()` / :ref:`Matrix4.from_()` because :py:`from` is + a Python keyword and thus can't be used as a name. - :cpp:`Math::gather()` and :cpp:`Math::scatter()` operations are implemented as real swizzles: diff --git a/doc/python/pages/changelog.rst b/doc/python/pages/changelog.rst index d7433110..acdb9441 100644 --- a/doc/python/pages/changelog.rst +++ b/doc/python/pages/changelog.rst @@ -35,6 +35,10 @@ Changelog `Changes since 2020.06`_ ======================== +- Renamed :py:`Matrix3.from()` / :py:`Matrix4.from()` to :ref:`Matrix3.from_()` + / :ref:`Matrix4.from_()` because :py:`from` is a Python keyword and it + would be silly to have to write :py:`getattr(Matrix4, 'from')` just to use + these APIs - Exposed :ref:`gl.Renderer.set_blend_function()`, :ref:`gl.Renderer.set_blend_equation()` and related enums (see :gh:`mosra/magnum-bindings#9`) - Exposed :ref:`gl.Renderer.Feature.CLIP_DISTANCEn ` diff --git a/src/python/magnum/math.matrix.h b/src/python/magnum/math.matrix.h index 0709f3e1..7baba7a8 100644 --- a/src/python/magnum/math.matrix.h +++ b/src/python/magnum/math.matrix.h @@ -560,7 +560,7 @@ template void matrices( "2D shearning matrix along the Y axis", py::arg("amount")) .def_static("projection", &Math::Matrix3::projection, "2D projection matrix", py::arg("size")) - .def_static("from", static_cast(*)(const Math::Matrix2x2&, const Math::Vector2&)>(&Math::Matrix3::from), + .def_static("from_", static_cast(*)(const Math::Matrix2x2&, const Math::Vector2&)>(&Math::Matrix3::from), "Create a matrix from a rotation/scaling part and a translation part", py::arg("rotation_scaling"), py::arg("translation")) .def(py::init&, const Math::Vector3&, const Math::Vector3&>(), @@ -760,7 +760,7 @@ Overloaded function. "3D off-center perspective projection matrix", py::arg("bottom_left"), py::arg("top_right"), py::arg("near"), py::arg("far")) .def_static("look_at", &Math::Matrix4::lookAt, "Matrix oriented towards a specific point", py::arg("eye"), py::arg("target"), py::arg("up")) - .def_static("from", static_cast(*)(const Math::Matrix3x3&, const Math::Vector3&)>(&Math::Matrix4::from), + .def_static("from_", static_cast(*)(const Math::Matrix3x3&, const Math::Vector3&)>(&Math::Matrix4::from), "Create a matrix from a rotation/scaling part and a translation part", py::arg("rotation_scaling"), py::arg("translation")) .def(py::init&, const Math::Vector4&, const Math::Vector4&, const Math::Vector4&>(), diff --git a/src/python/magnum/test/test_math.py b/src/python/magnum/test/test_math.py index a1804f83..ac08c435 100644 --- a/src/python/magnum/test/test_math.py +++ b/src/python/magnum/test/test_math.py @@ -619,6 +619,22 @@ def test_init_tuple_of_tuples(self): Vector4(13.0, 14.0, 15.0, 16.0))) def test_static_methods(self): + a = Matrix3.from_(Matrix2x2((1.0, 2.0), + (4.0, 5.0)), + Vector2(7.0, 8.0)) + self.assertEqual(a, Matrix3(Vector3(1.0, 2.0, 0.0), + Vector3(4.0, 5.0, 0.0), + Vector3(7.0, 8.0, 1.0))) + + a = Matrix4.from_(Matrix3x3((1.0, 2.0, 3.0), + (5.0, 6.0, 7.0), + (9.0, 10.0, 11.0)), + Vector3(13.0, 14.0, 15.0)) + self.assertEqual(a, Matrix4x4(Vector4(1.0, 2.0, 3.0, 0.0), + Vector4(5.0, 6.0, 7.0, 0.0), + Vector4(9.0, 10.0, 11.0, 0.0), + Vector4(13.0, 14.0, 15.0, 1.0))) + a = Matrix3x4.from_diagonal((1.0, 2.0, 3.0)) self.assertEqual(a.diagonal(), (1.0, 2.0, 3.0)) self.assertEqual(a, Matrix3x4((1.0, 0.0, 0.0, 0.0),