Remove py mathutils Euler.unique() method
[blender.git] / source / blender / python / generic / mathutils_euler.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joseph Gilbert
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "mathutils.h"
30
31 #include "BLI_math.h"
32 #include "BLI_utildefines.h"
33
34
35
36 #ifndef int32_t
37 #include "BLO_sys_types.h"
38 #endif
39
40 #define EULER_SIZE 3
41
42 //----------------------------------mathutils.Euler() -------------------
43 //makes a new euler for you to play with
44 static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
45 {
46         PyObject *seq= NULL;
47         char *order_str= NULL;
48
49         float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f};
50         short order= EULER_ORDER_XYZ;
51
52         if(kwds && PyDict_Size(kwds)) {
53                 PyErr_SetString(PyExc_TypeError, "mathutils.Euler(): takes no keyword args");
54                 return NULL;
55         }
56
57         if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
58                 return NULL;
59
60         switch(PyTuple_GET_SIZE(args)) {
61         case 0:
62                 break;
63         case 2:
64                 if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
65                         return NULL;
66                 /* intentionally pass through */
67         case 1:
68                 if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1)
69                         return NULL;
70                 break;
71         }
72         return newEulerObject(eul, order, Py_NEW, type);
73 }
74
75 short euler_order_from_string(const char *str, const char *error_prefix)
76 {
77         if((str[0] && str[1] && str[2] && str[3]=='\0')) {
78                 switch(*((int32_t *)str)) {
79                         case 'X'|'Y'<<8|'Z'<<16:        return EULER_ORDER_XYZ;
80                         case 'X'|'Z'<<8|'Y'<<16:        return EULER_ORDER_XZY;
81                         case 'Y'|'X'<<8|'Z'<<16:        return EULER_ORDER_YXZ;
82                         case 'Y'|'Z'<<8|'X'<<16:        return EULER_ORDER_YZX;
83                         case 'Z'|'X'<<8|'Y'<<16:        return EULER_ORDER_ZXY;
84                         case 'Z'|'Y'<<8|'X'<<16:        return EULER_ORDER_ZYX;
85                 }
86         }
87
88         PyErr_Format(PyExc_TypeError, "%s: invalid euler order '%s'", error_prefix, str);
89         return -1;
90 }
91
92 /* note: BaseMath_ReadCallback must be called beforehand */
93 static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits)
94 {
95         PyObject *ret;
96         int i;
97
98         ret= PyTuple_New(EULER_SIZE);
99
100         if(ndigits >= 0) {
101                 for(i= 0; i < EULER_SIZE; i++) {
102                         PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->eul[i], ndigits)));
103                 }
104         }
105         else {
106                 for(i= 0; i < EULER_SIZE; i++) {
107                         PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->eul[i]));
108                 }
109         }
110
111         return ret;
112 }
113
114 //-----------------------------METHODS----------------------------
115 //return a quaternion representation of the euler
116
117 static char Euler_ToQuat_doc[] =
118 ".. method:: to_quat()\n"
119 "\n"
120 "   Return a quaternion representation of the euler.\n"
121 "\n"
122 "   :return: Quaternion representation of the euler.\n"
123 "   :rtype: :class:`Quaternion`\n";
124
125 static PyObject *Euler_ToQuat(EulerObject * self)
126 {
127         float quat[4];
128
129         if(!BaseMath_ReadCallback(self))
130                 return NULL;
131
132         if(self->order==EULER_ORDER_XYZ)        eul_to_quat(quat, self->eul);
133         else                                                            eulO_to_quat(quat, self->eul, self->order);
134
135         return newQuaternionObject(quat, Py_NEW, NULL);
136 }
137
138 //return a matrix representation of the euler
139 static char Euler_ToMatrix_doc[] =
140 ".. method:: to_matrix()\n"
141 "\n"
142 "   Return a matrix representation of the euler.\n"
143 "\n"
144 "   :return: A 3x3 roation matrix representation of the euler.\n"
145 "   :rtype: :class:`Matrix`\n";
146
147 static PyObject *Euler_ToMatrix(EulerObject * self)
148 {
149         float mat[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
150
151         if(!BaseMath_ReadCallback(self))
152                 return NULL;
153
154         if(self->order==EULER_ORDER_XYZ)        eul_to_mat3((float (*)[3])mat, self->eul);
155         else                                                            eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
156
157         return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
158 }
159
160 //sets the euler to 0,0,0
161 static char Euler_Zero_doc[] =
162 ".. method:: zero()\n"
163 "\n"
164 "   Set all values to zero.\n"
165 "\n"
166 "   :return: an instance of itself\n"
167 "   :rtype: :class:`Euler`\n";
168
169 static PyObject *Euler_Zero(EulerObject * self)
170 {
171         self->eul[0] = 0.0;
172         self->eul[1] = 0.0;
173         self->eul[2] = 0.0;
174
175         (void)BaseMath_WriteCallback(self);
176         Py_INCREF(self);
177         return (PyObject *)self;
178 }
179
180 static char Euler_rotate_axis_doc[] =
181 ".. method:: rotate_axis(axis, angle)\n"
182 "\n"
183 "   Rotates the euler a certain amount and returning a unique euler rotation (no 720 degree pitches).\n"
184 "\n"
185 "   :arg axis: single character in ['X, 'Y', 'Z'].\n"
186 "   :type axis: string\n"
187 "   :arg angle: angle in radians.\n"
188 "   :type angle: float\n"
189 "   :return: an instance of itself\n"
190 "   :rtype: :class:`Euler`";
191
192 static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
193 {
194         float angle = 0.0f;
195         char *axis;
196
197         if(!PyArg_ParseTuple(args, "sf:rotate", &axis, &angle)){
198                 PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected angle (float) and axis (x,y,z)");
199                 return NULL;
200         }
201         if(!(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0')){
202                 PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'X', 'Y' or 'Z'");
203                 return NULL;
204         }
205
206         if(!BaseMath_ReadCallback(self))
207                 return NULL;
208
209         if(self->order == EULER_ORDER_XYZ)      rotate_eul(self->eul, *axis, angle);
210         else                                                            rotate_eulO(self->eul, self->order, *axis, angle);
211
212         (void)BaseMath_WriteCallback(self);
213         Py_INCREF(self);
214         return (PyObject *)self;
215 }
216
217 static char Euler_MakeCompatible_doc[] =
218 ".. method:: make_compatible(other)\n"
219 "\n"
220 "   Make this euler compatible with another, so interpolating between them works as intended.\n"
221 "\n"
222 "   :arg other: make compatible with this rotation.\n"
223 "   :type other: :class:`Euler`\n"
224 "   :return: an instance of itself.\n"
225 "   :rtype: :class:`Euler`\n"
226 "\n"
227 "   .. note:: the order of eulers must match or an exception is raised.\n";
228
229 static PyObject *Euler_MakeCompatible(EulerObject * self, EulerObject *value)
230 {
231         if(!EulerObject_Check(value)) {
232                 PyErr_SetString(PyExc_TypeError, "euler.make_compatible(euler): expected a single euler argument");
233                 return NULL;
234         }
235         
236         if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
237                 return NULL;
238
239         if(self->order != value->order) {
240                 PyErr_SetString(PyExc_ValueError, "euler.make_compatible(euler): rotation orders don't match");
241                 return NULL;
242         }
243
244         compatible_eul(self->eul, value->eul);
245
246         (void)BaseMath_WriteCallback(self);
247         Py_INCREF(self);
248         return (PyObject *)self;
249 }
250
251 //----------------------------Euler.rotate()-----------------------
252 // return a copy of the euler
253
254 static char Euler_copy_doc[] =
255 ".. function:: copy()\n"
256 "\n"
257 "   Returns a copy of this euler.\n"
258 "\n"
259 "   :return: A copy of the euler.\n"
260 "   :rtype: :class:`Euler`\n"
261 "\n"
262 "   .. note:: use this to get a copy of a wrapped euler with no reference to the original data.\n";
263
264 static PyObject *Euler_copy(EulerObject *self)
265 {
266         if(!BaseMath_ReadCallback(self))
267                 return NULL;
268
269         return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
270 }
271
272 //----------------------------print object (internal)--------------
273 //print the object to screen
274
275 static PyObject *Euler_repr(EulerObject * self)
276 {
277         PyObject *ret, *tuple;
278         
279         if(!BaseMath_ReadCallback(self))
280                 return NULL;
281
282         tuple= Euler_ToTupleExt(self, -1);
283
284         ret= PyUnicode_FromFormat("Euler(%R)", tuple);
285
286         Py_DECREF(tuple);
287         return ret;
288 }
289
290 //------------------------tp_richcmpr
291 //returns -1 execption, 0 false, 1 true
292 static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
293 {
294         EulerObject *eulA = NULL, *eulB = NULL;
295         int result = 0;
296
297         if(EulerObject_Check(objectA)) {
298                 eulA = (EulerObject*)objectA;
299                 if(!BaseMath_ReadCallback(eulA))
300                         return NULL;
301         }
302         if(EulerObject_Check(objectB)) {
303                 eulB = (EulerObject*)objectB;
304                 if(!BaseMath_ReadCallback(eulB))
305                         return NULL;
306         }
307
308         if (!eulA || !eulB){
309                 if (comparison_type == Py_NE){
310                         Py_RETURN_TRUE;
311                 }else{
312                         Py_RETURN_FALSE;
313                 }
314         }
315         eulA = (EulerObject*)objectA;
316         eulB = (EulerObject*)objectB;
317
318         switch (comparison_type){
319                 case Py_EQ:
320                         result = EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1);
321                         break;
322                 case Py_NE:
323                         result = !EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1);
324                         break;
325                 default:
326                         printf("The result of the comparison could not be evaluated");
327                         break;
328         }
329         if (result == 1){
330                 Py_RETURN_TRUE;
331         }else{
332                 Py_RETURN_FALSE;
333         }
334 }
335
336 //---------------------SEQUENCE PROTOCOLS------------------------
337 //----------------------------len(object)------------------------
338 //sequence length
339 static int Euler_len(EulerObject *UNUSED(self))
340 {
341         return EULER_SIZE;
342 }
343 //----------------------------object[]---------------------------
344 //sequence accessor (get)
345 static PyObject *Euler_item(EulerObject * self, int i)
346 {
347         if(i<0) i= EULER_SIZE-i;
348         
349         if(i < 0 || i >= EULER_SIZE) {
350                 PyErr_SetString(PyExc_IndexError, "euler[attribute]: array index out of range");
351                 return NULL;
352         }
353
354         if(!BaseMath_ReadIndexCallback(self, i))
355                 return NULL;
356
357         return PyFloat_FromDouble(self->eul[i]);
358
359 }
360 //----------------------------object[]-------------------------
361 //sequence accessor (set)
362 static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
363 {
364         float f = PyFloat_AsDouble(value);
365
366         if(f == -1 && PyErr_Occurred()) { // parsed item not a number
367                 PyErr_SetString(PyExc_TypeError, "euler[attribute] = x: argument not a number");
368                 return -1;
369         }
370
371         if(i<0) i= EULER_SIZE-i;
372         
373         if(i < 0 || i >= EULER_SIZE){
374                 PyErr_SetString(PyExc_IndexError, "euler[attribute] = x: array assignment index out of range");
375                 return -1;
376         }
377         
378         self->eul[i] = f;
379
380         if(!BaseMath_WriteIndexCallback(self, i))
381                 return -1;
382
383         return 0;
384 }
385 //----------------------------object[z:y]------------------------
386 //sequence slice (get)
387 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
388 {
389         PyObject *tuple;
390         int count;
391
392         if(!BaseMath_ReadCallback(self))
393                 return NULL;
394
395         CLAMP(begin, 0, EULER_SIZE);
396         if (end<0) end= (EULER_SIZE + 1) + end;
397         CLAMP(end, 0, EULER_SIZE);
398         begin= MIN2(begin, end);
399
400         tuple= PyTuple_New(end - begin);
401         for(count = begin; count < end; count++) {
402                 PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
403         }
404
405         return tuple;
406 }
407 //----------------------------object[z:y]------------------------
408 //sequence slice (set)
409 static int Euler_ass_slice(EulerObject * self, int begin, int end, PyObject * seq)
410 {
411         int i, size;
412         float eul[EULER_SIZE];
413
414         if(!BaseMath_ReadCallback(self))
415                 return -1;
416
417         CLAMP(begin, 0, EULER_SIZE);
418         if (end<0) end= (EULER_SIZE + 1) + end;
419         CLAMP(end, 0, EULER_SIZE);
420         begin = MIN2(begin,end);
421
422         if((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
423                 return -1;
424
425         if(size != (end - begin)){
426                 PyErr_SetString(PyExc_TypeError, "euler[begin:end] = []: size mismatch in slice assignment");
427                 return -1;
428         }
429
430         for(i= 0; i < EULER_SIZE; i++)
431                 self->eul[begin + i] = eul[i];
432
433         (void)BaseMath_WriteCallback(self);
434         return 0;
435 }
436
437 static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
438 {
439         if (PyIndex_Check(item)) {
440                 Py_ssize_t i;
441                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
442                 if (i == -1 && PyErr_Occurred())
443                         return NULL;
444                 if (i < 0)
445                         i += EULER_SIZE;
446                 return Euler_item(self, i);
447         } else if (PySlice_Check(item)) {
448                 Py_ssize_t start, stop, step, slicelength;
449
450                 if (PySlice_GetIndicesEx((PySliceObject*)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
451                         return NULL;
452
453                 if (slicelength <= 0) {
454                         return PyList_New(0);
455                 }
456                 else if (step == 1) {
457                         return Euler_slice(self, start, stop);
458                 }
459                 else {
460                         PyErr_SetString(PyExc_TypeError, "slice steps not supported with eulers");
461                         return NULL;
462                 }
463         }
464         else {
465                 PyErr_Format(PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
466                 return NULL;
467         }
468 }
469
470
471 static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
472 {
473         if (PyIndex_Check(item)) {
474                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
475                 if (i == -1 && PyErr_Occurred())
476                         return -1;
477                 if (i < 0)
478                         i += EULER_SIZE;
479                 return Euler_ass_item(self, i, value);
480         }
481         else if (PySlice_Check(item)) {
482                 Py_ssize_t start, stop, step, slicelength;
483
484                 if (PySlice_GetIndicesEx((PySliceObject*)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
485                         return -1;
486
487                 if (step == 1)
488                         return Euler_ass_slice(self, start, stop, value);
489                 else {
490                         PyErr_SetString(PyExc_TypeError, "slice steps not supported with euler");
491                         return -1;
492                 }
493         }
494         else {
495                 PyErr_Format(PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
496                 return -1;
497         }
498 }
499
500 //-----------------PROTCOL DECLARATIONS--------------------------
501 static PySequenceMethods Euler_SeqMethods = {
502         (lenfunc) Euler_len,                                    /* sq_length */
503         (binaryfunc) NULL,                                              /* sq_concat */
504         (ssizeargfunc) NULL,                                    /* sq_repeat */
505         (ssizeargfunc) Euler_item,                              /* sq_item */
506         (ssizessizeargfunc) NULL,                               /* sq_slice, deprecated  */
507         (ssizeobjargproc) Euler_ass_item,               /* sq_ass_item */
508         (ssizessizeobjargproc) NULL,                    /* sq_ass_slice, deprecated */
509         (objobjproc) NULL,                                              /* sq_contains */
510         (binaryfunc) NULL,                                              /* sq_inplace_concat */
511         (ssizeargfunc) NULL,                                    /* sq_inplace_repeat */
512 };
513
514 static PyMappingMethods Euler_AsMapping = {
515         (lenfunc)Euler_len,
516         (binaryfunc)Euler_subscript,
517         (objobjargproc)Euler_ass_subscript
518 };
519
520 /*
521  * euler axis, euler.x/y/z
522  */
523 static PyObject *Euler_getAxis(EulerObject *self, void *type )
524 {
525         return Euler_item(self, GET_INT_FROM_POINTER(type));
526 }
527
528 static int Euler_setAxis(EulerObject *self, PyObject *value, void *type)
529 {
530         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
531 }
532
533 /* rotation order */
534 static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
535 {
536         const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
537
538         if(!BaseMath_ReadCallback(self)) /* can read order too */
539                 return NULL;
540
541         return PyUnicode_FromString(order[self->order-EULER_ORDER_XYZ]);
542 }
543
544 static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
545 {
546         char *order_str= _PyUnicode_AsString(value);
547         short order= euler_order_from_string(order_str, "euler.order");
548
549         if(order == -1)
550                 return -1;
551
552         self->order= order;
553         (void)BaseMath_WriteCallback(self); /* order can be written back */
554         return 0;
555 }
556
557 /*****************************************************************************/
558 /* Python attributes get/set structure:                                      */
559 /*****************************************************************************/
560 static PyGetSetDef Euler_getseters[] = {
561         {(char *)"x", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler X axis in radians.\n\n:type: float", (void *)0},
562         {(char *)"y", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Y axis in radians.\n\n:type: float", (void *)1},
563         {(char *)"z", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Z axis in radians.\n\n:type: float", (void *)2},
564         {(char *)"order", (getter)Euler_getOrder, (setter)Euler_setOrder, (char *)"Euler rotation order.\n\n:type: string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
565
566         {(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL},
567         {(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL},
568         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
569 };
570
571
572 //-----------------------METHOD DEFINITIONS ----------------------
573 static struct PyMethodDef Euler_methods[] = {
574         {"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
575         {"to_matrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
576         {"to_quat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
577         {"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
578         {"make_compatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
579         {"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
580         {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
581         {NULL, NULL, 0, NULL}
582 };
583
584 //------------------PY_OBECT DEFINITION--------------------------
585 static char euler_doc[] =
586 "This object gives access to Eulers in Blender.";
587
588 PyTypeObject euler_Type = {
589         PyVarObject_HEAD_INIT(NULL, 0)
590         "mathutils.Euler",                                              //tp_name
591         sizeof(EulerObject),                    //tp_basicsize
592         0,                                                              //tp_itemsize
593         (destructor)BaseMathObject_dealloc,             //tp_dealloc
594         0,                                                              //tp_print
595         0,                                                              //tp_getattr
596         0,                                                              //tp_setattr
597         0,                                                              //tp_compare
598         (reprfunc) Euler_repr,                  //tp_repr
599         0,                              //tp_as_number
600         &Euler_SeqMethods,                              //tp_as_sequence
601         &Euler_AsMapping,                               //tp_as_mapping
602         0,                                                              //tp_hash
603         0,                                                              //tp_call
604         0,                                                              //tp_str
605         0,                                                              //tp_getattro
606         0,                                                              //tp_setattro
607         0,                                                              //tp_as_buffer
608         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
609         euler_doc, //tp_doc
610         0,                                                              //tp_traverse
611         0,                                                              //tp_clear
612         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
613         0,                                                              //tp_weaklistoffset
614         0,                                                              //tp_iter
615         0,                                                              //tp_iternext
616         Euler_methods,                                  //tp_methods
617         0,                                                              //tp_members
618         Euler_getseters,                                //tp_getset
619         0,                                                              //tp_base
620         0,                                                              //tp_dict
621         0,                                                              //tp_descr_get
622         0,                                                              //tp_descr_set
623         0,                                                              //tp_dictoffset
624         0,                                                              //tp_init
625         0,                                                              //tp_alloc
626         Euler_new,                                              //tp_new
627         0,                                                              //tp_free
628         0,                                                              //tp_is_gc
629         0,                                                              //tp_bases
630         0,                                                              //tp_mro
631         0,                                                              //tp_cache
632         0,                                                              //tp_subclasses
633         0,                                                              //tp_weaklist
634         0                                                               //tp_del
635 };
636 //------------------------newEulerObject (internal)-------------
637 //creates a new euler object
638 /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
639  (i.e. it was allocated elsewhere by MEM_mallocN())
640   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
641  (i.e. it must be created here with PyMEM_malloc())*/
642 PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
643 {
644         EulerObject *self;
645
646         if(base_type)   self = (EulerObject *)base_type->tp_alloc(base_type, 0);
647         else                    self = PyObject_NEW(EulerObject, &euler_Type);
648
649         /* init callbacks as NULL */
650         self->cb_user= NULL;
651         self->cb_type= self->cb_subtype= 0;
652
653         if(type == Py_WRAP) {
654                 self->eul = eul;
655                 self->wrapped = Py_WRAP;
656         }
657         else if (type == Py_NEW){
658                 self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
659                 if(eul)
660                         copy_v3_v3(self->eul, eul);
661                 else
662                         zero_v3(self->eul);
663
664                 self->wrapped = Py_NEW;
665         }
666         else{
667                 return NULL;
668         }
669
670         self->order= order;
671         return (PyObject *)self;
672 }
673
674 PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
675 {
676         EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
677         if(self) {
678                 Py_INCREF(cb_user);
679                 self->cb_user=                  cb_user;
680                 self->cb_type=                  (unsigned char)cb_type;
681                 self->cb_subtype=               (unsigned char)cb_subtype;
682         }
683
684         return (PyObject *)self;
685 }