Add mathutils.bvhtree API
[blender.git] / source / blender / python / mathutils / mathutils.c
1 /* 
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Joseph Gilbert, Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/python/mathutils/mathutils.c
24  *  \ingroup pymathutils
25  */
26
27 #include <Python.h>
28
29 #include "mathutils.h"
30
31 #include "BLI_math.h"
32 #include "BLI_utildefines.h"
33
34 #include "../generic/python_utildefines.h"
35
36 #ifndef MATH_STANDALONE
37 #  include "BLI_dynstr.h"
38 #endif
39
40 PyDoc_STRVAR(M_Mathutils_doc,
41 "This module provides access to the math classes:\n"
42 "\n"
43 "- :class:`Color`,\n"
44 "- :class:`Euler`,\n"
45 "- :class:`Matrix`,\n"
46 "- :class:`Quaternion`,\n"
47 "- :class:`Vector`,\n"
48 "\n"
49 ".. note::\n"
50 "\n"
51 "   Classes, methods and attributes that accept vectors also accept other numeric sequences,\n"
52 "   such as tuples, lists."
53 );
54 static int mathutils_array_parse_fast(float *array,
55                                       int size,
56                                       PyObject *value_fast,
57                                       const char *error_prefix)
58 {
59         PyObject *item;
60         PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
61
62         int i;
63
64         i = size;
65         do {
66                 i--;
67                 if (((array[i] = PyFloat_AsDouble((item = value_fast_items[i]))) == -1.0f) &&
68                     PyErr_Occurred())
69                 {
70                         PyErr_Format(PyExc_TypeError,
71                                      "%.200s: sequence index %d expected a number, "
72                                      "found '%.200s' type, ",
73                                      error_prefix, i, Py_TYPE(item)->tp_name);
74                         size = -1;
75                         break;
76                 }
77         } while (i);
78
79         return size;
80 }
81
82 /**
83  * helper function that returns a Python ``__hash__``.
84  *
85  * \note consistent with the equivalent tuple of floats (CPython's 'tuplehash')
86  */
87 Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
88 {
89         int i;
90         Py_uhash_t x;  /* Unsigned for defined overflow behavior. */
91         Py_hash_t y;
92         Py_uhash_t mult;
93         Py_ssize_t len;
94
95         mult = _PyHASH_MULTIPLIER;
96         len = array_len;
97         x = 0x345678UL;
98         i = 0;
99         while (--len >= 0) {
100                 y = _Py_HashDouble((double)(array[i++]));
101                 if (y == -1)
102                         return -1;
103                 x = (x ^ y) * mult;
104                 /* the cast might truncate len; that doesn't change hash stability */
105                 mult += (Py_hash_t)(82520UL + len + len);
106         }
107         x += 97531UL;
108         if (x == (Py_uhash_t)-1)
109                 x = -2;
110         return x;
111 }
112
113 /* helper function returns length of the 'value', -1 on error */
114 int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
115 {
116         const int flag = array_max;
117         int size;
118
119         array_max &= ~MU_ARRAY_FLAGS;
120
121 #if 1 /* approx 6x speedup for mathutils types */
122
123         if ((size = VectorObject_Check(value)     ? ((VectorObject *)value)->size : 0) ||
124             (size = EulerObject_Check(value)      ? 3 : 0) ||
125             (size = QuaternionObject_Check(value) ? 4 : 0) ||
126             (size = ColorObject_Check(value)      ? 3 : 0))
127         {
128                 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
129                         return -1;
130                 }
131
132                 if (flag & MU_ARRAY_SPILL) {
133                         CLAMP_MAX(size, array_max);
134                 }
135
136                 if (size > array_max || size < array_min) {
137                         if (array_max == array_min) {
138                                 PyErr_Format(PyExc_ValueError,
139                                              "%.200s: sequence size is %d, expected %d",
140                                              error_prefix, size, array_max);
141                         }
142                         else {
143                                 PyErr_Format(PyExc_ValueError,
144                                              "%.200s: sequence size is %d, expected [%d - %d]",
145                                              error_prefix, size, array_min, array_max);
146                         }
147                         return -1;
148                 }
149
150                 memcpy(array, ((BaseMathObject *)value)->data, size * sizeof(float));
151         }
152         else
153 #endif
154         {
155                 PyObject *value_fast = NULL;
156
157                 /* non list/tuple cases */
158                 if (!(value_fast = PySequence_Fast(value, error_prefix))) {
159                         /* PySequence_Fast sets the error */
160                         return -1;
161                 }
162
163                 size = PySequence_Fast_GET_SIZE(value_fast);
164
165                 if (flag & MU_ARRAY_SPILL) {
166                         CLAMP_MAX(size, array_max);
167                 }
168
169                 if (size > array_max || size < array_min) {
170                         if (array_max == array_min) {
171                                 PyErr_Format(PyExc_ValueError,
172                                              "%.200s: sequence size is %d, expected %d",
173                                              error_prefix, size, array_max);
174                         }
175                         else {
176                                 PyErr_Format(PyExc_ValueError,
177                                              "%.200s: sequence size is %d, expected [%d - %d]",
178                                              error_prefix, size, array_min, array_max);
179                         }
180                         Py_DECREF(value_fast);
181                         return -1;
182                 }
183
184                 size = mathutils_array_parse_fast(array, size, value_fast, error_prefix);
185                 Py_DECREF(value_fast);
186         }
187
188         if (size != -1) {
189                 if (flag & MU_ARRAY_ZERO) {
190                         int size_left = array_max - size;
191                         if (size_left) {
192                                 memset(&array[size], 0, sizeof(float) * size_left);
193                         }
194                 }
195         }
196
197         return size;
198 }
199
200 /* on error, -1 is returned and no allocation is made */
201 int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix)
202 {
203         int size;
204
205 #if 1 /* approx 6x speedup for mathutils types */
206
207         if ((size = VectorObject_Check(value)     ? ((VectorObject *)value)->size : 0) ||
208             (size = EulerObject_Check(value)      ? 3 : 0) ||
209             (size = QuaternionObject_Check(value) ? 4 : 0) ||
210             (size = ColorObject_Check(value)      ? 3 : 0))
211         {
212                 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
213                         return -1;
214                 }
215
216                 if (size < array_min) {
217                         PyErr_Format(PyExc_ValueError,
218                                      "%.200s: sequence size is %d, expected > %d",
219                                      error_prefix, size, array_min);
220                         return -1;
221                 }
222                 
223                 *array = PyMem_Malloc(size * sizeof(float));
224                 memcpy(*array, ((BaseMathObject *)value)->data, size * sizeof(float));
225                 return size;
226         }
227         else
228 #endif
229         {
230                 PyObject *value_fast = NULL;
231                 // *array = NULL;
232                 int ret;
233
234                 /* non list/tuple cases */
235                 if (!(value_fast = PySequence_Fast(value, error_prefix))) {
236                         /* PySequence_Fast sets the error */
237                         return -1;
238                 }
239
240                 size = PySequence_Fast_GET_SIZE(value_fast);
241
242                 if (size < array_min) {
243                         Py_DECREF(value_fast);
244                         PyErr_Format(PyExc_ValueError,
245                                      "%.200s: sequence size is %d, expected > %d",
246                                      error_prefix, size, array_min);
247                         return -1;
248                 }
249
250                 *array = PyMem_Malloc(size * sizeof(float));
251
252                 ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
253                 Py_DECREF(value_fast);
254
255                 if (ret == -1) {
256                         PyMem_Free(*array);
257                 }
258
259                 return ret;
260         }
261 }
262
263 /* parse an array of vectors */
264 int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
265 {
266         PyObject *value_fast;
267         const int array_dim_flag = array_dim;
268         int i, size;
269
270         /* non list/tuple cases */
271         if (!(value_fast = PySequence_Fast(value, error_prefix))) {
272                 /* PySequence_Fast sets the error */
273                 return -1;
274         }
275
276         size = PySequence_Fast_GET_SIZE(value_fast);
277
278         if (size != 0) {
279                 PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
280                 float *fp;
281
282                 array_dim &= ~MU_ARRAY_FLAGS;
283
284                 fp = *array = PyMem_Malloc(size * array_dim * sizeof(float));
285
286                 for (i = 0; i < size; i++, fp += array_dim) {
287                         PyObject *item = value_fast_items[i];
288
289                         if (mathutils_array_parse(fp, array_dim, array_dim_flag, item, error_prefix) == -1) {
290                                 PyMem_Free(*array);
291                                 *array = NULL;
292                                 size = -1;
293                                 break;
294                         }
295                 }
296         }
297
298         Py_DECREF(value_fast);
299         return size;
300 }
301
302 int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
303 {
304         if (EulerObject_Check(value)) {
305                 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
306                         return -1;
307                 }
308                 else {
309                         eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order);
310                         return 0;
311                 }
312         }
313         else if (QuaternionObject_Check(value)) {
314                 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
315                         return -1;
316                 }
317                 else {
318                         float tquat[4];
319                         normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat);
320                         quat_to_mat3(rmat, tquat);
321                         return 0;
322                 }
323         }
324         else if (MatrixObject_Check(value)) {
325                 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
326                         return -1;
327                 }
328                 else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
329                         PyErr_Format(PyExc_ValueError,
330                                      "%.200s: matrix must have minimum 3x3 dimensions",
331                                      error_prefix);
332                         return -1;
333                 }
334                 else {
335                         matrix_as_3x3(rmat, (MatrixObject *)value);
336                         normalize_m3(rmat);
337                         return 0;
338                 }
339         }
340         else {
341                 PyErr_Format(PyExc_TypeError,
342                              "%.200s: expected a Euler, Quaternion or Matrix type, "
343                              "found %.200s", error_prefix, Py_TYPE(value)->tp_name);
344                 return -1;
345         }
346 }
347
348
349 /* ----------------------------------MATRIX FUNCTIONS-------------------- */
350
351
352 /* Utility functions */
353
354 /* LomontRRDCompare4, Ever Faster Float Comparisons by Randy Dillon */
355 /* XXX We may want to use 'safer' BLI's compare_ff_relative ultimately?
356  *     LomontRRDCompare4() is an optimized version of Dawson's AlmostEqual2sComplement() (see [1] and [2]).
357  *     Dawson himself now claims this is not a 'safe' thing to do (pushing ULP method beyond its limits),
358  *     an recommands using work from [3] instead, which is done in BLI func...
359  *
360  *     [1] http://www.randydillon.org/Papers/2007/everfast.htm
361  *     [2] http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
362  *     [3] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ instead
363  */
364 #define SIGNMASK(i) (-(int)(((unsigned int)(i)) >> 31))
365
366 int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
367 {
368         /* solid, fast routine across all platforms
369          * with constant time behavior */
370         int ai = *(int *)(&af);
371         int bi = *(int *)(&bf);
372         int test = SIGNMASK(ai ^ bi);
373         int diff, v1, v2;
374
375         assert((0 == test) || (0xFFFFFFFF == test));
376         diff = (ai ^ (test & 0x7fffffff)) - bi;
377         v1 = maxDiff + diff;
378         v2 = maxDiff - diff;
379         return (v1 | v2) >= 0;
380 }
381
382 /*---------------------- EXPP_VectorsAreEqual -------------------------
383  * Builds on EXPP_FloatsAreEqual to test vectors */
384 int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
385 {
386         int x;
387         for (x = 0; x < size; x++) {
388                 if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0)
389                         return 0;
390         }
391         return 1;
392 }
393
394 #ifndef MATH_STANDALONE
395 /* dynstr as python string utility funcions, frees 'ds'! */
396 PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
397 {
398         const int ds_len = BLI_dynstr_get_len(ds); /* space for \0 */
399         char *ds_buf     = PyMem_Malloc(ds_len + 1);
400         PyObject *ret;
401         BLI_dynstr_get_cstring_ex(ds, ds_buf);
402         BLI_dynstr_free(ds);
403         ret = PyUnicode_FromStringAndSize(ds_buf, ds_len);
404         PyMem_Free(ds_buf);
405         return ret;
406 }
407 #endif
408
409 /* silly function, we dont use arg. just check its compatible with __deepcopy__ */
410 int mathutils_deepcopy_args_check(PyObject *args)
411 {
412         PyObject *dummy_pydict;
413         return PyArg_ParseTuple(args, "|O!:__deepcopy__", &PyDict_Type, &dummy_pydict) != 0;
414 }
415
416 /* Mathutils Callbacks */
417
418 /* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */
419 #define MATHUTILS_TOT_CB 17
420 static Mathutils_Callback *mathutils_callbacks[MATHUTILS_TOT_CB] = {NULL};
421
422 unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb)
423 {
424         unsigned char i;
425         
426         /* find the first free slot */
427         for (i = 0; mathutils_callbacks[i]; i++) {
428                 if (mathutils_callbacks[i] == cb) /* already registered? */
429                         return i;
430         }
431
432         BLI_assert(i + 1 < MATHUTILS_TOT_CB);
433
434         mathutils_callbacks[i] = cb;
435         return i;
436 }
437
438 /* use macros to check for NULL */
439 int _BaseMathObject_ReadCallback(BaseMathObject *self)
440 {
441         Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
442         if (LIKELY(cb->get(self, self->cb_subtype) != -1)) {
443                 return 0;
444         }
445
446         if (!PyErr_Occurred()) {
447                 PyErr_Format(PyExc_RuntimeError,
448                              "%s read, user has become invalid",
449                              Py_TYPE(self)->tp_name);
450         }
451         return -1;
452 }
453
454 int _BaseMathObject_WriteCallback(BaseMathObject *self)
455 {
456         Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
457         if (LIKELY(cb->set(self, self->cb_subtype) != -1)) {
458                 return 0;
459         }
460
461         if (!PyErr_Occurred()) {
462                 PyErr_Format(PyExc_RuntimeError,
463                              "%s write, user has become invalid",
464                              Py_TYPE(self)->tp_name);
465         }
466         return -1;
467 }
468
469 int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
470 {
471         Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
472         if (LIKELY(cb->get_index(self, self->cb_subtype, index) != -1)) {
473                 return 0;
474         }
475
476         if (!PyErr_Occurred()) {
477                 PyErr_Format(PyExc_RuntimeError,
478                              "%s read index, user has become invalid",
479                              Py_TYPE(self)->tp_name);
480         }
481         return -1;
482 }
483
484 int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index)
485 {
486         Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
487         if (LIKELY(cb->set_index(self, self->cb_subtype, index) != -1)) {
488                 return 0;
489         }
490
491         if (!PyErr_Occurred()) {
492                 PyErr_Format(PyExc_RuntimeError,
493                              "%s write index, user has become invalid",
494                              Py_TYPE(self)->tp_name);
495         }
496         return -1;
497 }
498
499 void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self)
500 {
501         PyErr_Format(PyExc_TypeError,
502                      "%s is frozen (immutable)",
503                      Py_TYPE(self)->tp_name);
504 }
505
506 void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self)
507 {
508         PyErr_Format(PyExc_TypeError,
509                      "%s is not frozen (mutable), call freeze first",
510                      Py_TYPE(self)->tp_name);
511 }
512
513 /* BaseMathObject generic functions for all mathutils types */
514 char BaseMathObject_owner_doc[] = "The item this is wrapping or None  (read-only).";
515 PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *UNUSED(closure))
516 {
517         PyObject *ret = self->cb_user ? self->cb_user : Py_None;
518         return Py_INCREF_RET(ret);
519 }
520
521 char BaseMathObject_is_wrapped_doc[] = "True when this object wraps external data (read-only).\n\n:type: boolean";
522 PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *UNUSED(closure))
523 {
524         return PyBool_FromLong((self->flag & BASE_MATH_FLAG_IS_WRAP) != 0);
525 }
526
527 char BaseMathObject_is_frozen_doc[] = "True when this object has been frozen (read-only).\n\n:type: boolean";
528 PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *UNUSED(closure))
529 {
530         return PyBool_FromLong((self->flag & BASE_MATH_FLAG_IS_FROZEN) != 0);
531 }
532
533 char BaseMathObject_freeze_doc[] =
534 ".. function:: freeze()\n"
535 "\n"
536 "   Make this object immutable.\n"
537 "\n"
538 "   After this the object can be hashed, used in dictionaries & sets.\n"
539 "\n"
540 "   :return: An instance of this object.\n"
541 ;
542 PyObject *BaseMathObject_freeze(BaseMathObject *self)
543 {
544         if (self->flag & BASE_MATH_FLAG_IS_WRAP) {
545                 PyErr_SetString(PyExc_TypeError, "Cannot freeze wrapped data");
546                 return NULL;
547         }
548
549         self->flag |= BASE_MATH_FLAG_IS_FROZEN;
550
551         return Py_INCREF_RET((PyObject *)self);
552 }
553
554 int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
555 {
556         Py_VISIT(self->cb_user);
557         return 0;
558 }
559
560 int BaseMathObject_clear(BaseMathObject *self)
561 {
562         Py_CLEAR(self->cb_user);
563         return 0;
564 }
565
566 void BaseMathObject_dealloc(BaseMathObject *self)
567 {
568         /* only free non wrapped */
569         if ((self->flag & BASE_MATH_FLAG_IS_WRAP) == 0) {
570                 PyMem_Free(self->data);
571         }
572
573         if (self->cb_user) {
574                 PyObject_GC_UnTrack(self);
575                 BaseMathObject_clear(self);
576         }
577
578         Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); // breaks subtypes
579 }
580
581 /*----------------------------MODULE INIT-------------------------*/
582 static struct PyMethodDef M_Mathutils_methods[] = {
583         {NULL, NULL, 0, NULL}
584 };
585
586 static struct PyModuleDef M_Mathutils_module_def = {
587         PyModuleDef_HEAD_INIT,
588         "mathutils",  /* m_name */
589         M_Mathutils_doc,  /* m_doc */
590         0,  /* m_size */
591         M_Mathutils_methods,  /* m_methods */
592         NULL,  /* m_reload */
593         NULL,  /* m_traverse */
594         NULL,  /* m_clear */
595         NULL,  /* m_free */
596 };
597
598
599 /* submodules only */
600 #include "mathutils_geometry.h"
601 #include "mathutils_interpolate.h"
602 #ifndef MATH_STANDALONE
603 #  include "mathutils_bvhtree.h"
604 #  include "mathutils_kdtree.h"
605 #  include "mathutils_noise.h"
606 #endif
607
608 PyMODINIT_FUNC PyInit_mathutils(void)
609 {
610         PyObject *mod;
611         PyObject *submodule;
612         PyObject *sys_modules = PyThreadState_GET()->interp->modules;
613
614         if (PyType_Ready(&vector_Type) < 0)
615                 return NULL;
616         if (PyType_Ready(&matrix_Type) < 0)
617                 return NULL;
618         if (PyType_Ready(&matrix_access_Type) < 0)
619                 return NULL;
620         if (PyType_Ready(&euler_Type) < 0)
621                 return NULL;
622         if (PyType_Ready(&quaternion_Type) < 0)
623                 return NULL;
624         if (PyType_Ready(&color_Type) < 0)
625                 return NULL;
626
627         mod = PyModule_Create(&M_Mathutils_module_def);
628         
629         /* each type has its own new() function */
630         PyModule_AddObject(mod, vector_Type.tp_name,     (PyObject *)&vector_Type);
631         PyModule_AddObject(mod, matrix_Type.tp_name,     (PyObject *)&matrix_Type);
632         PyModule_AddObject(mod, euler_Type.tp_name,      (PyObject *)&euler_Type);
633         PyModule_AddObject(mod, quaternion_Type.tp_name, (PyObject *)&quaternion_Type);
634         PyModule_AddObject(mod, color_Type.tp_name,      (PyObject *)&color_Type);
635         
636         /* submodule */
637         PyModule_AddObject(mod, "geometry",       (submodule = PyInit_mathutils_geometry()));
638         /* XXX, python doesnt do imports with this usefully yet
639          * 'from mathutils.geometry import PolyFill'
640          * ...fails without this. */
641         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
642         Py_INCREF(submodule);
643
644         PyModule_AddObject(mod, "interpolate",    (submodule = PyInit_mathutils_interpolate()));
645         /* XXX, python doesnt do imports with this usefully yet
646          * 'from mathutils.geometry import PolyFill'
647          * ...fails without this. */
648         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
649         Py_INCREF(submodule);
650
651 #ifndef MATH_STANDALONE
652         /* Noise submodule */
653         PyModule_AddObject(mod, "noise", (submodule = PyInit_mathutils_noise()));
654         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
655         Py_INCREF(submodule);
656
657         /* BVHTree submodule */
658         PyModule_AddObject(mod, "bvhtree", (submodule = PyInit_mathutils_bvhtree()));
659         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
660         Py_INCREF(submodule);
661
662         /* KDTree submodule */
663         PyModule_AddObject(mod, "kdtree", (submodule = PyInit_mathutils_kdtree()));
664         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
665         Py_INCREF(submodule);
666 #endif
667
668         mathutils_matrix_row_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_row_cb);
669         mathutils_matrix_col_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_col_cb);
670         mathutils_matrix_translation_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_translation_cb);
671
672         return mod;
673 }