Base: replace several reinterpret_cast

This commit is contained in:
wmayer
2022-05-11 20:01:40 +02:00
parent 43f5e3278d
commit 4b483807c7
7 changed files with 56 additions and 59 deletions

View File

@@ -54,7 +54,7 @@ int ExtensionContainerPy::initialization() {
// The PyTypeObject is shared by all instances of this type and therefore
// we have to add new methods only once.
PyObject* obj = (*it).second->getExtensionPyObject();
PyMethodDef* meth = reinterpret_cast<PyMethodDef*>(obj->ob_type->tp_methods);
PyMethodDef* meth = obj->ob_type->tp_methods;
PyTypeObject *type = this->ob_type;
PyObject *dict = type->tp_dict;
@@ -214,7 +214,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
str << "No extension found of type '" << typeId << "'" << std::ends;
throw Py::TypeError(str.str());
}
//register the extension
App::Extension* ext = static_cast<App::Extension*>(extension.createInstance());
//check if this really is a python extension!
@@ -224,14 +224,14 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
str << "Extension is not a python addable version: '" << typeId << "'" << std::ends;
throw Py::TypeError(str.str());
}
GetApplication().signalBeforeAddingDynamicExtension(*getExtensionContainerPtr(), typeId);
ext->initExtension(getExtensionContainerPtr());
// The PyTypeObject is shared by all instances of this type and therefore
// The PyTypeObject is shared by all instances of this type and therefore
// we have to add new methods only once.
PyObject* obj = ext->getExtensionPyObject();
PyMethodDef* meth = reinterpret_cast<PyMethodDef*>(obj->ob_type->tp_methods);
PyMethodDef* meth = obj->ob_type->tp_methods;
PyTypeObject *type = this->ob_type;
PyObject *dict = type->tp_dict;

View File

@@ -36,7 +36,7 @@ using namespace Base;
// returns a string which represents the object e.g. when printed in python
std::string AxisPy::representation() const
{
AxisPy::PointerType ptr = reinterpret_cast<AxisPy::PointerType>(_pcTwinPointer);
AxisPy::PointerType ptr = getAxisPtr();
std::stringstream str;
str << "Axis [Base=(";
str << ptr->getBase().x << ","<< ptr->getBase().y << "," << ptr->getBase().z;

View File

@@ -91,14 +91,12 @@ int BoundBoxPy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!O!",&(Base::VectorPy::Type), &object1,
&(Base::VectorPy::Type), &object2)) {
// Note: must be static_cast, not reinterpret_cast
ptr->Add(*(static_cast<Base::VectorPy*>(object1)->getVectorPtr()));
ptr->Add(*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
return 0;
}
PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object1)) {
// Note: must be static_cast, not reinterpret_cast
*ptr = *(static_cast<Base::BoundBoxPy*>(object1)->getBoundBoxPtr());
return 0;
}

View File

@@ -68,7 +68,7 @@ int MatrixPy::PyInit(PyObject* args, PyObject* /*kwd*/)
&a21,&a22,&a23,&a24,
&a31,&a32,&a33,&a34,
&a41,&a42,&a43,&a44)) {
MatrixPy::PointerType ptr = reinterpret_cast<MatrixPy::PointerType>(_pcTwinPointer);
MatrixPy::PointerType ptr = getMatrixPtr();
(*ptr) = Matrix4D(a11,a12,a13,a14,
a21,a22,a23,a24,
a31,a32,a33,a34,
@@ -79,7 +79,7 @@ int MatrixPy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyErr_Clear();
PyObject *o;
if (PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) {
MatrixPy::PointerType ptr = reinterpret_cast<MatrixPy::PointerType>(_pcTwinPointer);
MatrixPy::PointerType ptr = getMatrixPtr();
(*ptr) = static_cast<MatrixPy*>(o)->value();
return 0;
}

View File

@@ -40,7 +40,7 @@ using namespace Base;
std::string PlacementPy::representation() const
{
double A,B,C;
PlacementPy::PointerType ptr = reinterpret_cast<PlacementPy::PointerType>(_pcTwinPointer);
PlacementPy::PointerType ptr = getPlacementPtr();
std::stringstream str;
ptr->getRotation().getYawPitchRoll(A,B,C);

View File

@@ -37,7 +37,7 @@ using namespace Base;
// returns a string which represents the object e.g. when printed in python
std::string RotationPy::representation() const
{
RotationPy::PointerType ptr = reinterpret_cast<RotationPy::PointerType>(_pcTwinPointer);
RotationPy::PointerType ptr = getRotationPtr();
Py::Float q0(ptr->getValue()[0]);
Py::Float q1(ptr->getValue()[1]);
Py::Float q2(ptr->getValue()[2]);

View File

@@ -41,7 +41,7 @@ using namespace Base;
// returns a string which represent the object e.g. when printed in python
std::string VectorPy::representation() const
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
Py::Float x(ptr->x);
Py::Float y(ptr->y);
Py::Float z(ptr->z);
@@ -66,14 +66,13 @@ int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
double x=0.0,y=0.0,z=0.0;
PyObject *object;
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
if (PyArg_ParseTuple(args, "|ddd", &x,&y,&z)) {
ptr->Set(x,y,z);
return 0;
}
PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
// Note: must be static_cast, not reinterpret_cast
*ptr = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
return 0;
}
@@ -286,8 +285,8 @@ PyObject* VectorPy::add(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Base::Vector3d v = (*this_ptr) + (*vect_ptr);
return new VectorPy(v);
@@ -301,8 +300,8 @@ PyObject* VectorPy::sub(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Base::Vector3d v = (*this_ptr) - (*vect_ptr);
return new VectorPy(v);
@@ -313,7 +312,7 @@ PyObject* VectorPy::negative(PyObject *args)
if (!PyArg_ParseTuple(args, ""))
return nullptr;
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
Base::Vector3d v = -(*this_ptr);
return new VectorPy(v);
}
@@ -358,8 +357,8 @@ PyObject* VectorPy::isEqual(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Py::Boolean eq((*this_ptr).IsEqual(*vect_ptr, tolerance));
return Py::new_reference_to(eq);
@@ -370,7 +369,7 @@ PyObject* VectorPy::scale(PyObject *args)
double factorX, factorY, factorZ;
if (!PyArg_ParseTuple(args, "ddd", &factorX, &factorY, &factorZ))
return nullptr;
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
ptr->Scale(factorX, factorY, factorZ);
return Py::new_reference_to(this);
@@ -381,7 +380,7 @@ PyObject* VectorPy::multiply(PyObject *args)
double factor;
if (!PyArg_ParseTuple(args, "d", &factor))
return nullptr;
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
ptr->Scale(factor, factor, factor);
return Py::new_reference_to(this);
@@ -395,8 +394,8 @@ PyObject* VectorPy::dot(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Py::Float mult((*this_ptr) * (*vect_ptr));
return Py::new_reference_to(mult);
@@ -410,8 +409,8 @@ PyObject* VectorPy::cross(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Base::Vector3d v = (*this_ptr) % (*vect_ptr);
return new VectorPy(v);
@@ -434,9 +433,9 @@ PyObject* VectorPy::isOnLineSegment(PyObject *args)
VectorPy* start_vec = static_cast<VectorPy*>(start);
VectorPy* end_vec = static_cast<VectorPy*>(end);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType start_ptr = reinterpret_cast<VectorPy::PointerType>(start_vec->_pcTwinPointer);
VectorPy::PointerType end_ptr = reinterpret_cast<VectorPy::PointerType>(end_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType start_ptr = start_vec->getVectorPtr();
VectorPy::PointerType end_ptr = end_vec->getVectorPtr();
Py::Boolean result = this_ptr->IsOnLineSegment(*start_ptr, *end_ptr);
@@ -451,8 +450,8 @@ PyObject* VectorPy::getAngle(PyObject *args)
VectorPy* vec = static_cast<VectorPy*>(obj);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType vect_ptr = reinterpret_cast<VectorPy::PointerType>(vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType vect_ptr = vec->getVectorPtr();
Py::Float angle(this_ptr->GetAngle(*vect_ptr));
return Py::new_reference_to(angle);
@@ -462,7 +461,7 @@ PyObject* VectorPy::normalize(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
if (ptr->Length() < Vector3d::epsilon()) {
PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot normalize null vector");
return nullptr;
@@ -490,9 +489,9 @@ PyObject* VectorPy::projectToLine(PyObject *args)
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
VectorPy::PointerType line_ptr = line_vec->getVectorPtr();
this_ptr->ProjectToLine(*base_ptr, *line_ptr);
@@ -516,9 +515,9 @@ PyObject* VectorPy::projectToPlane(PyObject *args)
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
VectorPy::PointerType line_ptr = line_vec->getVectorPtr();
this_ptr->ProjectToPlane(*base_ptr, *line_ptr);
@@ -532,8 +531,8 @@ PyObject* VectorPy::distanceToPoint(PyObject *args)
return nullptr;
VectorPy* base_vec = static_cast<VectorPy*>(pnt);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
Py::Float dist(Base::Distance(*this_ptr, *base_ptr));
return Py::new_reference_to(dist);
@@ -556,9 +555,9 @@ PyObject* VectorPy::distanceToLine(PyObject *args)
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
VectorPy::PointerType line_ptr = line_vec->getVectorPtr();
Py::Float dist(this_ptr->DistanceToLine(*base_ptr, *line_ptr));
return Py::new_reference_to(dist);
@@ -581,9 +580,9 @@ PyObject* VectorPy::distanceToLineSegment(PyObject *args)
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
VectorPy::PointerType line_ptr = line_vec->getVectorPtr();
Vector3d v = this_ptr->DistanceToLineSegment(*base_ptr, *line_ptr);
return new VectorPy(v);
@@ -606,9 +605,9 @@ PyObject* VectorPy::distanceToPlane(PyObject *args)
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
VectorPy::PointerType this_ptr = getVectorPtr();
VectorPy::PointerType base_ptr = base_vec->getVectorPtr();
VectorPy::PointerType line_ptr = line_vec->getVectorPtr();
Py::Float dist(this_ptr->DistanceToPlane(*base_ptr, *line_ptr));
return Py::new_reference_to(dist);
@@ -616,13 +615,13 @@ PyObject* VectorPy::distanceToPlane(PyObject *args)
Py::Float VectorPy::getLength() const
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
return Py::Float(ptr->Length());
}
void VectorPy::setLength(Py::Float arg)
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
double len = ptr->Length();
if (len < Vector3d::epsilon()) {
throw Py::RuntimeError(std::string("Cannot set length of null vector"));
@@ -636,37 +635,37 @@ void VectorPy::setLength(Py::Float arg)
Py::Float VectorPy::getx() const
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
return Py::Float(ptr->x);
}
void VectorPy::setx(Py::Float arg)
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
ptr->x = static_cast<double>(arg);
}
Py::Float VectorPy::gety() const
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
return Py::Float(ptr->y);
}
void VectorPy::sety(Py::Float arg)
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
ptr->y = static_cast<double>(arg);
}
Py::Float VectorPy::getz() const
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
return Py::Float(ptr->z);
}
void VectorPy::setz(Py::Float arg)
{
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType ptr = getVectorPtr();
ptr->z = static_cast<double>(arg);
}