| 395 | " :return: A new vector.\n" |
| 396 | " :rtype: :class:`Vector`\n"); |
| 397 | static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) |
| 398 | { |
| 399 | float *vec; |
| 400 | float *iter_vec = nullptr; |
| 401 | int i, vec_num, value_num; |
| 402 | PyObject *value; |
| 403 | |
| 404 | if (!PyArg_ParseTuple(args, "Oi:Vector.Repeat", &value, &vec_num)) { |
| 405 | return nullptr; |
| 406 | } |
| 407 | |
| 408 | if (vec_num < 2) { |
| 409 | PyErr_SetString(PyExc_RuntimeError, "Vector.Repeat(): invalid vec_num"); |
| 410 | return nullptr; |
| 411 | } |
| 412 | |
| 413 | if ((value_num = mathutils_array_parse_alloc( |
| 414 | &iter_vec, 2, value, "Vector.Repeat(vector, vec_num), invalid 'vector' arg")) == -1) |
| 415 | { |
| 416 | return nullptr; |
| 417 | } |
| 418 | |
| 419 | if (iter_vec == nullptr) { |
| 420 | PyErr_SetString(PyExc_MemoryError, |
| 421 | "Vector.Repeat(): " |
| 422 | "problem allocating pointer space"); |
| 423 | return nullptr; |
| 424 | } |
| 425 | |
| 426 | vec = static_cast<float *>(PyMem_Malloc(vec_num * sizeof(float))); |
| 427 | |
| 428 | if (vec == nullptr) { |
| 429 | PyMem_Free(iter_vec); |
| 430 | PyErr_SetString(PyExc_MemoryError, |
| 431 | "Vector.Repeat(): " |
| 432 | "problem allocating pointer space"); |
| 433 | return nullptr; |
| 434 | } |
| 435 | |
| 436 | i = 0; |
| 437 | while (i < vec_num) { |
| 438 | vec[i] = iter_vec[i % value_num]; |
| 439 | i++; |
| 440 | } |
| 441 | |
| 442 | PyMem_Free(iter_vec); |
| 443 | |
| 444 | return Vector_CreatePyObject_alloc(vec, vec_num, reinterpret_cast<PyTypeObject *>(cls)); |
| 445 | } |
| 446 | |
| 447 | /** \} */ |
| 448 |
nothing calls this directly
no test coverage detected