Browse Source

python: apparently I can't name functions from(), hah.

pull/11/head
Vladimír Vondruš 5 years ago
parent
commit
cbb5358efd
  1. 3
      doc/python/magnum.math.rst
  2. 4
      doc/python/pages/changelog.rst
  3. 4
      src/python/magnum/math.matrix.h
  4. 16
      src/python/magnum/test/test_math.py

3
doc/python/magnum.math.rst

@ -192,6 +192,9 @@
- All vector and matrix classes implement :py:`len()`, which is used - All vector and matrix classes implement :py:`len()`, which is used
instead of e.g. :dox:`Math::Vector::Size`. Works on both classes instead of e.g. :dox:`Math::Vector::Size`. Works on both classes
and instances. 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 - :cpp:`Math::gather()` and :cpp:`Math::scatter()` operations are
implemented as real swizzles: implemented as real swizzles:

4
doc/python/pages/changelog.rst

@ -35,6 +35,10 @@ Changelog
`Changes since 2020.06`_ `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()`, - Exposed :ref:`gl.Renderer.set_blend_function()`,
:ref:`gl.Renderer.set_blend_equation()` and related enums (see :gh:`mosra/magnum-bindings#9`) :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>` - Exposed :ref:`gl.Renderer.Feature.CLIP_DISTANCEn <gl.Renderer.Feature.CLIP_DISTANCE0>`

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

@ -560,7 +560,7 @@ template<class T> void matrices(
"2D shearning matrix along the Y axis", py::arg("amount")) "2D shearning matrix along the Y axis", py::arg("amount"))
.def_static("projection", &Math::Matrix3<T>::projection, .def_static("projection", &Math::Matrix3<T>::projection,
"2D projection matrix", py::arg("size")) "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", "Create a matrix from a rotation/scaling part and a translation part",
py::arg("rotation_scaling"), py::arg("translation")) py::arg("rotation_scaling"), py::arg("translation"))
.def(py::init<const Math::Vector3<T>&, const Math::Vector3<T>&, const Math::Vector3<T>&>(), .def(py::init<const Math::Vector3<T>&, const Math::Vector3<T>&, const Math::Vector3<T>&>(),
@ -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")) "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, .def_static("look_at", &Math::Matrix4<T>::lookAt,
"Matrix oriented towards a specific point", py::arg("eye"), py::arg("target"), py::arg("up")) "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", "Create a matrix from a rotation/scaling part and a translation part",
py::arg("rotation_scaling"), py::arg("translation")) 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>&>(), .def(py::init<const Math::Vector4<T>&, const Math::Vector4<T>&, const Math::Vector4<T>&, const Math::Vector4<T>&>(),

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

@ -619,6 +619,22 @@ class Matrix(unittest.TestCase):
Vector4(13.0, 14.0, 15.0, 16.0))) Vector4(13.0, 14.0, 15.0, 16.0)))
def test_static_methods(self): 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)) a = Matrix3x4.from_diagonal((1.0, 2.0, 3.0))
self.assertEqual(a.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), self.assertEqual(a, Matrix3x4((1.0, 0.0, 0.0, 0.0),

Loading…
Cancel
Save