Tested and working
--HG-- branch : py3dutil
This commit is contained in:
parent
439d8d013d
commit
28eefb96cf
6 changed files with 290 additions and 273 deletions
66
cgrid.c
66
cgrid.c
|
@ -354,3 +354,69 @@ PyObject* Cgrid_remove(PyObject *self_in, PyObject *args)
|
|||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PySequenceMethods Cgrid_as_seq[] = {
|
||||
Cgrid_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Cgrid_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
0, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
Cgrid_contains, /* sq_contains */
|
||||
};
|
||||
|
||||
PyMethodDef Cgrid_methods[] = {
|
||||
{"insert", (PyCFunction)Cgrid_insert, METH_VARARGS, "allocate the array to a new size"},
|
||||
{"delete", (PyCFunction)Cgrid_delete, METH_VARARGS, "remove a grid cell"},
|
||||
{"remove", (PyCFunction)Cgrid_remove, METH_VARARGS, "remove an object from its grid cell"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
struct PyMemberDef Cgrid_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(CgridObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(CgridObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(CgridObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject CgridObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"pyobarr.cgrid", /* tp_name */
|
||||
sizeof(CgridObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
Cgrid_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Cgrid_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
Cgrid_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Cgrid_methods, /* tp_methods */
|
||||
Cgrid_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Cgrid_init, /* tp_init */
|
||||
};
|
70
cgrid.h
70
cgrid.h
|
@ -60,69 +60,7 @@ PyObject* Cgrid_delete(PyObject *self_in, PyObject *args);
|
|||
PyObject* Cgrid_remove(PyObject *self_in, PyObject *args);
|
||||
/*PyObject* Cgrid_remove(PyObject *self_in, PyObject *args);*/
|
||||
|
||||
|
||||
static PySequenceMethods Cgrid_as_seq[] = {
|
||||
Cgrid_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Cgrid_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
0, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
Cgrid_contains, /* sq_contains */
|
||||
};
|
||||
|
||||
static PyMethodDef Cgrid_methods[] = {
|
||||
{"insert", (PyCFunction)Cgrid_insert, METH_VARARGS, "allocate the array to a new size"},
|
||||
{"delete", (PyCFunction)Cgrid_delete, METH_VARARGS, "remove a grid cell"},
|
||||
{"remove", (PyCFunction)Cgrid_remove, METH_VARARGS, "remove an object from its grid cell"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static struct PyMemberDef Cgrid_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(CgridObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(CgridObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(CgridObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static PyTypeObject CgridObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"pyobarr.cgrid", /* tp_name */
|
||||
sizeof(CgridObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
Cgrid_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Cgrid_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
Cgrid_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Cgrid_methods, /* tp_methods */
|
||||
Cgrid_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Cgrid_init, /* tp_init */
|
||||
};
|
||||
extern PySequenceMethods Cgrid_as_seq[];
|
||||
extern PyMethodDef Cgrid_methods[];
|
||||
extern struct PyMemberDef Cgrid_members[];
|
||||
extern PyTypeObject CgridObjectType;
|
78
obarr.c
78
obarr.c
|
@ -422,3 +422,81 @@ PyObject* Obarr_debug(PyObject* self_in, PyObject* args)
|
|||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Python object definition structures */
|
||||
PySequenceMethods Obarr_as_seq[] = {
|
||||
Obarr_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Obarr_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
Obarr_setitem, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
Obarr_contains, /* sq_contains */
|
||||
};
|
||||
|
||||
PyMethodDef Obarr_methods[] = {
|
||||
{"resize", (PyCFunction)Obarr_resize, METH_VARARGS, "allocate the array to a new size"},
|
||||
{"clear", (PyCFunction)Obarr_clear, METH_NOARGS, "delete everything in the array"},
|
||||
{"append", (PyCFunction)Obarr_append, METH_VARARGS, "append the object to the array"},
|
||||
{"find", (PyCFunction)Obarr_find, METH_VARARGS, "find the index of an object in the array"},
|
||||
{"index", (PyCFunction)Obarr_index, METH_VARARGS, "find the index of an object in the array"},
|
||||
{"debug", (PyCFunction)Obarr_debug, METH_NOARGS, "debug"},
|
||||
{"delete", (PyCFunction)Obarr_delete, METH_VARARGS, "delete a specific index in the array"},
|
||||
{"remove", (PyCFunction)Obarr_remove, METH_VARARGS, "remove an object from the array"},
|
||||
{"sort", (PyCFunction)Obarr_sort, METH_VARARGS, "sorts the array using another obarr of floats as sortkeys"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
struct PyMemberDef Obarr_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(ObarrObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(ObarrObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(ObarrObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject ObarrObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"py3dutil.obarr", /* tp_name */
|
||||
sizeof(ObarrObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
Obarr_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Obarr_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
Obarr_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Obarr_methods, /* tp_methods */
|
||||
Obarr_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Obarr_init, /* tp_init */
|
||||
};
|
||||
|
||||
|
||||
|
|
79
obarr.h
79
obarr.h
|
@ -53,78 +53,7 @@ typedef struct _sortkey
|
|||
} sortkey;
|
||||
int compare_doubles(const void *a, const void *b);
|
||||
|
||||
|
||||
/* Python object definition structures */
|
||||
static PySequenceMethods Obarr_as_seq[] = {
|
||||
Obarr_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Obarr_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
Obarr_setitem, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
Obarr_contains, /* sq_contains */
|
||||
};
|
||||
|
||||
static PyMethodDef Obarr_methods[] = {
|
||||
{"resize", (PyCFunction)Obarr_resize, METH_VARARGS, "allocate the array to a new size"},
|
||||
{"clear", (PyCFunction)Obarr_clear, METH_NOARGS, "delete everything in the array"},
|
||||
{"append", (PyCFunction)Obarr_append, METH_VARARGS, "append the object to the array"},
|
||||
{"find", (PyCFunction)Obarr_find, METH_VARARGS, "find the index of an object in the array"},
|
||||
{"index", (PyCFunction)Obarr_index, METH_VARARGS, "find the index of an object in the array"},
|
||||
{"debug", (PyCFunction)Obarr_debug, METH_NOARGS, "debug"},
|
||||
{"delete", (PyCFunction)Obarr_delete, METH_VARARGS, "delete a specific index in the array"},
|
||||
{"remove", (PyCFunction)Obarr_remove, METH_VARARGS, "remove an object from the array"},
|
||||
{"sort", (PyCFunction)Obarr_sort, METH_VARARGS, "sorts the array using another obarr of floats as sortkeys"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static struct PyMemberDef Obarr_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(ObarrObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(ObarrObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(ObarrObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static PyTypeObject ObarrObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"pyobarr.obarr", /* tp_name */
|
||||
sizeof(ObarrObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
Obarr_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Obarr_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
Obarr_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Obarr_methods, /* tp_methods */
|
||||
Obarr_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Obarr_init, /* tp_init */
|
||||
};
|
||||
|
||||
|
||||
extern PySequenceMethods Obarr_as_seq[];
|
||||
extern PyMethodDef Obarr_methods[];
|
||||
extern struct PyMemberDef Obarr_members[];
|
||||
extern PyTypeObject ObarrObjectType;
|
||||
|
|
132
vect.c
132
vect.c
|
@ -607,3 +607,135 @@ PyObject* Vect_item(PyObject *self_in, Py_ssize_t index)
|
|||
|
||||
|
||||
|
||||
|
||||
PyNumberMethods Vect_as_number[] = {
|
||||
Vect_add, /* nb_add */
|
||||
Vect_sub, /* nb_subtract */
|
||||
Vect_mul, /* nb_multiply */
|
||||
Vect_div, /* nb_divide */
|
||||
0, /* nb_remainder */
|
||||
0, /* nb_divmod */
|
||||
0, /* nb_power */
|
||||
Vect_negate, /* nb_negative */
|
||||
0, /* nb_positive */
|
||||
0, /* nb_absolute */
|
||||
Vect_true, /* nb_nonzero */
|
||||
0, /* nb_invert */
|
||||
0, /* nb_lshift */
|
||||
0, /* nb_rshift */
|
||||
0, /* nb_and */
|
||||
0, /* nb_xor */
|
||||
0, /* nb_or */
|
||||
0, /* nb_coerce */
|
||||
0, /* nb_int */
|
||||
0, /* nb_long */
|
||||
0, /* nb_float */
|
||||
0, /* nb_oct */
|
||||
0, /* nb_hex */
|
||||
Vect_ip_add, /* nb_inplace_add */
|
||||
Vect_ip_sub, /* nb_inplace_subtract */
|
||||
Vect_ip_mul, /* nb_inplace_multiply */
|
||||
Vect_ip_div, /* nb_inplace_divide */
|
||||
0, /* nb_inplace_remainder */
|
||||
0, /* nb_inplace_power */
|
||||
0, /* nb_inplace_lshift */
|
||||
0, /* nb_inplace_rshift */
|
||||
0, /* nb_inplace_and */
|
||||
0, /* nb_inplace_xor */
|
||||
0, /* nb_inplace_or */
|
||||
0, /* nb_floordiv */
|
||||
0, /* nb_truediv */
|
||||
0, /* nb_inplace_floordiv */
|
||||
0, /* nb_inplace_truediv */
|
||||
|
||||
};
|
||||
|
||||
PySequenceMethods Vect_as_seq[] = {
|
||||
Vect_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Vect_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
0, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
0, /* sq_contains */
|
||||
};
|
||||
|
||||
PyGetSetDef Vect_getset[] = {
|
||||
{"x", Vect_getx, Vect_set_notallowed, "x", NULL},
|
||||
{"y", Vect_gety, Vect_set_notallowed, "y", NULL},
|
||||
#if defined (VEC3D)
|
||||
{"z", Vect_getz, Vect_set_notallowed, "z", NULL},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyMethodDef Vect_methods[] = {
|
||||
{"__add__", (PyCFunction)Vect_add, METH_O|METH_COEXIST, "add two vectors"},
|
||||
{"__sub__", (PyCFunction)Vect_sub, METH_O|METH_COEXIST, "subtract two vectors"},
|
||||
{"__mul__", (PyCFunction)Vect_mul, METH_O|METH_COEXIST, "multiply a vector by a scalar"},
|
||||
{"__div__", (PyCFunction)Vect_div, METH_O|METH_COEXIST, "divide a vector by a scalar"},
|
||||
{"__neg__", (PyCFunction)Vect_negate, METH_O|METH_COEXIST, "negate (reverse) a vector"},
|
||||
{"zero", (PyCFunction)Vect_ip_zero, METH_NOARGS, "sets all vector components to 0"},
|
||||
{"negate", (PyCFunction)Vect_ip_negate, METH_NOARGS, "negate (reverse) a vector in place"},
|
||||
{"normalize", (PyCFunction)Vect_ip_normalize, METH_NOARGS, "normalize a vector in place"},
|
||||
{"avg", (PyCFunction)Vect_average, METH_VARARGS, "find halfway between this and another vector"},
|
||||
{"dot", (PyCFunction)Vect_dotprod, METH_VARARGS, "compute the dot product of this and another vector"},
|
||||
{"cross", (PyCFunction)Vect_crossprod, METH_VARARGS, "compute the cross product of this and another vector"},
|
||||
{"dist", (PyCFunction)Vect_dist, METH_VARARGS, "compute the distance between this and another vector"},
|
||||
{"mag", (PyCFunction)Vect_mag, METH_NOARGS, "compute the vector magnitude"},
|
||||
{"mag2", (PyCFunction)Vect_mag2, METH_NOARGS, "compute the squared vector magnitude"},
|
||||
{"dir", (PyCFunction)Vect_dir, METH_NOARGS, "compute the vector direction (in Euler angles)"},
|
||||
{"copy", (PyCFunction)Vect_copy, METH_NOARGS, "makes a copy"},
|
||||
{"slerp", (PyCFunction)Vect_slerp, METH_VARARGS, "spherical linear interpolation"},
|
||||
{"sserp", (PyCFunction)Vect_sserp, METH_VARARGS, "spherical spherical interpolation"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
struct PyMemberDef Vect_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(VectObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(VectObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(VectObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject VectObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"py3dutil.vect", /* tp_name */
|
||||
sizeof(VectObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
0, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Vect_repr, /* tp_repr */
|
||||
Vect_as_number, /* tp_as_number */
|
||||
Vect_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Vect_methods, /* tp_methods */
|
||||
Vect_members, /* tp_members */
|
||||
Vect_getset, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Vect_init, /* tp_init */
|
||||
};
|
138
vect.h
138
vect.h
|
@ -69,135 +69,9 @@ PyObject* Vect_item(PyObject *self_in, Py_ssize_t index);
|
|||
|
||||
|
||||
|
||||
|
||||
static PyNumberMethods Vect_as_number[] = {
|
||||
Vect_add, /* nb_add */
|
||||
Vect_sub, /* nb_subtract */
|
||||
Vect_mul, /* nb_multiply */
|
||||
Vect_div, /* nb_divide */
|
||||
0, /* nb_remainder */
|
||||
0, /* nb_divmod */
|
||||
0, /* nb_power */
|
||||
Vect_negate, /* nb_negative */
|
||||
0, /* nb_positive */
|
||||
0, /* nb_absolute */
|
||||
Vect_true, /* nb_nonzero */
|
||||
0, /* nb_invert */
|
||||
0, /* nb_lshift */
|
||||
0, /* nb_rshift */
|
||||
0, /* nb_and */
|
||||
0, /* nb_xor */
|
||||
0, /* nb_or */
|
||||
0, /* nb_coerce */
|
||||
0, /* nb_int */
|
||||
0, /* nb_long */
|
||||
0, /* nb_float */
|
||||
0, /* nb_oct */
|
||||
0, /* nb_hex */
|
||||
Vect_ip_add, /* nb_inplace_add */
|
||||
Vect_ip_sub, /* nb_inplace_subtract */
|
||||
Vect_ip_mul, /* nb_inplace_multiply */
|
||||
Vect_ip_div, /* nb_inplace_divide */
|
||||
0, /* nb_inplace_remainder */
|
||||
0, /* nb_inplace_power */
|
||||
0, /* nb_inplace_lshift */
|
||||
0, /* nb_inplace_rshift */
|
||||
0, /* nb_inplace_and */
|
||||
0, /* nb_inplace_xor */
|
||||
0, /* nb_inplace_or */
|
||||
0, /* nb_floordiv */
|
||||
0, /* nb_truediv */
|
||||
0, /* nb_inplace_floordiv */
|
||||
0, /* nb_inplace_truediv */
|
||||
|
||||
};
|
||||
|
||||
static PySequenceMethods Vect_as_seq[] = {
|
||||
Vect_len, /* sq_length */
|
||||
0, /* sq_concat */
|
||||
0, /* sq_repeat */
|
||||
Vect_item, /* sq_item */
|
||||
0, /* sq_slice */
|
||||
0, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
0, /* sq_contains */
|
||||
};
|
||||
|
||||
static PyGetSetDef Vect_getset[] = {
|
||||
{"x", Vect_getx, Vect_set_notallowed, "x", NULL},
|
||||
{"y", Vect_gety, Vect_set_notallowed, "y", NULL},
|
||||
#if defined (VEC3D)
|
||||
{"z", Vect_getz, Vect_set_notallowed, "z", NULL},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static PyMethodDef Vect_methods[] = {
|
||||
{"__add__", (PyCFunction)Vect_add, METH_O|METH_COEXIST, "add two vectors"},
|
||||
{"__sub__", (PyCFunction)Vect_sub, METH_O|METH_COEXIST, "subtract two vectors"},
|
||||
{"__mul__", (PyCFunction)Vect_mul, METH_O|METH_COEXIST, "multiply a vector by a scalar"},
|
||||
{"__div__", (PyCFunction)Vect_div, METH_O|METH_COEXIST, "divide a vector by a scalar"},
|
||||
{"__neg__", (PyCFunction)Vect_negate, METH_O|METH_COEXIST, "negate (reverse) a vector"},
|
||||
{"zero", (PyCFunction)Vect_ip_zero, METH_NOARGS, "sets all vector components to 0"},
|
||||
{"negate", (PyCFunction)Vect_ip_negate, METH_NOARGS, "negate (reverse) a vector in place"},
|
||||
{"normalize", (PyCFunction)Vect_ip_normalize, METH_NOARGS, "normalize a vector in place"},
|
||||
{"avg", (PyCFunction)Vect_average, METH_VARARGS, "find halfway between this and another vector"},
|
||||
{"dot", (PyCFunction)Vect_dotprod, METH_VARARGS, "compute the dot product of this and another vector"},
|
||||
{"cross", (PyCFunction)Vect_crossprod, METH_VARARGS, "compute the cross product of this and another vector"},
|
||||
{"dist", (PyCFunction)Vect_dist, METH_VARARGS, "compute the distance between this and another vector"},
|
||||
{"mag", (PyCFunction)Vect_mag, METH_NOARGS, "compute the vector magnitude"},
|
||||
{"mag2", (PyCFunction)Vect_mag2, METH_NOARGS, "compute the squared vector magnitude"},
|
||||
{"dir", (PyCFunction)Vect_dir, METH_NOARGS, "compute the vector direction (in Euler angles)"},
|
||||
{"copy", (PyCFunction)Vect_copy, METH_NOARGS, "makes a copy"},
|
||||
{"slerp", (PyCFunction)Vect_slerp, METH_VARARGS, "spherical linear interpolation"},
|
||||
{"sserp", (PyCFunction)Vect_sserp, METH_VARARGS, "spherical spherical interpolation"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static struct PyMemberDef Vect_members[] = {
|
||||
/*{"x", T_OBJECT_EX, offsetof(VectObject, x), 0, "x"},
|
||||
{"y", T_OBJECT_EX, offsetof(VectObject, y), 0, "y"},
|
||||
{"z", T_OBJECT_EX, offsetof(VectObject, z), 0, "z"},*/
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static PyTypeObject VectObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"py3dutil.vect", /* tp_name */
|
||||
sizeof(VectObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
0, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
Vect_repr, /* tp_repr */
|
||||
Vect_as_number, /* tp_as_number */
|
||||
Vect_as_seq, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES, /* tp_flags */
|
||||
"Vector objects are simple.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
Vect_methods, /* tp_methods */
|
||||
Vect_members, /* tp_members */
|
||||
Vect_getset, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)Vect_init, /* tp_init */
|
||||
};
|
||||
extern PyNumberMethods Vect_as_number[];
|
||||
extern PySequenceMethods Vect_as_seq[];
|
||||
extern PyGetSetDef Vect_getset[];
|
||||
extern PyMethodDef Vect_methods[];
|
||||
extern struct PyMemberDef Vect_members[];
|
||||
extern PyTypeObject VectObjectType;
|
||||
|
|
Loading…
Add table
Reference in a new issue