Base: replace several reinterpret_cast
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user