2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup pymathutils
|
2011-02-27 20:10:08 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2025-01-07 12:39:13 +01:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "mathutils.hh"
|
|
|
|
|
|
2009-06-17 20:33:34 +00:00
|
|
|
extern PyTypeObject matrix_Type;
|
2011-12-24 07:03:19 +00:00
|
|
|
extern PyTypeObject matrix_access_Type;
|
2017-11-29 16:09:46 +11:00
|
|
|
|
2025-01-26 20:08:04 +01:00
|
|
|
using ushort = unsigned short;
|
2020-02-20 10:28:15 +01:00
|
|
|
|
2017-11-29 16:09:46 +11:00
|
|
|
#define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type)
|
|
|
|
|
#define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type)
|
|
|
|
|
|
2010-04-16 08:17:13 +00:00
|
|
|
#define MATRIX_MAX_DIM 4
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-12-19 05:23:52 +00:00
|
|
|
/* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
|
2011-12-19 03:12:10 +00:00
|
|
|
|
2023-12-04 15:13:06 +01:00
|
|
|
#ifndef NDEBUG
|
2011-12-20 05:48:35 +00:00
|
|
|
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
|
2022-03-28 11:06:01 +11:00
|
|
|
(BLI_assert(_row < (_mat)->row_num && _col < (_mat)->col_num))
|
2011-12-19 03:12:10 +00:00
|
|
|
#else
|
2011-12-19 05:23:52 +00:00
|
|
|
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
|
2011-12-19 03:12:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
2016-06-01 00:19:01 +10:00
|
|
|
#define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row))
|
2011-12-20 05:48:35 +00:00
|
|
|
#define MATRIX_ITEM_INDEX(_mat, _row, _col) \
|
2022-03-28 11:06:01 +11:00
|
|
|
(MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->row_num * (_col)) + (_row)))
|
2011-12-20 04:11:23 +00:00
|
|
|
#define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
|
|
|
|
|
#define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)])
|
2011-12-19 03:12:10 +00:00
|
|
|
|
2011-12-20 05:48:35 +00:00
|
|
|
#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
|
|
|
|
|
#define MATRIX_COL_PTR(_mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
|
2011-12-19 03:12:10 +00:00
|
|
|
|
2024-09-24 12:56:16 +02:00
|
|
|
struct MatrixObject {
|
2011-12-20 04:11:23 +00:00
|
|
|
BASE_MATH_MEMBERS(matrix);
|
2022-03-28 11:06:01 +11:00
|
|
|
ushort col_num;
|
|
|
|
|
ushort row_num;
|
2024-09-24 12:56:16 +02:00
|
|
|
};
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-12-19 05:23:52 +00:00
|
|
|
/* struct data contains a pointer to the actual data that the
|
|
|
|
|
* object uses. It can use either PyMem allocated data (which will
|
|
|
|
|
* be stored in py_data) or be a wrapper for data allocated through
|
|
|
|
|
* blender (stored in blend_data). This is an either/or struct not both */
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2022-05-25 12:33:15 +10:00
|
|
|
/* Prototypes. */
|
|
|
|
|
|
2025-06-28 00:15:23 +00:00
|
|
|
[[nodiscard]] PyObject *Matrix_CreatePyObject(const float *mat,
|
|
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
|
|
|
|
PyTypeObject *base_type);
|
|
|
|
|
[[nodiscard]] PyObject *Matrix_CreatePyObject_wrap(float *mat,
|
|
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
|
|
|
|
PyTypeObject *base_type) ATTR_NONNULL(1);
|
|
|
|
|
[[nodiscard]] PyObject *Matrix_CreatePyObject_cb(PyObject *cb_user,
|
|
|
|
|
unsigned short col_num,
|
|
|
|
|
unsigned short row_num,
|
|
|
|
|
unsigned char cb_type,
|
|
|
|
|
unsigned char cb_subtype);
|
2009-06-23 13:34:45 +00:00
|
|
|
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
|
|
|
|
* \param mat: Initialized matrix value to use in-place, allocated with #PyMem_Malloc
|
|
|
|
|
*/
|
2025-06-28 00:15:23 +00:00
|
|
|
[[nodiscard]] PyObject *Matrix_CreatePyObject_alloc(float *mat,
|
|
|
|
|
ushort col_num,
|
|
|
|
|
ushort row_num,
|
|
|
|
|
PyTypeObject *base_type);
|
2020-02-20 15:09:44 +11:00
|
|
|
|
2017-08-19 21:36:50 +10:00
|
|
|
/* PyArg_ParseTuple's "O&" formatting helpers. */
|
2022-05-25 12:33:15 +10:00
|
|
|
|
2025-06-28 00:15:23 +00:00
|
|
|
[[nodiscard]] int Matrix_ParseAny(PyObject *o, void *p);
|
|
|
|
|
[[nodiscard]] int Matrix_Parse2x2(PyObject *o, void *p);
|
|
|
|
|
[[nodiscard]] int Matrix_Parse3x3(PyObject *o, void *p);
|
|
|
|
|
[[nodiscard]] int Matrix_Parse4x4(PyObject *o, void *p);
|
2017-08-19 21:36:50 +10:00
|
|
|
|
2012-03-17 10:46:02 +00:00
|
|
|
extern unsigned char mathutils_matrix_row_cb_index; /* default */
|
|
|
|
|
extern unsigned char mathutils_matrix_col_cb_index;
|
|
|
|
|
extern unsigned char mathutils_matrix_translation_cb_index;
|
2011-12-26 00:05:41 +00:00
|
|
|
|
2011-12-24 06:13:58 +00:00
|
|
|
extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
|
|
|
|
|
extern struct Mathutils_Callback mathutils_matrix_col_cb;
|
2011-12-26 00:05:41 +00:00
|
|
|
extern struct Mathutils_Callback mathutils_matrix_translation_cb;
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-02-05 09:57:02 +00:00
|
|
|
void matrix_as_3x3(float mat[3][3], MatrixObject *self);
|