Browse Source

python: expose new Quaternion.xyzw and wxyz properties.

next
Vladimír Vondruš 1 year ago
parent
commit
20700b7e3d
  1. 5
      doc/python/pages/changelog.rst
  2. 3
      src/python/magnum/math.cpp
  3. 2
      src/python/magnum/test/test_math.py

5
doc/python/pages/changelog.rst

@ -69,8 +69,9 @@ Changelog
- Exposed :ref:`Color3.from_xyz()`, :ref:`Color3.from_linear_rgb_int()`, - Exposed :ref:`Color3.from_xyz()`, :ref:`Color3.from_linear_rgb_int()`,
:ref:`Color3.to_xyz()`, :ref:`Color3.to_linear_rgb_int()` and equivalent :ref:`Color3.to_xyz()`, :ref:`Color3.to_linear_rgb_int()` and equivalent
APIs on :ref:`Color4` APIs on :ref:`Color4`
- Exposed new :ref:`Quaternion.rotation()`, :ref:`Quaternion.reflection()` - Exposed new :ref:`Quaternion.rotation()`, :ref:`Quaternion.reflection()`,
and :ref:`Quaternion.reflect_vector()` APIs :ref:`Quaternion.reflect_vector()`, :ref:`Quaternion.xyzw` and
:ref:`Quaternion.wxyz` APIs
- Exposed :ref:`gl.Context` and its platform-specific subclasses for EGL, WGL - Exposed :ref:`gl.Context` and its platform-specific subclasses for EGL, WGL
and GLX and GLX
- Exposed :ref:`gl.Framebuffer.attach_texture()` and missing sRGB, depth - Exposed :ref:`gl.Framebuffer.attach_texture()` and missing sRGB, depth

3
src/python/magnum/math.cpp

@ -33,6 +33,7 @@
#include <Magnum/Math/BitVector.h> #include <Magnum/Math/BitVector.h>
#include <Magnum/Math/Functions.h> #include <Magnum/Math/Functions.h>
#include <Magnum/Math/Quaternion.h> #include <Magnum/Math/Quaternion.h>
#include <Magnum/Math/Vector4.h>
#include "magnum/bootstrap.h" #include "magnum/bootstrap.h"
#include "magnum/math.h" #include "magnum/math.h"
@ -486,6 +487,8 @@ template<class T> void quaternion(py::module_& m, py::class_<T>& c) {
static_cast<typename T::Type(T::*)() const>(&T::scalar), static_cast<typename T::Type(T::*)() const>(&T::scalar),
[](T& self, typename T::Type value) { self.scalar() = value; }, [](T& self, typename T::Type value) { self.scalar() = value; },
"Scalar part") "Scalar part")
.def_property_readonly("xyzw", &T::xyzw, "Quaternion components in a XYZW order")
.def_property_readonly("wxyz", &T::wxyz, "Quaternion components in a WXYZ order")
.def("__repr__", repr<T>, "Object representation"); .def("__repr__", repr<T>, "Object representation");
} }

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

@ -1558,6 +1558,8 @@ Matrix\\(2, 0, 0,
a.scalar = 4.0 a.scalar = 4.0
self.assertEqual(a.vector, Vector3(1.0, 2.0, 3.0)) self.assertEqual(a.vector, Vector3(1.0, 2.0, 3.0))
self.assertEqual(a.scalar, 4.0) self.assertEqual(a.scalar, 4.0)
self.assertEqual(a.xyzw, Vector4(1.0, 2.0, 3.0, 4.0))
self.assertEqual(a.wxyz, Vector4(4.0, 1.0, 2.0, 3.0))
self.assertEqual(a, Quaternion((1.0, 2.0, 3.0), 4.0)) self.assertEqual(a, Quaternion((1.0, 2.0, 3.0), 4.0))
def test_repr(self): def test_repr(self):

Loading…
Cancel
Save