Base: apply clang format
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "Vector3D.h"
|
||||
@@ -45,15 +45,14 @@ std::string VectorPy::representation() const
|
||||
Py::Float z(ptr->z);
|
||||
std::stringstream str;
|
||||
str << "Vector (";
|
||||
str << static_cast<std::string>(x.repr()) << ", "
|
||||
<< static_cast<std::string>(y.repr()) << ", "
|
||||
str << static_cast<std::string>(x.repr()) << ", " << static_cast<std::string>(y.repr()) << ", "
|
||||
<< static_cast<std::string>(z.repr());
|
||||
str << ")";
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject *VectorPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
PyObject* VectorPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of VectorPy and the Twin object
|
||||
return new VectorPy(new Vector3d);
|
||||
@@ -62,20 +61,20 @@ PyObject *VectorPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Pyt
|
||||
// constructor method
|
||||
int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
{
|
||||
double x=0.0,y=0.0,z=0.0;
|
||||
PyObject *object = nullptr;
|
||||
double x = 0.0, y = 0.0, z = 0.0;
|
||||
PyObject* object = nullptr;
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
if (PyArg_ParseTuple(args, "|ddd", &x,&y,&z)) {
|
||||
ptr->Set(x,y,z);
|
||||
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)) {
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type), &object)) {
|
||||
*ptr = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
|
||||
return 0;
|
||||
}
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
if (PyArg_ParseTuple(args,"O", &object)) {
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
if (PyArg_ParseTuple(args, "O", &object)) {
|
||||
try {
|
||||
*ptr = getVectorFromTuple<double>(object);
|
||||
return 0;
|
||||
@@ -89,10 +88,11 @@ int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::__reduce__(PyObject *args)
|
||||
PyObject* VectorPy::__reduce__(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Tuple tuple(2);
|
||||
|
||||
@@ -108,7 +108,7 @@ PyObject* VectorPy::__reduce__(PyObject *args)
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_add_handler(PyObject *self, PyObject *other)
|
||||
PyObject* VectorPy::number_add_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
@@ -120,10 +120,10 @@ PyObject* VectorPy::number_add_handler(PyObject *self, PyObject *other)
|
||||
}
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self)->value();
|
||||
Base::Vector3d b = static_cast<VectorPy*>(other)->value();
|
||||
return new VectorPy(a+b);
|
||||
return new VectorPy(a + b);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_subtract_handler(PyObject *self, PyObject *other)
|
||||
PyObject* VectorPy::number_subtract_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
@@ -135,13 +135,13 @@ PyObject* VectorPy::number_subtract_handler(PyObject *self, PyObject *other)
|
||||
}
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self)->value();
|
||||
Base::Vector3d b = static_cast<VectorPy*>(other)->value();
|
||||
return new VectorPy(a-b);
|
||||
return new VectorPy(a - b);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
PyObject* VectorPy::number_multiply_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self)->value();
|
||||
|
||||
if (PyObject_TypeCheck(other, &(VectorPy::Type))) {
|
||||
Base::Vector3d b = static_cast<VectorPy*>(other)->value();
|
||||
@@ -158,7 +158,7 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
}
|
||||
}
|
||||
else if (PyObject_TypeCheck(other, &(VectorPy::Type))) {
|
||||
Base::Vector3d a = static_cast<VectorPy*>(other) ->value();
|
||||
Base::Vector3d a = static_cast<VectorPy*>(other)->value();
|
||||
if (PyNumber_Check(self)) {
|
||||
double b = PyFloat_AsDouble(self);
|
||||
return new VectorPy(a * b);
|
||||
@@ -174,12 +174,12 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
}
|
||||
}
|
||||
|
||||
Py_ssize_t VectorPy::sequence_length(PyObject *)
|
||||
Py_ssize_t VectorPy::sequence_length(PyObject*)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::sequence_item (PyObject *self, Py_ssize_t index)
|
||||
PyObject* VectorPy::sequence_item(PyObject* self, Py_ssize_t index)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "first arg must be Vector");
|
||||
@@ -192,18 +192,18 @@ PyObject * VectorPy::sequence_item (PyObject *self, Py_ssize_t index)
|
||||
|
||||
VectorPy* self_ = static_cast<VectorPy*>(self);
|
||||
if (self_->sequence.length() == 0) {
|
||||
self_->sequence = Py::List{3};
|
||||
self_->sequence = Py::List {3};
|
||||
}
|
||||
|
||||
unsigned short pos = index % 3;
|
||||
Base::Vector3d vec = self_->value();
|
||||
Py::Float item{vec[pos]};
|
||||
Py::Float item {vec[pos]};
|
||||
self_->sequence.setItem(pos, item);
|
||||
|
||||
return Py::new_reference_to(item);
|
||||
}
|
||||
|
||||
int VectorPy::sequence_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
|
||||
int VectorPy::sequence_ass_item(PyObject* self, Py_ssize_t index, PyObject* value)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "first arg must be Vector");
|
||||
@@ -229,33 +229,33 @@ int VectorPy::sequence_ass_item(PyObject *self, Py_ssize_t index, PyObject *valu
|
||||
}
|
||||
|
||||
// http://renesd.blogspot.de/2009/07/python3-c-api-simple-slicing-sqslice.html
|
||||
PyObject * VectorPy::mapping_subscript(PyObject *self, PyObject *item)
|
||||
PyObject* VectorPy::mapping_subscript(PyObject* self, PyObject* item)
|
||||
{
|
||||
if (PyIndex_Check(item)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
|
||||
if (i == -1 && PyErr_Occurred())
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
return nullptr;
|
||||
if (i < 0)
|
||||
}
|
||||
if (i < 0) {
|
||||
i += sequence_length(self);
|
||||
}
|
||||
return sequence_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
Py_ssize_t start = 0, stop = 0, step = 0, slicelength = 0, cur = 0, i = 0;
|
||||
PyObject* slice = item;
|
||||
|
||||
if (PySlice_GetIndicesEx(slice,
|
||||
sequence_length(self),
|
||||
&start, &stop, &step, &slicelength) < 0) {
|
||||
if (PySlice_GetIndicesEx(slice, sequence_length(self), &start, &stop, &step, &slicelength)
|
||||
< 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (start == 0 && step == 1 &&
|
||||
slicelength == sequence_length(self) &&
|
||||
PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self) ->value();
|
||||
else if (start == 0 && step == 1 && slicelength == sequence_length(self)
|
||||
&& PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self)->value();
|
||||
Py::Tuple xyz(3);
|
||||
xyz.setItem(0, Py::Float(v.x));
|
||||
xyz.setItem(1, Py::Float(v.y));
|
||||
@@ -263,7 +263,7 @@ PyObject * VectorPy::mapping_subscript(PyObject *self, PyObject *item)
|
||||
return Py::new_reference_to(xyz);
|
||||
}
|
||||
else if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self)->value();
|
||||
Py::Tuple xyz(static_cast<size_t>(slicelength));
|
||||
|
||||
for (cur = start, i = 0; i < slicelength; cur += step, i++) {
|
||||
@@ -281,11 +281,12 @@ PyObject * VectorPy::mapping_subscript(PyObject *self, PyObject *item)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::add(PyObject *args)
|
||||
PyObject* VectorPy::add(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj))
|
||||
PyObject* obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -296,11 +297,12 @@ PyObject* VectorPy::add(PyObject *args)
|
||||
return new VectorPy(v);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::sub(PyObject *args)
|
||||
PyObject* VectorPy::sub(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj))
|
||||
PyObject* obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -311,36 +313,35 @@ PyObject* VectorPy::sub(PyObject *args)
|
||||
return new VectorPy(v);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::negative(PyObject *args)
|
||||
PyObject* VectorPy::negative(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy::PointerType this_ptr = getVectorPtr();
|
||||
Base::Vector3d v = -(*this_ptr);
|
||||
return new VectorPy(v);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::richCompare(PyObject *v, PyObject *w, int op)
|
||||
PyObject* VectorPy::richCompare(PyObject* v, PyObject* w, int op)
|
||||
{
|
||||
if (PyObject_TypeCheck(v, &(VectorPy::Type)) &&
|
||||
PyObject_TypeCheck(w, &(VectorPy::Type))) {
|
||||
if (PyObject_TypeCheck(v, &(VectorPy::Type)) && PyObject_TypeCheck(w, &(VectorPy::Type))) {
|
||||
Vector3d v1 = static_cast<VectorPy*>(v)->value();
|
||||
Vector3d v2 = static_cast<VectorPy*>(w)->value();
|
||||
|
||||
PyObject *res=nullptr;
|
||||
PyObject* res = nullptr;
|
||||
if (op != Py_EQ && op != Py_NE) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"no ordering relation is defined for Vector");
|
||||
PyErr_SetString(PyExc_TypeError, "no ordering relation is defined for Vector");
|
||||
return nullptr;
|
||||
}
|
||||
else if (op == Py_EQ) {
|
||||
res = (v1 == v2) ? Py_True : Py_False; //NOLINT
|
||||
res = (v1 == v2) ? Py_True : Py_False; // NOLINT
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
res = (v1 != v2) ? Py_True : Py_False; //NOLINT
|
||||
res = (v1 != v2) ? Py_True : Py_False; // NOLINT
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
@@ -352,12 +353,13 @@ PyObject* VectorPy::richCompare(PyObject *v, PyObject *w, int op)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* VectorPy::isEqual(PyObject *args)
|
||||
PyObject* VectorPy::isEqual(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
double tolerance=0;
|
||||
if (!PyArg_ParseTuple(args, "O!d", &(VectorPy::Type), &obj, &tolerance))
|
||||
PyObject* obj = nullptr;
|
||||
double tolerance = 0;
|
||||
if (!PyArg_ParseTuple(args, "O!d", &(VectorPy::Type), &obj, &tolerance)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -368,33 +370,36 @@ PyObject* VectorPy::isEqual(PyObject *args)
|
||||
return Py::new_reference_to(eq);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::scale(PyObject *args)
|
||||
PyObject* VectorPy::scale(PyObject* args)
|
||||
{
|
||||
double factorX = 0.0, factorY = 0.0, factorZ = 0.0;
|
||||
if (!PyArg_ParseTuple(args, "ddd", &factorX, &factorY, &factorZ))
|
||||
if (!PyArg_ParseTuple(args, "ddd", &factorX, &factorY, &factorZ)) {
|
||||
return nullptr;
|
||||
}
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
ptr->Scale(factorX, factorY, factorZ);
|
||||
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::multiply(PyObject *args)
|
||||
PyObject* VectorPy::multiply(PyObject* args)
|
||||
{
|
||||
double factor = 0.0;
|
||||
if (!PyArg_ParseTuple(args, "d", &factor))
|
||||
if (!PyArg_ParseTuple(args, "d", &factor)) {
|
||||
return nullptr;
|
||||
}
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
ptr->Scale(factor, factor, factor);
|
||||
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::dot(PyObject *args)
|
||||
PyObject* VectorPy::dot(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj))
|
||||
PyObject* obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -405,11 +410,12 @@ PyObject* VectorPy::dot(PyObject *args)
|
||||
return Py::new_reference_to(mult);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::cross(PyObject *args)
|
||||
PyObject* VectorPy::cross(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj))
|
||||
PyObject* obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -420,11 +426,12 @@ PyObject* VectorPy::cross(PyObject *args)
|
||||
return new VectorPy(v);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::isOnLineSegment(PyObject *args)
|
||||
PyObject* VectorPy::isOnLineSegment(PyObject* args)
|
||||
{
|
||||
PyObject *start = nullptr, *end = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&start, &end))
|
||||
if (!PyArg_ParseTuple(args, "OO", &start, &end)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(start, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -446,11 +453,12 @@ PyObject* VectorPy::isOnLineSegment(PyObject *args)
|
||||
return Py::new_reference_to(result);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::getAngle(PyObject *args)
|
||||
PyObject* VectorPy::getAngle(PyObject* args)
|
||||
{
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj))
|
||||
PyObject* obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* vec = static_cast<VectorPy*>(obj);
|
||||
|
||||
@@ -461,10 +469,11 @@ PyObject* VectorPy::getAngle(PyObject *args)
|
||||
return Py::new_reference_to(angle);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::normalize(PyObject *args)
|
||||
PyObject* VectorPy::normalize(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
if (ptr->Length() < Vector3d::epsilon()) {
|
||||
PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot normalize null vector");
|
||||
@@ -476,11 +485,12 @@ PyObject* VectorPy::normalize(PyObject *args)
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::projectToLine(PyObject *args)
|
||||
PyObject* VectorPy::projectToLine(PyObject* args)
|
||||
{
|
||||
PyObject *base = nullptr, *line = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&base, &line))
|
||||
if (!PyArg_ParseTuple(args, "OO", &base, &line)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -502,11 +512,12 @@ PyObject* VectorPy::projectToLine(PyObject *args)
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::projectToPlane(PyObject *args)
|
||||
PyObject* VectorPy::projectToPlane(PyObject* args)
|
||||
{
|
||||
PyObject *base = nullptr, *line = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&base, &line))
|
||||
if (!PyArg_ParseTuple(args, "OO", &base, &line)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -528,11 +539,12 @@ PyObject* VectorPy::projectToPlane(PyObject *args)
|
||||
return Py::new_reference_to(this);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::distanceToPoint(PyObject *args)
|
||||
PyObject* VectorPy::distanceToPoint(PyObject* args)
|
||||
{
|
||||
PyObject *pnt = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!",&(VectorPy::Type),&pnt))
|
||||
PyObject* pnt = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &pnt)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VectorPy* base_vec = static_cast<VectorPy*>(pnt);
|
||||
VectorPy::PointerType this_ptr = getVectorPtr();
|
||||
@@ -542,11 +554,12 @@ PyObject* VectorPy::distanceToPoint(PyObject *args)
|
||||
return Py::new_reference_to(dist);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::distanceToLine(PyObject *args)
|
||||
PyObject* VectorPy::distanceToLine(PyObject* args)
|
||||
{
|
||||
PyObject *base = nullptr, *line = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&base, &line))
|
||||
if (!PyArg_ParseTuple(args, "OO", &base, &line)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -567,11 +580,12 @@ PyObject* VectorPy::distanceToLine(PyObject *args)
|
||||
return Py::new_reference_to(dist);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::distanceToLineSegment(PyObject *args)
|
||||
PyObject* VectorPy::distanceToLineSegment(PyObject* args)
|
||||
{
|
||||
PyObject *base = nullptr, *line = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&base, &line))
|
||||
if (!PyArg_ParseTuple(args, "OO", &base, &line)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -592,11 +606,12 @@ PyObject* VectorPy::distanceToLineSegment(PyObject *args)
|
||||
return new VectorPy(v);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::distanceToPlane(PyObject *args)
|
||||
PyObject* VectorPy::distanceToPlane(PyObject* args)
|
||||
{
|
||||
PyObject *base = nullptr, *line = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO",&base, &line))
|
||||
if (!PyArg_ParseTuple(args, "OO", &base, &line)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
|
||||
return nullptr;
|
||||
@@ -623,7 +638,7 @@ Py::Float VectorPy::getLength() const
|
||||
return Py::Float(ptr->Length());
|
||||
}
|
||||
|
||||
void VectorPy::setLength(Py::Float arg)
|
||||
void VectorPy::setLength(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
double len = ptr->Length();
|
||||
@@ -631,7 +646,7 @@ void VectorPy::setLength(Py::Float arg)
|
||||
throw Py::RuntimeError(std::string("Cannot set length of null vector"));
|
||||
}
|
||||
|
||||
double val = static_cast<double>(arg)/len;
|
||||
double val = static_cast<double>(arg) / len;
|
||||
ptr->x *= val;
|
||||
ptr->y *= val;
|
||||
ptr->z *= val;
|
||||
@@ -643,7 +658,7 @@ Py::Float VectorPy::getx() const
|
||||
return Py::Float(ptr->x);
|
||||
}
|
||||
|
||||
void VectorPy::setx(Py::Float arg)
|
||||
void VectorPy::setx(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
ptr->x = static_cast<double>(arg);
|
||||
@@ -655,7 +670,7 @@ Py::Float VectorPy::gety() const
|
||||
return Py::Float(ptr->y);
|
||||
}
|
||||
|
||||
void VectorPy::sety(Py::Float arg)
|
||||
void VectorPy::sety(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
ptr->y = static_cast<double>(arg);
|
||||
@@ -667,13 +682,13 @@ Py::Float VectorPy::getz() const
|
||||
return Py::Float(ptr->z);
|
||||
}
|
||||
|
||||
void VectorPy::setz(Py::Float arg)
|
||||
void VectorPy::setz(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = getVectorPtr();
|
||||
ptr->z = static_cast<double>(arg);
|
||||
}
|
||||
|
||||
PyObject *VectorPy::getCustomAttributes(const char* /*attr*/) const
|
||||
PyObject* VectorPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -687,24 +702,24 @@ int VectorPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
// In generation script allow to more precisely define which slots
|
||||
// of the number protocol should be supported instead of setting all.
|
||||
|
||||
PyObject * VectorPy::number_divide_handler (PyObject* self, PyObject* other)
|
||||
PyObject* VectorPy::number_divide_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type)) &&
|
||||
PyNumber_Check(other)) {
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type)) && PyNumber_Check(other)) {
|
||||
// Vector passes PyNumber_Check because it sets nb_int and nb_float
|
||||
// slots of the PyNumberMethods structure. So, it must be explicitly
|
||||
// filered out here.
|
||||
if (PyObject_TypeCheck(other, &(VectorPy::Type))) {
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for /: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self)->value();
|
||||
double div = PyFloat_AsDouble(other);
|
||||
if (div == 0.0) {
|
||||
PyErr_Format(PyExc_ZeroDivisionError, "'%s' division by zero",
|
||||
Py_TYPE(self)->tp_name);
|
||||
PyErr_Format(PyExc_ZeroDivisionError, "'%s' division by zero", Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -712,136 +727,151 @@ PyObject * VectorPy::number_divide_handler (PyObject* self, PyObject* other)
|
||||
return new VectorPy(vec);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for /: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_remainder_handler (PyObject* self, PyObject* other)
|
||||
PyObject* VectorPy::number_remainder_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type)) &&
|
||||
PyObject_TypeCheck(other, &(VectorPy::Type)))
|
||||
{
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d b = static_cast<VectorPy*>(other) ->value();
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type))
|
||||
&& PyObject_TypeCheck(other, &(VectorPy::Type))) {
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self)->value();
|
||||
Base::Vector3d b = static_cast<VectorPy*>(other)->value();
|
||||
return new VectorPy(a % b);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for %%: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for %%: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_divmod_handler (PyObject* self, PyObject* other)
|
||||
PyObject* VectorPy::number_divmod_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for divmod(): '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_power_handler (PyObject* self, PyObject* other, PyObject* /*arg*/)
|
||||
PyObject* VectorPy::number_power_handler(PyObject* self, PyObject* other, PyObject* /*arg*/)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for ** or pow(): '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for ** or pow(): '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_negative_handler (PyObject* self)
|
||||
PyObject* VectorPy::number_negative_handler(PyObject* self)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self)->value();
|
||||
return new VectorPy(-vec);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary -: '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary -: '%s'", Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_positive_handler (PyObject* self)
|
||||
PyObject* VectorPy::number_positive_handler(PyObject* self)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self)->value();
|
||||
return new VectorPy(vec);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary +: '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary +: '%s'", Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_absolute_handler (PyObject* self)
|
||||
PyObject* VectorPy::number_absolute_handler(PyObject* self)
|
||||
{
|
||||
if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self) ->value();
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self)->value();
|
||||
vec.x = fabs(vec.x);
|
||||
vec.y = fabs(vec.y);
|
||||
vec.z = fabs(vec.z);
|
||||
return new VectorPy(vec);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for abs(): '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for abs(): '%s'", Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int VectorPy::number_nonzero_handler (PyObject* /*self*/)
|
||||
int VectorPy::number_nonzero_handler(PyObject* /*self*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_invert_handler (PyObject* self)
|
||||
PyObject* VectorPy::number_invert_handler(PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary ~: '%s'",
|
||||
PyErr_Format(PyExc_TypeError, "bad operand type for unary ~: '%s'", Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_lshift_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for <<: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_rshift_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for >>: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_and_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for &: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_xor_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for ^: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_or_handler(PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"unsupported operand type(s) for |: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_int_handler(PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"int() argument must be a string or a number, not '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_lshift_handler (PyObject* self, PyObject* other)
|
||||
PyObject* VectorPy::number_float_handler(PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_rshift_handler (PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for >>: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_and_handler (PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for &: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_xor_handler (PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for ^: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_or_handler (PyObject* self, PyObject* other)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for |: '%s' and '%s'",
|
||||
Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_int_handler (PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "int() argument must be a string or a number, not '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_float_handler (PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "float() argument must be a string or a number, not '%s'",
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"float() argument must be a string or a number, not '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user