Browse Source

python: don't be lazy and name arguments in math APIs.

Otherwise can't reference them from docs, can't match the function
signatures from external docs...
next
Vladimír Vondruš 2 years ago
parent
commit
daa78626fe
  1. 12
      src/python/magnum/math.cpp
  2. 44
      src/python/magnum/math.matrix.h
  3. 6
      src/python/magnum/math.vectorfloat.cpp

12
src/python/magnum/math.cpp

@ -301,10 +301,10 @@ template<class T> void quaternion(py::module_& m, py::class_<T>& c) {
m m
.def("dot", static_cast<typename T::Type(*)(const T&, const T&)>(&Math::dot), .def("dot", static_cast<typename T::Type(*)(const T&, const T&)>(&Math::dot),
"Dot product between two quaternions") "Dot product between two quaternions")
.def("half_angle", [](const T& a, const T& b) { .def("half_angle", [](const T& normalizedA, const T& normalizedB) {
/** @todo switch back to angle() once it's reintroduced with the /** @todo switch back to angle() once it's reintroduced with the
correct output again */ correct output again */
return Radd(Math::halfAngle(a, b)); return Radd(Math::halfAngle(normalizedA, normalizedB));
}, "Angle between normalized quaternions", py::arg("normalized_a"), py::arg("normalized_b")) }, "Angle between normalized quaternions", py::arg("normalized_a"), py::arg("normalized_b"))
.def("lerp", static_cast<T(*)(const T&, const T&, typename T::Type)>(&Math::lerp), .def("lerp", static_cast<T(*)(const T&, const T&, typename T::Type)>(&Math::lerp),
"Linear interpolation of two quaternions", py::arg("normalized_a"), py::arg("normalized_b"), py::arg("t")) "Linear interpolation of two quaternions", py::arg("normalized_a"), py::arg("normalized_b"), py::arg("t"))
@ -320,9 +320,9 @@ template<class T> void quaternion(py::module_& m, py::class_<T>& c) {
/* Constructors */ /* Constructors */
.def_static("rotation", [](Radd angle, const Math::Vector3<typename T::Type>& axis) { .def_static("rotation", [](Radd angle, const Math::Vector3<typename T::Type>& axis) {
return T::rotation(Math::Rad<typename T::Type>(angle), axis); return T::rotation(Math::Rad<typename T::Type>(angle), axis);
}, "Rotation quaternion") }, "Rotation quaternion", py::arg("angle"), py::arg("normalized_axis"))
.def_static("from_matrix", &T::fromMatrix, .def_static("from_matrix", &T::fromMatrix,
"Create a quaternion from rotation matrix") "Create a quaternion from rotation matrix", py::arg("matrix"))
.def_static("zero_init", []() { .def_static("zero_init", []() {
return T{Math::ZeroInit}; return T{Math::ZeroInit};
}, "Construct a zero-initialized quaternion") }, "Construct a zero-initialized quaternion")
@ -404,9 +404,9 @@ template<class T> void quaternion(py::module_& m, py::class_<T>& c) {
.def("inverted_normalized", &T::invertedNormalized, .def("inverted_normalized", &T::invertedNormalized,
"Inverted normalized quaternion") "Inverted normalized quaternion")
.def("transform_vector", &T::transformVector, .def("transform_vector", &T::transformVector,
"Rotate a vector with a quaternion") "Rotate a vector with a quaternion", py::arg("vector"))
.def("transform_vector_normalized", &T::transformVectorNormalized, .def("transform_vector_normalized", &T::transformVectorNormalized,
"Rotate a vector with a normalized quaternion") "Rotate a vector with a normalized quaternion", py::arg("vector"))
/* Properties */ /* Properties */
.def_property("vector", .def_property("vector",

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

@ -60,7 +60,7 @@ template<class T, class ...Args> void everyRectangularMatrix(py::class_<T, Args.
c c
.def_static("from_diagonal", [](const typename VectorTraits<T::DiagonalSize, typename T::Type>::Type& vector) { .def_static("from_diagonal", [](const typename VectorTraits<T::DiagonalSize, typename T::Type>::Type& vector) {
return T::fromDiagonal(vector); return T::fromDiagonal(vector);
}, "Construct a diagonal matrix") }, "Construct a diagonal matrix", py::arg("diagonal"))
.def_static("zero_init", []() { .def_static("zero_init", []() {
return T{Math::ZeroInit}; return T{Math::ZeroInit};
}, "Construct a zero-filled matrix") }, "Construct a zero-filled matrix")
@ -571,7 +571,7 @@ template<class T> void matrices(
/* Constructors. The translation() / scaling() / rotation() are handled /* Constructors. The translation() / scaling() / rotation() are handled
below as they conflict with member functions. */ below as they conflict with member functions. */
.def_static("reflection", &Math::Matrix3<T>::reflection, .def_static("reflection", &Math::Matrix3<T>::reflection,
"2D reflection matrix") "2D reflection matrix", py::arg("normal"))
.def_static("shearing_x", &Math::Matrix3<T>::shearingX, .def_static("shearing_x", &Math::Matrix3<T>::shearingX,
"2D shearing matrix along the X axis", py::arg("amount")) "2D shearing matrix along the X axis", py::arg("amount"))
.def_static("shearing_y", &Math::Matrix3<T>::shearingY, .def_static("shearing_y", &Math::Matrix3<T>::shearingY,
@ -616,9 +616,9 @@ template<class T> void matrices(
.def("inverted_rigid", &Math::Matrix3<T>::invertedRigid, .def("inverted_rigid", &Math::Matrix3<T>::invertedRigid,
"Inverted rigid transformation matrix") "Inverted rigid transformation matrix")
.def("transform_vector", &Math::Matrix3<T>::transformVector, .def("transform_vector", &Math::Matrix3<T>::transformVector,
"Transform a 2D vector with the matrix") "Transform a 2D vector with the matrix", py::arg("vector"))
.def("transform_point", &Math::Matrix3<T>::transformPoint, .def("transform_point", &Math::Matrix3<T>::transformPoint,
"Transform a 2D point with the matrix") "Transform a 2D point with the matrix", py::arg("vector"))
/* Properties. The translation is handled below together with a static /* Properties. The translation is handled below together with a static
translation(). */ translation(). */
@ -642,7 +642,7 @@ template<class T> void matrices(
R"(scaling(*args, **kwargs) R"(scaling(*args, **kwargs)
Overloaded function. Overloaded function.
1. scaling(arg0: _magnum.Vector2) -> _magnum.Matrix3 1. scaling(vector: _magnum.Vector2) -> _magnum.Matrix3
2D scaling matrix 2D scaling matrix
@ -653,7 +653,7 @@ Non-uniform scaling part of the matrix
R"(scaling(*args, **kwargs) R"(scaling(*args, **kwargs)
Overloaded function. Overloaded function.
1. scaling(arg0: _magnum.Vector2d) -> _magnum.Matrix3d 1. scaling(vector: _magnum.Vector2d) -> _magnum.Matrix3d
2D scaling matrix 2D scaling matrix
@ -665,7 +665,7 @@ Non-uniform scaling part of the matrix
R"(rotation(*args, **kwargs) R"(rotation(*args, **kwargs)
Overloaded function. Overloaded function.
1. rotation(arg0: _magnum.Rad) -> _magnum.Matrix3 1. rotation(angle: _magnum.Rad) -> _magnum.Matrix3
2D rotation matrix 2D rotation matrix
@ -676,7 +676,7 @@ Overloaded function.
R"(rotation(*args, **kwargs) R"(rotation(*args, **kwargs)
Overloaded function. Overloaded function.
1. rotation(arg0: _magnum.Rad) -> _magnum.Matrix3d 1. rotation(angle: _magnum.Rad) -> _magnum.Matrix3d
2D rotation matrix 2D rotation matrix
@ -689,14 +689,14 @@ Overloaded function.
R"(_stranslation(*args, **kwargs) R"(_stranslation(*args, **kwargs)
Overloaded function. Overloaded function.
1. translation(arg0: _magnum.Vector2) -> _magnum.Matrix3 1. translation(vector: _magnum.Vector2) -> _magnum.Matrix3
2D translation matrix 2D translation matrix
)", )",
R"(_stranslation(*args, **kwargs) R"(_stranslation(*args, **kwargs)
Overloaded function. Overloaded function.
1. translation(arg0: _magnum.Vector2d) -> _magnum.Matrix3d 1. translation(vector: _magnum.Vector2d) -> _magnum.Matrix3d
2D translation matrix 2D translation matrix
)"}; )"};
@ -752,15 +752,15 @@ Overloaded function.
below as they conflict with member functions. */ below as they conflict with member functions. */
.def_static("rotation_x", [](Radd angle) { .def_static("rotation_x", [](Radd angle) {
return Math::Matrix4<T>::rotationX(Math::Rad<T>(angle)); return Math::Matrix4<T>::rotationX(Math::Rad<T>(angle));
}, "3D rotation matrix around the X axis") }, "3D rotation matrix around the X axis", py::arg("angle"))
.def_static("rotation_y", [](Radd angle) { .def_static("rotation_y", [](Radd angle) {
return Math::Matrix4<T>::rotationY(Math::Rad<T>(angle)); return Math::Matrix4<T>::rotationY(Math::Rad<T>(angle));
}, "3D rotation matrix around the Y axis") }, "3D rotation matrix around the Y axis", py::arg("angle"))
.def_static("rotation_z", [](Radd angle) { .def_static("rotation_z", [](Radd angle) {
return Math::Matrix4<T>::rotationZ(Math::Rad<T>(angle)); return Math::Matrix4<T>::rotationZ(Math::Rad<T>(angle));
}, "3D rotation matrix around the Z axis") }, "3D rotation matrix around the Z axis", py::arg("angle"))
.def_static("reflection", &Math::Matrix4<T>::reflection, .def_static("reflection", &Math::Matrix4<T>::reflection,
"3D reflection matrix") "3D reflection matrix", py::arg("normal"))
.def_static("shearing_xy", &Math::Matrix4<T>::shearingXY, .def_static("shearing_xy", &Math::Matrix4<T>::shearingXY,
"3D shearing matrix along the XY plane", py::arg("amount_x"), py::arg("amount_y")) "3D shearing matrix along the XY plane", py::arg("amount_x"), py::arg("amount_y"))
.def_static("shearing_xz", &Math::Matrix4<T>::shearingXZ, .def_static("shearing_xz", &Math::Matrix4<T>::shearingXZ,
@ -822,9 +822,9 @@ Overloaded function.
.def("inverted_rigid", &Math::Matrix4<T>::invertedRigid, .def("inverted_rigid", &Math::Matrix4<T>::invertedRigid,
"Inverted rigid transformation matrix") "Inverted rigid transformation matrix")
.def("transform_vector", &Math::Matrix4<T>::transformVector, .def("transform_vector", &Math::Matrix4<T>::transformVector,
"Transform a 3D vector with the matrix") "Transform a 3D vector with the matrix", py::arg("vector"))
.def("transform_point", &Math::Matrix4<T>::transformPoint, .def("transform_point", &Math::Matrix4<T>::transformPoint,
"Transform a 3D point with the matrix") "Transform a 3D point with the matrix", py::arg("vector"))
/* Properties. The translation is handled below together with a static /* Properties. The translation is handled below together with a static
translation(). */ translation(). */
@ -852,7 +852,7 @@ Overloaded function.
R"(scaling(*args, **kwargs) R"(scaling(*args, **kwargs)
Overloaded function. Overloaded function.
1. scaling(arg0: _magnum.Vector3) -> _magnum.Matrix4 1. scaling(vector: _magnum.Vector3) -> _magnum.Matrix4
3D scaling matrix 3D scaling matrix
@ -863,7 +863,7 @@ Non-uniform scaling part of the matrix
R"(scaling(*args, **kwargs) R"(scaling(*args, **kwargs)
Overloaded function. Overloaded function.
1. scaling(arg0: _magnum.Vector3d) -> _magnum.Matrix4d 1. scaling(vector: _magnum.Vector3d) -> _magnum.Matrix4d
2D scaling matrix 2D scaling matrix
@ -876,7 +876,7 @@ Non-uniform scaling part of the matrix
R"(rotation(*args, **kwargs) R"(rotation(*args, **kwargs)
Overloaded function. Overloaded function.
1. rotation(arg0: _magnum.Rad, arg1: _magnum.Vector3) -> _magnum.Matrix4 1. rotation(angle: _magnum.Rad, normalized_axis: _magnum.Vector3) -> _magnum.Matrix4
3D rotation matrix 3D rotation matrix
@ -887,7 +887,7 @@ Overloaded function.
R"(rotation(*args, **kwargs) R"(rotation(*args, **kwargs)
Overloaded function. Overloaded function.
1. rotation(arg0: _magnum.Rad, arg1: _magnum.Vector3d) -> _magnum.Matrix4d 1. rotation(angle: _magnum.Rad, normalized_axis: _magnum.Vector3d) -> _magnum.Matrix4d
3D rotation matrix 3D rotation matrix
@ -901,14 +901,14 @@ Overloaded function.
R"(_stranslation(*args, **kwargs) R"(_stranslation(*args, **kwargs)
Overloaded function. Overloaded function.
1. translation(arg0: _magnum.Vector3) -> _magnum.Matrix4 1. translation(vector: _magnum.Vector3) -> _magnum.Matrix4
3D translation matrix 3D translation matrix
)", )",
R"(_stranslation(*args, **kwargs) R"(_stranslation(*args, **kwargs)
Overloaded function. Overloaded function.
1. translation(arg0: _magnum.Vector3d) -> _magnum.Matrix4d 1. translation(vector: _magnum.Vector3d) -> _magnum.Matrix4d
3D translation matrix 3D translation matrix
)"}; )"};

6
src/python/magnum/math.vectorfloat.cpp

@ -69,13 +69,13 @@ template<class T> void vectorFloat(py::module_& m, py::class_<T>& c) {
.def("normalized", static_cast<T(T::*)() const>(&T::normalized), .def("normalized", static_cast<T(T::*)() const>(&T::normalized),
"Normalized vector (of unit length)") "Normalized vector (of unit length)")
.def("resized", static_cast<T(T::*)(typename T::Type) const>(&T::resized), .def("resized", static_cast<T(T::*)(typename T::Type) const>(&T::resized),
"Resized vector") "Resized vector", py::arg("length"))
.def("projected", [](const T& self, const T& line) { .def("projected", [](const T& self, const T& line) {
return self.projected(line); return self.projected(line);
}, "Vector projected onto a line") }, "Vector projected onto a line", py::arg("line"))
.def("projected_onto_normalized", [](const T& self, const T& line) { .def("projected_onto_normalized", [](const T& self, const T& line) {
return self.projectedOntoNormalized(line); return self.projectedOntoNormalized(line);
}, "Vector projected onto a normalized line"); }, "Vector projected onto a normalized line", py::arg("line"));
} }
template<class T> void vectorsFloat(py::module_& m, py::class_<Math::Vector2<T>>& vector2_, py::class_<Math::Vector3<T>>& vector3_, py::class_<Math::Vector4<T>>& vector4_) { template<class T> void vectorsFloat(py::module_& m, py::class_<Math::Vector2<T>>& vector2_, py::class_<Math::Vector3<T>>& vector3_, py::class_<Math::Vector4<T>>& vector4_) {

Loading…
Cancel
Save