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