formatting edits in py api, no functional changes
[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, other_rmat, self_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,
268                                   "euler.make_compatible(other), invalid 'other' arg") == -1)
269         {
270                 return NULL;
271         }
272
273         compatible_eul(self->eul, teul);
274
275         (void)BaseMath_WriteCallback(self);
276
277         Py_RETURN_NONE;
278 }
279
280 //----------------------------Euler.rotate()-----------------------
281 // return a copy of the euler
282
283 PyDoc_STRVAR(Euler_copy_doc,
284 ".. function:: copy()\n"
285 "\n"
286 "   Returns a copy of this euler.\n"
287 "\n"
288 "   :return: A copy of the euler.\n"
289 "   :rtype: :class:`Euler`\n"
290 "\n"
291 "   .. note:: use this to get a copy of a wrapped euler with\n"
292 "      no reference to the original data.\n"
293 );
294 static PyObject *Euler_copy(EulerObject *self)
295 {
296         if (BaseMath_ReadCallback(self) == -1)
297                 return NULL;
298
299         return Euler_CreatePyObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
300 }
301
302 //----------------------------print object (internal)--------------
303 //print the object to screen
304
305 static PyObject *Euler_repr(EulerObject * self)
306 {
307         PyObject *ret, *tuple;
308
309         if (BaseMath_ReadCallback(self) == -1)
310                 return NULL;
311
312         tuple= Euler_ToTupleExt(self, -1);
313
314         ret= PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self));
315
316         Py_DECREF(tuple);
317         return ret;
318 }
319
320 static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
321 {
322         PyObject *res;
323         int ok= -1; /* zero is true */
324
325         if (EulerObject_Check(a) && EulerObject_Check(b)) {
326                 EulerObject *eulA= (EulerObject*)a;
327                 EulerObject *eulB= (EulerObject*)b;
328
329                 if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
330                         return NULL;
331
332                 ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
333         }
334
335         switch (op) {
336         case Py_NE:
337                 ok = !ok; /* pass through */
338         case Py_EQ:
339                 res = ok ? Py_False : Py_True;
340                 break;
341
342         case Py_LT:
343         case Py_LE:
344         case Py_GT:
345         case Py_GE:
346                 res = Py_NotImplemented;
347                 break;
348         default:
349                 PyErr_BadArgument();
350                 return NULL;
351         }
352
353         return Py_INCREF(res), res;
354 }
355
356 //---------------------SEQUENCE PROTOCOLS------------------------
357 //----------------------------len(object)------------------------
358 //sequence length
359 static int Euler_len(EulerObject *UNUSED(self))
360 {
361         return EULER_SIZE;
362 }
363 //----------------------------object[]---------------------------
364 //sequence accessor (get)
365 static PyObject *Euler_item(EulerObject * self, int i)
366 {
367         if (i<0) i= EULER_SIZE-i;
368
369         if (i < 0 || i >= EULER_SIZE) {
370                 PyErr_SetString(PyExc_IndexError,
371                                 "euler[attribute]: "
372                                 "array index out of range");
373                 return NULL;
374         }
375
376         if (BaseMath_ReadIndexCallback(self, i) == -1)
377                 return NULL;
378
379         return PyFloat_FromDouble(self->eul[i]);
380
381 }
382 //----------------------------object[]-------------------------
383 //sequence accessor (set)
384 static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
385 {
386         float f = PyFloat_AsDouble(value);
387
388         if (f == -1 && PyErr_Occurred()) { // parsed item not a number
389                 PyErr_SetString(PyExc_TypeError,
390                                 "euler[attribute] = x: "
391                                 "argument not a number");
392                 return -1;
393         }
394
395         if (i<0) i= EULER_SIZE-i;
396
397         if (i < 0 || i >= EULER_SIZE) {
398                 PyErr_SetString(PyExc_IndexError,
399                                 "euler[attribute] = x: "
400                                 "array assignment index out of range");
401                 return -1;
402         }
403
404         self->eul[i] = f;
405
406         if (BaseMath_WriteIndexCallback(self, i) == -1)
407                 return -1;
408
409         return 0;
410 }
411 //----------------------------object[z:y]------------------------
412 //sequence slice (get)
413 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
414 {
415         PyObject *tuple;
416         int count;
417
418         if (BaseMath_ReadCallback(self) == -1)
419                 return NULL;
420
421         CLAMP(begin, 0, EULER_SIZE);
422         if (end<0) end= (EULER_SIZE + 1) + end;
423         CLAMP(end, 0, EULER_SIZE);
424         begin= MIN2(begin, end);
425
426         tuple= PyTuple_New(end - begin);
427         for (count = begin; count < end; count++) {
428                 PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
429         }
430
431         return tuple;
432 }
433 //----------------------------object[z:y]------------------------
434 //sequence slice (set)
435 static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
436 {
437         int i, size;
438         float eul[EULER_SIZE];
439
440         if (BaseMath_ReadCallback(self) == -1)
441                 return -1;
442
443         CLAMP(begin, 0, EULER_SIZE);
444         if (end<0) end= (EULER_SIZE + 1) + end;
445         CLAMP(end, 0, EULER_SIZE);
446         begin = MIN2(begin, end);
447
448         if ((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
449                 return -1;
450
451         if (size != (end - begin)) {
452                 PyErr_SetString(PyExc_ValueError,
453                                 "euler[begin:end] = []: "
454                                 "size mismatch in slice assignment");
455                 return -1;
456         }
457
458         for (i= 0; i < EULER_SIZE; i++)
459                 self->eul[begin + i] = eul[i];
460
461         (void)BaseMath_WriteCallback(self);
462         return 0;
463 }
464
465 static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
466 {
467         if (PyIndex_Check(item)) {
468                 Py_ssize_t i;
469                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
470                 if (i == -1 && PyErr_Occurred())
471                         return NULL;
472                 if (i < 0)
473                         i += EULER_SIZE;
474                 return Euler_item(self, i);
475         }
476         else if (PySlice_Check(item)) {
477                 Py_ssize_t start, stop, step, slicelength;
478
479                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
480                         return NULL;
481
482                 if (slicelength <= 0) {
483                         return PyTuple_New(0);
484                 }
485                 else if (step == 1) {
486                         return Euler_slice(self, start, stop);
487                 }
488                 else {
489                         PyErr_SetString(PyExc_IndexError,
490                                         "slice steps not supported with eulers");
491                         return NULL;
492                 }
493         }
494         else {
495                 PyErr_Format(PyExc_TypeError,
496                              "euler indices must be integers, not %.200s",
497                              Py_TYPE(item)->tp_name);
498                 return NULL;
499         }
500 }
501
502
503 static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
504 {
505         if (PyIndex_Check(item)) {
506                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
507                 if (i == -1 && PyErr_Occurred())
508                         return -1;
509                 if (i < 0)
510                         i += EULER_SIZE;
511                 return Euler_ass_item(self, i, value);
512         }
513         else if (PySlice_Check(item)) {
514                 Py_ssize_t start, stop, step, slicelength;
515
516                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
517                         return -1;
518
519                 if (step == 1)
520                         return Euler_ass_slice(self, start, stop, value);
521                 else {
522                         PyErr_SetString(PyExc_IndexError,
523                                         "slice steps not supported with euler");
524                         return -1;
525                 }
526         }
527         else {
528                 PyErr_Format(PyExc_TypeError,
529                              "euler indices must be integers, not %.200s",
530                              Py_TYPE(item)->tp_name);
531                 return -1;
532         }
533 }
534
535 //-----------------PROTCOL DECLARATIONS--------------------------
536 static PySequenceMethods Euler_SeqMethods = {
537         (lenfunc) Euler_len,                                    /* sq_length */
538         (binaryfunc) NULL,                                              /* sq_concat */
539         (ssizeargfunc) NULL,                                    /* sq_repeat */
540         (ssizeargfunc) Euler_item,                              /* sq_item */
541         (ssizessizeargfunc) NULL,                               /* sq_slice, deprecated  */
542         (ssizeobjargproc) Euler_ass_item,               /* sq_ass_item */
543         (ssizessizeobjargproc) NULL,                    /* sq_ass_slice, deprecated */
544         (objobjproc) NULL,                                              /* sq_contains */
545         (binaryfunc) NULL,                                              /* sq_inplace_concat */
546         (ssizeargfunc) NULL,                                    /* sq_inplace_repeat */
547 };
548
549 static PyMappingMethods Euler_AsMapping = {
550         (lenfunc)Euler_len,
551         (binaryfunc)Euler_subscript,
552         (objobjargproc)Euler_ass_subscript
553 };
554
555 /*
556  * euler axis, euler.x/y/z
557  */
558 static PyObject *Euler_getAxis(EulerObject *self, void *type)
559 {
560         return Euler_item(self, GET_INT_FROM_POINTER(type));
561 }
562
563 static int Euler_setAxis(EulerObject *self, PyObject *value, void *type)
564 {
565         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
566 }
567
568 /* rotation order */
569 static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
570 {
571         if (BaseMath_ReadCallback(self) == -1) /* can read order too */
572                 return NULL;
573
574         return PyUnicode_FromString(euler_order_str(self));
575 }
576
577 static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
578 {
579         const char *order_str= _PyUnicode_AsString(value);
580         short order= euler_order_from_string(order_str, "euler.order");
581
582         if (order == -1)
583                 return -1;
584
585         self->order= order;
586         (void)BaseMath_WriteCallback(self); /* order can be written back */
587         return 0;
588 }
589
590 /*****************************************************************************/
591 /* Python attributes get/set structure:                                      */
592 /*****************************************************************************/
593 static PyGetSetDef Euler_getseters[] = {
594         {(char *)"x", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler X axis in radians.\n\n:type: float", (void *)0},
595         {(char *)"y", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Y axis in radians.\n\n:type: float", (void *)1},
596         {(char *)"z", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Z axis in radians.\n\n:type: float", (void *)2},
597         {(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},
598
599         {(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL},
600         {(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL},
601         {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
602 };
603
604
605 //-----------------------METHOD DEFINITIONS ----------------------
606 static struct PyMethodDef Euler_methods[] = {
607         {"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc},
608         {"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc},
609         {"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
610         {"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
611         {"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc},
612         {"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
613         {"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
614         {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
615         {NULL, NULL, 0, NULL}
616 };
617
618 //------------------PY_OBECT DEFINITION--------------------------
619 PyDoc_STRVAR(euler_doc,
620 "This object gives access to Eulers in Blender."
621 );
622 PyTypeObject euler_Type = {
623         PyVarObject_HEAD_INIT(NULL, 0)
624         "mathutils.Euler",                              //tp_name
625         sizeof(EulerObject),                    //tp_basicsize
626         0,                                                              //tp_itemsize
627         (destructor)BaseMathObject_dealloc,             //tp_dealloc
628         NULL,                                                   //tp_print
629         NULL,                                                   //tp_getattr
630         NULL,                                                   //tp_setattr
631         NULL,                                                   //tp_compare
632         (reprfunc) Euler_repr,                  //tp_repr
633         NULL,                                                   //tp_as_number
634         &Euler_SeqMethods,                              //tp_as_sequence
635         &Euler_AsMapping,                               //tp_as_mapping
636         NULL,                                                   //tp_hash
637         NULL,                                                   //tp_call
638         NULL,                                                   //tp_str
639         NULL,                                                   //tp_getattro
640         NULL,                                                   //tp_setattro
641         NULL,                                                   //tp_as_buffer
642         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, //tp_flags
643         euler_doc, //tp_doc
644         (traverseproc)BaseMathObject_traverse,  //tp_traverse
645         (inquiry)BaseMathObject_clear,  //tp_clear
646         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
647         0,                                                              //tp_weaklistoffset
648         NULL,                                                   //tp_iter
649         NULL,                                                   //tp_iternext
650         Euler_methods,                                  //tp_methods
651         NULL,                                                   //tp_members
652         Euler_getseters,                                //tp_getset
653         NULL,                                                   //tp_base
654         NULL,                                                   //tp_dict
655         NULL,                                                   //tp_descr_get
656         NULL,                                                   //tp_descr_set
657         0,                                                              //tp_dictoffset
658         NULL,                                                   //tp_init
659         NULL,                                                   //tp_alloc
660         Euler_new,                                              //tp_new
661         NULL,                                                   //tp_free
662         NULL,                                                   //tp_is_gc
663         NULL,                                                   //tp_bases
664         NULL,                                                   //tp_mro
665         NULL,                                                   //tp_cache
666         NULL,                                                   //tp_subclasses
667         NULL,                                                   //tp_weaklist
668         NULL                                                    //tp_del
669 };
670 //------------------------Euler_CreatePyObject (internal)-------------
671 //creates a new euler object
672 /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
673  (i.e. it was allocated elsewhere by MEM_mallocN())
674   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
675  (i.e. it must be created here with PyMEM_malloc())*/
676 PyObject *Euler_CreatePyObject(float *eul, short order, int type, PyTypeObject *base_type)
677 {
678         EulerObject *self;
679
680         self= base_type ?       (EulerObject *)base_type->tp_alloc(base_type, 0) :
681                                                 (EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
682
683         if (self) {
684                 /* init callbacks as NULL */
685                 self->cb_user= NULL;
686                 self->cb_type= self->cb_subtype= 0;
687
688                 if (type == Py_WRAP) {
689                         self->eul = eul;
690                         self->wrapped = Py_WRAP;
691                 }
692                 else if (type == Py_NEW) {
693                         self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
694                         if (eul) {
695                                 copy_v3_v3(self->eul, eul);
696                         }
697                         else {
698                                 zero_v3(self->eul);
699                         }
700
701                         self->wrapped = Py_NEW;
702                 }
703                 else {
704                         Py_FatalError("Euler(): invalid type!");
705                 }
706
707                 self->order= order;
708         }
709
710         return (PyObject *)self;
711 }
712
713 PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
714 {
715         EulerObject *self= (EulerObject *)Euler_CreatePyObject(NULL, order, Py_NEW, NULL);
716         if (self) {
717                 Py_INCREF(cb_user);
718                 self->cb_user=                  cb_user;
719                 self->cb_type=                  (unsigned char)cb_type;
720                 self->cb_subtype=               (unsigned char)cb_subtype;
721                 PyObject_GC_Track(self);
722         }
723
724         return (PyObject *)self;
725 }