diff --git a/src/python/magnum/math.cpp b/src/python/magnum/math.cpp index 00bb92e..4b81111 100644 --- a/src/python/magnum/math.cpp +++ b/src/python/magnum/math.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "magnum/bootstrap.h" @@ -296,6 +297,18 @@ void math(py::module& root, py::module& m) { m.attr("nan") = Constantsd::nan(); m.attr("inf") = Constantsd::inf(); + /* Functions */ + m + .def("sin", [](Radd angle) { return Math::sin(angle); }, "Sine") + .def("cos", [](Radd angle) { return Math::cos(angle); }, "Cosine") + .def("sincos", [](Radd angle) { + return Math::sincos(angle); + }, "Sine and cosine") + .def("tan", [](Radd angle) { return Math::tan(angle); }, "Tangent") + .def("asin", [](Double angle) { return Math::asin(angle); }, "Arc sine") + .def("acos", [](Double angle) { return Math::acos(angle); }, "Arc cosine") + .def("atan", [](Double angle) { return Math::atan(angle); }, "Arc tangent"); + /* These are needed for the quaternion, so register them before */ magnum::mathVectorFloat(root, m); magnum::mathVectorIntegral(root, m); diff --git a/src/python/magnum/test/test_math.py b/src/python/magnum/test/test_math.py index 863d79f..e359da2 100644 --- a/src/python/magnum/test/test_math.py +++ b/src/python/magnum/test/test_math.py @@ -107,6 +107,15 @@ class Constants(unittest.TestCase): self.assertAlmostEqual(math.sqrt2**2, 2.0, 6) self.assertAlmostEqual(math.sqrt3**2, 3.0) +class Functions(unittest.TestCase): + def test(self): + self.assertAlmostEqual(math.sin(Deg(45.0)), 0.7071067811865475) + self.assertAlmostEqual(Deg(math.asin(0.7071067811865475)), Deg(45.0)) + + sincos = math.sincos(Deg(90.0)) + self.assertAlmostEqual(sincos[0], 1.0) + self.assertAlmostEqual(sincos[1], 0.0) + class Vector(unittest.TestCase): def test_init(self): a = Vector4i()