Base: add Python number protocol support to Placement/Rotation

This commit is contained in:
Zheng, Lei
2019-09-03 17:38:15 +08:00
committed by wmayer
parent 8dec78747f
commit 83284a3cdd
6 changed files with 408 additions and 2 deletions

View File

@@ -94,7 +94,7 @@ int MatrixPy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyObject* MatrixPy::number_add_handler(PyObject *self, PyObject *other)
{
if (!PyObject_TypeCheck(self, &(MatrixPy::Type))) {
PyErr_SetString(PyExc_TypeError, "First arg must be Matrix");
PyErr_SetString(PyExc_NotImplementedError, "");
return 0;
}
if (!PyObject_TypeCheck(other, &(MatrixPy::Type))) {
@@ -109,7 +109,7 @@ PyObject* MatrixPy::number_add_handler(PyObject *self, PyObject *other)
PyObject* MatrixPy::number_subtract_handler(PyObject *self, PyObject *other)
{
if (!PyObject_TypeCheck(self, &(MatrixPy::Type))) {
PyErr_SetString(PyExc_TypeError, "First arg must be Matrix");
PyErr_SetString(PyExc_NotImplementedError, "");
return 0;
}
if (!PyObject_TypeCheck(other, &(MatrixPy::Type))) {
@@ -138,6 +138,11 @@ PyObject* MatrixPy::number_multiply_handler(PyObject *self, PyObject *other)
return new MatrixPy(a*b);
}
if (PyObject_TypeCheck(other, &(PlacementPy::Type))) {
auto b = static_cast<PlacementPy*>(other)->value();
return new MatrixPy(a*b.toMatrix());
}
if (PyObject_TypeCheck(other, &(MatrixPy::Type))) {
Base::Matrix4D b = static_cast<MatrixPy*>(other)->value();
return new MatrixPy(a*b);