~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/point.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * $Id: point.c 14444 2008-04-16 22:40:48Z hos $
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., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
19
 
 *
20
 
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
 
 * All rights reserved.
22
 
 *
23
 
 * This is a new part of Blender.
24
 
 *
25
 
 * Contributor(s): Joseph Gilbert
26
 
 *
27
 
 * ***** END GPL LICENSE BLOCK *****
28
 
*/
29
 
#include "Mathutils.h"
30
 
 
31
 
#include "BLI_blenlib.h"
32
 
#include "BKE_utildefines.h"
33
 
#include "gen_utils.h"
34
 
 
35
 
//-------------------------DOC STRINGS ---------------------------
36
 
char Point_Zero_doc[] = "() - set all values in the point to 0";
37
 
char Point_toVector_doc[] = "() - create a vector representation of this point";
38
 
//-----------------------METHOD DEFINITIONS ----------------------
39
 
struct PyMethodDef Point_methods[] = {
40
 
        {"zero", (PyCFunction) Point_Zero, METH_NOARGS, Point_Zero_doc},
41
 
        {"toVector", (PyCFunction) Point_toVector, METH_NOARGS, Point_toVector_doc},
42
 
        {NULL, NULL, 0, NULL}
43
 
};
44
 
//-----------------------------METHODS----------------------------
45
 
//--------------------------Vector.toPoint()----------------------
46
 
//create a new point object to represent this vector
47
 
PyObject *Point_toVector(PointObject * self)
48
 
{
49
 
        float vec[3];
50
 
        int x;
51
 
 
52
 
        for(x = 0; x < self->size; x++){
53
 
                vec[x] = self->coord[x];
54
 
        }
55
 
        
56
 
        return newVectorObject(vec, self->size, Py_NEW);
57
 
}
58
 
//----------------------------Point.zero() ----------------------
59
 
//set the point data to 0,0,0
60
 
PyObject *Point_Zero(PointObject * self)
61
 
{
62
 
        int x;
63
 
        for(x = 0; x < self->size; x++) {
64
 
                self->coord[x] = 0.0f;
65
 
        }
66
 
        return EXPP_incr_ret((PyObject*)self);
67
 
}
68
 
//----------------------------dealloc()(internal) ----------------
69
 
//free the py_object
70
 
static void Point_dealloc(PointObject * self)
71
 
{
72
 
        Py_XDECREF(self->coerced_object);
73
 
        //only free py_data
74
 
        if(self->data.py_data){
75
 
                PyMem_Free(self->data.py_data);
76
 
        }
77
 
        PyObject_DEL(self);
78
 
}
79
 
//----------------------------getattr()(internal) ----------------
80
 
//object.attribute access (get)
81
 
static PyObject *Point_getattr(PointObject * self, char *name)
82
 
{
83
 
        if(STREQ(name,"x")){
84
 
                return PyFloat_FromDouble(self->coord[0]);
85
 
        }else if(STREQ(name, "y")){
86
 
                return PyFloat_FromDouble(self->coord[1]);
87
 
        }else if(STREQ(name, "z")){
88
 
                if(self->size > 2){
89
 
                        return PyFloat_FromDouble(self->coord[2]);
90
 
                }else{
91
 
                        return EXPP_ReturnPyObjError(PyExc_AttributeError,
92
 
                                "point.z: illegal attribute access\n");
93
 
                }
94
 
        }
95
 
        if(STREQ(name, "wrapped")){
96
 
                if(self->wrapped == Py_WRAP)
97
 
                        return EXPP_incr_ret((PyObject *)Py_True);
98
 
                else 
99
 
                        return EXPP_incr_ret((PyObject *)Py_False);
100
 
        }
101
 
        return Py_FindMethod(Point_methods, (PyObject *) self, name);
102
 
}
103
 
//----------------------------setattr()(internal) ----------------
104
 
//object.attribute access (set)
105
 
static int Point_setattr(PointObject * self, char *name, PyObject * v)
106
 
{
107
 
        PyObject *f = NULL;
108
 
 
109
 
        f = PyNumber_Float(v);
110
 
        if(f == NULL) { // parsed item not a number
111
 
                return EXPP_ReturnIntError(PyExc_TypeError, 
112
 
                        "point.attribute = x: argument not a number\n");
113
 
        }
114
 
 
115
 
        if(STREQ(name,"x")){
116
 
                self->coord[0] = (float)PyFloat_AS_DOUBLE(f);
117
 
        }else if(STREQ(name, "y")){
118
 
                self->coord[1] = (float)PyFloat_AS_DOUBLE(f);
119
 
        }else if(STREQ(name, "z")){
120
 
                if(self->size > 2){
121
 
                        self->coord[2] = (float)PyFloat_AS_DOUBLE(f);
122
 
                }else{
123
 
                        Py_DECREF(f);
124
 
                        return EXPP_ReturnIntError(PyExc_AttributeError,
125
 
                                "point.z = x: illegal attribute access\n");
126
 
                }
127
 
        }else{
128
 
                Py_DECREF(f);
129
 
                return EXPP_ReturnIntError(PyExc_AttributeError,
130
 
                                "point.attribute = x: unknown attribute\n");
131
 
        }
132
 
 
133
 
        Py_DECREF(f);
134
 
        return 0;
135
 
}
136
 
//----------------------------print object (internal)-------------
137
 
//print the object to screen
138
 
static PyObject *Point_repr(PointObject * self)
139
 
{
140
 
        int i;
141
 
        char buffer[48], str[1024];
142
 
 
143
 
        BLI_strncpy(str,"[",1024);
144
 
        for(i = 0; i < self->size; i++){
145
 
                if(i < (self->size - 1)){
146
 
                        sprintf(buffer, "%.6f, ", self->coord[i]);
147
 
                        strcat(str,buffer);
148
 
                }else{
149
 
                        sprintf(buffer, "%.6f", self->coord[i]);
150
 
                        strcat(str,buffer);
151
 
                }
152
 
        }
153
 
        strcat(str, "](point)");
154
 
 
155
 
        return PyString_FromString(str);
156
 
}
157
 
//---------------------SEQUENCE PROTOCOLS------------------------
158
 
//----------------------------len(object)------------------------
159
 
//sequence length
160
 
static int Point_len(PointObject * self)
161
 
{
162
 
        return self->size;
163
 
}
164
 
//----------------------------object[]---------------------------
165
 
//sequence accessor (get)
166
 
static PyObject *Point_item(PointObject * self, int i)
167
 
{
168
 
        if(i < 0 || i >= self->size)
169
 
                return EXPP_ReturnPyObjError(PyExc_IndexError,
170
 
                "point[attribute]: array index out of range\n");
171
 
 
172
 
        return PyFloat_FromDouble( (double)self->coord[i] );
173
 
 
174
 
}
175
 
//----------------------------object[]-------------------------
176
 
//sequence accessor (set)
177
 
static int Point_ass_item(PointObject * self, int i, PyObject * ob)
178
 
{
179
 
        PyObject *f = NULL;
180
 
 
181
 
        f = PyNumber_Float(ob);
182
 
        if(f == NULL) { // parsed item not a number
183
 
                return EXPP_ReturnIntError(PyExc_TypeError, 
184
 
                        "point[attribute] = x: argument not a number\n");
185
 
        }
186
 
 
187
 
        if(i < 0 || i >= self->size){
188
 
                Py_DECREF(f);
189
 
                return EXPP_ReturnIntError(PyExc_IndexError,
190
 
                        "point[attribute] = x: array assignment index out of range\n");
191
 
        }
192
 
        self->coord[i] = (float)PyFloat_AS_DOUBLE(f);
193
 
        Py_DECREF(f);
194
 
        return 0;
195
 
}
196
 
//----------------------------object[z:y]------------------------
197
 
//sequence slice (get)
198
 
static PyObject *Point_slice(PointObject * self, int begin, int end)
199
 
{
200
 
        PyObject *list = NULL;
201
 
        int count;
202
 
 
203
 
        CLAMP(begin, 0, self->size);
204
 
        CLAMP(end, 0, self->size);
205
 
        begin = MIN2(begin,end);
206
 
 
207
 
        list = PyList_New(end - begin);
208
 
        for(count = begin; count < end; count++) {
209
 
                PyList_SetItem(list, count - begin,
210
 
                                PyFloat_FromDouble(self->coord[count]));
211
 
        }
212
 
 
213
 
        return list;
214
 
}
215
 
//----------------------------object[z:y]------------------------
216
 
//sequence slice (set)
217
 
static int Point_ass_slice(PointObject * self, int begin, int end,
218
 
                             PyObject * seq)
219
 
{
220
 
        int i, y, size = 0;
221
 
        float coord[3];
222
 
        PyObject *v, *f;
223
 
 
224
 
        CLAMP(begin, 0, self->size);
225
 
        CLAMP(end, 0, self->size);
226
 
        begin = MIN2(begin,end);
227
 
 
228
 
        size = PySequence_Length(seq);
229
 
        if(size != (end - begin)){
230
 
                return EXPP_ReturnIntError(PyExc_TypeError,
231
 
                        "point[begin:end] = []: size mismatch in slice assignment\n");
232
 
        }
233
 
 
234
 
        for (i = 0; i < size; i++) {
235
 
                v = PySequence_GetItem(seq, i);
236
 
                if (v == NULL) { // Failed to read sequence
237
 
                        return EXPP_ReturnIntError(PyExc_RuntimeError, 
238
 
                                "point[begin:end] = []: unable to read sequence\n");
239
 
                }
240
 
                f = PyNumber_Float(v);
241
 
                if(f == NULL) { // parsed item not a number
242
 
                        Py_DECREF(v);
243
 
                        return EXPP_ReturnIntError(PyExc_TypeError, 
244
 
                                "point[begin:end] = []: sequence argument not a number\n");
245
 
                }
246
 
 
247
 
                coord[i] = (float)PyFloat_AS_DOUBLE(f);
248
 
                EXPP_decr2(f,v);
249
 
        }
250
 
        //parsed well - now set in point
251
 
        for(y = 0; y < size; y++){
252
 
                self->coord[begin + y] = coord[y];
253
 
        }
254
 
        return 0;
255
 
}
256
 
//------------------------NUMERIC PROTOCOLS----------------------
257
 
//------------------------obj + obj------------------------------
258
 
//addition
259
 
static PyObject *Point_add(PyObject * v1, PyObject * v2)
260
 
{
261
 
        int x, size;
262
 
        float coord[3];
263
 
        PointObject *coord1 = NULL, *coord2 = NULL;
264
 
        VectorObject *vec = NULL;
265
 
 
266
 
        coord1 = (PointObject*)v1;
267
 
        coord2 = (PointObject*)v2;
268
 
 
269
 
        if(!coord1->coerced_object){
270
 
                if(coord2->coerced_object){
271
 
                        if(VectorObject_Check(coord2->coerced_object)){  //POINT + VECTOR
272
 
                                //Point translation
273
 
                                vec = (VectorObject*)coord2->coerced_object;
274
 
                                size = coord1->size;
275
 
                                if(vec->size == size){
276
 
                                        for(x = 0; x < size; x++){
277
 
                                                coord[x] = coord1->coord[x] + vec->vec[x];
278
 
                                        }       
279
 
                                }else{
280
 
                                        return EXPP_ReturnPyObjError(PyExc_AttributeError,
281
 
                                                "Point addition: arguments are the wrong size....\n");
282
 
                                }
283
 
                                return newPointObject(coord, size, Py_NEW);
284
 
                        }       
285
 
                }else{  //POINT + POINT
286
 
                        size = coord1->size;
287
 
                        if(coord2->size == size){
288
 
                                for(x = 0; x < size; x++) {
289
 
                                        coord[x] = coord1->coord[x] + coord2->coord[x];
290
 
                                }
291
 
                        }else{
292
 
                                return EXPP_ReturnPyObjError(PyExc_AttributeError,
293
 
                                        "Point addition: arguments are the wrong size....\n");
294
 
                        }
295
 
                        return newPointObject(coord, size, Py_NEW);
296
 
                }
297
 
        }
298
 
 
299
 
        return EXPP_ReturnPyObjError(PyExc_AttributeError,
300
 
                "Point addition: arguments not valid for this operation....\n");
301
 
}
302
 
//------------------------obj - obj------------------------------
303
 
//subtraction
304
 
static PyObject *Point_sub(PyObject * v1, PyObject * v2)
305
 
{
306
 
        int x, size;
307
 
        float coord[3];
308
 
        PointObject *coord1 = NULL, *coord2 = NULL;
309
 
 
310
 
        coord1 = (PointObject*)v1;
311
 
        coord2 = (PointObject*)v2;
312
 
 
313
 
        if(coord1->coerced_object || coord2->coerced_object){
314
 
                return EXPP_ReturnPyObjError(PyExc_AttributeError,
315
 
                        "Point subtraction: arguments not valid for this operation....\n");
316
 
        }
317
 
        if(coord1->size != coord2->size){
318
 
                return EXPP_ReturnPyObjError(PyExc_AttributeError,
319
 
                "Point subtraction: points must have the same dimensions for this operation\n");
320
 
        }
321
 
 
322
 
        size = coord1->size;
323
 
        for(x = 0; x < size; x++) {
324
 
                coord[x] = coord1->coord[x] -   coord2->coord[x];
325
 
        }
326
 
 
327
 
        //Point - Point = Vector
328
 
        return newVectorObject(coord, size, Py_NEW);
329
 
}
330
 
//------------------------obj * obj------------------------------
331
 
//mulplication
332
 
static PyObject *Point_mul(PyObject * p1, PyObject * p2)
333
 
{
334
 
        int x, size;
335
 
        float coord[3], scalar;
336
 
        PointObject *coord1 = NULL, *coord2 = NULL;
337
 
        PyObject *f = NULL;
338
 
        MatrixObject *mat = NULL;
339
 
        QuaternionObject *quat = NULL;
340
 
 
341
 
        coord1 = (PointObject*)p1;
342
 
        coord2 = (PointObject*)p2;
343
 
 
344
 
        if(coord1->coerced_object){
345
 
                if (PyFloat_Check(coord1->coerced_object) || 
346
 
                        PyInt_Check(coord1->coerced_object)){   // FLOAT/INT * POINT
347
 
                        f = PyNumber_Float(coord1->coerced_object);
348
 
                        if(f == NULL) { // parsed item not a number
349
 
                                return EXPP_ReturnPyObjError(PyExc_TypeError, 
350
 
                                        "Point multiplication: arguments not acceptable for this operation\n");
351
 
                        }
352
 
 
353
 
                        scalar = (float)PyFloat_AS_DOUBLE(f);
354
 
                        size = coord2->size;
355
 
                        for(x = 0; x < size; x++) {
356
 
                                coord[x] = coord2->coord[x] *   scalar;
357
 
                        }
358
 
                        Py_DECREF(f);
359
 
                        return newPointObject(coord, size, Py_NEW);
360
 
                }
361
 
        }else{
362
 
                if(coord2->coerced_object){
363
 
                        if (PyFloat_Check(coord2->coerced_object) || 
364
 
                                PyInt_Check(coord2->coerced_object)){   // POINT * FLOAT/INT
365
 
                                f = PyNumber_Float(coord2->coerced_object);
366
 
                                if(f == NULL) { // parsed item not a number
367
 
                                        return EXPP_ReturnPyObjError(PyExc_TypeError, 
368
 
                                                "Point multiplication: arguments not acceptable for this operation\n");
369
 
                                }
370
 
 
371
 
                                scalar = (float)PyFloat_AS_DOUBLE(f);
372
 
                                size = coord1->size;
373
 
                                for(x = 0; x < size; x++) {
374
 
                                        coord[x] = coord1->coord[x] *   scalar;
375
 
                                }
376
 
                                Py_DECREF(f);
377
 
                                return newPointObject(coord, size, Py_NEW);
378
 
                        }else if(MatrixObject_Check(coord2->coerced_object)){ //POINT * MATRIX
379
 
                                mat = (MatrixObject*)coord2->coerced_object;
380
 
                                return row_point_multiplication(coord1, mat);
381
 
                        }else if(QuaternionObject_Check(coord2->coerced_object)){  //POINT * QUATERNION
382
 
                                quat = (QuaternionObject*)coord2->coerced_object;
383
 
                                if(coord1->size != 3){
384
 
                                        return EXPP_ReturnPyObjError(PyExc_TypeError, 
385
 
                                                "Point multiplication: only 3D point rotations (with quats) currently supported\n");
386
 
                                }
387
 
                                return quat_rotation((PyObject*)coord1, (PyObject*)quat);
388
 
                        }
389
 
                }
390
 
        }
391
 
 
392
 
        return EXPP_ReturnPyObjError(PyExc_TypeError, 
393
 
                "Point multiplication: arguments not acceptable for this operation\n");
394
 
}
395
 
//-------------------------- -obj -------------------------------
396
 
//returns the negative of this object
397
 
static PyObject *Point_neg(PointObject *self)
398
 
{
399
 
        int x;
400
 
        float coord[3];
401
 
 
402
 
        for(x = 0; x < self->size; x++)
403
 
                coord[x] = -self->coord[x];
404
 
 
405
 
        return newPointObject(coord, self->size, Py_NEW);
406
 
}
407
 
 
408
 
//------------------------coerce(obj, obj)-----------------------
409
 
//coercion of unknown types to type PointObject for numeric protocols
410
 
/*Coercion() is called whenever a math operation has 2 operands that
411
 
 it doesn't understand how to evaluate. 2+Matrix for example. We want to 
412
 
 evaluate some of these operations like: (vector * 2), however, for math
413
 
 to proceed, the unknown operand must be cast to a type that python math will
414
 
 understand. (e.g. in the case above case, 2 must be cast to a vector and 
415
 
 then call vector.multiply(vector, scalar_cast_as_vector)*/
416
 
static int Point_coerce(PyObject ** p1, PyObject ** p2)
417
 
{
418
 
        if(VectorObject_Check(*p2) || PyFloat_Check(*p2) || PyInt_Check(*p2) ||
419
 
                        MatrixObject_Check(*p2) || QuaternionObject_Check(*p2)) {
420
 
                PyObject *coerced = EXPP_incr_ret(*p2);
421
 
                *p2 = newPointObject(NULL,3,Py_NEW);
422
 
                ((PointObject*)*p2)->coerced_object = coerced;
423
 
                Py_INCREF (*p1);
424
 
                return 0;
425
 
        }
426
 
 
427
 
        return EXPP_ReturnIntError(PyExc_TypeError, 
428
 
                "point.coerce(): unknown operand - can't coerce for numeric protocols");
429
 
}
430
 
//-----------------PROTOCOL DECLARATIONS--------------------------
431
 
static PySequenceMethods Point_SeqMethods = {
432
 
        (inquiry) Point_len,                                            /* sq_length */
433
 
        (binaryfunc) 0,                                                         /* sq_concat */
434
 
        (intargfunc) 0,                                                         /* sq_repeat */
435
 
        (intargfunc) Point_item,                                        /* sq_item */
436
 
        (intintargfunc) Point_slice,                            /* sq_slice */
437
 
        (intobjargproc) Point_ass_item,                         /* sq_ass_item */
438
 
        (intintobjargproc) Point_ass_slice,                     /* sq_ass_slice */
439
 
};
440
 
static PyNumberMethods Point_NumMethods = {
441
 
        (binaryfunc) Point_add,                                         /* __add__ */
442
 
        (binaryfunc) Point_sub,                                         /* __sub__ */
443
 
        (binaryfunc) Point_mul,                                         /* __mul__ */
444
 
        (binaryfunc) 0,                                                         /* __div__ */
445
 
        (binaryfunc) 0,                                                         /* __mod__ */
446
 
        (binaryfunc) 0,                                                         /* __divmod__ */
447
 
        (ternaryfunc) 0,                                                        /* __pow__ */
448
 
        (unaryfunc) Point_neg,                                          /* __neg__ */
449
 
        (unaryfunc) 0,                                                          /* __pos__ */
450
 
        (unaryfunc) 0,                                                          /* __abs__ */
451
 
        (inquiry) 0,                                                            /* __nonzero__ */
452
 
        (unaryfunc) 0,                                                          /* __invert__ */
453
 
        (binaryfunc) 0,                                                         /* __lshift__ */
454
 
        (binaryfunc) 0,                                                         /* __rshift__ */
455
 
        (binaryfunc) 0,                                                         /* __and__ */
456
 
        (binaryfunc) 0,                                                         /* __xor__ */
457
 
        (binaryfunc) 0,                                                         /* __or__ */
458
 
        (coercion)  Point_coerce,                                       /* __coerce__ */
459
 
        (unaryfunc) 0,                                                          /* __int__ */
460
 
        (unaryfunc) 0,                                                          /* __long__ */
461
 
        (unaryfunc) 0,                                                          /* __float__ */
462
 
        (unaryfunc) 0,                                                          /* __oct__ */
463
 
        (unaryfunc) 0,                                                          /* __hex__ */
464
 
 
465
 
};
466
 
//------------------PY_OBECT DEFINITION--------------------------
467
 
PyTypeObject point_Type = {
468
 
        PyObject_HEAD_INIT(NULL) 
469
 
        0,                                                                                      /*ob_size */
470
 
        "point",                                                                        /*tp_name */
471
 
        sizeof(PointObject),                                            /*tp_basicsize */
472
 
        0,                                                                                      /*tp_itemsize */
473
 
        (destructor) Point_dealloc,                                     /*tp_dealloc */
474
 
        (printfunc) 0,                                                          /*tp_print */
475
 
        (getattrfunc) Point_getattr,                            /*tp_getattr */
476
 
        (setattrfunc) Point_setattr,                            /*tp_setattr */
477
 
        0,                                                                                      /*tp_compare */
478
 
        (reprfunc) Point_repr,                                          /*tp_repr */
479
 
        &Point_NumMethods,                                                      /*tp_as_number */
480
 
        &Point_SeqMethods,                                                      /*tp_as_sequence */
481
 
};
482
 
//------------------------newPointObject (internal)-------------
483
 
//creates a new point object
484
 
/*pass Py_WRAP - if point is a WRAPPER for data allocated by BLENDER
485
 
 (i.e. it was allocated elsewhere by MEM_mallocN())
486
 
  pass Py_NEW - if point is not a WRAPPER and managed by PYTHON
487
 
 (i.e. it must be created here with PyMEM_malloc())*/
488
 
PyObject *newPointObject(float *coord, int size, int type)
489
 
{
490
 
        PointObject *self;
491
 
        int x;
492
 
 
493
 
        point_Type.ob_type = &PyType_Type;
494
 
        self = PyObject_NEW(PointObject, &point_Type);
495
 
        self->data.blend_data = NULL;
496
 
        self->data.py_data = NULL;
497
 
        if(size > 3 || size < 2)
498
 
                return NULL;
499
 
        self->size = size;
500
 
        self->coerced_object = NULL;
501
 
 
502
 
        if(type == Py_WRAP){
503
 
                self->data.blend_data = coord;
504
 
                self->coord = self->data.blend_data;
505
 
                self->wrapped = Py_WRAP;
506
 
        }else if (type == Py_NEW){
507
 
                self->data.py_data = PyMem_Malloc(size * sizeof(float));
508
 
                self->coord = self->data.py_data;
509
 
                if(!coord) { //new empty
510
 
                        for(x = 0; x < size; x++){
511
 
                                self->coord[x] = 0.0f;
512
 
                        }
513
 
                }else{
514
 
                        for(x = 0; x < size; x++){
515
 
                                self->coord[x] = coord[x];
516
 
                        }
517
 
                }
518
 
                self->wrapped = Py_NEW;
519
 
        }else{ //bad type
520
 
                return NULL;
521
 
        }
522
 
        return (PyObject *) self;
523
 
}