Blender V4.3
mathutils_Matrix.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11extern PyTypeObject matrix_Type;
12extern PyTypeObject matrix_access_Type;
13
14typedef unsigned short ushort;
15
16#define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type)
17#define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type)
18
19#define MATRIX_MAX_DIM 4
20
21/* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
22
23#ifndef NDEBUG
24# define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
25 (BLI_assert(_row < (_mat)->row_num && _col < (_mat)->col_num))
26#else
27# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
28#endif
29
30#define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row))
31#define MATRIX_ITEM_INDEX(_mat, _row, _col) \
32 (MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->row_num * (_col)) + (_row)))
33#define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
34#define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)])
35
36#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
37#define MATRIX_COL_PTR(_mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
38
44
45/* struct data contains a pointer to the actual data that the
46 * object uses. It can use either PyMem allocated data (which will
47 * be stored in py_data) or be a wrapper for data allocated through
48 * blender (stored in blend_data). This is an either/or struct not both */
49
50/* Prototypes. */
51
52PyObject *Matrix_CreatePyObject(const float *mat,
53 ushort col_num,
54 ushort row_num,
55 PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
56PyObject *Matrix_CreatePyObject_wrap(float *mat,
57 ushort col_num,
58 ushort row_num,
59 PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
60 ATTR_NONNULL(1);
61PyObject *Matrix_CreatePyObject_cb(PyObject *cb_user,
62 unsigned short col_num,
63 unsigned short row_num,
64 unsigned char cb_type,
65 unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
66
70PyObject *Matrix_CreatePyObject_alloc(float *mat,
71 ushort col_num,
72 ushort row_num,
73 PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
74
75/* PyArg_ParseTuple's "O&" formatting helpers. */
76
77int Matrix_ParseAny(PyObject *o, void *p);
78int Matrix_Parse2x2(PyObject *o, void *p);
79int Matrix_Parse3x3(PyObject *o, void *p);
80int Matrix_Parse4x4(PyObject *o, void *p);
81
82extern unsigned char mathutils_matrix_row_cb_index; /* default */
83extern unsigned char mathutils_matrix_col_cb_index;
84extern unsigned char mathutils_matrix_translation_cb_index;
85
86extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
89
90void matrix_as_3x3(float mat[3][3], MatrixObject *self);
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned short ushort
PyObject * self
int Matrix_Parse3x3(PyObject *o, void *p)
int Matrix_ParseAny(PyObject *o, void *p)
unsigned char mathutils_matrix_translation_cb_index
PyObject * Matrix_CreatePyObject_wrap(float *mat, ushort col_num, ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned char mathutils_matrix_row_cb_index
PyTypeObject matrix_access_Type
PyObject * Matrix_CreatePyObject(const float *mat, ushort col_num, ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
struct Mathutils_Callback mathutils_matrix_row_cb
void matrix_as_3x3(float mat[3][3], MatrixObject *self)
int Matrix_Parse2x2(PyObject *o, void *p)
PyObject * Matrix_CreatePyObject_alloc(float *mat, ushort col_num, ushort row_num, PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
struct Mathutils_Callback mathutils_matrix_col_cb
int Matrix_Parse4x4(PyObject *o, void *p)
unsigned short ushort
PyObject * Matrix_CreatePyObject_cb(PyObject *cb_user, unsigned short col_num, unsigned short row_num, 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)