Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions | Variables
mathutils.h File Reference
#include "BLI_compiler_attrs.h"
#include "mathutils_Color.h"
#include "mathutils_Euler.h"
#include "mathutils_Matrix.h"
#include "mathutils_Quaternion.h"
#include "mathutils_Vector.h"

Go to the source code of this file.

Classes

struct  BaseMathObject
 
struct  Mathutils_Callback
 

Macros

#define BASE_MATH_NEW(struct_name, root_type, base_type)
 
#define BASE_MATH_FLAG_DEFAULT   0
 
#define BASE_MATH_MEMBERS(_data)
 
#define BaseMathObject_CheckExact(v)   (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)
 
#define BaseMath_CheckCallback(_self)    (((_self)->cb_user ? _BaseMathObject_CheckCallback((BaseMathObject *)_self) : 0))
 
#define BaseMath_ReadCallback(_self)    (((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0))
 
#define BaseMath_WriteCallback(_self)    (((_self)->cb_user ? _BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0))
 
#define BaseMath_ReadIndexCallback(_self, _index)    (((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0))
 
#define BaseMath_WriteIndexCallback(_self, _index)    (((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0))
 
#define BaseMath_ReadCallback_ForWrite(_self)
 
#define BaseMath_ReadIndexCallback_ForWrite(_self, _index)
 
#define BaseMath_Prepare_ForWrite(_self)
 
#define BaseMathObject_Prepare_ForHash(_self)
 
#define MU_ARRAY_ZERO   (1u << 30)
 
#define MU_ARRAY_SPILL   (1u << 31)
 
#define MU_ARRAY_FLAGS   (MU_ARRAY_ZERO | MU_ARRAY_SPILL)
 

Typedefs

typedef struct Mathutils_Callback Mathutils_Callback
 
typedef int(* BaseMathCheckFunc) (BaseMathObject *)
 
typedef int(* BaseMathGetFunc) (BaseMathObject *, int)
 
typedef int(* BaseMathSetFunc) (BaseMathObject *, int)
 
typedef int(* BaseMathGetIndexFunc) (BaseMathObject *, int, int)
 
typedef int(* BaseMathSetIndexFunc) (BaseMathObject *, int, int)
 

Enumerations

enum  { BASE_MATH_FLAG_IS_WRAP = (1 << 0) , BASE_MATH_FLAG_IS_FROZEN = (1 << 1) }
 

Functions

PyObject * BaseMathObject_owner_get (BaseMathObject *self, void *)
 
PyObject * BaseMathObject_is_wrapped_get (BaseMathObject *self, void *)
 
PyObject * BaseMathObject_is_frozen_get (BaseMathObject *self, void *)
 
PyObject * BaseMathObject_is_valid_get (BaseMathObject *self, void *)
 
PyObject * BaseMathObject_freeze (BaseMathObject *self)
 
int BaseMathObject_traverse (BaseMathObject *self, visitproc visit, void *arg)
 
int BaseMathObject_clear (BaseMathObject *self)
 
void BaseMathObject_dealloc (BaseMathObject *self)
 
PyMODINIT_FUNC PyInit_mathutils (void)
 
int EXPP_FloatsAreEqual (float A, float B, int maxDiff)
 
int EXPP_VectorsAreEqual (const float *vecA, const float *vecB, int size, int floatSteps)
 
unsigned char Mathutils_RegisterCallback (Mathutils_Callback *cb)
 
int _BaseMathObject_CheckCallback (BaseMathObject *self)
 
int _BaseMathObject_ReadCallback (BaseMathObject *self)
 
int _BaseMathObject_WriteCallback (BaseMathObject *self)
 
int _BaseMathObject_ReadIndexCallback (BaseMathObject *self, int index)
 
int _BaseMathObject_WriteIndexCallback (BaseMathObject *self, int index)
 
void _BaseMathObject_RaiseFrozenExc (const BaseMathObject *self)
 
void _BaseMathObject_RaiseNotFrozenExc (const BaseMathObject *self)
 
int mathutils_array_parse (float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
 
int mathutils_array_parse_alloc (float **array, int array_num_min, PyObject *value, const char *error_prefix)
 
int mathutils_array_parse_alloc_v (float **array, int array_dim, PyObject *value, const char *error_prefix)
 
int mathutils_int_array_parse (int *array, int array_dim, PyObject *value, const char *error_prefix)
 
int mathutils_array_parse_alloc_vi (int **array, int array_dim, PyObject *value, const char *error_prefix)
 
int mathutils_array_parse_alloc_viseq (int **array, int **start_table, int **len_table, PyObject *value, const char *error_prefix)
 
int mathutils_any_to_rotmat (float rmat[3][3], PyObject *value, const char *error_prefix)
 
Py_hash_t mathutils_array_hash (const float *float_array, size_t array_len)
 
int column_vector_multiplication (float r_vec[4], VectorObject *vec, MatrixObject *mat)
 
PyObject * mathutils_dynstr_to_py (struct DynStr *ds)
 

Variables

char BaseMathObject_is_wrapped_doc []
 
char BaseMathObject_is_frozen_doc []
 
char BaseMathObject_is_valid_doc []
 
char BaseMathObject_owner_doc []
 
char BaseMathObject_freeze_doc []
 

Macro Definition Documentation

◆ BASE_MATH_FLAG_DEFAULT

#define BASE_MATH_FLAG_DEFAULT   0

Definition at line 38 of file mathutils.h.

◆ BASE_MATH_MEMBERS

#define BASE_MATH_MEMBERS (   _data)
Value:
\
PyObject_VAR_HEAD \
float *_data; \ \
PyObject *cb_user; \ \
unsigned char cb_type; \ \
unsigned char cb_subtype; \ \
unsigned char flag

Definition at line 40 of file mathutils.h.

◆ BASE_MATH_NEW

#define BASE_MATH_NEW (   struct_name,
  root_type,
  base_type 
)
Value:
((struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : \
_PyObject_GC_New(&(root_type)))))

Definition at line 20 of file mathutils.h.

◆ BaseMath_CheckCallback

#define BaseMath_CheckCallback (   _self)     (((_self)->cb_user ? _BaseMathObject_CheckCallback((BaseMathObject *)_self) : 0))

Definition at line 117 of file mathutils.h.

◆ BaseMath_Prepare_ForWrite

#define BaseMath_Prepare_ForWrite (   _self)
Value:
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
0)
#define UNLIKELY(x)
@ BASE_MATH_FLAG_IS_FROZEN
Definition: mathutils.h:36
void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self)
Definition: mathutils.c:633

Definition at line 139 of file mathutils.h.

◆ BaseMath_ReadCallback

#define BaseMath_ReadCallback (   _self)     (((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0))

Definition at line 119 of file mathutils.h.

◆ BaseMath_ReadCallback_ForWrite

#define BaseMath_ReadCallback_ForWrite (   _self)
Value:
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
#define BaseMath_ReadCallback(_self)
Definition: mathutils.h:119

Definition at line 129 of file mathutils.h.

◆ BaseMath_ReadIndexCallback

#define BaseMath_ReadIndexCallback (   _self,
  _index 
)     (((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0))

Definition at line 123 of file mathutils.h.

◆ BaseMath_ReadIndexCallback_ForWrite

#define BaseMath_ReadIndexCallback_ForWrite (   _self,
  _index 
)
Value:
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
(BaseMath_ReadIndexCallback(_self, _index)))
#define BaseMath_ReadIndexCallback(_self, _index)
Definition: mathutils.h:123

Definition at line 134 of file mathutils.h.

◆ BaseMath_WriteCallback

#define BaseMath_WriteCallback (   _self)     (((_self)->cb_user ? _BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0))

Definition at line 121 of file mathutils.h.

◆ BaseMath_WriteIndexCallback

#define BaseMath_WriteIndexCallback (   _self,
  _index 
)     (((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0))

Definition at line 125 of file mathutils.h.

◆ BaseMathObject_CheckExact

#define BaseMathObject_CheckExact (   v)    (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)

Definition at line 65 of file mathutils.h.

◆ BaseMathObject_Prepare_ForHash

#define BaseMathObject_Prepare_ForHash (   _self)
Value:
(UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
0)
void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self)
Definition: mathutils.c:638

Definition at line 144 of file mathutils.h.

◆ MU_ARRAY_FLAGS

#define MU_ARRAY_FLAGS   (MU_ARRAY_ZERO | MU_ARRAY_SPILL)

Definition at line 208 of file mathutils.h.

◆ MU_ARRAY_SPILL

#define MU_ARRAY_SPILL   (1u << 31)

Definition at line 206 of file mathutils.h.

◆ MU_ARRAY_ZERO

#define MU_ARRAY_ZERO   (1u << 30)

Definition at line 203 of file mathutils.h.

Typedef Documentation

◆ BaseMathCheckFunc

typedef int(* BaseMathCheckFunc) (BaseMathObject *)

Checks the user is still valid.

Definition at line 87 of file mathutils.h.

◆ BaseMathGetFunc

typedef int(* BaseMathGetFunc) (BaseMathObject *, int)

Gets the vector from the user.

Definition at line 89 of file mathutils.h.

◆ BaseMathGetIndexFunc

typedef int(* BaseMathGetIndexFunc) (BaseMathObject *, int, int)

Same as above but only for an index.

Definition at line 93 of file mathutils.h.

◆ BaseMathSetFunc

typedef int(* BaseMathSetFunc) (BaseMathObject *, int)

Sets the users vector values once its modified.

Definition at line 91 of file mathutils.h.

◆ BaseMathSetIndexFunc

typedef int(* BaseMathSetIndexFunc) (BaseMathObject *, int, int)

Same as above but only for an index.

Definition at line 95 of file mathutils.h.

◆ Mathutils_Callback

Definition at line 82 of file mathutils.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

BaseMathObject.flag

Enumerator
BASE_MATH_FLAG_IS_WRAP 

Do not own the memory used in this vector,

Note
This is error prone if the memory may be freed while this vector is in use. Prefer using callbacks where possible, see: Mathutils_RegisterCallback
BASE_MATH_FLAG_IS_FROZEN 

Prevent changes to the vector so it can be used as a set or dictionary key for example. (typical use cases for tuple).

Definition at line 25 of file mathutils.h.

Function Documentation

◆ _BaseMathObject_CheckCallback()

int _BaseMathObject_CheckCallback ( BaseMathObject self)

Definition at line 569 of file mathutils.c.

References Mathutils_Callback::check, LIKELY, and mathutils_callbacks.

◆ _BaseMathObject_RaiseFrozenExc()

void _BaseMathObject_RaiseFrozenExc ( const BaseMathObject self)

Definition at line 633 of file mathutils.c.

◆ _BaseMathObject_RaiseNotFrozenExc()

void _BaseMathObject_RaiseNotFrozenExc ( const BaseMathObject self)

Definition at line 638 of file mathutils.c.

◆ _BaseMathObject_ReadCallback()

int _BaseMathObject_ReadCallback ( BaseMathObject self)

Definition at line 579 of file mathutils.c.

References Mathutils_Callback::get, LIKELY, mathutils_callbacks, and self.

◆ _BaseMathObject_ReadIndexCallback()

int _BaseMathObject_ReadIndexCallback ( BaseMathObject self,
int  index 
)

Definition at line 605 of file mathutils.c.

References Mathutils_Callback::get_index, LIKELY, mathutils_callbacks, and self.

◆ _BaseMathObject_WriteCallback()

int _BaseMathObject_WriteCallback ( BaseMathObject self)

Definition at line 592 of file mathutils.c.

References LIKELY, mathutils_callbacks, self, and Mathutils_Callback::set.

◆ _BaseMathObject_WriteIndexCallback()

int _BaseMathObject_WriteIndexCallback ( BaseMathObject self,
int  index 
)

Definition at line 619 of file mathutils.c.

References LIKELY, mathutils_callbacks, self, and Mathutils_Callback::set_index.

◆ BaseMathObject_clear()

int BaseMathObject_clear ( BaseMathObject self)

Definition at line 699 of file mathutils.c.

References self.

Referenced by BaseMathObject_dealloc().

◆ BaseMathObject_dealloc()

void BaseMathObject_dealloc ( BaseMathObject self)

Definition at line 705 of file mathutils.c.

References BASE_MATH_FLAG_IS_WRAP, BaseMathObject_clear(), and self.

◆ BaseMathObject_freeze()

PyObject* BaseMathObject_freeze ( BaseMathObject self)

Definition at line 681 of file mathutils.c.

References BASE_MATH_FLAG_IS_FROZEN, BASE_MATH_FLAG_IS_WRAP, NULL, and self.

◆ BaseMathObject_is_frozen_get()

PyObject* BaseMathObject_is_frozen_get ( BaseMathObject self,
void  
)

◆ BaseMathObject_is_valid_get()

PyObject* BaseMathObject_is_valid_get ( BaseMathObject self,
void  
)

◆ BaseMathObject_is_wrapped_get()

PyObject* BaseMathObject_is_wrapped_get ( BaseMathObject self,
void  
)

◆ BaseMathObject_owner_get()

PyObject* BaseMathObject_owner_get ( BaseMathObject self,
void  
)

◆ BaseMathObject_traverse()

int BaseMathObject_traverse ( BaseMathObject self,
visitproc  visit,
void arg 
)

Definition at line 693 of file mathutils.c.

References self.

◆ column_vector_multiplication()

int column_vector_multiplication ( float  r_vec[4],
VectorObject vec,
MatrixObject mat 
)

Column vector multiplication (Matrix * Vector).

[1][4][7]   [a]
[2][5][8] * [b]
[3][6][9]   [c]
Note
Vector/Matrix multiplication is not commutative.
Assume read callbacks have been done first.

Referenced by Matrix_matmul().

◆ EXPP_FloatsAreEqual()

int EXPP_FloatsAreEqual ( float  A,
float  B,
int  maxDiff 
)

Definition at line 501 of file mathutils.c.

References BLI_assert, KDL::diff(), SIGNMASK, v1, and v2.

Referenced by EXPP_VectorsAreEqual(), and quat__axis_angle_sanitize().

◆ EXPP_VectorsAreEqual()

int EXPP_VectorsAreEqual ( const float vecA,
const float vecB,
int  size,
int  floatSteps 
)

◆ mathutils_any_to_rotmat()

int mathutils_any_to_rotmat ( float  rmat[3][3],
PyObject *  value,
const char *  error_prefix 
)

◆ mathutils_array_hash()

Py_hash_t mathutils_array_hash ( const float float_array,
size_t  array_len 
)

helper function that returns a Python __hash__.

Note
consistent with the equivalent tuple of floats (CPython's 'tuplehash')

Definition at line 66 of file mathutils.c.

References len, mult(), NULL, x, and y.

Referenced by Color_hash(), Euler_hash(), Matrix_hash(), Quaternion_hash(), and Vector_hash().

◆ mathutils_array_parse()

int mathutils_array_parse ( float array,
int  array_num_min,
int  array_num_max,
PyObject *  value,
const char *  error_prefix 
)

Helper function.

Returns
length of value, -1 on error.

Definition at line 98 of file mathutils.c.

References BaseMath_ReadCallback, CLAMP_MAX, ColorObject_Check, data, EulerObject_Check, mathutils_array_parse_fast(), MU_ARRAY_FLAGS, MU_ARRAY_SPILL, MU_ARRAY_ZERO, NULL, QuaternionObject_Check, and VectorObject_Check.

Referenced by bpy_bm_geometry_intersect_face_point(), bpy_bmface_normal_set(), BPy_BMLayerItem_SetItem(), BPy_BMLoopColor_AssignPyObject(), bpy_bmloopuv_uv_set(), bpy_bmvert_co_set(), bpy_bmvert_normal_set(), bpy_bmvertseq_new(), bpy_bmvertskin_radius_set(), bpy_slot_from_py(), C_BVHTree_FromPolygons(), C_Matrix_Diagonal(), C_Matrix_LocRotScale(), C_Matrix_OrthoProjection(), C_Matrix_Rotation(), C_Matrix_Scale(), C_Matrix_Shear(), C_Matrix_Translation(), Color_ass_slice(), Color_hsv_set(), Color_new(), convert_v2(), convert_v3(), convert_v4(), Euler_ass_slice(), Euler_make_compatible(), Euler_new(), FEdgeSharp_normal_left_set(), FEdgeSharp_normal_right_set(), FEdgeSmooth_normal_set(), Freestyle_blendRamp(), FrsMaterial_ambient_set(), FrsMaterial_diffuse_set(), FrsMaterial_emission_set(), FrsMaterial_line_set(), FrsMaterial_specular_set(), M_Geometry_area_tri(), M_Geometry_barycentric_transform(), M_Geometry_closest_point_on_tri(), M_Geometry_distance_point_to_plane(), M_Geometry_interpolate_bezier(), M_Geometry_intersect_line_line(), M_Geometry_intersect_line_line_2d(), M_Geometry_intersect_line_plane(), M_Geometry_intersect_line_sphere(), M_Geometry_intersect_line_sphere_2d(), M_Geometry_intersect_plane_plane(), M_Geometry_intersect_point_line(), M_Geometry_intersect_point_quad_2d(), M_Geometry_intersect_point_tri(), M_Geometry_intersect_point_tri_2d(), M_Geometry_intersect_ray_tri(), M_Geometry_intersect_sphere_sphere_2d(), M_Geometry_intersect_tri_tri_2d(), M_Geometry_tessellate_polygon(), M_Geometry_volume_tetrahedron(), M_Interpolate_poly_3d_calc(), M_Noise_fractal(), M_Noise_hetero_terrain(), M_Noise_hybrid_multi_fractal(), M_Noise_multi_fractal(), M_Noise_noise(), M_Noise_noise_vector(), M_Noise_ridged_multi_fractal(), M_Noise_turbulence(), M_Noise_turbulence_vector(), M_Noise_variable_lacunarity(), M_Noise_voronoi(), mathutils_array_parse_alloc_v(), Matrix_ass_item_col(), Matrix_ass_item_row(), Matrix_ass_slice(), Matrix_translation_set(), py_bvhtree_find_nearest(), py_bvhtree_find_nearest_range(), py_bvhtree_ray_cast(), py_kdtree_find(), py_kdtree_find_n(), py_kdtree_find_range(), py_kdtree_insert(), pygpu_framebuffer_clear(), pygpu_matrix_scale(), pygpu_matrix_translate(), pygpu_shader_uniform_float(), Quaternion_ass_slice(), Quaternion_axis_vector_set(), Quaternion_cross(), Quaternion_dot(), Quaternion_make_compatible(), Quaternion_new(), Quaternion_rotation_difference(), Quaternion_slerp(), StrokeAttribute_color_set(), StrokeAttribute_thickness_set(), StrokeVertex_point_set(), SVertex_point_2d_set(), SVertex_point_3d_set(), Vector_angle(), Vector_angle_signed(), Vector_cross(), Vector_reflect(), Vector_rotation_difference(), Vector_slerp(), and Vector_swizzle_set().

◆ mathutils_array_parse_alloc()

int mathutils_array_parse_alloc ( float **  array,
int  array_num_min,
PyObject *  value,
const char *  error_prefix 
)

◆ mathutils_array_parse_alloc_v()

int mathutils_array_parse_alloc_v ( float **  array,
int  array_dim,
PyObject *  value,
const char *  error_prefix 
)

Parse an array of vectors.

Definition at line 259 of file mathutils.c.

References mathutils_array_parse(), MU_ARRAY_FLAGS, and NULL.

Referenced by bpy_bm_utils_face_split(), M_Geometry_normal(), M_Geometry_points_in_planes(), and M_Interpolate_poly_3d_calc().

◆ mathutils_array_parse_alloc_vi()

int mathutils_array_parse_alloc_vi ( int **  array,
int  array_dim,
PyObject *  value,
const char *  error_prefix 
)

Parse sequence of array_dim sequences of integers and return allocated result.

Definition at line 335 of file mathutils.c.

References mathutils_int_array_parse(), NULL, and size().

◆ mathutils_array_parse_alloc_viseq()

int mathutils_array_parse_alloc_viseq ( int **  array,
int **  start_table,
int **  len_table,
PyObject *  value,
const char *  error_prefix 
)

Parse sequence of variable-length sequences of int and return allocated triple of arrays to represent the result: The flattened sequences are put into *array. The start index of each sequence goes into start_table. The length of each index goes into len_table.

Definition at line 372 of file mathutils.c.

References mathutils_int_array_parse(), NULL, and size().

◆ mathutils_dynstr_to_py()

PyObject* mathutils_dynstr_to_py ( struct DynStr ds)

◆ mathutils_int_array_parse()

int mathutils_int_array_parse ( int *  array,
int  array_dim,
PyObject *  value,
const char *  error_prefix 
)

Parse an sequence array_dim integers into array.

Definition at line 300 of file mathutils.c.

References size().

Referenced by mathutils_array_parse_alloc_vi(), and mathutils_array_parse_alloc_viseq().

◆ Mathutils_RegisterCallback()

unsigned char Mathutils_RegisterCallback ( Mathutils_Callback cb)

◆ PyInit_mathutils()

PyMODINIT_FUNC PyInit_mathutils ( void  )

Variable Documentation

◆ BaseMathObject_freeze_doc

char BaseMathObject_freeze_doc[]
extern

Definition at line 673 of file mathutils.c.

◆ BaseMathObject_is_frozen_doc

char BaseMathObject_is_frozen_doc[]
extern

Definition at line 659 of file mathutils.c.

◆ BaseMathObject_is_valid_doc

char BaseMathObject_is_valid_doc[]
extern

Definition at line 666 of file mathutils.c.

◆ BaseMathObject_is_wrapped_doc

char BaseMathObject_is_wrapped_doc[]
extern

Definition at line 652 of file mathutils.c.

◆ BaseMathObject_owner_doc

char BaseMathObject_owner_doc[]
extern

Definition at line 645 of file mathutils.c.