Base: add Python number protocol support to Placement/Rotation
This commit is contained in:
@@ -384,4 +384,197 @@ int RotationPy::setCustomAttributes(const char* attr, PyObject* obj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* RotationPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(RotationPy::Type))) {
|
||||
auto a = static_cast<RotationPy*>(self)->value();
|
||||
|
||||
if (PyObject_TypeCheck(other, &(VectorPy::Type))) {
|
||||
Vector3d res;
|
||||
a.multVec(static_cast<VectorPy*>(other)->value(),res);
|
||||
return new VectorPy(res);
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(other, &(PlacementPy::Type))) {
|
||||
const auto &b = static_cast<PlacementPy*>(other)->value();
|
||||
return new PlacementPy(Placement(Vector3d(),a)*b);
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(other, &(RotationPy::Type))) {
|
||||
const auto &b = static_cast<RotationPy*>(other)->value();
|
||||
return new RotationPy(a*b);
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(other, &(MatrixPy::Type))) {
|
||||
const auto &b = static_cast<MatrixPy*>(other)->value();
|
||||
Matrix4D mat;
|
||||
a.getValue(mat);
|
||||
return new MatrixPy(mat*b);
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_power_handler (PyObject* self, PyObject* other, PyObject* arg)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(RotationPy::Type)) ||
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
!PyInt_Check(other)
|
||||
#else
|
||||
!PyLong_Check(other)
|
||||
#endif
|
||||
|| arg != Py_None
|
||||
)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Rotation a = static_cast<RotationPy*>(self)->value();
|
||||
|
||||
long b = Py::Int(other);
|
||||
if(!b)
|
||||
return new RotationPy(Rotation());
|
||||
|
||||
if(b < 0) {
|
||||
b = 1+b;
|
||||
a.invert();
|
||||
}
|
||||
auto res = a;
|
||||
for(;b;--b)
|
||||
res *= a;
|
||||
return new RotationPy(res);
|
||||
}
|
||||
|
||||
PyObject* RotationPy::number_add_handler(PyObject * /*self*/, PyObject * /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* RotationPy::number_subtract_handler(PyObject * /*self*/, PyObject * /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_divide_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_remainder_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_divmod_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_negative_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_positive_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_absolute_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RotationPy::number_nonzero_handler (PyObject* /*self*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_invert_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_lshift_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_rshift_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_and_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_xor_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_or_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int RotationPy::number_coerce_handler (PyObject ** /*self*/, PyObject ** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * RotationPy::number_int_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * RotationPy::number_long_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * RotationPy::number_float_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * RotationPy::number_oct_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_hex_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user