pygame2.math
The pygame2.math C API contains various objects and functions for
math and vector operations.
Import
Include headers:
-
int import_pygame2_math(void)
- Imports the pygame2.math module. This returns 0 on success and
-1 on failure.
Macros
-
VEC_EPSILON
A small fractional value to come around rounding issues on floating
point calculations. VEC_EPSILON is usually used to soothe rounding
differences and thus to allow the system to return an appropriate
state, with a small tradeoff for the exactness.
Example:
(0.0000000000001 - 0.0000000000009) == 0.0
Given that VEC_EPSILON is large enough, the above calculation will be
true. To get over rounding issues on vector operations with small
fractional parts or to make them more exact, the concrete epsilon
value can be adjusted on a per PyVector basis.
Functions
-
double* VectorCoordsFromObj(PyObject *obj, Py_ssize_t *size)
- Tries to retrieve as many double values as possible from the passed obj.
If *obj is a PyVector, a copy of all its elements is returned.
Otherwise the method treats obj as a sequence of float values. The total
amount of doubles returned will be stored in size. The caller has to free
the return value using PyMem_Free(). This returns 1 on success and 0
on failure.
PyVector
-
PyVector
-
PyVector_Type
The PyVector object is a generic vector implementation, which can deal with
any dimension size. Specialized (and in some terms faster) implementations
for 2 and 3 dimensions can be found in the PyVector2 and
PyVector3 implementations.
Members
-
double* PyVector.coords
- The vector coordinates. It holds up to dim values.
-
Py_ssize_t PyVector.dim
- The number of dimensions (coordinate values), the PyVector can hold.
-
double PyVector.epsilon
- The fractional delta to use for soothing round differences for
floating point operations on the PyVector. see VEC_EPSILON
for more details.
Functions
-
int PyVector_Check(PyObject *obj)
- Returns true, if the argument is a PyVector or a subclass of
PyVector.
-
PyObject* PyVector_New(Py_ssize_t dims)
- Creates a new PyVector object with the given number of dimensions.
On failure, this returns NULL.
-
PyObject* PyVector_NewFromSeq(PyObject *obj)
- Creates a new PyVector object from the passed obj. obj is treated
as a sequence of float values (or PyVector). On failure, this
returns NULL.
-
PyVector_NewSpecialized(Py_ssize_t dims)
- This behaves like PyVector_New(), but creates specialized
PyVector2 or PyVector3 instances for a dims value of 2 or
3. On failure, this returns NULL.
PyVector2
-
PyVector2
-
PyVector2_Type
A specialized PyVector class limited to two dimensions.
Functions
-
int PyVector2_Check(PyObject *obj)
- Returns true, if the argument is a PyVector2 or a subclass of
PyVector2.
-
PyObject* PyVector2_New(double x, double y)
- Creates a new PyVector2 object with the specified x and y
coordinates. On failure, this returns NULL.
PyVector3
-
PyVector3
-
PyVector3_Type
A specialized PyVector class limited to three dimensions.
Functions
-
int PyVector3_Check(PyObject *obj)
- Returns true, if the argument is a PyVector3 or a subclass of
PyVector3.
-
PyObject* PyVector3_New(double x, double y, double z)
- Creates a new PyVector3 object with the specified x, y and z
coordinates. On failure, this returns NULL.