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