diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-05-20 09:46:20 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-05-20 09:46:20 -0600 |
commit | f8507034753eca08c6f5dcab3e515a72d48e6aa0 (patch) | |
tree | fc665d6eb1a3d479b12545deec37988e0180c18f /libdimension-python/Matrix.c | |
parent | 74722ac194ca76ecb54df9153b9f831e79b2bd22 (diff) | |
download | dimension-f8507034753eca08c6f5dcab3e515a72d48e6aa0.tar.xz |
Improve dmnsn_py_Vector_args() API.
Diffstat (limited to 'libdimension-python/Matrix.c')
-rw-r--r-- | libdimension-python/Matrix.c | 87 |
1 files changed, 19 insertions, 68 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 * |