23#ifndef MATH_STANDALONE
34#define MAX_DIMENSIONS 4
41#define SWIZZLE_BITS_PER_AXIS 3
42#define SWIZZLE_VALID_AXIS 0x4
43#define SWIZZLE_AXIS 0x3
66 int row, col,
z = 0, vec_num = vec->
vec_num;
69 if (mat->
row_num == 4 && vec_num == 3) {
73 PyErr_SetString(PyExc_ValueError,
74 "vector * matrix: matrix column size "
75 "and the vector size must be the same");
84 memcpy(vec_cpy, vec->vec, vec_num *
sizeof(
float));
88 for (col = 0; col < mat->
col_num; col++) {
90 for (row = 0; row < mat->
row_num; row++) {
103 Py_DECREF(ret_dummy);
120 for (i = 0; i < self->
vec_num; i++) {
121 PyTuple_SET_ITEM(
ret, i, PyFloat_FromDouble(
double_round(
double(self->vec[i]), ndigits)));
125 for (i = 0; i < self->
vec_num; i++) {
126 PyTuple_SET_ITEM(
ret, i, PyFloat_FromDouble(self->vec[i]));
144 PyObject *
const *args,
148 if (kwnames && PyTuple_GET_SIZE(kwnames)) [[unlikely]] {
149 PyErr_SetString(PyExc_TypeError,
151 "takes no keyword args");
155 float *vec =
nullptr;
158 const size_t nargs = PyVectorcall_NARGS(nargsf);
161 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
163 if (vec ==
nullptr) {
164 PyErr_SetString(PyExc_MemoryError,
166 "problem allocating pointer space");
170 std::fill_n(vec, vec_num, 0.0f);
180 PyErr_Format(PyExc_TypeError,
181 "mathutils.Vector(): "
182 "takes at most 1 argument (%zd given)",
190static PyObject *
Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
192 if (kwds && PyDict_GET_SIZE(kwds)) [[unlikely]] {
193 PyErr_SetString(PyExc_TypeError,
195 "takes no keyword args");
198 PyObject *
const *args_array = &PyTuple_GET_ITEM(args, 0);
199 const size_t args_array_num = PyTuple_GET_SIZE(args);
201 reinterpret_cast<PyObject *
>(type), args_array, args_array_num,
nullptr);
213 ".. classmethod:: Fill(size, fill=0.0, /)\n"
215 " Create a vector of length size with all values set to fill.\n"
217 " :param size: The length of the vector to be created.\n"
219 " :param fill: The value used to fill the vector.\n"
220 " :type fill: float\n"
221 " :return: A new vector.\n"
222 " :rtype: :class:`Vector`\n");
229 if (!PyArg_ParseTuple(args,
241 PyErr_SetString(PyExc_RuntimeError,
"Vector(): invalid size");
245 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
247 if (vec ==
nullptr) {
248 PyErr_SetString(PyExc_MemoryError,
250 "problem allocating pointer space");
254 std::fill_n(vec, vec_num, fill);
262 ".. classmethod:: Range(start, stop, step=1, /)\n"
264 " Create a vector filled with a range of values.\n"
266 " This method can also be called with a single argument, "
267 "in which case the argument is interpreted as ``stop`` and ``start`` defaults to 0.\n"
269 " :param start: The start of the range used to fill the vector.\n"
270 " :type start: int\n"
271 " :param stop: The end of the range used to fill the vector.\n"
273 " :param step: The step between successive values in the vector.\n"
275 " :return: A new vector.\n"
276 " :rtype: :class:`Vector`\n");
284 if (!PyArg_ParseTuple(args,
297 switch (PyTuple_GET_SIZE(args)) {
305 PyErr_SetString(PyExc_RuntimeError,
306 "Start value is larger "
307 "than the stop value");
311 vec_num = stop - start;
316 PyErr_SetString(PyExc_RuntimeError,
317 "Start value is larger "
318 "than the stop value");
322 vec_num = (stop - start);
324 if ((vec_num %
step) != 0) {
335 PyErr_SetString(PyExc_RuntimeError,
"Vector(): invalid size");
339 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
341 if (vec ==
nullptr) {
342 PyErr_SetString(PyExc_MemoryError,
344 "problem allocating pointer space");
355 C_Vector_Linspace_doc,
356 ".. classmethod:: Linspace(start, stop, size, /)\n"
358 " Create a vector of the specified size which is filled with linearly spaced "
359 "values between start and stop values.\n"
361 " :param start: The start of the range used to fill the vector.\n"
362 " :type start: float\n"
363 " :param stop: The end of the range used to fill the vector.\n"
364 " :type stop: float\n"
365 " :param size: The size of the vector to be created.\n"
367 " :return: A new vector.\n"
368 " :rtype: :class:`Vector`\n");
373 float start, end,
step;
375 if (!PyArg_ParseTuple(args,
388 PyErr_SetString(PyExc_RuntimeError,
"Vector.Linspace(): invalid size");
392 step = (end - start) /
float(vec_num - 1);
394 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
396 if (vec ==
nullptr) {
397 PyErr_SetString(PyExc_MemoryError,
398 "Vector.Linspace(): "
399 "problem allocating pointer space");
411 ".. classmethod:: Repeat(vector, size, /)\n"
413 " Create a vector by repeating the values in vector until the required size is reached.\n"
415 " :param vector: The vector to draw values from.\n"
416 " :type vector: :class:`Vector`\n"
417 " :param size: The size of the vector to be created.\n"
419 " :return: A new vector.\n"
420 " :rtype: :class:`Vector`\n");
424 float *iter_vec =
nullptr;
425 int i, vec_num, value_num;
428 if (!PyArg_ParseTuple(args,
439 PyErr_SetString(PyExc_RuntimeError,
"Vector.Repeat(): invalid vec_num");
444 &iter_vec, 2, value,
"Vector.Repeat(vector, vec_num), invalid 'vector' arg")) == -1)
449 if (iter_vec ==
nullptr) {
450 PyErr_SetString(PyExc_MemoryError,
452 "problem allocating pointer space");
456 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
458 if (vec ==
nullptr) {
459 PyMem_Free(iter_vec);
460 PyErr_SetString(PyExc_MemoryError,
462 "problem allocating pointer space");
467 while (i < vec_num) {
468 vec[i] = iter_vec[i % value_num];
472 PyMem_Free(iter_vec);
486 ".. method:: zero()\n"
488 " Set all values to zero.\n");
495 std::fill_n(self->vec, self->
vec_num, 0.0f);
512 Vector_normalize_doc,
513 ".. method:: normalize()\n"
515 " Normalize the vector, making the length of the vector always 1.0.\n"
517 " .. warning:: Normalizing a vector where all values are zero has no effect.\n"
519 " .. note:: For 4D vectors, only the x, y, z components are normalized;\n"
520 " the w component is left untouched.\n"
521 " The resulting 4D vector may not have unit length.\n");
536 Vector_normalized_doc,
537 ".. method:: normalized()\n"
539 " Return a new, normalized vector.\n"
541 " .. note:: For 4D vectors, only the x, y, z components are normalized;\n"
542 " the w component is left untouched.\n"
543 " The resulting 4D vector may not have unit length.\n"
545 " :return: a normalized copy of the vector\n"
546 " :rtype: :class:`Vector`\n");
561 ".. method:: resize(size, /)\n"
563 " Resize the vector to have size number of elements.\n"
565 " :param size: The new size of the vector.\n"
566 " :type size: int\n");
577 if (((vec_num = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
578 PyErr_SetString(PyExc_TypeError,
579 "Vector.resize(size): "
580 "expected size argument to be an integer");
585 PyErr_SetString(PyExc_RuntimeError,
"Vector.resize(): invalid size");
589 self->vec =
static_cast<float *
>(PyMem_Realloc(self->vec, (vec_num *
sizeof(
float))));
590 if (self->vec ==
nullptr) {
591 PyErr_SetString(PyExc_MemoryError,
593 "problem allocating pointer space");
599 std::fill_n(self->vec + self->
vec_num, vec_num - self->
vec_num, 0.0f);
609 ".. method:: resized(size, /)\n"
611 " Return a resized copy of the vector with size number of elements.\n"
613 " :param size: The new size of the vector.\n"
615 " :return: A new vector.\n"
616 " :rtype: :class:`Vector`\n");
622 if (((vec_num = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
627 PyErr_SetString(PyExc_RuntimeError,
"Vector.resized(): invalid size");
635 vec =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
637 if (vec ==
nullptr) {
638 PyErr_SetString(PyExc_MemoryError,
640 "problem allocating pointer space");
644 const int vec_num_copy = std::min(self->
vec_num, vec_num);
645 memcpy(vec, self->vec, vec_num_copy *
sizeof(
float));
646 if (vec_num_copy != vec_num) {
647 std::fill_n(vec + vec_num_copy, vec_num - vec_num_copy, 0.0f);
655 Vector_resize_2d_doc,
656 ".. method:: resize_2d()\n"
658 " Resize the vector to 2D (x, y).\n");
666 self->vec =
static_cast<float *
>(PyMem_Realloc(self->vec,
sizeof(
float[2])));
667 if (self->vec ==
nullptr) {
668 PyErr_SetString(PyExc_MemoryError,
669 "Vector.resize_2d(): "
670 "problem allocating pointer space");
680 Vector_resize_3d_doc,
681 ".. method:: resize_3d()\n"
683 " Resize the vector to 3D (x, y, z).\n");
691 self->vec =
static_cast<float *
>(PyMem_Realloc(self->vec,
sizeof(
float[3])));
692 if (self->vec ==
nullptr) {
693 PyErr_SetString(PyExc_MemoryError,
694 "Vector.resize_3d(): "
695 "problem allocating pointer space");
709 Vector_resize_4d_doc,
710 ".. method:: resize_4d()\n"
712 " Resize the vector to 4D (x, y, z, w).\n");
720 self->vec =
static_cast<float *
>(PyMem_Realloc(self->vec,
sizeof(
float[4])));
721 if (self->vec ==
nullptr) {
722 PyErr_SetString(PyExc_MemoryError,
723 "Vector.resize_4d(): "
724 "problem allocating pointer space");
748 ".. method:: to_2d()\n"
750 " Return a 2d copy of the vector.\n"
752 " :return: a new vector\n"
753 " :rtype: :class:`Vector`\n");
765 ".. method:: to_3d()\n"
767 " Return a 3d copy of the vector.\n"
769 " :return: a new vector\n"
770 " :rtype: :class:`Vector`\n");
773 float tvec[3] = {0.0f};
779 memcpy(tvec, self->vec,
sizeof(
float) * std::min(self->
vec_num, 3));
785 ".. method:: to_4d()\n"
787 " Return a 4d copy of the vector.\n"
789 " :return: a new vector\n"
790 " :rtype: :class:`Vector`\n");
793 float tvec[4] = {0.0f, 0.0f, 0.0f, 1.0f};
799 memcpy(tvec, self->vec,
sizeof(
float) * std::min(self->
vec_num, 4));
812 ".. method:: to_tuple(precision=-1, /)\n"
814 " Return this vector as a tuple with a given precision.\n"
816 " :param precision: The number to round the value to in [-1, 21].\n"
817 " :type precision: int\n"
818 " :return: the values of the vector rounded by *precision*\n"
819 " :rtype: tuple[float, ...]\n");
824 if (!PyArg_ParseTuple(args,
833 if (ndigits > 22 || ndigits < -1) {
834 PyErr_SetString(PyExc_ValueError,
835 "Vector.to_tuple(precision): "
836 "precision must be between -1 and 21");
855 Vector_to_track_quat_doc,
856 ".. method:: to_track_quat(track='Z', up='Y', /)\n"
858 " Return a quaternion rotation from the vector and the track and up axis.\n"
860 " :param track: Track axis string.\n"
861 " :type track: Literal['X', 'Y', 'Z', '-X', '-Y', '-Z']\n"
862 " :param up: Up axis string.\n"
863 " :type up: Literal['X', 'Y', 'Z']\n"
864 " :return: rotation from the vector and the track and up axis.\n"
865 " :rtype: :class:`Quaternion`\n");
868 float vec[3], quat[4];
869 const char *strack =
nullptr;
870 const char *sup =
nullptr;
871 short track = 2, up = 1;
873 if (!PyArg_ParseTuple(args,
885 PyErr_SetString(PyExc_TypeError,
886 "Vector.to_track_quat(): "
887 "only for 3D vectors");
896 const char *axis_err_msg =
"only X, -X, Y, -Y, Z or -Z for track axis";
898 if (strlen(strack) == 2) {
899 if (strack[0] ==
'-') {
914 PyErr_SetString(PyExc_ValueError, axis_err_msg);
920 PyErr_SetString(PyExc_ValueError, axis_err_msg);
924 else if (strlen(strack) == 1) {
940 PyErr_SetString(PyExc_ValueError, axis_err_msg);
946 PyErr_SetString(PyExc_ValueError, axis_err_msg);
952 const char *axis_err_msg =
"only X, Y or Z for up axis";
953 if (strlen(sup) == 1) {
968 PyErr_SetString(PyExc_ValueError, axis_err_msg);
974 PyErr_SetString(PyExc_ValueError, axis_err_msg);
980 PyErr_SetString(PyExc_ValueError,
"Can't have the same axis for track and up");
1001 Vector_orthogonal_doc,
1002 ".. method:: orthogonal()\n"
1004 " Return a perpendicular vector.\n"
1006 " :return: a new vector 90 degrees from this vector.\n"
1007 " :rtype: :class:`Vector`\n"
1009 " .. note:: the axis is undefined, only use when any orthogonal vector is acceptable.\n");
1015 PyErr_SetString(PyExc_TypeError,
1016 "Vector.orthogonal(): "
1017 "Vector must be 3D or 2D");
1047 ".. method:: reflect(mirror, /)\n"
1049 " Return the reflection vector from the *mirror* argument.\n"
1051 " :param mirror: This vector could be a normal from the reflecting surface.\n"
1052 " :type mirror: :class:`Vector`\n"
1053 " :return: The reflected vector matching the size of this vector.\n"
1054 " :rtype: :class:`Vector`\n");
1058 float mirror[3], vec[3];
1067 tvec, 2, 4, value,
"Vector.reflect(other), invalid 'other' arg")) == -1)
1073 PyErr_SetString(PyExc_ValueError,
"Vector must be 2D, 3D or 4D");
1077 mirror[0] = tvec[0];
1078 mirror[1] = tvec[1];
1079 mirror[2] = (value_num > 2) ? tvec[2] : 0.0f;
1081 vec[0] = self->vec[0];
1082 vec[1] = self->vec[1];
1083 vec[2] = (value_num > 2) ? self->vec[2] : 0.0f;
1100 ".. method:: cross(other, /)\n"
1102 " Return the cross product of this vector and another.\n"
1104 " :param other: The other vector to perform the cross product with.\n"
1105 " :type other: :class:`Vector`\n"
1106 " :return: The cross product as a vector or a float when 2D vectors are used.\n"
1107 " :rtype: :class:`Vector` | float\n"
1109 " .. note:: both vectors must be 2D or 3D\n");
1120 PyErr_SetString(PyExc_ValueError,
"Vector must be 2D or 3D");
1125 tvec, self->
vec_num, self->
vec_num, value,
"Vector.cross(other), invalid 'other' arg") ==
1151 ".. method:: dot(other, /)\n"
1153 " Return the dot product of this vector and another.\n"
1155 " :param other: The other vector to perform the dot product with.\n"
1156 " :type other: :class:`Vector`\n"
1157 " :return: The dot product.\n"
1158 " :rtype: float\n");
1169 &tvec, self->
vec_num, value,
"Vector.dot(other), invalid 'other' arg") == -1)
1188 ".. method:: angle(other, fallback=None, /)\n"
1190 " Return the angle between two vectors.\n"
1192 " .. note:: For 4D vectors, only the x, y, z components are used.\n"
1194 " :param other: another vector to compare the angle with\n"
1195 " :type other: :class:`Vector`\n"
1196 " :param fallback: return this when the angle can't be calculated (zero length vector),\n"
1197 " (instead of raising a :exc:`ValueError`).\n"
1198 " :type fallback: Any\n"
1199 " :return: angle in radians or fallback when given\n"
1200 " :rtype: float | Any\n");
1203 const int vec_num = std::min(self->
vec_num, 3);
1206 double dot = 0.0f, dot_self = 0.0f, dot_other = 0.0f;
1208 PyObject *fallback =
nullptr;
1210 if (!PyArg_ParseTuple(args,
1226 PyErr_SetString(PyExc_ValueError,
"Vector must be 2D, 3D or 4D");
1233 tvec, self->
vec_num, self->
vec_num, value,
"Vector.angle(other), invalid 'other' arg") ==
1239 for (
x = 0;
x < vec_num;
x++) {
1240 dot_self += double(self->vec[
x]) * double(self->vec[
x]);
1241 dot_other += double(tvec[
x]) * double(tvec[
x]);
1242 dot += double(self->vec[
x]) * double(tvec[
x]);
1245 if (!dot_self || !dot_other) {
1248 Py_INCREF(fallback);
1252 PyErr_SetString(PyExc_ValueError,
1253 "Vector.angle(other): "
1254 "zero length vectors have no valid angle");
1269 Vector_angle_signed_doc,
1270 ".. method:: angle_signed(other, fallback=None, /)\n"
1272 " Return the signed angle between two 2D vectors (clockwise is positive).\n"
1274 " :param other: another vector to compare the angle with\n"
1275 " :type other: :class:`Vector`\n"
1276 " :param fallback: return this when the angle can't be calculated (zero length vector),\n"
1277 " (instead of raising a :exc:`ValueError`).\n"
1278 " :type fallback: Any\n"
1279 " :return: angle in radians or fallback when given\n"
1280 " :rtype: float | Any\n");
1286 PyObject *fallback =
nullptr;
1288 if (!PyArg_ParseTuple(args,
1304 tvec, 2, 2, value,
"Vector.angle_signed(other), invalid 'other' arg") == -1)
1310 PyErr_SetString(PyExc_ValueError,
"Vector must be 2D");
1317 Py_INCREF(fallback);
1321 PyErr_SetString(PyExc_ValueError,
1322 "Vector.angle_signed(other): "
1323 "zero length vectors have no valid angle");
1338 Vector_rotation_difference_doc,
1339 ".. method:: rotation_difference(other, /)\n"
1341 " Returns a quaternion representing the rotational difference between this\n"
1342 " vector and another.\n"
1344 " :param other: second vector.\n"
1345 " :type other: :class:`Vector`\n"
1346 " :return: the rotational difference between the two vectors.\n"
1347 " :rtype: :class:`Quaternion`\n"
1349 " .. note:: 2D vectors raise an :exc:`AttributeError`.\n");
1355 PyErr_SetString(PyExc_ValueError,
1356 "vec.difference(value): "
1357 "expects both vectors to be size 3 or 4");
1366 vec_b, 3,
MAX_DIMENSIONS, value,
"Vector.difference(other), invalid 'other' arg") == -1)
1388 ".. method:: project(other, /)\n"
1390 " Return the projection of this vector onto the *other*.\n"
1392 " :param other: second vector.\n"
1393 " :type other: :class:`Vector`\n"
1394 " :return: the parallel projection vector\n"
1395 " :rtype: :class:`Vector`\n");
1398 const int vec_num = self->
vec_num;
1400 double dot = 0.0f, dot2 = 0.0f;
1408 &tvec, vec_num, value,
"Vector.project(other), invalid 'other' arg") == -1)
1414 for (
x = 0;
x < vec_num;
x++) {
1415 dot += double(self->vec[
x] * tvec[
x]);
1416 dot2 += double(tvec[
x] * tvec[
x]);
1420 for (
x = 0;
x < vec_num;
x++) {
1435 ".. method:: lerp(other, factor, /)\n"
1437 " Returns the interpolation of two vectors.\n"
1439 " :param other: value to interpolate with.\n"
1440 " :type other: :class:`Vector`\n"
1441 " :param factor: The interpolation value in [0.0, 1.0].\n"
1442 " :type factor: float\n"
1443 " :return: The interpolated vector.\n"
1444 " :rtype: :class:`Vector`\n");
1447 const int vec_num = self->
vec_num;
1448 PyObject *value =
nullptr;
1452 if (!PyArg_ParseTuple(args,
1467 &tvec, vec_num, value,
"Vector.lerp(other), invalid 'other' arg") == -1)
1486 ".. method:: slerp(other, factor, fallback=None, /)\n"
1488 " Returns the interpolation of two non-zero vectors (spherical coordinates).\n"
1490 " :param other: value to interpolate with.\n"
1491 " :type other: :class:`Vector`\n"
1492 " :param factor: The interpolation value typically in [0.0, 1.0].\n"
1493 " :type factor: float\n"
1494 " :param fallback: return this when the vector can't be calculated (zero length "
1495 "vector or direct opposites),\n"
1496 " (instead of raising a :exc:`ValueError`).\n"
1497 " :type fallback: Any\n"
1498 " :return: The interpolated vector.\n"
1499 " :rtype: :class:`Vector`\n");
1502 const int vec_num = self->
vec_num;
1503 PyObject *value =
nullptr;
1504 float fac, cosom,
w[2];
1505 float self_vec[3], other_vec[3], ret_vec[3];
1506 float self_len_sq, other_len_sq;
1508 PyObject *fallback =
nullptr;
1510 if (!PyArg_ParseTuple(args,
1528 PyErr_SetString(PyExc_ValueError,
"Vector must be 2D or 3D");
1533 other_vec, vec_num, vec_num, value,
"Vector.slerp(other), invalid 'other' arg") == -1)
1545 Py_INCREF(fallback);
1549 PyErr_SetString(PyExc_ValueError,
1551 "zero length vectors unsupported");
1562 Py_INCREF(fallback);
1566 PyErr_SetString(PyExc_ValueError,
1568 "opposite vectors unsupported");
1574 for (
x = 0;
x < vec_num;
x++) {
1575 ret_vec[
x] = (
w[0] * self_vec[
x]) + (
w[1] * other_vec[
x]);
1590 ".. method:: rotate(other, /)\n"
1592 " Rotate the vector by a rotation value.\n"
1594 " .. note:: 2D vectors are a special case that can only be rotated by a 2x2 matrix.\n"
1596 " :param other: rotation component of mathutils value\n"
1597 " :type other: :class:`Euler` | :class:`Quaternion` | :class:`Matrix`\n");
1606 float other_rmat[2][2];
1611 normalize_m2_m2(other_rmat,
reinterpret_cast<const float (*)[2]
>(pymat->matrix));
1616 float other_rmat[3][3];
1638 ".. method:: negate()\n"
1640 " Set all values to their negative.\n");
1662 ".. method:: copy()\n"
1664 " Returns a copy of this vector.\n"
1666 " :return: A copy of the vector.\n"
1667 " :rtype: :class:`Vector`\n"
1669 " .. note:: use this to get a copy of a wrapped vector with\n"
1670 " no reference to the original data.\n");
1695 PyObject *
ret, *tuple;
1702 ret = PyUnicode_FromFormat(
"Vector(%R)", tuple);
1707#ifndef MATH_STANDALONE
1722 for (i = 0; i < self->
vec_num; i++) {
1748 memset(view, 0,
sizeof(*view));
1750 view->obj =
reinterpret_cast<PyObject *
>(self);
1751 view->buf =
static_cast<void *
>(self->vec);
1752 view->len = Py_ssize_t(self->
vec_num *
sizeof(
float));
1753 view->itemsize =
sizeof(
float);
1755 if ((flags & PyBUF_WRITABLE) == 0) {
1758 if (flags & PyBUF_FORMAT) {
1759 view->format =
const_cast<char *
>(
"f");
1773 if (view->readonly == 0) {
1791static PyObject *
Vector_richcmpr(PyObject *objectA, PyObject *objectB,
int comparison_type)
1795 const double epsilon = 0.000001f;
1799 if (comparison_type == Py_NE) {
1812 if (vecA->
vec_num != vecB->vec_num) {
1813 if (comparison_type == Py_NE) {
1820 switch (comparison_type) {
1836 result = (((lenA + epsilon) > lenB) && ((lenA - epsilon) < lenB));
1863 result = (((lenA + epsilon) > lenB) && ((lenA - epsilon) < lenB));
1868 printf(
"The result of the comparison could not be evaluated");
1912 if (i < 0 || i >= self->
vec_num) {
1914 PyErr_Format(PyExc_AttributeError,
1915 "Vector.%c: unavailable on %dd vector",
1916 *((
static_cast<const char *
>(
"xyzw")) + i),
1920 PyErr_SetString(PyExc_IndexError,
"vector[index]: out of range");
1929 return PyFloat_FromDouble(self->vec[i]);
1946 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
1948 PyErr_SetString(PyExc_TypeError,
1949 "vector[index] = x: "
1950 "assigned value not a number");
1954 if (i < 0 || i >= self->
vec_num) {
1956 PyErr_Format(PyExc_AttributeError,
1957 "Vector.%c = x: unavailable on %dd vector",
1958 *((
static_cast<const char *
>(
"xyzw")) + i),
1962 PyErr_SetString(PyExc_IndexError,
1963 "vector[index] = x: "
1964 "assignment index out of range");
1968 self->vec[i] = scalar;
1986 Py_ssize_t slice_length)
1992 PyObject *tuple = PyTuple_New(slice_length);
1993 Py_ssize_t
index = start;
1994 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
1996 PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(self->vec[
index]));
2007 VectorObject *self, Py_ssize_t start, Py_ssize_t
step, Py_ssize_t slice_length, PyObject *
seq)
2009 float *vec =
nullptr;
2024 &vec,
int(slice_length),
seq,
"vector[slice] = seq");
2025 if (parsed_size == -1) {
2033 if (parsed_size != slice_length) {
2035 PyErr_Format(PyExc_ValueError,
2036 "vector[slice] = seq: sequence size is %d, expected %d",
2042 Py_ssize_t
index = start;
2043 for (Py_ssize_t i = 0; i < slice_length; i++,
index +=
step) {
2045 self->vec[
index] = vec[i];
2060 if (PyIndex_Check(item)) {
2062 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2063 if (i == -1 && PyErr_Occurred()) {
2071 if (PySlice_Check(item)) {
2072 Py_ssize_t start, stop,
step, slice_length;
2074 if (PySlice_GetIndicesEx(item, self->
vec_num, &start, &stop, &
step, &slice_length) < 0) {
2082 PyExc_TypeError,
"vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
2089 if (PyIndex_Check(item)) {
2090 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2091 if (i == -1 && PyErr_Occurred()) {
2099 if (PySlice_Check(item)) {
2100 Py_ssize_t start, stop,
step, slice_length;
2102 if (PySlice_GetIndicesEx(item, self->
vec_num, &start, &stop, &
step, &slice_length) < 0) {
2110 PyExc_TypeError,
"vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
2124 float *vec =
nullptr;
2127 PyErr_Format(PyExc_AttributeError,
2128 "Vector addition: (%s + %s) "
2129 "invalid type for this operation",
2130 Py_TYPE(v1)->tp_name,
2131 Py_TYPE(
v2)->tp_name);
2142 if (vec1->
vec_num != vec2->vec_num) {
2143 PyErr_SetString(PyExc_AttributeError,
2145 "vectors must have the same dimensions for this operation");
2149 vec =
static_cast<float *
>(PyMem_Malloc(vec1->
vec_num *
sizeof(
float)));
2150 if (vec ==
nullptr) {
2151 PyErr_SetString(PyExc_MemoryError,
2153 "problem allocating pointer space");
2168 PyErr_Format(PyExc_AttributeError,
2169 "Vector addition: (%s += %s) "
2170 "invalid type for this operation",
2171 Py_TYPE(v1)->tp_name,
2172 Py_TYPE(
v2)->tp_name);
2178 if (vec1->
vec_num != vec2->vec_num) {
2179 PyErr_SetString(PyExc_AttributeError,
2181 "vectors must have the same dimensions for this operation");
2203 PyErr_Format(PyExc_AttributeError,
2204 "Vector subtraction: (%s - %s) "
2205 "invalid type for this operation",
2206 Py_TYPE(v1)->tp_name,
2207 Py_TYPE(
v2)->tp_name);
2217 if (vec1->
vec_num != vec2->vec_num) {
2218 PyErr_SetString(PyExc_AttributeError,
2219 "Vector subtraction: "
2220 "vectors must have the same dimensions for this operation");
2224 vec =
static_cast<float *
>(PyMem_Malloc(vec1->
vec_num *
sizeof(
float)));
2225 if (vec ==
nullptr) {
2226 PyErr_SetString(PyExc_MemoryError,
2228 "problem allocating pointer space");
2243 PyErr_Format(PyExc_AttributeError,
2244 "Vector subtraction: (%s -= %s) "
2245 "invalid type for this operation",
2246 Py_TYPE(v1)->tp_name,
2247 Py_TYPE(
v2)->tp_name);
2253 if (vec1->
vec_num != vec2->vec_num) {
2254 PyErr_SetString(PyExc_AttributeError,
2255 "Vector subtraction: "
2256 "vectors must have the same dimensions for this operation");
2276 int row, col,
z = 0;
2283 PyErr_SetString(PyExc_ValueError,
2285 "len(matrix.col) and len(vector) must be the same, "
2286 "except for 4x4 matrix * 3D vector.");
2291 memcpy(vec_cpy, vec->vec, vec->
vec_num *
sizeof(
float));
2295 for (row = 0; row < mat->
row_num; row++) {
2297 for (col = 0; col < mat->
col_num; col++) {
2308 float *tvec =
static_cast<float *
>(PyMem_Malloc(vec->
vec_num *
sizeof(
float)));
2309 if (tvec ==
nullptr) {
2310 PyErr_SetString(PyExc_MemoryError,
2312 "problem allocating pointer space");
2322 float *tvec =
static_cast<float *
>(PyMem_Malloc(vec1->
vec_num *
sizeof(
float)));
2323 if (tvec ==
nullptr) {
2324 PyErr_SetString(PyExc_MemoryError,
2326 "problem allocating pointer space");
2357 if (vec1->
vec_num != vec2->vec_num) {
2358 PyErr_SetString(PyExc_ValueError,
2359 "Vector multiplication: "
2360 "vectors must have the same dimensions for this operation");
2368 if (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0) {
2373 if (((scalar = PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred()) == 0) {
2378 PyErr_Format(PyExc_TypeError,
2379 "Element-wise multiplication: "
2380 "not supported between '%.200s' and '%.200s' types",
2381 Py_TYPE(v1)->tp_name,
2382 Py_TYPE(
v2)->tp_name);
2412 if (vec1->
vec_num != vec2->vec_num) {
2413 PyErr_SetString(PyExc_ValueError,
2414 "Vector multiplication: "
2415 "vectors must have the same dimensions for this operation");
2422 else if (vec1 && (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0)) {
2427 PyErr_Format(PyExc_TypeError,
2428 "In place element-wise multiplication: "
2429 "not supported between '%.200s' and '%.200s' types",
2430 Py_TYPE(v1)->tp_name,
2431 Py_TYPE(
v2)->tp_name);
2463 if (vec1->
vec_num != vec2->vec_num) {
2464 PyErr_SetString(PyExc_ValueError,
2465 "Vector multiplication: "
2466 "vectors must have the same dimensions for this operation");
2496 PyErr_Format(PyExc_TypeError,
2497 "Vector multiplication: "
2498 "not supported between '%.200s' and '%.200s' types",
2499 Py_TYPE(v1)->tp_name,
2500 Py_TYPE(
v2)->tp_name);
2507 PyErr_Format(PyExc_TypeError,
2508 "In place vector multiplication: "
2509 "not supported between '%.200s' and '%.200s' types",
2510 Py_TYPE(v1)->tp_name,
2511 Py_TYPE(
v2)->tp_name);
2518 float *vec =
nullptr, scalar;
2522 PyErr_SetString(PyExc_TypeError,
2524 "Vector must be divided by a float");
2533 if ((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) {
2535 PyErr_SetString(PyExc_TypeError,
2537 "Vector must be divided by a float");
2541 if (scalar == 0.0f) {
2542 PyErr_SetString(PyExc_ZeroDivisionError,
2544 "divide by zero error");
2548 vec =
static_cast<float *
>(PyMem_Malloc(vec1->
vec_num *
sizeof(
float)));
2550 if (vec ==
nullptr) {
2551 PyErr_SetString(PyExc_MemoryError,
2553 "problem allocating pointer space");
2572 if ((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) {
2574 PyErr_SetString(PyExc_TypeError,
2576 "Vector must be divided by a float");
2580 if (scalar == 0.0f) {
2581 PyErr_SetString(PyExc_ZeroDivisionError,
2583 "divide by zero error");
2604 tvec =
static_cast<float *
>(PyMem_Malloc(self->
vec_num *
sizeof(
float)));
2696 "Vector Z axis (3D Vectors only).\n"
2702 "Vector W axis (4D Vectors only).\n"
2735 double dot = 0.0f, param;
2741 if ((param = PyFloat_AsDouble(value)) == -1.0 && PyErr_Occurred()) {
2742 PyErr_SetString(PyExc_TypeError,
"length must be set to a number");
2747 PyErr_SetString(PyExc_ValueError,
"cannot set a vectors length to a negative value");
2751 std::fill_n(self->vec, self->
vec_num, 0.0f);
2780 Vector_length_squared_doc,
2781 "Vector length squared (v.dot(v)).\n"
2797 ":type: :class:`Vector`");
2889 uint swizzleClosure;
2900 if (axis_from >= self->
vec_num) {
2901 PyErr_SetString(PyExc_AttributeError,
2903 "specified axis not present");
2907 vec[axis_to] = self->vec[axis_from];
2934 uint swizzleClosure;
2950 if (axis_to >= self->
vec_num) {
2951 PyErr_SetString(PyExc_AttributeError,
2953 "specified axis not present");
2960 if (((scalarVal = PyFloat_AsDouble(value)) == -1 && PyErr_Occurred()) == 0) {
2964 vec_assign[i] = scalarVal;
2967 size_from = axis_from;
2969 else if (PyErr_Clear(),
2971 vec_assign, 2, 4, value,
"Vector.**** = swizzle assignment"))) ==
size_t(-1))
2976 if (axis_from != size_from) {
2977 PyErr_SetString(PyExc_AttributeError,
"Vector swizzle: size does not match swizzle");
2989 memcpy(tvec, self->vec, tvec_num *
sizeof(
float));
2993 tvec[axis_to] = vec_assign[axis_from];
3000 memcpy(self->vec, tvec, tvec_num *
sizeof(
float));
3010#define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS)
3011#define _SWIZZLE2(a, b) (_SWIZZLE1(a) | (((b) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS)))
3012#define _SWIZZLE3(a, b, c) \
3013 (_SWIZZLE2(a, b) | (((c) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))
3014#define _SWIZZLE4(a, b, c, d) \
3015 (_SWIZZLE3(a, b, c) | (((d) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3)))
3017#define SWIZZLE2(a, b) POINTER_FROM_INT(_SWIZZLE2(a, b))
3018#define SWIZZLE3(a, b, c) POINTER_FROM_INT(_SWIZZLE3(a, b, c))
3019#define SWIZZLE4(a, b, c, d) POINTER_FROM_INT(_SWIZZLE4(a, b, c, d))
3021#define VECTOR_SWIZZLE2_RW_DEF(attr, a, b) \
3024 (getter)Vector_swizzle_get, \
3025 (setter)Vector_swizzle_set, \
3026 Vector_swizzle_doc, \
3029#define VECTOR_SWIZZLE2_RO_DEF(attr, a, b) \
3032 (getter)Vector_swizzle_get, \
3034 Vector_swizzle_doc, \
3037#define VECTOR_SWIZZLE3_RW_DEF(attr, a, b, c) \
3040 (getter)Vector_swizzle_get, \
3041 (setter)Vector_swizzle_set, \
3042 Vector_swizzle_doc, \
3043 SWIZZLE3(a, b, c), \
3045#define VECTOR_SWIZZLE3_RO_DEF(attr, a, b, c) \
3048 (getter)Vector_swizzle_get, \
3050 Vector_swizzle_doc, \
3051 SWIZZLE3(a, b, c), \
3053#define VECTOR_SWIZZLE4_RW_DEF(attr, a, b, c, d) \
3056 (getter)Vector_swizzle_get, \
3057 (setter)Vector_swizzle_set, \
3058 Vector_swizzle_doc, \
3059 SWIZZLE4(a, b, c, d), \
3061#define VECTOR_SWIZZLE4_RO_DEF(attr, a, b, c, d) \
3062 {attr, (getter)Vector_swizzle_get, (setter) nullptr, Vector_swizzle_doc, SWIZZLE4(a, b, c, d)}
3072# pragma clang diagnostic push
3073# pragma clang diagnostic ignored "-Wcast-function-type"
3075# pragma GCC diagnostic push
3076# pragma GCC diagnostic ignored "-Wcast-function-type"
3108 static_cast<setter
>(
nullptr),
3109 Vector_length_squared_doc,
3118 static_cast<setter
>(
nullptr),
3123 static_cast<setter
>(
nullptr),
3128 static_cast<setter
>(
nullptr),
3133 static_cast<setter
>(
nullptr),
3475#undef AXIS_FROM_CHAR
3485#undef VECTOR_SWIZZLE2_RW_DEF
3486#undef VECTOR_SWIZZLE2_RO_DEF
3487#undef VECTOR_SWIZZLE3_RW_DEF
3488#undef VECTOR_SWIZZLE3_RO_DEF
3489#undef VECTOR_SWIZZLE4_RW_DEF
3490#undef VECTOR_SWIZZLE4_RO_DEF
3492 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
3497# pragma clang diagnostic pop
3499# pragma GCC diagnostic pop
3511# pragma clang diagnostic push
3512# pragma clang diagnostic ignored "-Wcast-function-type"
3514# pragma GCC diagnostic push
3515# pragma GCC diagnostic ignored "-Wcast-function-type"
3523 METH_VARARGS | METH_CLASS,
3527 METH_VARARGS | METH_CLASS,
3528 C_Vector_Range_doc},
3531 METH_VARARGS | METH_CLASS,
3532 C_Vector_Linspace_doc},
3535 METH_VARARGS | METH_CLASS,
3536 C_Vector_Repeat_doc},
3539 {
"zero",
reinterpret_cast<PyCFunction
>(
Vector_zero), METH_NOARGS, Vector_zero_doc},
3540 {
"negate",
reinterpret_cast<PyCFunction
>(
Vector_negate), METH_NOARGS, Vector_negate_doc},
3546 Vector_normalize_doc},
3550 Vector_normalized_doc},
3552 {
"resize",
reinterpret_cast<PyCFunction
>(
Vector_resize), METH_O, Vector_resize_doc},
3553 {
"resized",
reinterpret_cast<PyCFunction
>(
Vector_resized), METH_O, Vector_resized_doc},
3554 {
"to_2d",
reinterpret_cast<PyCFunction
>(
Vector_to_2d), METH_NOARGS, Vector_to_2d_doc},
3558 Vector_resize_2d_doc},
3559 {
"to_3d",
reinterpret_cast<PyCFunction
>(
Vector_to_3d), METH_NOARGS, Vector_to_3d_doc},
3563 Vector_resize_3d_doc},
3564 {
"to_4d",
reinterpret_cast<PyCFunction
>(
Vector_to_4d), METH_NOARGS, Vector_to_4d_doc},
3568 Vector_resize_4d_doc},
3572 Vector_to_tuple_doc},
3576 Vector_to_track_quat_doc},
3580 Vector_orthogonal_doc},
3583 {
"reflect",
reinterpret_cast<PyCFunction
>(
Vector_reflect), METH_O, Vector_reflect_doc},
3584 {
"cross",
reinterpret_cast<PyCFunction
>(
Vector_cross), METH_O, Vector_cross_doc},
3585 {
"dot",
reinterpret_cast<PyCFunction
>(
Vector_dot), METH_O, Vector_dot_doc},
3586 {
"angle",
reinterpret_cast<PyCFunction
>(
Vector_angle), METH_VARARGS, Vector_angle_doc},
3590 Vector_angle_signed_doc},
3591 {
"rotation_difference",
3594 Vector_rotation_difference_doc},
3595 {
"project",
reinterpret_cast<PyCFunction
>(
Vector_project), METH_O, Vector_project_doc},
3596 {
"lerp",
reinterpret_cast<PyCFunction
>(
Vector_lerp), METH_VARARGS, Vector_lerp_doc},
3597 {
"slerp",
reinterpret_cast<PyCFunction
>(
Vector_slerp), METH_VARARGS, Vector_slerp_doc},
3598 {
"rotate",
reinterpret_cast<PyCFunction
>(
Vector_rotate), METH_O, Vector_rotate_doc},
3606 {
"copy",
reinterpret_cast<PyCFunction
>(
Vector_copy), METH_NOARGS, Vector_copy_doc},
3607 {
"__copy__",
reinterpret_cast<PyCFunction
>(
Vector_copy), METH_NOARGS,
nullptr},
3608 {
"__deepcopy__",
reinterpret_cast<PyCFunction
>(
Vector_deepcopy), METH_VARARGS,
nullptr},
3609 {
nullptr,
nullptr, 0,
nullptr},
3614# pragma clang diagnostic pop
3616# pragma GCC diagnostic pop
3630#ifdef MATH_STANDALONE
3631# define Vector_str nullptr
3637 ".. class:: Vector(seq=(0.0, 0.0, 0.0), /)\n"
3639 " This object gives access to Vectors in Blender.\n"
3641 " :param seq: Components of the vector, must be a sequence of at least two.\n"
3642 " :type seq: Sequence[float]\n");
3644 PyVarObject_HEAD_INIT(
nullptr, 0)
3663 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
3695#ifdef MATH_STANDALONE
3696# undef Vector_str nullptr
3711 PyErr_SetString(PyExc_RuntimeError,
"Vector(): invalid size");
3715 vec_alloc =
static_cast<float *
>(PyMem_Malloc(vec_num *
sizeof(
float)));
3716 if (vec_alloc ==
nullptr) [[unlikely]] {
3717 PyErr_SetString(PyExc_MemoryError,
3719 "problem allocating data");
3725 self->vec = vec_alloc;
3729 self->cb_user =
nullptr;
3730 self->cb_type = self->cb_subtype = 0;
3733 memcpy(self->vec, vec, vec_num *
sizeof(
float));
3736 std::fill_n(self->vec, vec_num, 0.0f);
3738 self->vec[3] = 1.0f;
3744 PyMem_Free(vec_alloc);
3747 return reinterpret_cast<PyObject *
>(self);
3755 PyErr_SetString(PyExc_RuntimeError,
"Vector(): invalid size");
3764 self->cb_user =
nullptr;
3765 self->cb_type = self->cb_subtype = 0;
3770 return reinterpret_cast<PyObject *
>(self);
3778 self->cb_user = Py_NewRef(cb_user);
3779 self->cb_type = cb_type;
3780 self->cb_subtype = cb_subtype;
3781 BLI_assert(!PyObject_GC_IsTracked((PyObject *)self));
3782 PyObject_GC_Track(self);
3785 return reinterpret_cast<PyObject *
>(self);
3796 return reinterpret_cast<PyObject *
>(self);
A dynamically sized string ADT.
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define BaseMathObject_Prepare_ForResize(_self, error_prefix)
#define BaseMath_ReadCallback_ForWrite(_self)
#define BaseMath_Prepare_ForBufferAccess(_self, _view, _flags)
#define BaseMath_ReadIndexCallback(_self, _index)
#define BaseMath_WriteCallback(_self)
#define BASE_MATH_NEW(struct_name, root_type, base_type)
#define BaseMathObject_Prepare_ForHash(_self)
#define BASE_MATH_FLAG_DEFAULT
#define BaseMath_Prepare_ForWrite(_self)
#define BaseMath_ReadCallback(_self)
#define BaseMath_WriteIndexCallback(_self, _index)
#define MatrixObject_Check(v)
#define MATRIX_ITEM(_mat, _row, _col)
#define VECTOR_SWIZZLE2_RO_DEF(attr, a, b)
#define VECTOR_SWIZZLE3_RW_DEF(attr, a, b, c)
#define SWIZZLE_VALID_AXIS
#define VECTOR_SWIZZLE2_RW_DEF(attr, a, b)
#define SWIZZLE_BITS_PER_AXIS
#define VECTOR_SWIZZLE4_RO_DEF(attr, a, b, c, d)
#define VECTOR_SWIZZLE3_RO_DEF(attr, a, b, c)
#define VECTOR_SWIZZLE4_RW_DEF(attr, a, b, c, d)
#define VectorObject_Check(v)
char BaseMathObject_owner_doc[]
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void mul_vn_fl(float *array_tar, int size, float f)
static PyObject * Vector_length_get(VectorObject *self, void *)
char BaseMathObject_freeze_doc[]
MINLINE void negate_v3_v3(float r[3], const float a[3])
void mul_m3_v3(const float M[3][3], float r[3])
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
float normalize_vn_vn(float *array_tar, const float *array_src, int size)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
MINLINE bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
bool mathutils_slice_is_subset(Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length, Py_ssize_t array_num)
static PyObject * Vector_subscript(VectorObject *self, PyObject *item)
static PyObject * Vector_neg(VectorObject *self)
void BaseMathObject_dealloc(BaseMathObject *self)
static PyObject * C_Vector_Linspace(PyObject *cls, PyObject *args)
int PyC_CheckArgs_DeepCopy(PyObject *args)
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
static PyObject * Vector_lerp(VectorObject *self, PyObject *args)
static PyObject * Vector_axis_get(VectorObject *self, void *type)
static PyObject * Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject * Vector_to_3d(VectorObject *self)
Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
void add_vn_vn(float *array_tar, const float *array_src, int size)
static PyObject * Vector_cross(VectorObject *self, PyObject *value)
void vec_to_quat(float q[4], const float vec[3], short axis, short upflag)
PyObject * mathutils_dynstr_to_py(DynStr *ds)
float normalize_vn(float *array_tar, int size)
void mul_vn_vn_fl(float *array_tar, const float *array_src, int size, float f)
MINLINE float cross_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
static PyObject * Vector_idiv(PyObject *v1, PyObject *v2)
static PyObject * vector_item_internal(VectorObject *self, int i, const bool is_attr)
static PyObject * C_Vector_Range(PyObject *cls, PyObject *args)
static int Vector_axis_set(VectorObject *self, PyObject *value, void *type)
static PyObject * Vector_slice(VectorObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length)
static PyObject * C_Vector_Fill(PyObject *cls, PyObject *args)
static PyObject * Vector_to_track_quat(VectorObject *self, PyObject *args)
PyObject * Vector_CreatePyObject_wrap(float *vec, const int vec_num, PyTypeObject *base_type)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
PyObject * BaseMathObject_owner_get(BaseMathObject *self, void *)
static PyObject * Vector_negate(VectorObject *self)
MINLINE float safe_acosf(float a)
static PySequenceMethods Vector_SeqMethods
int Matrix_Parse2x2(PyObject *o, void *p)
void ortho_v2_v2(float out[2], const float v[2])
static PyObject * Vector_matmul(PyObject *v1, PyObject *v2)
static PyObject * vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), VectorObject *self)
float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
double double_round(double x, int ndigits)
void interp_vn_vn(float *array_tar, const float *array_src, float t, int size)
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
static PyObject * Vector_resize_4d(VectorObject *self)
int BaseMathObject_clear(BaseMathObject *self)
void interp_dot_slerp(float t, float cosom, float r_w[2])
PyObject * BaseMathObject_freeze(BaseMathObject *self)
static PyObject * Vector_add(PyObject *v1, PyObject *v2)
static Py_hash_t Vector_hash(VectorObject *self)
static PyObject * Vector_imatmul(PyObject *v1, PyObject *v2)
static PyObject * Vector_length_squared_get(VectorObject *self, void *)
void range_vn_fl(float *array_tar, int size, float start, float step)
static PyGetSetDef Vector_getseters[]
static PyObject * Vector_repr(VectorObject *self)
static int Vector_getbuffer(PyObject *obj, Py_buffer *view, int flags)
void normalize_m2_m2(float R[2][2], const float M[2][2]) ATTR_NONNULL()
PyObject * Vector_CreatePyObject_alloc(float *vec, const int vec_num, PyTypeObject *base_type)
int BaseMathObject_is_gc(BaseMathObject *self)
int mathutils_array_parse_alloc(float **array, int array_num_min, PyObject *value, const char *error_prefix)
static PyObject * Vector_to_tuple(VectorObject *self, PyObject *args)
static PyObject * Vector_str(VectorObject *self)
PyObject * BaseMathObject_is_frozen_get(BaseMathObject *self, void *)
static PyObject * Vector_resize_3d(VectorObject *self)
static PyObject * Vector_iadd(PyObject *v1, PyObject *v2)
static PyObject * Vector_zero(VectorObject *self)
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
PyObject * Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type)
PyObject * BaseMathObject_is_valid_get(BaseMathObject *self, void *)
static PyObject * Vector_copy(VectorObject *self)
double dot_vn_vn(const float *array_src_a, const float *array_src_b, int size) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
static Py_ssize_t Vector_len(VectorObject *self)
PyObject * Quaternion_CreatePyObject(const float quat[4], PyTypeObject *base_type)
static PyObject * Vector_angle(VectorObject *self, PyObject *args)
static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, const bool is_attr)
static PyObject * Vector_item(VectorObject *self, Py_ssize_t i)
static PyObject * Vector_vectorcall(PyObject *type, PyObject *const *args, const size_t nargsf, PyObject *kwnames)
static PyObject * Vector_angle_signed(VectorObject *self, PyObject *args)
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
@ BASE_MATH_FLAG_HAS_BUFFER_VIEW
static PyObject * Vector_resize_2d(VectorObject *self)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
double len_squared_vn(const float *array, int size) ATTR_WARN_UNUSED_RESULT
int column_vector_multiplication(float r_vec[4], VectorObject *vec, MatrixObject *mat)
static PyObject * Vector_reflect(VectorObject *self, PyObject *value)
static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value)
void mul_vn_vn(float *array_tar, const float *array_src, int size)
static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
void mul_m2_v2(const float mat[2][2], float vec[2])
static PyObject * Vector_sub(PyObject *v1, PyObject *v2)
static PyObject * Vector_isub(PyObject *v1, PyObject *v2)
void reflect_v3_v3v3(float out[3], const float v[3], const float normal[3])
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure)
static PyObject * Vector_imul(PyObject *v1, PyObject *v2)
static PyObject * Vector_normalize(VectorObject *self)
void ortho_v3_v3(float out[3], const float v[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
static PyObject * Vector_dot(VectorObject *self, PyObject *value)
static PyObject * Vector_mul(PyObject *v1, PyObject *v2)
static PyObject * Vector_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
MINLINE float normalize_v3(float n[3])
static PyNumberMethods Vector_NumMethods
static void Vector_releasebuffer(PyObject *, Py_buffer *view)
static PyObject * Vector_deepcopy(VectorObject *self, PyObject *args)
static PyObject * Vector_rotation_difference(VectorObject *self, PyObject *value)
PyObject * BaseMathObject_is_wrapped_get(BaseMathObject *self, void *)
char BaseMathObject_is_valid_doc[]
void sub_vn_vn(float *array_tar, const float *array_src, int size)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
static PyObject * Vector_to_4d(VectorObject *self)
static int Vector_ass_slice(VectorObject *self, Py_ssize_t start, Py_ssize_t step, Py_ssize_t slice_length, PyObject *seq)
static PyObject * Vector_slerp(VectorObject *self, PyObject *args)
static PyObject * Vector_swizzle_get(VectorObject *self, void *closure)
static PyObject * Vector_rotate(VectorObject *self, PyObject *value)
static PyMappingMethods Vector_AsMapping
static PyObject * Vector_normalized(VectorObject *self)
void negate_vn(float *array_tar, int size)
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
void negate_vn_vn(float *array_tar, const float *array_src, int size)
char BaseMathObject_is_frozen_doc[]
static PyObject * Vector_resized(VectorObject *self, PyObject *value)
static int Vector_ass_item(VectorObject *self, Py_ssize_t i, PyObject *value)
static PyMethodDef Vector_methods[]
static PyObject * Vector_div(PyObject *v1, PyObject *v2)
void mul_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
static PyObject * C_Vector_Repeat(PyObject *cls, PyObject *args)
static int Vector_length_set(VectorObject *self, PyObject *value)
static PyObject * Vector_resize(VectorObject *self, PyObject *value)
static PyObject * Vector_project(VectorObject *self, PyObject *value)
static PyObject * Vector_to_2d(VectorObject *self)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
static PyBufferProcs Vector_as_buffer
static PyObject * Vector_to_tuple_ex(VectorObject *self, int ndigits)
static PyObject * vector_mul_float(VectorObject *vec, const float scalar)
static PyObject * Vector_orthogonal(VectorObject *self)
static PyObject * vector_mul_vec(VectorObject *vec1, VectorObject *vec2)
char BaseMathObject_is_wrapped_doc[]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float