summaryrefslogtreecommitdiffstats
path: root/libdimension-python/Vector.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-19 22:59:29 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-19 22:59:29 -0600
commitf4053866258e48dd98136142471ecabf6c138160 (patch)
tree5d472c9b0072dc7e493882f41f548b113b0c624d /libdimension-python/Vector.c
parent05ffbe15e92140617e90fe0ccbc22cc1fe0ac3e3 (diff)
downloaddimension-f4053866258e48dd98136142471ecabf6c138160.tar.xz
Add matricies to Python module.
Diffstat (limited to 'libdimension-python/Vector.c')
-rw-r--r--libdimension-python/Vector.c26
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;