From daa78626fe05e3f99af342b264ee8087a92808d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 5 Dec 2023 20:38:59 +0100 Subject: [PATCH] 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... --- src/python/magnum/math.cpp | 12 +++---- src/python/magnum/math.matrix.h | 44 +++++++++++++------------- src/python/magnum/math.vectorfloat.cpp | 6 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/python/magnum/math.cpp b/src/python/magnum/math.cpp index 6c1b58f..94d9432 100644 --- a/src/python/magnum/math.cpp +++ b/src/python/magnum/math.cpp @@ -301,10 +301,10 @@ template void quaternion(py::module_& m, py::class_& c) { m .def("dot", static_cast(&Math::dot), "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 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")) .def("lerp", static_cast(&Math::lerp), "Linear interpolation of two quaternions", py::arg("normalized_a"), py::arg("normalized_b"), py::arg("t")) @@ -320,9 +320,9 @@ template void quaternion(py::module_& m, py::class_& c) { /* Constructors */ .def_static("rotation", [](Radd angle, const Math::Vector3& axis) { return T::rotation(Math::Rad(angle), axis); - }, "Rotation quaternion") + }, "Rotation quaternion", py::arg("angle"), py::arg("normalized_axis")) .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", []() { return T{Math::ZeroInit}; }, "Construct a zero-initialized quaternion") @@ -404,9 +404,9 @@ template void quaternion(py::module_& m, py::class_& c) { .def("inverted_normalized", &T::invertedNormalized, "Inverted normalized quaternion") .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, - "Rotate a vector with a normalized quaternion") + "Rotate a vector with a normalized quaternion", py::arg("vector")) /* Properties */ .def_property("vector", diff --git a/src/python/magnum/math.matrix.h b/src/python/magnum/math.matrix.h index eee29cb..f97cd8a 100644 --- a/src/python/magnum/math.matrix.h +++ b/src/python/magnum/math.matrix.h @@ -60,7 +60,7 @@ template void everyRectangularMatrix(py::class_::Type& vector) { return T::fromDiagonal(vector); - }, "Construct a diagonal matrix") + }, "Construct a diagonal matrix", py::arg("diagonal")) .def_static("zero_init", []() { return T{Math::ZeroInit}; }, "Construct a zero-filled matrix") @@ -571,7 +571,7 @@ template void matrices( /* Constructors. The translation() / scaling() / rotation() are handled below as they conflict with member functions. */ .def_static("reflection", &Math::Matrix3::reflection, - "2D reflection matrix") + "2D reflection matrix", py::arg("normal")) .def_static("shearing_x", &Math::Matrix3::shearingX, "2D shearing matrix along the X axis", py::arg("amount")) .def_static("shearing_y", &Math::Matrix3::shearingY, @@ -616,9 +616,9 @@ template void matrices( .def("inverted_rigid", &Math::Matrix3::invertedRigid, "Inverted rigid transformation matrix") .def("transform_vector", &Math::Matrix3::transformVector, - "Transform a 2D vector with the matrix") + "Transform a 2D vector with the matrix", py::arg("vector")) .def("transform_point", &Math::Matrix3::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 translation(). */ @@ -642,7 +642,7 @@ template void matrices( R"(scaling(*args, **kwargs) Overloaded function. -1. scaling(arg0: _magnum.Vector2) -> _magnum.Matrix3 +1. scaling(vector: _magnum.Vector2) -> _magnum.Matrix3 2D scaling matrix @@ -653,7 +653,7 @@ Non-uniform scaling part of the matrix R"(scaling(*args, **kwargs) Overloaded function. -1. scaling(arg0: _magnum.Vector2d) -> _magnum.Matrix3d +1. scaling(vector: _magnum.Vector2d) -> _magnum.Matrix3d 2D scaling matrix @@ -665,7 +665,7 @@ Non-uniform scaling part of the matrix R"(rotation(*args, **kwargs) Overloaded function. -1. rotation(arg0: _magnum.Rad) -> _magnum.Matrix3 +1. rotation(angle: _magnum.Rad) -> _magnum.Matrix3 2D rotation matrix @@ -676,7 +676,7 @@ Overloaded function. R"(rotation(*args, **kwargs) Overloaded function. -1. rotation(arg0: _magnum.Rad) -> _magnum.Matrix3d +1. rotation(angle: _magnum.Rad) -> _magnum.Matrix3d 2D rotation matrix @@ -689,14 +689,14 @@ Overloaded function. R"(_stranslation(*args, **kwargs) Overloaded function. -1. translation(arg0: _magnum.Vector2) -> _magnum.Matrix3 +1. translation(vector: _magnum.Vector2) -> _magnum.Matrix3 2D translation matrix )", R"(_stranslation(*args, **kwargs) Overloaded function. -1. translation(arg0: _magnum.Vector2d) -> _magnum.Matrix3d +1. translation(vector: _magnum.Vector2d) -> _magnum.Matrix3d 2D translation matrix )"}; @@ -752,15 +752,15 @@ Overloaded function. below as they conflict with member functions. */ .def_static("rotation_x", [](Radd angle) { return Math::Matrix4::rotationX(Math::Rad(angle)); - }, "3D rotation matrix around the X axis") + }, "3D rotation matrix around the X axis", py::arg("angle")) .def_static("rotation_y", [](Radd angle) { return Math::Matrix4::rotationY(Math::Rad(angle)); - }, "3D rotation matrix around the Y axis") + }, "3D rotation matrix around the Y axis", py::arg("angle")) .def_static("rotation_z", [](Radd angle) { return Math::Matrix4::rotationZ(Math::Rad(angle)); - }, "3D rotation matrix around the Z axis") + }, "3D rotation matrix around the Z axis", py::arg("angle")) .def_static("reflection", &Math::Matrix4::reflection, - "3D reflection matrix") + "3D reflection matrix", py::arg("normal")) .def_static("shearing_xy", &Math::Matrix4::shearingXY, "3D shearing matrix along the XY plane", py::arg("amount_x"), py::arg("amount_y")) .def_static("shearing_xz", &Math::Matrix4::shearingXZ, @@ -822,9 +822,9 @@ Overloaded function. .def("inverted_rigid", &Math::Matrix4::invertedRigid, "Inverted rigid transformation matrix") .def("transform_vector", &Math::Matrix4::transformVector, - "Transform a 3D vector with the matrix") + "Transform a 3D vector with the matrix", py::arg("vector")) .def("transform_point", &Math::Matrix4::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 translation(). */ @@ -852,7 +852,7 @@ Overloaded function. R"(scaling(*args, **kwargs) Overloaded function. -1. scaling(arg0: _magnum.Vector3) -> _magnum.Matrix4 +1. scaling(vector: _magnum.Vector3) -> _magnum.Matrix4 3D scaling matrix @@ -863,7 +863,7 @@ Non-uniform scaling part of the matrix R"(scaling(*args, **kwargs) Overloaded function. -1. scaling(arg0: _magnum.Vector3d) -> _magnum.Matrix4d +1. scaling(vector: _magnum.Vector3d) -> _magnum.Matrix4d 2D scaling matrix @@ -876,7 +876,7 @@ Non-uniform scaling part of the matrix R"(rotation(*args, **kwargs) 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 @@ -887,7 +887,7 @@ Overloaded function. R"(rotation(*args, **kwargs) 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 @@ -901,14 +901,14 @@ Overloaded function. R"(_stranslation(*args, **kwargs) Overloaded function. -1. translation(arg0: _magnum.Vector3) -> _magnum.Matrix4 +1. translation(vector: _magnum.Vector3) -> _magnum.Matrix4 3D translation matrix )", R"(_stranslation(*args, **kwargs) Overloaded function. -1. translation(arg0: _magnum.Vector3d) -> _magnum.Matrix4d +1. translation(vector: _magnum.Vector3d) -> _magnum.Matrix4d 3D translation matrix )"}; diff --git a/src/python/magnum/math.vectorfloat.cpp b/src/python/magnum/math.vectorfloat.cpp index 1d0b652..2712ce2 100644 --- a/src/python/magnum/math.vectorfloat.cpp +++ b/src/python/magnum/math.vectorfloat.cpp @@ -69,13 +69,13 @@ template void vectorFloat(py::module_& m, py::class_& c) { .def("normalized", static_cast(&T::normalized), "Normalized vector (of unit length)") .def("resized", static_cast(&T::resized), - "Resized vector") + "Resized vector", py::arg("length")) .def("projected", [](const T& self, const T& 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) { return self.projectedOntoNormalized(line); - }, "Vector projected onto a normalized line"); + }, "Vector projected onto a normalized line", py::arg("line")); } template void vectorsFloat(py::module_& m, py::class_>& vector2_, py::class_>& vector3_, py::class_>& vector4_) {