Skip to content

Commit

Permalink
python: apparently I can't name functions from(), hah.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Feb 5, 2021
1 parent a2d16c1 commit cbb5358
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/python/magnum.math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 4 additions & 0 deletions doc/python/pages/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gl.Renderer.Feature.CLIP_DISTANCE0>`
Expand Down
4 changes: 2 additions & 2 deletions src/python/magnum/math.matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ template<class T> void matrices(
"2D shearning matrix along the Y axis", py::arg("amount"))
.def_static("projection", &Math::Matrix3<T>::projection,
"2D projection matrix", py::arg("size"))
.def_static("from", static_cast<Math::Matrix3<T>(*)(const Math::Matrix2x2<T>&, const Math::Vector2<T>&)>(&Math::Matrix3<T>::from),
.def_static("from_", static_cast<Math::Matrix3<T>(*)(const Math::Matrix2x2<T>&, const Math::Vector2<T>&)>(&Math::Matrix3<T>::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<T>&, const Math::Vector3<T>&, const Math::Vector3<T>&>(),
Expand Down Expand Up @@ -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<T>::lookAt,
"Matrix oriented towards a specific point", py::arg("eye"), py::arg("target"), py::arg("up"))
.def_static("from", static_cast<Math::Matrix4<T>(*)(const Math::Matrix3x3<T>&, const Math::Vector3<T>&)>(&Math::Matrix4<T>::from),
.def_static("from_", static_cast<Math::Matrix4<T>(*)(const Math::Matrix3x3<T>&, const Math::Vector3<T>&)>(&Math::Matrix4<T>::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<T>&, const Math::Vector4<T>&, const Math::Vector4<T>&, const Math::Vector4<T>&>(),
Expand Down
16 changes: 16 additions & 0 deletions src/python/magnum/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit cbb5358

Please sign in to comment.