Blender  V3.3
mathutils.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 /* Can cast different mathutils types to this, use for generic funcs */
10 
11 #include "BLI_compiler_attrs.h"
12 
13 struct DynStr;
14 
15 extern char BaseMathObject_is_wrapped_doc[];
16 extern char BaseMathObject_is_frozen_doc[];
17 extern char BaseMathObject_is_valid_doc[];
18 extern char BaseMathObject_owner_doc[];
19 
20 #define BASE_MATH_NEW(struct_name, root_type, base_type) \
21  ((struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : \
22  _PyObject_GC_New(&(root_type)))))
23 
25 enum {
37 };
38 #define BASE_MATH_FLAG_DEFAULT 0
39 
40 #define BASE_MATH_MEMBERS(_data) \
41  \
42  PyObject_VAR_HEAD \
43  float *_data; \
44  \
45  PyObject *cb_user; \
46  \
47  unsigned char cb_type; \
48  \
50  unsigned char cb_subtype; \
51  \
52  unsigned char flag
53 
54 typedef struct {
57 
58 /* types */
59 #include "mathutils_Color.h"
60 #include "mathutils_Euler.h"
61 #include "mathutils_Matrix.h"
62 #include "mathutils_Quaternion.h"
63 #include "mathutils_Vector.h"
64 
65 /* avoid checking all types */
66 #define BaseMathObject_CheckExact(v) (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)
67 
68 PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *);
71 PyObject *BaseMathObject_is_valid_get(BaseMathObject *self, void *);
72 
73 extern char BaseMathObject_freeze_doc[];
74 PyObject *BaseMathObject_freeze(BaseMathObject *self);
75 
76 int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
79 
80 PyMODINIT_FUNC PyInit_mathutils(void);
81 
82 int EXPP_FloatsAreEqual(float A, float B, int maxDiff);
83 int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps);
84 
86 
88 typedef int (*BaseMathCheckFunc)(BaseMathObject *);
90 typedef int (*BaseMathGetFunc)(BaseMathObject *, int);
92 typedef int (*BaseMathSetFunc)(BaseMathObject *, int);
94 typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int);
96 typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int);
97 
104 };
105 
107 
113 
116 
117 /* since this is called so often avoid where possible */
118 #define BaseMath_CheckCallback(_self) \
119  (((_self)->cb_user ? _BaseMathObject_CheckCallback((BaseMathObject *)_self) : 0))
120 #define BaseMath_ReadCallback(_self) \
121  (((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0))
122 #define BaseMath_WriteCallback(_self) \
123  (((_self)->cb_user ? _BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0))
124 #define BaseMath_ReadIndexCallback(_self, _index) \
125  (((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0))
126 #define BaseMath_WriteIndexCallback(_self, _index) \
127  (((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0))
128 
129 /* support BASE_MATH_FLAG_IS_FROZEN */
130 #define BaseMath_ReadCallback_ForWrite(_self) \
131  (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
132  (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
133  (BaseMath_ReadCallback(_self)))
134 
135 #define BaseMath_ReadIndexCallback_ForWrite(_self, _index) \
136  (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
137  (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
138  (BaseMath_ReadIndexCallback(_self, _index)))
139 
140 #define BaseMath_Prepare_ForWrite(_self) \
141  (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
142  (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
143  0)
144 
145 #define BaseMathObject_Prepare_ForHash(_self) \
146  (UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
147  (_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : \
148  0)
149 
150 /* utility func */
156  float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix);
161  int array_num_min,
162  PyObject *value,
163  const char *error_prefix);
168  int array_dim,
169  PyObject *value,
170  const char *error_prefix);
175  int array_dim,
176  PyObject *value,
177  const char *error_prefix);
182  int array_dim,
183  PyObject *value,
184  const char *error_prefix);
193  int **array, int **start_table, int **len_table, PyObject *value, const char *error_prefix);
194 int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
195 
201 Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len);
202 
203 /* zero remaining unused elements of the array */
204 #define MU_ARRAY_ZERO (1u << 30)
205 /* ignore larger py sequences than requested (just use first elements),
206  * handy when using 3d vectors as 2d */
207 #define MU_ARRAY_SPILL (1u << 31)
208 
209 #define MU_ARRAY_FLAGS (MU_ARRAY_ZERO | MU_ARRAY_SPILL)
210 
222 int column_vector_multiplication(float r_vec[4], VectorObject *vec, MatrixObject *mat);
223 
224 #ifndef MATH_STANDALONE
225 /* dynstr as python string utility functions */
226 /* dynstr as python string utility functions, frees 'ds'! */
227 PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
228 #endif
#define A
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
int(* BaseMathGetFunc)(BaseMathObject *, int)
Definition: mathutils.h:89
int EXPP_FloatsAreEqual(float A, float B, int maxDiff)
Definition: mathutils.c:501
PyObject * BaseMathObject_freeze(BaseMathObject *self)
Definition: mathutils.c:681
PyObject * BaseMathObject_is_valid_get(BaseMathObject *self, void *)
int _BaseMathObject_CheckCallback(BaseMathObject *self)
Definition: mathutils.c:569
PyMODINIT_FUNC PyInit_mathutils(void)
Definition: mathutils.c:746
@ BASE_MATH_FLAG_IS_WRAP
Definition: mathutils.h:31
@ BASE_MATH_FLAG_IS_FROZEN
Definition: mathutils.h:36
int(* BaseMathGetIndexFunc)(BaseMathObject *, int, int)
Definition: mathutils.h:93
PyObject * BaseMathObject_is_wrapped_get(BaseMathObject *self, void *)
PyObject * mathutils_dynstr_to_py(struct DynStr *ds)
Definition: mathutils.c:531
int mathutils_array_parse_alloc(float **array, int array_num_min, PyObject *value, const char *error_prefix)
Definition: mathutils.c:193
int mathutils_array_parse_alloc_viseq(int **array, int **start_table, int **len_table, PyObject *value, const char *error_prefix)
Definition: mathutils.c:372
int(* BaseMathSetIndexFunc)(BaseMathObject *, int, int)
Definition: mathutils.h:95
void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self)
Definition: mathutils.c:633
void BaseMathObject_dealloc(BaseMathObject *self)
Definition: mathutils.c:705
int _BaseMathObject_WriteCallback(BaseMathObject *self)
Definition: mathutils.c:592
int mathutils_int_array_parse(int *array, int array_dim, PyObject *value, const char *error_prefix)
Definition: mathutils.c:300
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
Definition: mathutils.c:519
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition: mathutils.c:98
int(* BaseMathSetFunc)(BaseMathObject *, int)
Definition: mathutils.h:91
int mathutils_array_parse_alloc_vi(int **array, int array_dim, PyObject *value, const char *error_prefix)
Definition: mathutils.c:335
Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len)
Definition: mathutils.c:66
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
Definition: mathutils.c:259
char BaseMathObject_is_valid_doc[]
Definition: mathutils.c:666
char BaseMathObject_is_wrapped_doc[]
Definition: mathutils.c:652
char BaseMathObject_is_frozen_doc[]
Definition: mathutils.c:659
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
Definition: mathutils.c:439
int column_vector_multiplication(float r_vec[4], VectorObject *vec, MatrixObject *mat)
PyObject * BaseMathObject_owner_get(BaseMathObject *self, void *)
#define BASE_MATH_MEMBERS(_data)
Definition: mathutils.h:40
char BaseMathObject_owner_doc[]
Definition: mathutils.c:645
int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index)
Definition: mathutils.c:619
char BaseMathObject_freeze_doc[]
Definition: mathutils.c:673
int BaseMathObject_clear(BaseMathObject *self)
Definition: mathutils.c:699
int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
Definition: mathutils.c:605
int _BaseMathObject_ReadCallback(BaseMathObject *self)
Definition: mathutils.c:579
int(* BaseMathCheckFunc)(BaseMathObject *)
Definition: mathutils.h:87
PyObject * BaseMathObject_is_frozen_get(BaseMathObject *self, void *)
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb)
Definition: mathutils.c:551
void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self)
Definition: mathutils.c:638
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
Definition: mathutils.c:693
#define B
BaseMathSetIndexFunc set_index
Definition: mathutils.h:102
BaseMathCheckFunc check
Definition: mathutils.h:98
BaseMathGetIndexFunc get_index
Definition: mathutils.h:101
BaseMathSetFunc set
Definition: mathutils.h:100
BaseMathGetFunc get
Definition: mathutils.h:99