Blender  V2.93
Macros | Functions | Variables
mathutils_Vector.c File Reference
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "../generic/py_capi_utils.h"
#include "BLI_dynstr.h"

Go to the source code of this file.

Macros

#define MAX_DIMENSIONS   4
 
#define SWIZZLE_BITS_PER_AXIS   3
 
#define SWIZZLE_VALID_AXIS   0x4
 
#define SWIZZLE_AXIS   0x3
 
#define _SWIZZLE1(a)   ((a) | SWIZZLE_VALID_AXIS)
 
#define _SWIZZLE2(a, b)   (_SWIZZLE1(a) | (((b) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS)))
 
#define _SWIZZLE3(a, b, c)    (_SWIZZLE2(a, b) | (((c) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))
 
#define _SWIZZLE4(a, b, c, d)    (_SWIZZLE3(a, b, c) | (((d) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3)))
 
#define SWIZZLE2(a, b)   POINTER_FROM_INT(_SWIZZLE2(a, b))
 
#define SWIZZLE3(a, b, c)   POINTER_FROM_INT(_SWIZZLE3(a, b, c))
 
#define SWIZZLE4(a, b, c, d)   POINTER_FROM_INT(_SWIZZLE4(a, b, c, d))
 

Functions

static PyObject * Vector_copy (VectorObject *self)
 
static PyObject * Vector_deepcopy (VectorObject *self, PyObject *args)
 
static PyObject * Vector_to_tuple_ex (VectorObject *self, int ndigits)
 
static int row_vector_multiplication (float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
 
static PyObject * Vector_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 
static PyObject * vec__apply_to_copy (PyObject *(*vec_func)(VectorObject *), VectorObject *self)
 
 PyDoc_STRVAR (C_Vector_Fill_doc, ".. classmethod:: Fill(size, fill=0.0)\n" "\n" " Create a vector of length size with all values set to fill.\n" "\n" " :arg size: The length of the vector to be created.\n" " :type size: int\n" " :arg fill: The value used to fill the vector.\n" " :type fill: float\n")
 
static PyObject * C_Vector_Fill (PyObject *cls, PyObject *args)
 
 PyDoc_STRVAR (C_Vector_Range_doc, ".. classmethod:: Range(start=0, stop, step=1)\n" "\n" " Create a filled with a range of values.\n" "\n" " :arg start: The start of the range used to fill the vector.\n" " :type start: int\n" " :arg stop: The end of the range used to fill the vector.\n" " :type stop: int\n" " :arg step: The step between successive values in the vector.\n" " :type step: int\n")
 
static PyObject * C_Vector_Range (PyObject *cls, PyObject *args)
 
 PyDoc_STRVAR (C_Vector_Linspace_doc, ".. classmethod:: Linspace(start, stop, size)\n" "\n" " Create a vector of the specified size which is filled with linearly spaced " "values between start and stop values.\n" "\n" " :arg start: The start of the range used to fill the vector.\n" " :type start: int\n" " :arg stop: The end of the range used to fill the vector.\n" " :type stop: int\n" " :arg size: The size of the vector to be created.\n" " :type size: int\n")
 
static PyObject * C_Vector_Linspace (PyObject *cls, PyObject *args)
 
 PyDoc_STRVAR (C_Vector_Repeat_doc, ".. classmethod:: Repeat(vector, size)\n" "\n" " Create a vector by repeating the values in vector until the required size is reached.\n" "\n" " :arg tuple: The vector to draw values from.\n" " :type tuple: :class:`mathutils.Vector`\n" " :arg size: The size of the vector to be created.\n" " :type size: int\n")
 
static PyObject * C_Vector_Repeat (PyObject *cls, PyObject *args)
 
 PyDoc_STRVAR (Vector_zero_doc, ".. method:: zero()\n" "\n" " Set all values to zero.\n")
 
static PyObject * Vector_zero (VectorObject *self)
 
 PyDoc_STRVAR (Vector_normalize_doc, ".. method:: normalize()\n" "\n" " Normalize the vector, making the length of the vector always 1.0.\n" "\n" " .. warning:: Normalizing a vector where all values are zero has no effect.\n" "\n" " .. note:: Normalize works for vectors of all sizes,\n" " however 4D Vectors w axis is left untouched.\n")
 
static PyObject * Vector_normalize (VectorObject *self)
 
 PyDoc_STRVAR (Vector_normalized_doc, ".. method:: normalized()\n" "\n" " Return a new, normalized vector.\n" "\n" " :return: a normalized copy of the vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_normalized (VectorObject *self)
 
 PyDoc_STRVAR (Vector_resize_doc, ".. method:: resize(size=3)\n" "\n" " Resize the vector to have size number of elements.\n")
 
static PyObject * Vector_resize (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_resized_doc, ".. method:: resized(size=3)\n" "\n" " Return a resized copy of the vector with size number of elements.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_resized (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_resize_2d_doc, ".. method:: resize_2d()\n" "\n" " Resize the vector to 2D (x, y).\n")
 
static PyObject * Vector_resize_2d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_resize_3d_doc, ".. method:: resize_3d()\n" "\n" " Resize the vector to 3D (x, y, z).\n")
 
static PyObject * Vector_resize_3d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_resize_4d_doc, ".. method:: resize_4d()\n" "\n" " Resize the vector to 4D (x, y, z, w).\n")
 
static PyObject * Vector_resize_4d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_to_2d_doc, ".. method:: to_2d()\n" "\n" " Return a 2d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_to_2d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_to_3d_doc, ".. method:: to_3d()\n" "\n" " Return a 3d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_to_3d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_to_4d_doc, ".. method:: to_4d()\n" "\n" " Return a 4d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_to_4d (VectorObject *self)
 
 PyDoc_STRVAR (Vector_to_tuple_doc, ".. method:: to_tuple(precision=-1)\n" "\n" " Return this vector as a tuple with.\n" "\n" " :arg precision: The number to round the value to in [-1, 21].\n" " :type precision: int\n" " :return: the values of the vector rounded by *precision*\n" " :rtype: tuple\n")
 
static PyObject * Vector_to_tuple (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_to_track_quat_doc, ".. method:: to_track_quat(track, up)\n" "\n" " Return a quaternion rotation from the vector and the track and up axis.\n" "\n" " :arg track: Track axis in ['X', 'Y', 'Z', '-X', '-Y', '-Z'].\n" " :type track: string\n" " :arg up: Up axis in ['X', 'Y', 'Z'].\n" " :type up: string\n" " :return: rotation from the vector and the track and up axis.\n" " :rtype: :class:`Quaternion`\n")
 
static PyObject * Vector_to_track_quat (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_orthogonal_doc, ".. method:: orthogonal()\n" "\n" " Return a perpendicular vector.\n" "\n" " :return: a new vector 90 degrees from this vector.\n" " :rtype: :class:`Vector`\n" "\n" " .. note:: the axis is undefined, only use when any orthogonal vector is acceptable.\n")
 
static PyObject * Vector_orthogonal (VectorObject *self)
 
 PyDoc_STRVAR (Vector_reflect_doc, ".. method:: reflect(mirror)\n" "\n" " Return the reflection vector from the *mirror* argument.\n" "\n" " :arg mirror: This vector could be a normal from the reflecting surface.\n" " :type mirror: :class:`Vector`\n" " :return: The reflected vector matching the size of this vector.\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_reflect (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_cross_doc, ".. method:: cross(other)\n" "\n" " Return the cross product of this vector and another.\n" "\n" " :arg other: The other vector to perform the cross product with.\n" " :type other: :class:`Vector`\n" " :return: The cross product.\n" " :rtype: :class:`Vector` or float when 2D vectors are used\n" "\n" " .. note:: both vectors must be 2D or 3D\n")
 
static PyObject * Vector_cross (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_dot_doc, ".. method:: dot(other)\n" "\n" " Return the dot product of this vector and another.\n" "\n" " :arg other: The other vector to perform the dot product with.\n" " :type other: :class:`Vector`\n" " :return: The dot product.\n" " :rtype: float\n")
 
static PyObject * Vector_dot (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_angle_doc, ".. function:: angle(other, fallback=None)\n" "\n" " Return the angle between two vectors.\n" "\n" " :arg other: another vector to compare the angle with\n" " :type other: :class:`Vector`\n" " :arg fallback: return this when the angle can't be calculated (zero length vector),\n" " (instead of raising a :exc:`ValueError`).\n" " :type fallback: any\n" " :return: angle in radians or fallback when given\n" " :rtype: float\n")
 
static PyObject * Vector_angle (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_angle_signed_doc, ".. function:: angle_signed(other, fallback)\n" "\n" " Return the signed angle between two 2D vectors (clockwise is positive).\n" "\n" " :arg other: another vector to compare the angle with\n" " :type other: :class:`Vector`\n" " :arg fallback: return this when the angle can't be calculated (zero length vector),\n" " (instead of raising a :exc:`ValueError`).\n" " :type fallback: any\n" " :return: angle in radians or fallback when given\n" " :rtype: float\n")
 
static PyObject * Vector_angle_signed (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_rotation_difference_doc, ".. function:: rotation_difference(other)\n" "\n" " Returns a quaternion representing the rotational difference between this\n" " vector and another.\n" "\n" " :arg other: second vector.\n" " :type other: :class:`Vector`\n" " :return: the rotational difference between the two vectors.\n" " :rtype: :class:`Quaternion`\n" "\n" " .. note:: 2D vectors raise an :exc:`AttributeError`.\n")
 
static PyObject * Vector_rotation_difference (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_project_doc, ".. function:: project(other)\n" "\n" " Return the projection of this vector onto the *other*.\n" "\n" " :arg other: second vector.\n" " :type other: :class:`Vector`\n" " :return: the parallel projection vector\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_project (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_lerp_doc, ".. function:: lerp(other, factor)\n" "\n" " Returns the interpolation of two vectors.\n" "\n" " :arg other: value to interpolate with.\n" " :type other: :class:`Vector`\n" " :arg factor: The interpolation value in [0.0, 1.0].\n" " :type factor: float\n" " :return: The interpolated vector.\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_lerp (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_slerp_doc, ".. function:: slerp(other, factor, fallback=None)\n" "\n" " Returns the interpolation of two non-zero vectors (spherical coordinates).\n" "\n" " :arg other: value to interpolate with.\n" " :type other: :class:`Vector`\n" " :arg factor: The interpolation value typically in [0.0, 1.0].\n" " :type factor: float\n" " :arg fallback: return this when the vector can't be calculated (zero length " "vector or direct opposites),\n" " (instead of raising a :exc:`ValueError`).\n" " :type fallback: any\n" " :return: The interpolated vector.\n" " :rtype: :class:`Vector`\n")
 
static PyObject * Vector_slerp (VectorObject *self, PyObject *args)
 
 PyDoc_STRVAR (Vector_rotate_doc, ".. function:: rotate(other)\n" "\n" " Rotate the vector by a rotation value.\n" "\n" " .. note:: 2D vectors are a special case that can only be rotated by a 2x2 matrix.\n" "\n" " :arg other: rotation component of mathutils value\n" " :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n")
 
static PyObject * Vector_rotate (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_copy_doc, ".. function:: copy()\n" "\n" " Returns a copy of this vector.\n" "\n" " :return: A copy of the vector.\n" " :rtype: :class:`Vector`\n" "\n" " .. note:: use this to get a copy of a wrapped vector with\n" " no reference to the original data.\n")
 
static PyObject * Vector_repr (VectorObject *self)
 
static PyObject * Vector_str (VectorObject *self)
 
static int Vector_len (VectorObject *self)
 
static PyObject * vector_item_internal (VectorObject *self, int i, const bool is_attr)
 
static PyObject * Vector_item (VectorObject *self, int i)
 
static int vector_ass_item_internal (VectorObject *self, int i, PyObject *value, const bool is_attr)
 
static int Vector_ass_item (VectorObject *self, int i, PyObject *value)
 
static PyObject * Vector_slice (VectorObject *self, int begin, int end)
 
static int Vector_ass_slice (VectorObject *self, int begin, int end, PyObject *seq)
 
static PyObject * Vector_add (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_iadd (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_sub (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_isub (PyObject *v1, PyObject *v2)
 
int column_vector_multiplication (float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
 
static PyObject * vector_mul_float (VectorObject *vec, const float scalar)
 
static PyObject * vector_mul_vec (VectorObject *vec1, VectorObject *vec2)
 
static PyObject * Vector_mul (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_imul (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_matmul (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_imatmul (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_div (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_idiv (PyObject *v1, PyObject *v2)
 
static PyObject * Vector_neg (VectorObject *self)
 
static PyObject * Vector_richcmpr (PyObject *objectA, PyObject *objectB, int comparison_type)
 
static Py_hash_t Vector_hash (VectorObject *self)
 
static PyObject * Vector_subscript (VectorObject *self, PyObject *item)
 
static int Vector_ass_subscript (VectorObject *self, PyObject *item, PyObject *value)
 
 PyDoc_STRVAR (Vector_axis_x_doc, "Vector X axis.\n\n:type: float")
 
 PyDoc_STRVAR (Vector_axis_y_doc, "Vector Y axis.\n\n:type: float")
 
 PyDoc_STRVAR (Vector_axis_z_doc, "Vector Z axis (3D Vectors only).\n\n:type: float")
 
 PyDoc_STRVAR (Vector_axis_w_doc, "Vector W axis (4D Vectors only).\n\n:type: float")
 
static PyObject * Vector_axis_get (VectorObject *self, void *type)
 
static int Vector_axis_set (VectorObject *self, PyObject *value, void *type)
 
 PyDoc_STRVAR (Vector_length_doc, "Vector Length.\n\n:type: float")
 
static PyObject * Vector_length_get (VectorObject *self, void *UNUSED(closure))
 
static int Vector_length_set (VectorObject *self, PyObject *value)
 
 PyDoc_STRVAR (Vector_length_squared_doc, "Vector length squared (v.dot(v)).\n\n:type: float")
 
static PyObject * Vector_length_squared_get (VectorObject *self, void *UNUSED(closure))
 
static PyObject * Vector_swizzle_get (VectorObject *self, void *closure)
 
static int Vector_swizzle_set (VectorObject *self, PyObject *value, void *closure)
 
 PyDoc_STRVAR (Vector_negate_doc, ".. method:: negate()\n" "\n" " Set all values to their negative.\n")
 
static PyObject * Vector_negate (VectorObject *self)
 
 PyDoc_STRVAR (vector_doc, ".. class:: Vector(seq)\n" "\n" " This object gives access to Vectors in Blender.\n" "\n" " :param seq: Components of the vector, must be a sequence of at least two\n" " :type seq: sequence of numbers\n")
 
PyObject * Vector_CreatePyObject (const float *vec, const int size, PyTypeObject *base_type)
 
PyObject * Vector_CreatePyObject_wrap (float *vec, const int size, PyTypeObject *base_type)
 
PyObject * Vector_CreatePyObject_cb (PyObject *cb_user, int size, uchar cb_type, uchar cb_subtype)
 
PyObject * Vector_CreatePyObject_alloc (float *vec, const int size, PyTypeObject *base_type)
 

Variables

static PySequenceMethods Vector_SeqMethods
 
static PyMappingMethods Vector_AsMapping
 
static PyNumberMethods Vector_NumMethods
 
static PyGetSetDef Vector_getseters []
 
static struct PyMethodDef Vector_methods []
 
PyTypeObject vector_Type
 

Macro Definition Documentation

◆ _SWIZZLE1

#define _SWIZZLE1 (   a)    ((a) | SWIZZLE_VALID_AXIS)

Definition at line 2518 of file mathutils_Vector.c.

◆ _SWIZZLE2

#define _SWIZZLE2 (   a,
 
)    (_SWIZZLE1(a) | (((b) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS)))

Definition at line 2519 of file mathutils_Vector.c.

◆ _SWIZZLE3

#define _SWIZZLE3 (   a,
  b,
 
)     (_SWIZZLE2(a, b) | (((c) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))

Definition at line 2520 of file mathutils_Vector.c.

◆ _SWIZZLE4

#define _SWIZZLE4 (   a,
  b,
  c,
 
)     (_SWIZZLE3(a, b, c) | (((d) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3)))

Definition at line 2522 of file mathutils_Vector.c.

◆ MAX_DIMENSIONS

#define MAX_DIMENSIONS   4

Higher dimensions are supported, for many common operations (dealing with vector/matrix multiply or handling as 3D locations) stack memory is used with a fixed size - defined here.

Definition at line 39 of file mathutils_Vector.c.

◆ SWIZZLE2

#define SWIZZLE2 (   a,
 
)    POINTER_FROM_INT(_SWIZZLE2(a, b))

Definition at line 2525 of file mathutils_Vector.c.

◆ SWIZZLE3

#define SWIZZLE3 (   a,
  b,
 
)    POINTER_FROM_INT(_SWIZZLE3(a, b, c))

Definition at line 2526 of file mathutils_Vector.c.

◆ SWIZZLE4

#define SWIZZLE4 (   a,
  b,
  c,
 
)    POINTER_FROM_INT(_SWIZZLE4(a, b, c, d))

Definition at line 2527 of file mathutils_Vector.c.

◆ SWIZZLE_AXIS

#define SWIZZLE_AXIS   0x3

Definition at line 46 of file mathutils_Vector.c.

◆ SWIZZLE_BITS_PER_AXIS

#define SWIZZLE_BITS_PER_AXIS   3

Definition at line 44 of file mathutils_Vector.c.

◆ SWIZZLE_VALID_AXIS

#define SWIZZLE_VALID_AXIS   0x4

Definition at line 45 of file mathutils_Vector.c.

Function Documentation

◆ C_Vector_Fill()

static PyObject* C_Vector_Fill ( PyObject *  cls,
PyObject *  args 
)
static

Definition at line 122 of file mathutils_Vector.c.

References copy_vn_fl(), NULL, size(), and Vector_CreatePyObject_alloc().

◆ C_Vector_Linspace()

static PyObject* C_Vector_Linspace ( PyObject *  cls,
PyObject *  args 
)
static

Definition at line 238 of file mathutils_Vector.c.

References NULL, range_vn_fl(), size(), and Vector_CreatePyObject_alloc().

◆ C_Vector_Range()

static PyObject* C_Vector_Range ( PyObject *  cls,
PyObject *  args 
)
static

Definition at line 162 of file mathutils_Vector.c.

References NULL, range_vn_fl(), size(), and Vector_CreatePyObject_alloc().

◆ C_Vector_Repeat()

static PyObject* C_Vector_Repeat ( PyObject *  cls,
PyObject *  args 
)
static

◆ column_vector_multiplication()

int column_vector_multiplication ( float  r_vec[MAX_DIMENSIONS],
VectorObject vec,
MatrixObject mat 
)

Column vector multiplication (Matrix * Vector).

[1][4][7]   [a]
[2][5][8] * [b]
[3][6][9]   [c]
Note
Vector/Matrix multiplication is not commutative.
Assume read callbacks have been done first.

Definition at line 1690 of file mathutils_Vector.c.

References col, double(), float(), MATRIX_ITEM, MAX_DIMENSIONS, MatrixObject::num_col, MatrixObject::num_row, VectorObject::size, and z.

◆ PyDoc_STRVAR() [1/37]

PyDoc_STRVAR ( C_Vector_Fill_doc  ,
".. classmethod:: Fill(size, fill=0.0)\n" "\n" " Create a vector of length size with all values set to fill.\n" "\n" " :arg size: The length of the vector to be created.\n" " :type size: int\n" " :arg fill: The value used to fill the vector.\n" " :type fill: float\n"   
)

◆ PyDoc_STRVAR() [2/37]

PyDoc_STRVAR ( C_Vector_Linspace_doc  ,
".. classmethod:: Linspace(start, stop, size)\n" "\n" " Create a vector of the specified size which is filled with linearly spaced " "values between start and stop values.\n" "\n" " :arg start: The start of the range used to fill the vector.\n" " :type start: int\n" " :arg stop: The end of the range used to fill the vector.\n" " :type stop: int\n" " :arg size: The size of the vector to be created.\n" " :type size: int\n"   
)

◆ PyDoc_STRVAR() [3/37]

PyDoc_STRVAR ( C_Vector_Range_doc  ,
".. classmethod:: Range(start=0, stop, step=1)\n" "\n" " Create a filled with a range of values.\n" "\n" " :arg start: The start of the range used to fill the vector.\n" " :type start: int\n" " :arg stop: The end of the range used to fill the vector.\n" " :type stop: int\n" " :arg step: The step between successive values in the vector.\n" " :type step: int\n"   
)

◆ PyDoc_STRVAR() [4/37]

PyDoc_STRVAR ( C_Vector_Repeat_doc  ,
".. classmethod:: Repeat(vector, size)\n" "\n" " Create a vector by repeating the values in vector until the required size is reached.\n" "\n" " :arg tuple: The vector to draw values from.\n" " :type tuple: :class:`mathutils.Vector`\n" " :arg size: The size of the vector to be created.\n" " :type size: int\n"   
)

◆ PyDoc_STRVAR() [5/37]

PyDoc_STRVAR ( Vector_angle_doc  ,
".. function::   angleother, fallback=None)\n" "\n" " Return the angle between two vectors.\n" "\n" " :arg other: another vector to compare the angle with\n" " :type other: :class:`Vector`\n" " :arg fallback: return this when the angle can't be calculated (zero length vector,
\n" "(instead of raising a :exc:`ValueError`).\n" " :type fallback:any\n" " :return:angle in radians or fallback when given\n" " :rtype:float\n"   
)

◆ PyDoc_STRVAR() [6/37]

PyDoc_STRVAR ( Vector_angle_signed_doc  ,
".. function::   angle_signedother, fallback)\n" "\n" " Return the signed angle between two 2D vectors (clockwise is positive).\n" "\n" " :arg other: another vector to compare the angle with\n" " :type other: :class:`Vector`\n" " :arg fallback: return this when the angle can't be calculated (zero length vector,
\n" "(instead of raising a :exc:`ValueError`).\n" " :type fallback:any\n" " :return:angle in radians or fallback when given\n" " :rtype:float\n"   
)

◆ PyDoc_STRVAR() [7/37]

PyDoc_STRVAR ( Vector_axis_w_doc  ,
"Vector W axis (4D Vectors only).\n\n:type: float  
)

◆ PyDoc_STRVAR() [8/37]

PyDoc_STRVAR ( Vector_axis_x_doc  ,
"Vector X axis.\n\n:type: float  
)

◆ PyDoc_STRVAR() [9/37]

PyDoc_STRVAR ( Vector_axis_y_doc  ,
"Vector Y axis.\n\n:type: float  
)

◆ PyDoc_STRVAR() [10/37]

PyDoc_STRVAR ( Vector_axis_z_doc  ,
"Vector Z axis (3D Vectors only).\n\n:type: float  
)

◆ PyDoc_STRVAR() [11/37]

PyDoc_STRVAR ( Vector_copy_doc  ,
".. function:: copy()\n" "\n" " Returns a copy of this vector.\n" "\n" " :return: A copy of the vector.\n" " :rtype: :class:`Vector`\n" "\n" " .. note:: use this to get a copy of a wrapped vector with\n" " no reference to the original data.\n"   
)

◆ PyDoc_STRVAR() [12/37]

PyDoc_STRVAR ( Vector_cross_doc  ,
".. method:: cross(other)\n" "\n" " Return the cross product of this vector and another.\n" "\n" " :arg other: The other vector to perform the cross product with.\n" " :type other: :class:`Vector`\n" " :return: The cross product.\n" " :rtype: :class:`Vector` or float when 2D vectors are used\n" "\n" " .. note:: both vectors must be 2D or 3D\n"   
)

◆ PyDoc_STRVAR() [13/37]

PyDoc_STRVAR ( vector_doc  ,
".. class:: Vector(seq)\n" "\n" " This object gives access to Vectors in Blender.\n" "\n" " :param seq: Components of the  vector,
must be a sequence of at least two\n" " :type seq:sequence of numbers\n"   
)

Note: #Py_TPFLAGS_CHECKTYPES allows us to avoid casting all types to Vector when coercing but this means for eg that (vec * mat) and (mat * vec) both get sent to Vector_mul and it needs to sort out the order

◆ PyDoc_STRVAR() [14/37]

PyDoc_STRVAR ( Vector_dot_doc  ,
".. method:: dot(other)\n" "\n" " Return the dot product of this vector and another.\n" "\n" " :arg other: The other vector to perform the dot product with.\n" " :type other: :class:`Vector`\n" " :return: The dot product.\n" " :rtype: float\n"   
)

◆ PyDoc_STRVAR() [15/37]

PyDoc_STRVAR ( Vector_length_doc  ,
"Vector Length.\n\n:type: float  
)

◆ PyDoc_STRVAR() [16/37]

PyDoc_STRVAR ( Vector_length_squared_doc  ,
"Vector length squared (v.dot(v)).\n\n:type: float  
)

◆ PyDoc_STRVAR() [17/37]

PyDoc_STRVAR ( Vector_lerp_doc  ,
".. function:: lerp(other, factor)\n" "\n" " Returns the interpolation of two vectors.\n" "\n" " :arg other: value to interpolate with.\n" " :type other: :class:`Vector`\n" " :arg factor: The interpolation value in .\n" " :type factor: float\n" " :return: The interpolated vector.\n" " :rtype: :class:`Vector`\n"  [0.0, 1.0] 
)

◆ PyDoc_STRVAR() [18/37]

PyDoc_STRVAR ( Vector_negate_doc  ,
".. method:: negate()\n" "\n" " Set all values to their negative.\n"   
)

◆ PyDoc_STRVAR() [19/37]

PyDoc_STRVAR ( Vector_normalize_doc  ,
".. method:: normalize()\n" "\n" " Normalize the  vector,
making the length of the vector always 1.0.\n" "\n" " .. warning::Normalizing a vector where all values are zero has no effect.\n" "\n" " .. note::Normalize works for vectors of all  sizes,
\n" " however 4D Vectors w axis is left untouched.\n"   
)

◆ PyDoc_STRVAR() [20/37]

PyDoc_STRVAR ( Vector_normalized_doc  ,
".. method:: normalized()\n" "\n" " Return a  new,
normalized vector.\n" "\n" " :return:a normalized copy of the vector\n" " :rtype::class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [21/37]

PyDoc_STRVAR ( Vector_orthogonal_doc  ,
".. method:: orthogonal()\n" "\n" " Return a perpendicular vector.\n" "\n" " :return: a new vector 90 degrees from this vector.\n" " :rtype: :class:`Vector`\n" "\n" " .. note:: the axis is  undefined,
only use when any orthogonal vector is acceptable.\n"   
)

◆ PyDoc_STRVAR() [22/37]

PyDoc_STRVAR ( Vector_project_doc  ,
".. function:: project(other)\n" "\n" " Return the projection of this vector onto the *other*.\n" "\n" " :arg other: second vector.\n" " :type other: :class:`Vector`\n" " :return: the parallel projection vector\n" " :rtype: :class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [23/37]

PyDoc_STRVAR ( Vector_reflect_doc  ,
".. method:: reflect(mirror)\n" "\n" " Return the reflection vector from the *mirror* argument.\n" "\n" " :arg mirror: This vector could be a normal from the reflecting surface.\n" " :type mirror: :class:`Vector`\n" " :return: The reflected vector matching the size of this vector.\n" " :rtype: :class:`Vector`\n"   
)

Vector.reflect(mirror): return a reflected vector on the mirror normal.

vec - ((2 * dot(vec, mirror)) * mirror)

◆ PyDoc_STRVAR() [24/37]

PyDoc_STRVAR ( Vector_resize_2d_doc  ,
".. method:: resize_2d()\n" "\n" " Resize the vector to 2D (x, y).\n"   
)

◆ PyDoc_STRVAR() [25/37]

PyDoc_STRVAR ( Vector_resize_3d_doc  ,
".. method:: resize_3d()\n" "\n" " Resize the vector to 3D (x, y, z).\n"   
)

◆ PyDoc_STRVAR() [26/37]

PyDoc_STRVAR ( Vector_resize_4d_doc  ,
".. method:: resize_4d()\n" "\n" " Resize the vector to 4D (x, y, z, w).\n"   
)

◆ PyDoc_STRVAR() [27/37]

PyDoc_STRVAR ( Vector_resize_doc  ,
".. method:: resize(size=3)\n" "\n" " Resize the vector to have size number of elements.\n"   
)

◆ PyDoc_STRVAR() [28/37]

PyDoc_STRVAR ( Vector_resized_doc  ,
".. method:: resized(size=3)\n" "\n" " Return a resized copy of the vector with size number of elements.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [29/37]

PyDoc_STRVAR ( Vector_rotate_doc  ,
".. function:: rotate(other)\n" "\n" " Rotate the vector by a rotation value.\n" "\n" " .. note:: 2D vectors are a special case that can only be rotated by a 2x2 matrix.\n" "\n" " :arg other: rotation component of mathutils value\n" " :type other: :class:`Euler`  ,
:class:`Quaternion` or :class:`Matrix`\n"   
)

◆ PyDoc_STRVAR() [30/37]

PyDoc_STRVAR ( Vector_rotation_difference_doc  ,
".. function:: rotation_difference(other)\n" "\n" " Returns a quaternion representing the rotational difference between this\n" " vector and another.\n" "\n" " :arg other: second vector.\n" " :type other: :class:`Vector`\n" " :return: the rotational difference between the two vectors.\n" " :rtype: :class:`Quaternion`\n" "\n" " .. note:: 2D vectors raise an :exc:`AttributeError`.\n"   
)

◆ PyDoc_STRVAR() [31/37]

PyDoc_STRVAR ( Vector_slerp_doc  ,
".. function::   slerp(other, factor, fallback=None)\n" "\n" " Returns the interpolation of two non-zero vectors (spherical coordinates).\n" "\n" " :arg other: value to interpolate with.\n" " :type other: :class:`Vector`\n" " :arg factor: The interpolation value typically in .\n" " :type factor: float\n" " :arg fallback: return this when the vector can't be calculated (zero length " "vector or direct opposites)[0.0, 1.0],
\n" "(instead of raising a :exc:`ValueError`).\n" " :type fallback:any\n" " :return:The interpolated vector.\n" " :rtype::class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [32/37]

PyDoc_STRVAR ( Vector_to_2d_doc  ,
".. method:: to_2d()\n" "\n" " Return a 2d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [33/37]

PyDoc_STRVAR ( Vector_to_3d_doc  ,
".. method:: to_3d()\n" "\n" " Return a 3d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [34/37]

PyDoc_STRVAR ( Vector_to_4d_doc  ,
".. method:: to_4d()\n" "\n" " Return a 4d copy of the vector.\n" "\n" " :return: a new vector\n" " :rtype: :class:`Vector`\n"   
)

◆ PyDoc_STRVAR() [35/37]

PyDoc_STRVAR ( Vector_to_track_quat_doc  ,
".. method:: to_track_quat(track, up)\n" "\n" " Return a quaternion rotation from the vector and the track and up axis.\n" "\n" " :arg track: Track axis in .\n" " :type track: string\n" " :arg up: Up axis in .\n" " :type up: string\n" " :return: rotation from the vector and the track and up axis.\n" " :rtype: :class:`Quaternion`\n"  [ 'X', 'Y', 'Z', '-X', '-Y', '-Z'][ 'X', 'Y', 'Z'] 
)

◆ PyDoc_STRVAR() [36/37]

PyDoc_STRVAR ( Vector_to_tuple_doc  ,
".. method:: to_tuple(precision=-1)\n" "\n" " Return this vector as a tuple with.\n" "\n" " :arg precision: The number to round the value to in .\n" " :type precision: int\n" " :return: the values of the vector rounded by *precision*\n" " :rtype: tuple\n"  [-1, 21] 
)

◆ PyDoc_STRVAR() [37/37]

PyDoc_STRVAR ( Vector_zero_doc  ,
".. method:: zero()\n" "\n" " Set all values to zero.\n"   
)

◆ row_vector_multiplication()

static int row_vector_multiplication ( float  r_vec[MAX_DIMENSIONS],
VectorObject vec,
MatrixObject mat 
)
static

Row vector multiplication - (Vector * Matrix)

[x][y][z] * [1][4][7]
            [2][5][8]
            [3][6][9]
Note
vector/matrix multiplication is not commutative.

Definition at line 2916 of file mathutils_Vector.c.

References BaseMath_ReadCallback, col, double(), float(), MATRIX_ITEM, MAX_DIMENSIONS, MatrixObject::num_col, MatrixObject::num_row, VectorObject::size, and z.

Referenced by Vector_matmul().

◆ vec__apply_to_copy()

static PyObject* vec__apply_to_copy ( PyObject *(*)(VectorObject *)  vec_func,
VectorObject self 
)
static

Definition at line 99 of file mathutils_Vector.c.

References NULL, ret, and Vector_copy().

Referenced by Vector_normalized().

◆ Vector_add()

static PyObject* Vector_add ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_angle()

static PyObject* Vector_angle ( VectorObject self,
PyObject *  args 
)
static

◆ Vector_angle_signed()

static PyObject* Vector_angle_signed ( VectorObject self,
PyObject *  args 
)
static

◆ Vector_ass_item()

static int Vector_ass_item ( VectorObject self,
int  i,
PyObject *  value 
)
static

Definition at line 1457 of file mathutils_Vector.c.

References vector_ass_item_internal().

Referenced by Vector_ass_subscript().

◆ vector_ass_item_internal()

static int vector_ass_item_internal ( VectorObject self,
int  i,
PyObject *  value,
const bool  is_attr 
)
static

◆ Vector_ass_slice()

static int Vector_ass_slice ( VectorObject self,
int  begin,
int  end,
PyObject *  seq 
)
static

◆ Vector_ass_subscript()

static int Vector_ass_subscript ( VectorObject self,
PyObject *  item,
PyObject *  value 
)
static

Definition at line 2170 of file mathutils_Vector.c.

References self, Vector_ass_item(), and Vector_ass_slice().

◆ Vector_axis_get()

static PyObject* Vector_axis_get ( VectorObject self,
void *  type 
)
static

Definition at line 2256 of file mathutils_Vector.c.

References POINTER_AS_INT, type, and vector_item_internal().

◆ Vector_axis_set()

static int Vector_axis_set ( VectorObject self,
PyObject *  value,
void *  type 
)
static

Definition at line 2261 of file mathutils_Vector.c.

References POINTER_AS_INT, type, and vector_ass_item_internal().

◆ Vector_copy()

static PyObject * Vector_copy ( VectorObject self)
static

Definition at line 1322 of file mathutils_Vector.c.

References BaseMath_ReadCallback, NULL, self, and Vector_CreatePyObject().

Referenced by vec__apply_to_copy(), and Vector_deepcopy().

◆ Vector_CreatePyObject()

PyObject* Vector_CreatePyObject ( const float vec,
const int  size,
PyTypeObject *  base_type 
)

Definition at line 3120 of file mathutils_Vector.c.

References BASE_MATH_FLAG_DEFAULT, BASE_MATH_NEW, copy_vn_fl(), NULL, self, size(), UNLIKELY, and vector_Type.

Referenced by bpy_bmedge_calc_tangent(), bpy_bmface_calc_center_bounds(), bpy_bmface_calc_center_mean(), bpy_bmface_calc_center_median_weighted(), bpy_bmface_calc_tangent_edge(), bpy_bmface_calc_tangent_edge_diagonal(), bpy_bmface_calc_tangent_edge_pair(), bpy_bmface_calc_tangent_vert_diagonal(), bpy_bmloop_calc_normal(), bpy_bmloop_calc_tangent(), bpy_slot_to_py(), Freestyle_blendRamp(), Freestyle_evaluateColorRamp(), kdtree_nearest_to_py_tuple(), M_Geometry_barycentric_transform(), M_Geometry_closest_point_on_tri(), M_Geometry_interpolate_bezier(), M_Geometry_intersect_line_line(), M_Geometry_intersect_line_line_2d(), M_Geometry_intersect_line_plane(), M_Geometry_intersect_line_sphere(), M_Geometry_intersect_line_sphere_2d(), M_Geometry_intersect_plane_plane(), M_Geometry_intersect_point_line(), M_Geometry_intersect_point_tri(), M_Geometry_intersect_ray_tri(), M_Geometry_intersect_sphere_sphere_2d(), M_Geometry_normal(), M_Noise_noise_vector(), M_Noise_random_unit_vector(), M_Noise_turbulence_vector(), M_Noise_voronoi(), Matrix_decompose(), Matrix_matmul(), Matrix_to_scale(), Matrix_to_translation(), points_in_planes_fn(), py_bvhtree_nearest_to_py_tuple(), py_bvhtree_raycast_to_py_tuple(), pyrna_math_object_from_array(), pyrna_param_to_py(), Quaternion_axis_vector_get(), Quaternion_matmul(), Quaternion_to_axis_angle(), Quaternion_to_exponential_map(), Vector_copy(), Vector_CreatePyObject_cb(), Vector_cross(), Vector_from_Vec2f(), Vector_from_Vec3f(), Vector_from_Vec3r(), Vector_matmul(), Vector_orthogonal(), Vector_reflect(), Vector_slerp(), Vector_swizzle_get(), Vector_to_2d(), Vector_to_3d(), and Vector_to_4d().

◆ Vector_CreatePyObject_alloc()

PyObject* Vector_CreatePyObject_alloc ( float vec,
const int  size,
PyTypeObject *  base_type 
)

◆ Vector_CreatePyObject_cb()

PyObject* Vector_CreatePyObject_cb ( PyObject *  cb_user,
int  size,
uchar  cb_type,
uchar  cb_subtype 
)

◆ Vector_CreatePyObject_wrap()

PyObject* Vector_CreatePyObject_wrap ( float vec,
const int  size,
PyTypeObject *  base_type 
)

◆ Vector_cross()

static PyObject* Vector_cross ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_deepcopy()

static PyObject * Vector_deepcopy ( VectorObject self,
PyObject *  args 
)
static

Definition at line 1330 of file mathutils_Vector.c.

References NULL, PyC_CheckArgs_DeepCopy(), and Vector_copy().

◆ Vector_div()

static PyObject* Vector_div ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_dot()

static PyObject* Vector_dot ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_hash()

static Py_hash_t Vector_hash ( VectorObject self)
static

◆ Vector_iadd()

static PyObject* Vector_iadd ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_idiv()

static PyObject* Vector_idiv ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_imatmul()

static PyObject* Vector_imatmul ( PyObject *  v1,
PyObject *  v2 
)
static

Definition at line 1919 of file mathutils_Vector.c.

References NULL, v1, and v2.

◆ Vector_imul()

static PyObject* Vector_imul ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_isub()

static PyObject* Vector_isub ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_item()

static PyObject* Vector_item ( VectorObject self,
int  i 
)
static

Definition at line 1410 of file mathutils_Vector.c.

References vector_item_internal().

Referenced by Vector_subscript().

◆ vector_item_internal()

static PyObject* vector_item_internal ( VectorObject self,
int  i,
const bool  is_attr 
)
static

Definition at line 1384 of file mathutils_Vector.c.

References BaseMath_ReadIndexCallback, NULL, and self.

Referenced by Vector_axis_get(), and Vector_item().

◆ Vector_len()

static int Vector_len ( VectorObject self)
static

Definition at line 1379 of file mathutils_Vector.c.

◆ Vector_length_get()

static PyObject* Vector_length_get ( VectorObject self,
void *  UNUSEDclosure 
)
static

Definition at line 2269 of file mathutils_Vector.c.

References BaseMath_ReadCallback, dot_vn_vn(), NULL, self, and sqrt().

◆ Vector_length_set()

static int Vector_length_set ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_length_squared_get()

static PyObject* Vector_length_squared_get ( VectorObject self,
void *  UNUSEDclosure 
)
static

Definition at line 2324 of file mathutils_Vector.c.

References BaseMath_ReadCallback, dot_vn_vn(), NULL, and self.

◆ Vector_lerp()

static PyObject* Vector_lerp ( VectorObject self,
PyObject *  args 
)
static

◆ Vector_matmul()

static PyObject* Vector_matmul ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_mul()

static PyObject* Vector_mul ( PyObject *  v1,
PyObject *  v2 
)
static

◆ vector_mul_float()

static PyObject* vector_mul_float ( VectorObject vec,
const float  scalar 
)
static

Definition at line 1723 of file mathutils_Vector.c.

References mul_vn_vn_fl(), NULL, VectorObject::size, and Vector_CreatePyObject_alloc().

Referenced by Vector_mul().

◆ vector_mul_vec()

static PyObject* vector_mul_vec ( VectorObject vec1,
VectorObject vec2 
)
static

Definition at line 1737 of file mathutils_Vector.c.

References mul_vn_vnvn(), NULL, VectorObject::size, and Vector_CreatePyObject_alloc().

Referenced by Vector_mul().

◆ Vector_neg()

static PyObject* Vector_neg ( VectorObject self)
static

◆ Vector_negate()

static PyObject* Vector_negate ( VectorObject self)
static

Definition at line 2958 of file mathutils_Vector.c.

◆ Vector_new()

static PyObject* Vector_new ( PyTypeObject *  type,
PyObject *  args,
PyObject *  kwds 
)
static

Supports 2D, 3D, and 4D vector objects both int and float values accepted. Mixed float and int values accepted. Ints are parsed to float

Definition at line 59 of file mathutils_Vector.c.

References copy_vn_fl(), mathutils_array_parse_alloc(), NULL, size(), type, and Vector_CreatePyObject_alloc().

◆ Vector_normalize()

static PyObject* Vector_normalize ( VectorObject self)
static

◆ Vector_normalized()

static PyObject* Vector_normalized ( VectorObject self)
static

Definition at line 376 of file mathutils_Vector.c.

References vec__apply_to_copy(), and Vector_normalize().

◆ Vector_orthogonal()

static PyObject* Vector_orthogonal ( VectorObject self)
static

◆ Vector_project()

static PyObject* Vector_project ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_reflect()

static PyObject* Vector_reflect ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_repr()

static PyObject* Vector_repr ( VectorObject self)
static

Definition at line 1338 of file mathutils_Vector.c.

References BaseMath_ReadCallback, NULL, ret, and Vector_to_tuple_ex().

◆ Vector_resize()

static PyObject* Vector_resize ( VectorObject self,
PyObject *  value 
)
static

Definition at line 385 of file mathutils_Vector.c.

References BASE_MATH_FLAG_IS_WRAP, copy_vn_fl(), NULL, self, and size().

◆ Vector_resize_2d()

static PyObject* Vector_resize_2d ( VectorObject self)
static

Definition at line 471 of file mathutils_Vector.c.

References BASE_MATH_FLAG_IS_WRAP, NULL, and self.

◆ Vector_resize_3d()

static PyObject* Vector_resize_3d ( VectorObject self)
static

Definition at line 502 of file mathutils_Vector.c.

References BASE_MATH_FLAG_IS_WRAP, NULL, and self.

◆ Vector_resize_4d()

static PyObject* Vector_resize_4d ( VectorObject self)
static

Definition at line 537 of file mathutils_Vector.c.

References BASE_MATH_FLAG_IS_WRAP, NULL, and self.

◆ Vector_resized()

static PyObject* Vector_resized ( VectorObject self,
PyObject *  value 
)
static

Definition at line 438 of file mathutils_Vector.c.

References copy_vn_fl(), NULL, self, size(), and Vector_CreatePyObject_alloc().

◆ Vector_richcmpr()

static PyObject* Vector_richcmpr ( PyObject *  objectA,
PyObject *  objectB,
int  comparison_type 
)
static

◆ Vector_rotate()

static PyObject* Vector_rotate ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_rotation_difference()

static PyObject* Vector_rotation_difference ( VectorObject self,
PyObject *  value 
)
static

◆ Vector_slerp()

static PyObject* Vector_slerp ( VectorObject self,
PyObject *  args 
)
static

◆ Vector_slice()

static PyObject* Vector_slice ( VectorObject self,
int  begin,
int  end 
)
static

Definition at line 1463 of file mathutils_Vector.c.

References BaseMath_ReadCallback, CLAMP, count, MIN2, NULL, and self.

Referenced by Vector_subscript().

◆ Vector_str()

static PyObject* Vector_str ( VectorObject self)
static

◆ Vector_sub()

static PyObject* Vector_sub ( PyObject *  v1,
PyObject *  v2 
)
static

◆ Vector_subscript()

static PyObject* Vector_subscript ( VectorObject self,
PyObject *  item 
)
static

Definition at line 2134 of file mathutils_Vector.c.

References NULL, self, Vector_item(), and Vector_slice().

◆ Vector_swizzle_get()

static PyObject* Vector_swizzle_get ( VectorObject self,
void *  closure 
)
static

Python script used to make swizzle array:

SWIZZLE_BITS_PER_AXIS = 3
SWIZZLE_VALID_AXIS = 0x4
axis_dict = {}
axis_pos = {'x': 0, 'y': 1, 'z': 2, 'w': 3}
axis_chars = 'xyzw'
while len(axis_chars) >= 2:
for axis_0 in axis_chars:
axis_0_pos = axis_pos[axis_0]
for axis_1 in axis_chars:
axis_1_pos = axis_pos[axis_1]
axis_dict[axis_0 + axis_1] = (
'((%s | SWIZZLE_VALID_AXIS) | '
'((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS))' %
(axis_0_pos, axis_1_pos))
if len(axis_chars) > 2:
for axis_2 in axis_chars:
axis_2_pos = axis_pos[axis_2]
axis_dict[axis_0 + axis_1 + axis_2] = (
'((%s | SWIZZLE_VALID_AXIS) | '
'((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | '
'((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))' %
(axis_0_pos, axis_1_pos, axis_2_pos))
if len(axis_chars) > 3:
for axis_3 in axis_chars:
axis_3_pos = axis_pos[axis_3]
axis_dict[axis_0 + axis_1 + axis_2 + axis_3] = (
'((%s | SWIZZLE_VALID_AXIS) | '
'((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | '
'((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)) | '
'((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3))) '
%
(axis_0_pos, axis_1_pos, axis_2_pos, axis_3_pos))
axis_chars = axis_chars[:-1]
items = list(axis_dict.items())
items.sort(
key=lambda a: a[0].replace('x', '0').replace('y', '1').replace('z', '2').replace('w', '3')
)
unique = set()
for key, val in items:
num = eval(val)
set_str = 'Vector_swizzle_set' if (len(set(key)) == len(key)) else 'NULL'
key_args = ', '.join(["'%s'" % c for c in key.upper()])
print('\t{"%s", %s(getter)Vector_swizzle_get, (setter)%s, NULL, SWIZZLE%d(%s)},' %
(key, (' ' * (4 - len(key))), set_str, len(key), key_args))
unique.add(num)
if len(unique) != len(items):
print("ERROR, duplicate values found")
uint len

Get a new Vector according to the provided swizzle bits.

Definition at line 2394 of file mathutils_Vector.c.

References BaseMath_ReadCallback, MAX_DIMENSIONS, NULL, POINTER_AS_INT, self, SWIZZLE_AXIS, SWIZZLE_BITS_PER_AXIS, SWIZZLE_VALID_AXIS, and Vector_CreatePyObject().

◆ Vector_swizzle_set()

static int Vector_swizzle_set ( VectorObject self,
PyObject *  value,
void *  closure 
)
static

Set the items of this vector using a swizzle.

  • If value is a vector or list this operates like an array copy, except that the destination is effectively re-ordered as defined by the swizzle. At most min(len(source), len(dest)) values will be copied.
  • If the value is scalar, it is copied to all axes listed in the swizzle.
  • If an axis appears more than once in the swizzle, the final occurrence is the one that determines its value.
Returns
0 on success and -1 on failure. On failure, the vector will be unchanged.

Definition at line 2436 of file mathutils_Vector.c.

References BaseMath_ReadCallback_ForWrite, BaseMath_WriteCallback, mathutils_array_parse(), MAX_DIMENSIONS, POINTER_AS_INT, self, SWIZZLE_AXIS, SWIZZLE_BITS_PER_AXIS, and SWIZZLE_VALID_AXIS.

◆ Vector_to_2d()

static PyObject* Vector_to_2d ( VectorObject self)
static

Definition at line 577 of file mathutils_Vector.c.

References BaseMath_ReadCallback, NULL, self, and Vector_CreatePyObject().

◆ Vector_to_3d()

static PyObject* Vector_to_3d ( VectorObject self)
static

Definition at line 592 of file mathutils_Vector.c.

References BaseMath_ReadCallback, MIN2, NULL, self, and Vector_CreatePyObject().

◆ Vector_to_4d()

static PyObject* Vector_to_4d ( VectorObject self)
static

Definition at line 610 of file mathutils_Vector.c.

References BaseMath_ReadCallback, MIN2, NULL, self, and Vector_CreatePyObject().

◆ Vector_to_track_quat()

static PyObject* Vector_to_track_quat ( VectorObject self,
PyObject *  args 
)
static

◆ Vector_to_tuple()

static PyObject* Vector_to_tuple ( VectorObject self,
PyObject *  args 
)
static

Definition at line 653 of file mathutils_Vector.c.

References BaseMath_ReadCallback, NULL, and Vector_to_tuple_ex().

◆ Vector_to_tuple_ex()

static PyObject * Vector_to_tuple_ex ( VectorObject self,
int  ndigits 
)
static

Definition at line 632 of file mathutils_Vector.c.

References double_round(), ret, and self.

Referenced by Vector_repr(), and Vector_to_tuple().

◆ Vector_zero()

static PyObject* Vector_zero ( VectorObject self)
static

Variable Documentation

◆ Vector_AsMapping

PyMappingMethods Vector_AsMapping
static
Initial value:
= {
(lenfunc)Vector_len,
(binaryfunc)Vector_subscript,
(objobjargproc)Vector_ass_subscript,
}
static PyObject * Vector_subscript(VectorObject *self, PyObject *item)
static int Vector_len(VectorObject *self)
static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value)

Definition at line 2202 of file mathutils_Vector.c.

◆ Vector_getseters

PyGetSetDef Vector_getseters[]
static

Definition at line 2532 of file mathutils_Vector.c.

◆ Vector_methods

struct PyMethodDef Vector_methods[]
static

Definition at line 2958 of file mathutils_Vector.c.

◆ Vector_NumMethods

PyNumberMethods Vector_NumMethods
static

Definition at line 2208 of file mathutils_Vector.c.

◆ Vector_SeqMethods

PySequenceMethods Vector_SeqMethods
static
Initial value:
= {
(lenfunc)Vector_len,
(binaryfunc)NULL,
(ssizeargfunc)NULL,
(ssizeargfunc)Vector_item,
NULL,
(ssizeobjargproc)Vector_ass_item,
NULL,
(objobjproc)NULL,
(binaryfunc)NULL,
(ssizeargfunc)NULL,
}
static int Vector_ass_item(VectorObject *self, int i, PyObject *value)
static PyObject * Vector_item(VectorObject *self, int i)

Definition at line 2121 of file mathutils_Vector.c.

◆ vector_Type

PyTypeObject vector_Type