Blender  V2.93
mathutils_Matrix.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 extern PyTypeObject matrix_Type;
24 extern PyTypeObject matrix_access_Type;
25 
26 typedef unsigned short ushort;
27 
28 #define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type)
29 #define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type)
30 
31 #define MATRIX_MAX_DIM 4
32 
33 /* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
34 
35 #ifdef DEBUG
36 # define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
37  (BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col))
38 #else
39 # define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
40 #endif
41 
42 #define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row))
43 #define MATRIX_ITEM_INDEX(_mat, _row, _col) \
44  (MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->num_row * (_col)) + (_row)))
45 #define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
46 #define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)])
47 
48 #define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
49 #define MATRIX_COL_PTR(_mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
50 
51 typedef struct {
55 } MatrixObject;
56 
57 /* struct data contains a pointer to the actual data that the
58  * object uses. It can use either PyMem allocated data (which will
59  * be stored in py_data) or be a wrapper for data allocated through
60  * blender (stored in blend_data). This is an either/or struct not both */
61 
62 /* prototypes */
63 PyObject *Matrix_CreatePyObject(const float *mat,
64  const ushort num_col,
65  const ushort num_row,
66  PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
67 PyObject *Matrix_CreatePyObject_wrap(float *mat,
68  const ushort num_col,
69  const ushort num_row,
70  PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
71  ATTR_NONNULL(1);
72 PyObject *Matrix_CreatePyObject_cb(PyObject *user,
73  const unsigned short num_col,
74  const unsigned short num_row,
75  unsigned char cb_type,
76  unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
77 
78 PyObject *Matrix_CreatePyObject_alloc(float *mat,
79  const ushort num_col,
80  const ushort num_row,
81  PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
82 
83 /* PyArg_ParseTuple's "O&" formatting helpers. */
84 int Matrix_ParseAny(PyObject *o, void *p);
85 int Matrix_Parse2x2(PyObject *o, void *p);
86 int Matrix_Parse3x3(PyObject *o, void *p);
87 int Matrix_Parse4x4(PyObject *o, void *p);
88 
89 extern unsigned char mathutils_matrix_row_cb_index; /* default */
90 extern unsigned char mathutils_matrix_col_cb_index;
91 extern unsigned char mathutils_matrix_translation_cb_index;
92 
93 extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
96 
97 void matrix_as_3x3(float mat[3][3], MatrixObject *self);
#define ATTR_NONNULL(...)
void BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() ATTR_WARN_UNUSED_RESULT
unsigned short ushort
Definition: BLI_sys_types.h:84
int Matrix_Parse3x3(PyObject *o, void *p)
int Matrix_ParseAny(PyObject *o, void *p)
unsigned char mathutils_matrix_translation_cb_index
unsigned char mathutils_matrix_row_cb_index
PyObject * Matrix_CreatePyObject_alloc(float *mat, const ushort num_col, const ushort num_row, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
PyObject * Matrix_CreatePyObject(const float *mat, const ushort num_col, const ushort num_row, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
PyObject * Matrix_CreatePyObject_wrap(float *mat, const ushort num_col, const ushort num_row, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
PyTypeObject matrix_access_Type
struct Mathutils_Callback mathutils_matrix_row_cb
void matrix_as_3x3(float mat[3][3], MatrixObject *self)
int Matrix_Parse2x2(PyObject *o, void *p)
struct Mathutils_Callback mathutils_matrix_col_cb
int Matrix_Parse4x4(PyObject *o, void *p)
unsigned short ushort
PyObject * Matrix_CreatePyObject_cb(PyObject *user, const unsigned short num_col, const unsigned short num_row, unsigned char cb_type, unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT
unsigned char mathutils_matrix_col_cb_index
PyTypeObject matrix_Type
struct Mathutils_Callback mathutils_matrix_translation_cb
BASE_MATH_MEMBERS(matrix)