MCPcopy Create free account
hub / github.com/UPBGE/upbge / Vector_CreatePyObject

Function Vector_CreatePyObject

source/blender/python/mathutils/mathutils_Vector.c:3124–3167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3122};
3123
3124PyObject *Vector_CreatePyObject(const float *vec, const int size, PyTypeObject *base_type)
3125{
3126 VectorObject *self;
3127 float *vec_alloc;
3128
3129 if (size < 2) {
3130 PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size");
3131 return NULL;
3132 }
3133
3134 vec_alloc = PyMem_Malloc(size * sizeof(float));
3135 if (UNLIKELY(vec_alloc == NULL)) {
3136 PyErr_SetString(PyExc_MemoryError,
3137 "Vector(): "
3138 "problem allocating data");
3139 return NULL;
3140 }
3141
3142 self = BASE_MATH_NEW(VectorObject, vector_Type, base_type);
3143 if (self) {
3144 self->vec = vec_alloc;
3145 self->size = size;
3146
3147 /* init callbacks as NULL */
3148 self->cb_user = NULL;
3149 self->cb_type = self->cb_subtype = 0;
3150
3151 if (vec) {
3152 memcpy(self->vec, vec, size * sizeof(float));
3153 }
3154 else { /* new empty */
3155 copy_vn_fl(self->vec, size, 0.0f);
3156 if (size == 4) { /* do the homogeneous thing */
3157 self->vec[3] = 1.0f;
3158 }
3159 }
3160 self->flag = BASE_MATH_FLAG_DEFAULT;
3161 }
3162 else {
3163 PyMem_Free(vec_alloc);
3164 }
3165
3166 return (PyObject *)self;
3167}
3168
3169/**
3170 * Create a vector that wraps existing memory.

Callers 15

Quaternion_to_axis_angleFunction · 0.85
Quaternion_matmulFunction · 0.85
Matrix_to_translationFunction · 0.85
Matrix_to_scaleFunction · 0.85
Matrix_decomposeFunction · 0.85
Matrix_matmulFunction · 0.85
M_Noise_noise_vectorFunction · 0.85

Calls 1

copy_vn_flFunction · 0.85

Tested by

no test coverage detected