| 
									
										
										
										
											2012-04-30 14:24:11 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 09:50:34 +02:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2012-04-30 14:24:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pymathutils | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | /* Can cast different mathutils types to this, use for generic funcs */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | #include "BLI_compiler_attrs.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | struct DynStr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | extern char BaseMathObject_is_wrapped_doc[]; | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | extern char BaseMathObject_is_frozen_doc[]; | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | extern char BaseMathObject_owner_doc[]; | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | #define BASE_MATH_NEW(struct_name, root_type, base_type) \
 | 
					
						
							| 
									
										
										
										
											2019-04-20 11:28:21 +02:00
										 |  |  |   ((struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : \ | 
					
						
							|  |  |  |                                 _PyObject_GC_New(&(root_type))))) | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 11:02:26 +10:00
										 |  |  | /** BaseMathObject.flag */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | enum { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * 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_WRAP = (1 << 0), | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Prevent changes to the vector so it can be used as a set or dictionary key for example. | 
					
						
							|  |  |  |    * (typical use cases for tuple). | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   BASE_MATH_FLAG_IS_FROZEN = (1 << 1), | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | }; | 
					
						
							|  |  |  | #define BASE_MATH_FLAG_DEFAULT 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define BASE_MATH_MEMBERS(_data) \
 | 
					
						
							| 
									
										
										
										
											2019-04-18 07:21:26 +02:00
										 |  |  |   /** Array of data (alias), wrapped status depends on wrapped status. */ \ | 
					
						
							| 
									
										
										
										
											2021-04-01 11:15:47 +11:00
										 |  |  |   PyObject_VAR_HEAD \ | 
					
						
							|  |  |  |   float *_data; \ | 
					
						
							| 
									
										
										
										
											2019-04-18 07:21:26 +02:00
										 |  |  |   /** If this vector references another object, otherwise NULL, *Note* this owns its reference */ \ | 
					
						
							|  |  |  |   PyObject *cb_user; \ | 
					
						
							|  |  |  |   /** Which user funcs do we adhere to, RNA, etc */ \ | 
					
						
							|  |  |  |   unsigned char cb_type; \ | 
					
						
							|  |  |  |   /** Subtype: location, rotation... \
 | 
					
						
							|  |  |  |    * to avoid defining many new functions for every attribute of the same type */ \ | 
					
						
							|  |  |  |   unsigned char cb_subtype; \ | 
					
						
							|  |  |  |   /** Wrapped data type. */ \ | 
					
						
							|  |  |  |   unsigned char flag | 
					
						
							| 
									
										
										
										
											2010-04-16 08:17:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BASE_MATH_MEMBERS(data); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | } BaseMathObject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 10:28:52 +00:00
										 |  |  | /* types */ | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "mathutils_Color.h"
 | 
					
						
							|  |  |  | #include "mathutils_Euler.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-14 04:15:25 +00:00
										 |  |  | #include "mathutils_Matrix.h"
 | 
					
						
							|  |  |  | #include "mathutils_Quaternion.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "mathutils_Vector.h"
 | 
					
						
							| 
									
										
										
										
											2011-11-29 10:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 16:09:46 +11:00
										 |  |  | /* avoid checking all types */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define BaseMathObject_CheckExact(v) (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)
 | 
					
						
							| 
									
										
										
										
											2017-11-29 16:09:46 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 07:29:01 +00:00
										 |  |  | PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *); | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *); | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern char BaseMathObject_freeze_doc[]; | 
					
						
							|  |  |  | PyObject *BaseMathObject_freeze(BaseMathObject *self); | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg); | 
					
						
							|  |  |  | int BaseMathObject_clear(BaseMathObject *self); | 
					
						
							| 
									
										
										
										
											2013-03-26 07:29:01 +00:00
										 |  |  | void BaseMathObject_dealloc(BaseMathObject *self); | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | PyMODINIT_FUNC PyInit_mathutils(void); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | int EXPP_FloatsAreEqual(float A, float B, int maxDiff); | 
					
						
							| 
									
										
										
										
											2012-12-02 04:51:15 +00:00
										 |  |  | int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | typedef struct Mathutils_Callback Mathutils_Callback; | 
					
						
							| 
									
										
										
										
											2009-07-10 18:09:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 23:29:46 +10:00
										 |  |  | /** Checks the user is still valid. */ | 
					
						
							|  |  |  | typedef int (*BaseMathCheckFunc)(BaseMathObject *); | 
					
						
							|  |  |  | /** Gets the vector from the user. */ | 
					
						
							|  |  |  | typedef int (*BaseMathGetFunc)(BaseMathObject *, int); | 
					
						
							|  |  |  | /** Sets the users vector values once its modified. */ | 
					
						
							|  |  |  | typedef int (*BaseMathSetFunc)(BaseMathObject *, int); | 
					
						
							|  |  |  | /** Same as above but only for an index. */ | 
					
						
							|  |  |  | typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int); | 
					
						
							|  |  |  | /** Same as above but only for an index. */ | 
					
						
							|  |  |  | typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int); | 
					
						
							| 
									
										
										
										
											2009-07-10 18:09:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | struct Mathutils_Callback { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BaseMathCheckFunc check; | 
					
						
							|  |  |  |   BaseMathGetFunc get; | 
					
						
							|  |  |  |   BaseMathSetFunc set; | 
					
						
							|  |  |  |   BaseMathGetIndexFunc get_index; | 
					
						
							|  |  |  |   BaseMathSetIndexFunc set_index; | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-17 10:46:02 +00:00
										 |  |  | unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | int _BaseMathObject_ReadCallback(BaseMathObject *self); | 
					
						
							|  |  |  | int _BaseMathObject_WriteCallback(BaseMathObject *self); | 
					
						
							|  |  |  | int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index); | 
					
						
							|  |  |  | int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index); | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self); | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self); | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-23 13:34:45 +00:00
										 |  |  | /* since this is called so often avoid where possible */ | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | #define BaseMath_ReadCallback(_self) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0)) | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | #define BaseMath_WriteCallback(_self) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (((_self)->cb_user ? _BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0)) | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | #define BaseMath_ReadIndexCallback(_self, _index) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0)) | 
					
						
							| 
									
										
										
										
											2011-11-29 20:22:35 +00:00
										 |  |  | #define BaseMath_WriteIndexCallback(_self, _index) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0)) | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | /* support BASE_MATH_FLAG_IS_FROZEN */ | 
					
						
							|  |  |  | #define BaseMath_ReadCallback_ForWrite(_self) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \ | 
					
						
							|  |  |  |        (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \ | 
					
						
							|  |  |  |        (BaseMath_ReadCallback(_self))) | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define BaseMath_ReadIndexCallback_ForWrite(_self, _index) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \ | 
					
						
							|  |  |  |        (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \ | 
					
						
							|  |  |  |        (BaseMath_ReadIndexCallback(_self, _index))) | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define BaseMath_Prepare_ForWrite(_self) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \ | 
					
						
							|  |  |  |        (_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \ | 
					
						
							|  |  |  |        0) | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | #define BaseMathObject_Prepare_ForHash(_self) \
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   (UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \ | 
					
						
							|  |  |  |        (_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : \ | 
					
						
							|  |  |  |        0) | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | /* utility func */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | int mathutils_array_parse( | 
					
						
							|  |  |  |     float *array, int array_min, int array_max, PyObject *value, const char *error_prefix); | 
					
						
							|  |  |  | int mathutils_array_parse_alloc(float **array, | 
					
						
							|  |  |  |                                 int array_min, | 
					
						
							|  |  |  |                                 PyObject *value, | 
					
						
							|  |  |  |                                 const char *error_prefix); | 
					
						
							|  |  |  | int mathutils_array_parse_alloc_v(float **array, | 
					
						
							|  |  |  |                                   int array_dim, | 
					
						
							|  |  |  |                                   PyObject *value, | 
					
						
							|  |  |  |                                   const char *error_prefix); | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix); | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  | /* zero remaining unused elements of the array */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define MU_ARRAY_ZERO (1u << 30)
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  | /* ignore larger py sequences than requested (just use first elements),
 | 
					
						
							|  |  |  |  * handy when using 3d vectors as 2d */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define MU_ARRAY_SPILL (1u << 31)
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  | #define MU_ARRAY_FLAGS (MU_ARRAY_ZERO | MU_ARRAY_SPILL)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | int column_vector_multiplication(float r_vec[4], VectorObject *vec, MatrixObject *mat); | 
					
						
							| 
									
										
										
										
											2011-07-25 01:44:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2018-09-03 16:49:08 +02:00
										 |  |  | /* dynstr as python string utility functions */ | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | PyObject *mathutils_dynstr_to_py(struct DynStr *ds); | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 |