MCPcopy Create free account
hub / github.com/blender/blender / Vector_vectorcall

Function Vector_vectorcall

source/blender/python/mathutils/mathutils_Vector.cc:143–188  ·  view source on GitHub ↗

* Supports 2D, 3D, and 4D vector objects both int and float values accepted. * Mixed float and integer values accepted. Integers are converted to float. */

Source from the content-addressed store, hash-verified

141 * Mixed float and integer values accepted. Integers are converted to float.
142 */
143static PyObject *Vector_vectorcall(PyObject *type,
144 PyObject *const *args,
145 const size_t nargsf,
146 PyObject *kwnames)
147{
148 if (UNLIKELY(kwnames && PyTuple_GET_SIZE(kwnames))) {
149 PyErr_SetString(PyExc_TypeError,
150 "Vector(): "
151 "takes no keyword args");
152 return nullptr;
153 }
154
155 float *vec = nullptr;
156 int vec_num = 3; /* Default to a 3D vector. */
157
158 const size_t nargs = PyVectorcall_NARGS(nargsf);
159 switch (nargs) {
160 case 0: {
161 vec = static_cast<float *>(PyMem_Malloc(vec_num * sizeof(float)));
162
163 if (vec == nullptr) {
164 PyErr_SetString(PyExc_MemoryError,
165 "Vector(): "
166 "problem allocating pointer space");
167 return nullptr;
168 }
169
170 copy_vn_fl(vec, vec_num, 0.0f);
171 break;
172 }
173 case 1: {
174 if ((vec_num = mathutils_array_parse_alloc(&vec, 2, args[0], "mathutils.Vector()")) == -1) {
175 return nullptr;
176 }
177 break;
178 }
179 default: {
180 PyErr_Format(PyExc_TypeError,
181 "mathutils.Vector(): "
182 "takes at most 1 argument (%zd given)",
183 nargs);
184 return nullptr;
185 }
186 }
187 return Vector_CreatePyObject_alloc(vec, vec_num, reinterpret_cast<PyTypeObject *>(type));
188}
189
190static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
191{

Callers 1

Vector_newFunction · 0.85

Calls 3

copy_vn_flFunction · 0.85

Tested by

no test coverage detected