summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-20 09:46:20 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-20 09:46:20 -0600
commitf8507034753eca08c6f5dcab3e515a72d48e6aa0 (patch)
treefc665d6eb1a3d479b12545deec37988e0180c18f /libdimension-python
parent74722ac194ca76ecb54df9153b9f831e79b2bd22 (diff)
downloaddimension-f8507034753eca08c6f5dcab3e515a72d48e6aa0.tar.xz
Improve dmnsn_py_Vector_args() API.
Diffstat (limited to 'libdimension-python')
-rw-r--r--libdimension-python/Matrix.c87
-rw-r--r--libdimension-python/Vector.c18
2 files changed, 35 insertions, 70 deletions
diff --git a/libdimension-python/Matrix.c b/libdimension-python/Matrix.c
index a414622..0de8acc 100644
--- a/libdimension-python/Matrix.c
+++ b/libdimension-python/Matrix.c
@@ -45,92 +45,43 @@ PyObject *
dmnsn_py_Matrix_scale(PyObject *self, PyObject *args, PyObject *kwds)
{
dmnsn_vector scale;
- if (dmnsn_py_Vector_args(&scale, args, kwds)) {
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_scale_matrix(scale);
- }
- return (PyObject *)ret;
- } else {
- PyErr_Clear();
- if (kwds) {
- PyErr_SetString(PyExc_TypeError,
- "Keywords only make sense for component syntax");
- return NULL;
- }
-
- dmnsn_py_Vector *scale;
- if (!PyArg_ParseTuple(args, "O!", &dmnsn_py_VectorType, &scale))
- return NULL;
+ if (!dmnsn_py_Vector_args(&scale, args, kwds))
+ return NULL;
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_scale_matrix(scale->v);
- }
- return (PyObject *)ret;
+ dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
+ if (ret) {
+ ret->m = dmnsn_scale_matrix(scale);
}
+ return (PyObject *)ret;
}
PyObject *
dmnsn_py_Matrix_translate(PyObject *self, PyObject *args, PyObject *kwds)
{
dmnsn_vector translate;
- if (dmnsn_py_Vector_args(&translate, args, kwds)) {
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_translation_matrix(translate);
- }
- return (PyObject *)ret;
- } else {
- PyErr_Clear();
- if (kwds) {
- PyErr_SetString(PyExc_TypeError,
- "Keywords only make sense for component syntax");
- return NULL;
- }
-
- dmnsn_py_Vector *translate;
- if (!PyArg_ParseTuple(args, "O!", &dmnsn_py_VectorType, &translate))
- return NULL;
+ if (!dmnsn_py_Vector_args(&translate, args, kwds))
+ return NULL;
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_translation_matrix(translate->v);
- }
- return (PyObject *)ret;
+ dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
+ if (ret) {
+ ret->m = dmnsn_translation_matrix(translate);
}
+ return (PyObject *)ret;
}
PyObject *
dmnsn_py_Matrix_rotate(PyObject *self, PyObject *args, PyObject *kwds)
{
dmnsn_vector rotate;
- if (dmnsn_py_Vector_args(&rotate, args, kwds)) {
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_rotation_matrix(dmnsn_vector_mul(dmnsn_radians(1.0),
- rotate));
- }
- return (PyObject *)ret;
- } else {
- PyErr_Clear();
- if (kwds) {
- PyErr_SetString(PyExc_TypeError,
- "Keywords only make sense for component syntax");
- return NULL;
- }
-
- dmnsn_py_Vector *rotate;
- if (!PyArg_ParseTuple(args, "O!", &dmnsn_py_VectorType, &rotate))
- return NULL;
+ if (!dmnsn_py_Vector_args(&rotate, args, kwds))
+ return NULL;
- dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
- if (ret) {
- ret->m = dmnsn_rotation_matrix(dmnsn_vector_mul(dmnsn_radians(1.0),
- rotate->v));
- }
- return (PyObject *)ret;
+ dmnsn_py_Matrix *ret = PyObject_New(dmnsn_py_Matrix, &dmnsn_py_MatrixType);
+ if (ret) {
+ ret->m = dmnsn_rotation_matrix(dmnsn_vector_mul(dmnsn_radians(1.0),
+ rotate));
}
+ return (PyObject *)ret;
}
static PyObject *
diff --git a/libdimension-python/Vector.c b/libdimension-python/Vector.c
index 8cd7f05..3fdc90c 100644
--- a/libdimension-python/Vector.c
+++ b/libdimension-python/Vector.c
@@ -24,8 +24,22 @@ 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,
+ &v->x, &v->y, &v->z)) {
+ return true;
+ } else {
+ if (kwds)
+ return false;
+
+ PyErr_Clear();
+
+ dmnsn_py_Vector *vec;
+ if (!PyArg_ParseTuple(args, "O!", &dmnsn_py_VectorType, &vec))
+ return false;
+
+ *v = vec->v;
+ return true;
+ }
}
static int