Skip to content

Commit

Permalink
fixes #2419: Matrix rotation and Units compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 25, 2017
1 parent 0ad9436 commit 25fb77a
Showing 1 changed file with 64 additions and 12 deletions.
76 changes: 64 additions & 12 deletions src/Base/MatrixPyImp.cpp
Expand Up @@ -30,6 +30,7 @@
// inclusion of the generated files (generated out of MatrixPy.xml)
#include "VectorPy.h"
#include "GeometryPyCXX.h"
#include "QuantityPy.h"
#include "MatrixPy.h"
#include "MatrixPy.cpp"

Expand Down Expand Up @@ -277,12 +278,29 @@ PyObject* MatrixPy::transform(PyObject * args)

PyObject* MatrixPy::rotateX(PyObject * args)
{
double a;
if (!PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &a)) // convert args: Python->C
return NULL; // NULL triggers exception
double angle = 0;
do {
PyObject *object;
if (PyArg_ParseTuple(args,"O!",&(Base::QuantityPy::Type), &object)) {
Quantity *q = static_cast<Base::QuantityPy*>(object)->getQuantityPtr();
if (q->getUnit() == Base::Unit::Angle) {
angle = q->getValueAs(Base::Quantity::Radian);
break;
}
}

PyErr_Clear();
if (PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &angle)) {
break;
}

PyErr_SetString(PyExc_TypeError, "For angle either float or Quantity expected");
return 0;
}
while (false);

PY_TRY {
getMatrixPtr()->rotX(a);
getMatrixPtr()->rotX(angle);
}
PY_CATCH;

Expand All @@ -291,12 +309,29 @@ PyObject* MatrixPy::rotateX(PyObject * args)

PyObject* MatrixPy::rotateY(PyObject * args)
{
double a;
if (!PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &a)) // convert args: Python->C
return NULL; // NULL triggers exception
double angle = 0;
do {
PyObject *object;
if (PyArg_ParseTuple(args,"O!",&(Base::QuantityPy::Type), &object)) {
Quantity *q = static_cast<Base::QuantityPy*>(object)->getQuantityPtr();
if (q->getUnit() == Base::Unit::Angle) {
angle = q->getValueAs(Base::Quantity::Radian);
break;
}
}

PyErr_Clear();
if (PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &angle)) {
break;
}

PyErr_SetString(PyExc_TypeError, "For angle either float or Quantity expected");
return 0;
}
while (false);

PY_TRY {
getMatrixPtr()->rotY(a);
getMatrixPtr()->rotY(angle);
}
PY_CATCH;

Expand All @@ -305,12 +340,29 @@ PyObject* MatrixPy::rotateY(PyObject * args)

PyObject* MatrixPy::rotateZ(PyObject * args)
{
double a;
if (!PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &a)) // convert args: Python->C
return NULL; // NULL triggers exception
double angle = 0;
do {
PyObject *object;
if (PyArg_ParseTuple(args,"O!",&(Base::QuantityPy::Type), &object)) {
Quantity *q = static_cast<Base::QuantityPy*>(object)->getQuantityPtr();
if (q->getUnit() == Base::Unit::Angle) {
angle = q->getValueAs(Base::Quantity::Radian);
break;
}
}

PyErr_Clear();
if (PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &angle)) {
break;
}

PyErr_SetString(PyExc_TypeError, "For angle either float or Quantity expected");
return 0;
}
while (false);

PY_TRY {
getMatrixPtr()->rotZ(a);
getMatrixPtr()->rotZ(angle);
}
PY_CATCH;

Expand Down

0 comments on commit 25fb77a

Please sign in to comment.