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