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