builds and installs properly now

--HG--
branch : py3dutil
This commit is contained in:
cecilkorik 2007-11-15 20:10:16 +00:00
parent 65350ebdfc
commit 439d8d013d
4 changed files with 46 additions and 41 deletions

View file

@ -1,5 +1,6 @@
#include "obarr.h" #include "obarr.h"
#include "cgrid.h" #include "cgrid.h"
#include "vect.h"
static PyMethodDef ModMethods[] = { static PyMethodDef ModMethods[] = {
@ -13,14 +14,17 @@ initpy3dutil(void)
ObarrObjectType.tp_new = PyType_GenericNew; ObarrObjectType.tp_new = PyType_GenericNew;
CgridObjectType.tp_new = PyType_GenericNew; CgridObjectType.tp_new = PyType_GenericNew;
VectObjectType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ObarrObjectType) < 0) if (PyType_Ready(&ObarrObjectType) < 0)
return; return;
if (PyType_Ready(&CgridObjectType) < 0) if (PyType_Ready(&CgridObjectType) < 0)
return; return;
if (PyType_Ready(&VectObjectType) < 0)
return;
(void) Py_InitModule("py3dutil", ModMethods); (void) Py_InitModule("py3dutil", ModMethods);
m = Py_InitModule3("py3dutil", NULL, m = Py_InitModule3("py3dutil", NULL,
"Example module that creates an extension type."); "Various 3d utilities to accelerate 3d games");
if (m == NULL) if (m == NULL)
return; return;
@ -28,4 +32,5 @@ initpy3dutil(void)
Py_INCREF(&CgridObjectType); Py_INCREF(&CgridObjectType);
PyModule_AddObject(m, "obarr", (PyObject *)&ObarrObjectType); PyModule_AddObject(m, "obarr", (PyObject *)&ObarrObjectType);
PyModule_AddObject(m, "cgrid", (PyObject *)&CgridObjectType); PyModule_AddObject(m, "cgrid", (PyObject *)&CgridObjectType);
PyModule_AddObject(m, "vect", (PyObject *)&VectObjectType);
} }

View file

@ -2,7 +2,7 @@ from distutils.core import setup, Extension
from cPickle import load, dump from cPickle import load, dump
import os import os
module1 = Extension('pyobarr', sources = ['pyobarr.c', 'obarr.c', 'cgrid.c', 'red_black_tree.c', 'misc.c']) module1 = Extension('py3dutil', sources = ['py3dutil.c', 'obarr.c', 'cgrid.c', 'red_black_tree.c', 'misc.c', 'vect.c'])
buildno = 0 buildno = 0
if os.path.exists('buildno'): if os.path.exists('buildno'):

56
vect.c
View file

@ -1,4 +1,4 @@
#include "vect.h"
#include <math.h> #include <math.h>
#ifdef _MSC_VER #ifdef _MSC_VER
@ -22,8 +22,6 @@
staticforward PyTypeObject VectObjectType;
int Vect_init(VectObject *self, PyObject *args, PyObject *kwds) int Vect_init(VectObject *self, PyObject *args, PyObject *kwds)
{ {
#if defined (VEC3D) #if defined (VEC3D)
@ -46,7 +44,7 @@ int Vect_init(VectObject *self, PyObject *args, PyObject *kwds)
return 0; return 0;
} }
PyObject* vect_get_element(PyObject* self_in, int index) PyObject* vect_get_element(PyObject* self_in, long index)
{ {
VectObject* self = (VectObject*)self_in; VectObject* self = (VectObject*)self_in;
return PyFloat_FromDouble(self->elements[index]); return PyFloat_FromDouble(self->elements[index]);
@ -103,7 +101,7 @@ int Vect_true(PyObject *self_in)
{ {
VectObject *self = (VectObject*)self_in; VectObject *self = (VectObject*)self_in;
int b = 1; int b = 1;
int i; long i;
double x; double x;
for (i = 0; i < VECLEN; i++) for (i = 0; i < VECLEN; i++)
{ {
@ -117,7 +115,7 @@ int Vect_true(PyObject *self_in)
PyObject* Vect_add(PyObject *self_in, PyObject *other_in) PyObject* Vect_add(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *other, *rv; VectObject *self, *other, *rv;
int i; long i;
if (!Vect_Check(self_in) || !Vect_Check(other_in)) if (!Vect_Check(self_in) || !Vect_Check(other_in))
{ {
PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'"); PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'");
@ -135,7 +133,7 @@ PyObject* Vect_add(PyObject *self_in, PyObject *other_in)
PyObject* Vect_sub(PyObject *self_in, PyObject *other_in) PyObject* Vect_sub(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *other, *rv; VectObject *self, *other, *rv;
int i; long i;
if (!Vect_Check(self_in) || !Vect_Check(other_in)) if (!Vect_Check(self_in) || !Vect_Check(other_in))
{ {
PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'"); PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'");
@ -153,7 +151,7 @@ PyObject* Vect_sub(PyObject *self_in, PyObject *other_in)
PyObject* Vect_mul(PyObject *self_in, PyObject *other_in) PyObject* Vect_mul(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *rv; VectObject *self, *rv;
int i; long i;
double scalar; double scalar;
if (!Vect_Check(self_in) || !PyFloat_Check(other_in)) if (!Vect_Check(self_in) || !PyFloat_Check(other_in))
{ {
@ -173,7 +171,7 @@ PyObject* Vect_mul(PyObject *self_in, PyObject *other_in)
PyObject* Vect_div(PyObject *self_in, PyObject *other_in) PyObject* Vect_div(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *rv; VectObject *self, *rv;
int i; long i;
double scalar; double scalar;
if (!Vect_Check(self_in) || !PyFloat_Check(other_in)) if (!Vect_Check(self_in) || !PyFloat_Check(other_in))
{ {
@ -192,7 +190,7 @@ PyObject* Vect_div(PyObject *self_in, PyObject *other_in)
PyObject* Vect_ip_add(PyObject *self_in, PyObject *other_in) PyObject* Vect_ip_add(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *other; VectObject *self, *other;
int i; long i;
if (!Vect_Check(self_in) || !Vect_Check(other_in)) if (!Vect_Check(self_in) || !Vect_Check(other_in))
{ {
PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'"); PyErr_SetString(PyExc_TypeError, "both arguments must be of type 'vect'");
@ -210,7 +208,7 @@ PyObject* Vect_ip_add(PyObject *self_in, PyObject *other_in)
PyObject* Vect_ip_sub(PyObject *self_in, PyObject *other_in) PyObject* Vect_ip_sub(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self, *other; VectObject *self, *other;
int i; long i;
if (!Vect_Check(self_in) || !Vect_Check(other_in)) if (!Vect_Check(self_in) || !Vect_Check(other_in))
{ {
@ -229,7 +227,7 @@ PyObject* Vect_ip_sub(PyObject *self_in, PyObject *other_in)
PyObject* Vect_ip_mul(PyObject *self_in, PyObject *other_in) PyObject* Vect_ip_mul(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self; VectObject *self;
int i; long i;
double scalar; double scalar;
if (!Vect_Check(self_in) || !PyFloat_Check(other_in)) if (!Vect_Check(self_in) || !PyFloat_Check(other_in))
{ {
@ -248,7 +246,7 @@ PyObject* Vect_ip_mul(PyObject *self_in, PyObject *other_in)
PyObject* Vect_ip_div(PyObject *self_in, PyObject *other_in) PyObject* Vect_ip_div(PyObject *self_in, PyObject *other_in)
{ {
VectObject *self; VectObject *self;
int i; long i;
double scalar; double scalar;
if (!Vect_Check(self_in) || !PyFloat_Check(other_in)) if (!Vect_Check(self_in) || !PyFloat_Check(other_in))
{ {
@ -267,7 +265,7 @@ PyObject* Vect_ip_div(PyObject *self_in, PyObject *other_in)
PyObject* Vect_negate(PyObject *self_in) PyObject* Vect_negate(PyObject *self_in)
{ {
VectObject *self, *rv; VectObject *self, *rv;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -284,7 +282,7 @@ PyObject* Vect_negate(PyObject *self_in)
PyObject* Vect_ip_negate(PyObject *self_in, PyObject *unused) PyObject* Vect_ip_negate(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -301,7 +299,7 @@ PyObject* Vect_ip_negate(PyObject *self_in, PyObject *unused)
PyObject* Vect_ip_zero(PyObject *self_in, PyObject *unused) PyObject* Vect_ip_zero(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -319,7 +317,7 @@ PyObject* Vect_ip_normalize(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
double mag, mag2; double mag, mag2;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -344,7 +342,7 @@ PyObject* Vect_mag(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
double d; double d;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -363,7 +361,7 @@ PyObject* Vect_mag2(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
double d; double d;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -381,7 +379,7 @@ PyObject* Vect_dotprod(PyObject *self_in, PyObject *args)
{ {
VectObject *self, *other; VectObject *self, *other;
double d; double d;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -413,7 +411,7 @@ PyObject* Vect_crossprod(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
double d; double d;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -431,7 +429,7 @@ PyObject* Vect_crossprod(PyObject *self_in, PyObject *unused)
PyObject* Vect_average(PyObject *self_in, PyObject *args) PyObject* Vect_average(PyObject *self_in, PyObject *args)
{ {
VectObject *self, *other, *rv; VectObject *self, *other, *rv;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -454,7 +452,7 @@ PyObject* Vect_dir(PyObject *self_in, PyObject *unused)
{ {
VectObject *self; VectObject *self;
double d; double d;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -471,7 +469,7 @@ PyObject* Vect_dir(PyObject *self_in, PyObject *unused)
PyObject* Vect_copy(PyObject *self_in, PyObject *unused) PyObject* Vect_copy(PyObject *self_in, PyObject *unused)
{ {
VectObject *self, *rv; VectObject *self, *rv;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -489,7 +487,7 @@ PyObject* Vect_dist(PyObject *self_in, PyObject *args)
{ {
VectObject *self, *other; VectObject *self, *other;
double d, dd; double d, dd;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -516,7 +514,7 @@ PyObject* Vect_slerp(PyObject *self_in, PyObject *args)
{ {
VectObject *self, *other, *rv; VectObject *self, *other, *rv;
double amt, oamt; double amt, oamt;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -544,7 +542,7 @@ PyObject* Vect_sserp(PyObject *self_in, PyObject *args)
{ {
VectObject *self, *other, *rv, *norm; VectObject *self, *other, *rv, *norm;
double amt, oamt, smag, omag; double amt, oamt, smag, omag;
int i; long i;
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
PyErr_SetString(PyExc_TypeError, "not a vector"); PyErr_SetString(PyExc_TypeError, "not a vector");
@ -579,7 +577,7 @@ PyObject* Vect_sserp(PyObject *self_in, PyObject *args)
} }
int Vect_len(PyObject *self_in) Py_ssize_t Vect_len(PyObject *self_in)
{ {
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {
@ -590,7 +588,7 @@ int Vect_len(PyObject *self_in)
} }
PyObject* Vect_item(PyObject *self_in, int index) PyObject* Vect_item(PyObject *self_in, Py_ssize_t index)
{ {
if (!Vect_Check(self_in)) if (!Vect_Check(self_in))
{ {

22
vect.h
View file

@ -7,13 +7,6 @@ typedef int Py_ssize_t;
#define PY_SSIZE_T_MIN INT_MIN #define PY_SSIZE_T_MIN INT_MIN
#endif #endif
typedef struct {
PyObject_HEAD
double elements[VECLEN];
} VectObject;
#define Vect_Check(op) PyObject_TypeCheck(op, &VectObjectType)
#define VEC3D #define VEC3D
#ifdef VEC3D #ifdef VEC3D
@ -25,8 +18,17 @@ typedef struct {
#endif #endif
typedef struct VectObject {
PyObject_HEAD
double elements[VECLEN];
} VectObject;
#define Vect_Check(op) PyObject_TypeCheck(op, &VectObjectType)
// internal functions // internal functions
PyObject* vect_get_element(PyObject* self_in, int index); PyObject* vect_get_element(PyObject* self_in, long index);
// Python API functions // Python API functions
int Vect_init(VectObject *self, PyObject *args, PyObject *kwds); int Vect_init(VectObject *self, PyObject *args, PyObject *kwds);
@ -60,8 +62,8 @@ PyObject* Vect_copy(PyObject *self_in, PyObject *unused);
PyObject* Vect_dist(PyObject *self_in, PyObject *args); PyObject* Vect_dist(PyObject *self_in, PyObject *args);
PyObject* Vect_slerp(PyObject *self_in, PyObject *args); PyObject* Vect_slerp(PyObject *self_in, PyObject *args);
PyObject* Vect_sserp(PyObject *self_in, PyObject *args); PyObject* Vect_sserp(PyObject *self_in, PyObject *args);
int Vect_len(PyObject *self_in); Py_ssize_t Vect_len(PyObject *self_in);
PyObject* Vect_item(PyObject *self_in, int index); PyObject* Vect_item(PyObject *self_in, Py_ssize_t index);