static PyObject * Vector3D_cross(PyVector3D * self, PyVector3D * other) { if (!PyVector3D_Check(other)) { PyErr_SetString(PyExc_TypeError, "Can only cross with Vector3D"); return NULL; } PyVector3D * ret = newPyVector3D(); if (ret != NULL) { ret->coords = Cross(self->coords, other->coords); } return (PyObject *)ret; }
static PyVector3D*Vector3D_num_sub(PyVector3D*self,PyVector3D*other) { if (!PyVector3D_Check(other)) { PyErr_SetString(PyExc_TypeError, "Can only sub Vector3D from Vector3D"); return NULL; } PyVector3D * ret = newPyVector3D(); if (ret != NULL) { ret->coords = (self->coords - other->coords); } return ret; }
static PyObject *Point3D_unit_vector_to(PyPoint3D * self, PyPoint3D * other) { if (!PyPoint3D_Check(other)) { PyErr_SetString(PyExc_TypeError, "Can get unit vector to Point3D"); return NULL; } PyVector3D * ret = newPyVector3D(); if (ret != NULL) { ret->coords = (other->coords - self->coords); ret->coords.normalize(); } return (PyObject *)ret; }
static PyObject * Vector3D_unit_vector(PyVector3D * self) { PyVector3D * ret = newPyVector3D(); if (ret == NULL) { return NULL; } ret->coords = self->coords; WFMath::CoordType the_mag = ret->coords.mag(); if (!the_mag > 0) { PyErr_SetString(PyExc_ZeroDivisionError, "Attempt to normalize a vector with zero magnitude"); return NULL; } ret->coords /= the_mag; return (PyObject *)ret; }
static PyVector3D * Vector3D_num_div(PyVector3D * self, PyObject * _other) { double other; if (PyInt_Check(_other)) { other = PyInt_AsLong(_other); } else if (PyFloat_Check(_other)) { other = PyFloat_AsDouble(_other); } else { PyErr_SetString(PyExc_TypeError, "Vector3D can only be divided by numeric value"); return NULL; } PyVector3D * ret = newPyVector3D(); if (ret != NULL) { ret->coords = (self->coords / other); } return ret; }
static PyObject *Vector3D_unit_vector_to(PyVector3D * self, PyVector3D * other) { if (!PyVector3D_Check(other)) { PyErr_SetString(PyExc_TypeError, "Argument must be a Vector3D"); return NULL; } PyVector3D * ret = newPyVector3D(); if (ret == NULL) { return NULL; } ret->coords = (other->coords - self->coords); WFMath::CoordType the_mag = ret->coords.mag(); if (!the_mag > 0) { PyErr_SetString(PyExc_ZeroDivisionError, "Attempt to normalize a vector with zero magnitude"); return NULL; } ret->coords /= the_mag; return (PyObject *)ret; }
int main(int argc, char ** argv) { loadConfig(argc, argv); init_python_api("f5a8a981-e9ac-4f3b-a8f6-528add44da87"); PyVector3D * pv = newPyVector3D(); if (PyErr_Occurred() != 0) { PyErr_Print(); } PyObject * pv2 = PyInstance_New((PyObject*)&PyVector3D_Type, 0, 0); if (PyErr_Occurred() != 0) { PyErr_Print(); } shutdown_python_api(); }
static PyObject * Point3D_num_sub(PyPoint3D * self, PyObject * other) { if (PyVector3D_Check(other)) { PyVector3D * ovec = (PyVector3D *)other; PyPoint3D * ret = newPyPoint3D(); if (ret != NULL) { ret->coords = (self->coords - ovec->coords); } return (PyObject *)ret; } else if (PyPoint3D_Check(other)) { PyPoint3D * opoint = (PyPoint3D *)other; PyVector3D * ret = newPyVector3D(); if (ret != NULL) { ret->coords = (self->coords - opoint->coords); } return (PyObject *)ret; } else { PyErr_SetString(PyExc_TypeError, "Can only subtract Vector3D or Point3D from Point3D"); return NULL; } }