From ccbd5792e9bc23d3e8cdb37dddfc5d84e25b8dbe Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 7 Oct 2019 19:23:14 +0200 Subject: [PATCH] improve RotationPy::number_power_handler: make computation more efficient and less prone to round-off errors --- src/Base/RotationPyImp.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index f144a5716f..98585530c3 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -441,19 +441,16 @@ PyObject * RotationPy::number_power_handler (PyObject* self, PyObject* other, Py } Rotation a = static_cast(self)->value(); - long b = Py::Int(other); - if(!b) - return new RotationPy(Rotation()); - if(b < 0) { - b = -b; - a.invert(); - } - auto res = a; - for(--b;b;--b) - res *= a; - return new RotationPy(res); + Vector3d axis; + double rfAngle; + + a.getRawValue(axis, rfAngle); + rfAngle *= b; + a.setValue(axis, rfAngle); + + return new RotationPy(a); } PyObject* RotationPy::number_add_handler(PyObject * /*self*/, PyObject * /*other*/)