diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-05-19 22:59:29 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-05-19 22:59:29 -0600 |
commit | f4053866258e48dd98136142471ecabf6c138160 (patch) | |
tree | 5d472c9b0072dc7e493882f41f548b113b0c624d /libdimension-python/Vector.c | |
parent | 05ffbe15e92140617e90fe0ccbc22cc1fe0ac3e3 (diff) | |
download | dimension-f4053866258e48dd98136142471ecabf6c138160.tar.xz |
Add matricies to Python module.
Diffstat (limited to 'libdimension-python/Vector.c')
-rw-r--r-- | libdimension-python/Vector.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/libdimension-python/Vector.c b/libdimension-python/Vector.c index d4ed533..8cd7f05 100644 --- a/libdimension-python/Vector.c +++ b/libdimension-python/Vector.c @@ -19,18 +19,19 @@ *************************************************************************/ #include "Vector.h" -#include "dimension.h" -static int -dmnsn_py_Vector_init(dmnsn_py_Vector *self, PyObject *args, PyObject *kwds) +bool +dmnsn_py_Vector_args(dmnsn_vector *v, PyObject *args, PyObject *kwds) { static char *kwlist[] = { "x", "y", "z", NULL }; + return PyArg_ParseTupleAndKeywords(args, kwds, "ddd", kwlist, + &v->x, &v->y, &v->z); +} - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ddd", kwlist, - &self->v.x, &self->v.y, &self->v.z)) - return -1; - - return 0; +static int +dmnsn_py_Vector_init(dmnsn_py_Vector *self, PyObject *args, PyObject *kwds) +{ + return dmnsn_py_Vector_args(&self->v, args, kwds) ? 0 : -1; } static PyObject * @@ -79,12 +80,9 @@ dmnsn_py_Vector_str(dmnsn_py_Vector *self) static PyObject * dmnsn_py_Vector_richcompare(PyObject *lhs, PyObject *rhs, int op) { - if (!PyObject_TypeCheck(lhs, &dmnsn_py_VectorType)) { - PyErr_SetString(PyExc_TypeError, - "Vectors can only be compared with Vectors"); - return NULL; - } - if (!PyObject_TypeCheck(lhs, &dmnsn_py_VectorType)) { + if (!PyObject_TypeCheck(lhs, &dmnsn_py_VectorType) + || !PyObject_TypeCheck(rhs, &dmnsn_py_VectorType)) + { PyErr_SetString(PyExc_TypeError, "Vectors can only be compared with Vectors"); return NULL; |