summaryrefslogtreecommitdiffstats
path: root/libdimension-python/Vector.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-20 13:18:41 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-20 13:18:41 -0600
commit387c1b8b1fcf80233d3fc73aa3be766bfea83dc8 (patch)
tree934405241c57a7c75da50ce9ed62170689fb8c0e /libdimension-python/Vector.c
parent7c0e81ee456be8eded08da4b41b361e1db5416f1 (diff)
downloaddimension-387c1b8b1fcf80233d3fc73aa3be766bfea83dc8.tar.xz
Add Colors to the Python extension.
Diffstat (limited to 'libdimension-python/Vector.c')
-rw-r--r--libdimension-python/Vector.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/libdimension-python/Vector.c b/libdimension-python/Vector.c
index 3fdc90c..6a1928f 100644
--- a/libdimension-python/Vector.c
+++ b/libdimension-python/Vector.c
@@ -84,11 +84,11 @@ dmnsn_py_Vector_str(dmnsn_py_Vector *self)
return NULL;
}
- PyObject *repr = PyUnicode_FromFormat("<%S, %S, %S>", x, y, z);
+ PyObject *str = PyUnicode_FromFormat("<%S, %S, %S>", x, y, z);
Py_DECREF(z);
Py_DECREF(y);
Py_DECREF(x);
- return repr;
+ return str;
}
static PyObject *
@@ -315,27 +315,27 @@ static PyMethodDef dmnsn_py_Vector_methods[] = {
};
static PyObject *
-dmnsn_py_Vector_getx(dmnsn_py_Vector *self, void *closure)
+dmnsn_py_Vector_get_x(dmnsn_py_Vector *self, void *closure)
{
return PyFloat_FromDouble(self->v.x);
}
static PyObject *
-dmnsn_py_Vector_gety(dmnsn_py_Vector *self, void *closure)
+dmnsn_py_Vector_get_y(dmnsn_py_Vector *self, void *closure)
{
return PyFloat_FromDouble(self->v.y);
}
static PyObject *
-dmnsn_py_Vector_getz(dmnsn_py_Vector *self, void *closure)
+dmnsn_py_Vector_get_z(dmnsn_py_Vector *self, void *closure)
{
return PyFloat_FromDouble(self->v.z);
}
static PyGetSetDef dmnsn_py_Vector_getsetters[] = {
- { "x", (getter)dmnsn_py_Vector_getx, NULL, "x coordinate", NULL },
- { "y", (getter)dmnsn_py_Vector_gety, NULL, "y coordinate", NULL },
- { "z", (getter)dmnsn_py_Vector_getz, NULL, "z coordinate", NULL },
+ { "x", (getter)dmnsn_py_Vector_get_x, NULL, "x coordinate", NULL },
+ { "y", (getter)dmnsn_py_Vector_get_y, NULL, "y coordinate", NULL },
+ { "z", (getter)dmnsn_py_Vector_get_z, NULL, "z coordinate", NULL },
{ NULL }
};
@@ -354,10 +354,24 @@ PyTypeObject dmnsn_py_VectorType = {
.tp_init = (initproc)dmnsn_py_Vector_init,
};
+#define dmnsn_py_Vector_global(name) \
+ dmnsn_py_Vector name = { \
+ PyObject_HEAD_INIT(&dmnsn_py_VectorType) \
+ };
+
+dmnsn_py_Vector_global(dmnsn_py_Zero);
+dmnsn_py_Vector_global(dmnsn_py_X);
+dmnsn_py_Vector_global(dmnsn_py_Y);
+dmnsn_py_Vector_global(dmnsn_py_Z);
+
bool
dmnsn_py_init_VectorType(void)
{
+ dmnsn_py_Zero.v = dmnsn_zero;
+ dmnsn_py_X.v = dmnsn_x;
+ dmnsn_py_Y.v = dmnsn_y;
+ dmnsn_py_Z.v = dmnsn_z;
+
dmnsn_py_VectorType.tp_new = PyType_GenericNew;
- Py_INCREF(&dmnsn_py_VectorType);
return PyType_Ready(&dmnsn_py_VectorType) >= 0;
}