Blender V4.3
mathutils_Vector.cc File Reference
#include <algorithm>
#include <Python.h>
#include "mathutils.hh"
#include "BLI_math_base_safe.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "../generic/py_capi_utils.hh"
#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
 

Functions

Vector Methods: Copy/Deep-Copy
static PyObject * Vector_copy (VectorObject *self)
 
static PyObject * Vector_deepcopy (VectorObject *self, PyObject *args)
 
 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")
 
Utilities
static int row_vector_multiplication (float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
 
static PyObject * vec__apply_to_copy (PyObject *(*vec_func)(VectorObject *), VectorObject *self)
 
static PyObject * Vector_to_tuple_ex (VectorObject *self, int ndigits)
 
Vector Type: <tt>__new__</tt> / <tt>mathutils.Vector()</tt>
static PyObject * Vector_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 
Vector Class Methods
 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, 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 vector: The vector to draw values from.\n" " :type vector: :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)
 
Vector Methods: Zero
 PyDoc_STRVAR (Vector_zero_doc, ".. method:: zero()\n" "\n" " Set all values to zero.\n")
 
static PyObject * Vector_zero (VectorObject *self)
 
Vector Methods: Normalize
 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)
 
Vector Methods: Resize
 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)
 
Vector Methods: To N-dimensions
 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)
 
Vector Methods: To Tuple
 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[float]\n")
 
static PyObject * Vector_to_tuple (VectorObject *self, PyObject *args)
 
Vector Methods: To Track Quaternion
 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: str\n" " :arg up: Up axis in ['X', 'Y', 'Z'].\n" " :type up: str\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)
 
Vector Methods: Orthogonal
 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)
 
Vector Methods: Reflect

Vector.reflect(mirror): return a reflected vector on the mirror normal: vec - ((2 * dot(vec, mirror)) * mirror).

 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)
 
Vector Methods: Cross Product
 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 as a vector or a float when 2D vectors are used.\n" " :rtype: :class:`Vector` | float\n" "\n" " .. note:: both vectors must be 2D or 3D\n")
 
static PyObject * Vector_cross (VectorObject *self, PyObject *value)
 
Vector Methods: Dot Product
 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)
 
Vector Methods: Angle
 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 | Any\n")
 
static PyObject * Vector_angle (VectorObject *self, PyObject *args)
 
Vector Methods: Angle Signed
 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 | Any\n")
 
static PyObject * Vector_angle_signed (VectorObject *self, PyObject *args)
 
Vector Methods: Rotation Difference
 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)
 
Vector Methods: Project
 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)
 
Vector Methods: Linear Interpolation
 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)
 
Vector Methods: Spherical Interpolation
 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)
 
Vector Methods: Rotate
 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` | :class:`Matrix`\n")
 
static PyObject * Vector_rotate (VectorObject *self, PyObject *value)
 
Vector Methods: Negate
 PyDoc_STRVAR (Vector_negate_doc, ".. method:: negate()\n" "\n" " Set all values to their negative.\n")
 
static PyObject * Vector_negate (VectorObject *self)
 
Vector Type: <tt>__repr__</tt> & <tt>__str__</tt>
static PyObject * Vector_repr (VectorObject *self)
 
static PyObject * Vector_str (VectorObject *self)
 
Vector Type: Rich Compare
static PyObject * Vector_richcmpr (PyObject *objectA, PyObject *objectB, int comparison_type)
 
Vector Type: Hash (<tt>__hash__</tt>)
static Py_hash_t Vector_hash (VectorObject *self)
 
Vector Type: Sequence & Mapping Protocols Implementation
static Py_ssize_t Vector_len (VectorObject *self)
 
static PyObject * vector_item_internal (VectorObject *self, int i, const bool is_attr)
 
static PyObject * Vector_item (VectorObject *self, Py_ssize_t i)
 
static int vector_ass_item_internal (VectorObject *self, int i, PyObject *value, const bool is_attr)
 
static int Vector_ass_item (VectorObject *self, Py_ssize_t 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_subscript (VectorObject *self, PyObject *item)
 
static int Vector_ass_subscript (VectorObject *self, PyObject *item, PyObject *value)
 
Vector Type: Numeric Protocol Implementation
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)
 
Vector Type: C/API Constructors
PyObject * Vector_CreatePyObject (const float *vec, const int vec_num, PyTypeObject *base_type)
 
PyObject * Vector_CreatePyObject_wrap (float *vec, const int vec_num, PyTypeObject *base_type)
 
PyObject * Vector_CreatePyObject_cb (PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
 
PyObject * Vector_CreatePyObject_alloc (float *vec, const int vec_num, PyTypeObject *base_type)
 

Variables

Vector Type: Protocol Declarations
static PySequenceMethods Vector_SeqMethods
 
static PyMappingMethods Vector_AsMapping
 
static PyNumberMethods Vector_NumMethods
 
Vector Type: Get/Set Item Definitions
static PyGetSetDef Vector_getseters []
 
Vector Type: Method Definitions
static PyMethodDef Vector_methods []
 

Vector Type: Get/Set Item Implementation

#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))
 
#define VECTOR_SWIZZLE2_RW_DEF(attr, a, b)
 
#define VECTOR_SWIZZLE2_RO_DEF(attr, a, b)
 
#define VECTOR_SWIZZLE3_RW_DEF(attr, a, b, c)
 
#define VECTOR_SWIZZLE3_RO_DEF(attr, a, b, c)
 
#define VECTOR_SWIZZLE4_RW_DEF(attr, a, b, c, d)
 
#define VECTOR_SWIZZLE4_RO_DEF(attr, a, b, c, d)
 
 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 *)
 
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 *)
 
 PyDoc_STRVAR (Vector_swizzle_doc, ":type: :class:`Vector`")
 
static PyObject * Vector_swizzle_get (VectorObject *self, void *closure)
 
static int Vector_swizzle_set (VectorObject *self, PyObject *value, void *closure)
 

Vector Type: Python Object Definition

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
PyTypeObject vector_Type
 
 PyDoc_STRVAR (vector_doc, ".. class:: Vector(seq)\n" "\n" " This object gives access to Vectors in Blender.\n" "\n" " :arg seq: Components of the vector, must be a sequence of at least two.\n" " :type seq: Sequence[float]\n")
 

Macro Definition Documentation

◆ _SWIZZLE1

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

Definition at line 2856 of file mathutils_Vector.cc.

◆ _SWIZZLE2

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

Definition at line 2857 of file mathutils_Vector.cc.

◆ _SWIZZLE3

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

Definition at line 2858 of file mathutils_Vector.cc.

◆ _SWIZZLE4

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

Definition at line 2860 of file mathutils_Vector.cc.

◆ 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 32 of file mathutils_Vector.cc.

Referenced by column_vector_multiplication(), row_vector_multiplication(), Vector_angle(), Vector_matmul(), Vector_reflect(), Vector_rotation_difference(), Vector_swizzle_get(), and Vector_swizzle_set().

◆ SWIZZLE2

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

Definition at line 2863 of file mathutils_Vector.cc.

◆ SWIZZLE3

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

Definition at line 2864 of file mathutils_Vector.cc.

◆ SWIZZLE4

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

Definition at line 2865 of file mathutils_Vector.cc.

◆ SWIZZLE_AXIS

#define SWIZZLE_AXIS   0x3

Definition at line 41 of file mathutils_Vector.cc.

Referenced by Vector_swizzle_get(), and Vector_swizzle_set().

◆ SWIZZLE_BITS_PER_AXIS

#define SWIZZLE_BITS_PER_AXIS   3

Swizzle axes get packed into a single value that is used as a closure. Each axis uses SWIZZLE_BITS_PER_AXIS bits. The first bit (SWIZZLE_VALID_AXIS) is used as a sentinel: if it is unset, the axis is not valid.

Definition at line 39 of file mathutils_Vector.cc.

Referenced by Vector_swizzle_get(), and Vector_swizzle_set().

◆ SWIZZLE_VALID_AXIS

#define SWIZZLE_VALID_AXIS   0x4

Definition at line 40 of file mathutils_Vector.cc.

Referenced by Vector_swizzle_get(), and Vector_swizzle_set().

◆ VECTOR_SWIZZLE2_RO_DEF

#define VECTOR_SWIZZLE2_RO_DEF ( attr,
a,
b )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter) nullptr, Vector_swizzle_doc, SWIZZLE2(a, b), \
}
local_group_size(16, 16) .push_constant(Type b
static PyObject * Vector_swizzle_get(VectorObject *self, void *closure)
#define SWIZZLE2(a, b)

Definition at line 2872 of file mathutils_Vector.cc.

◆ VECTOR_SWIZZLE2_RW_DEF

#define VECTOR_SWIZZLE2_RW_DEF ( attr,
a,
b )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, Vector_swizzle_doc, \
SWIZZLE2(a, b), \
}
static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure)

Definition at line 2867 of file mathutils_Vector.cc.

◆ VECTOR_SWIZZLE3_RO_DEF

#define VECTOR_SWIZZLE3_RO_DEF ( attr,
a,
b,
c )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter) nullptr, Vector_swizzle_doc, SWIZZLE3(a, b, c), \
}
#define SWIZZLE3(a, b, c)

Definition at line 2881 of file mathutils_Vector.cc.

◆ VECTOR_SWIZZLE3_RW_DEF

#define VECTOR_SWIZZLE3_RW_DEF ( attr,
a,
b,
c )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, Vector_swizzle_doc, \
SWIZZLE3(a, b, c), \
}

Definition at line 2876 of file mathutils_Vector.cc.

◆ VECTOR_SWIZZLE4_RO_DEF

#define VECTOR_SWIZZLE4_RO_DEF ( attr,
a,
b,
c,
d )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter) nullptr, Vector_swizzle_doc, SWIZZLE4(a, b, c, d) \
}
#define SWIZZLE4(a, b, c, d)

Definition at line 2890 of file mathutils_Vector.cc.

◆ VECTOR_SWIZZLE4_RW_DEF

#define VECTOR_SWIZZLE4_RW_DEF ( attr,
a,
b,
c,
d )
Value:
{ \
attr, (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, Vector_swizzle_doc, \
SWIZZLE4(a, b, c, d), \
}

Definition at line 2885 of file mathutils_Vector.cc.

Function Documentation

◆ C_Vector_Fill()

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

Definition at line 199 of file mathutils_Vector.cc.

References copy_vn_fl(), and Vector_CreatePyObject_alloc().

◆ C_Vector_Linspace()

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

Definition at line 319 of file mathutils_Vector.cc.

References range_vn_fl(), and Vector_CreatePyObject_alloc().

◆ C_Vector_Range()

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

Definition at line 241 of file mathutils_Vector.cc.

References range_vn_fl(), 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 )

◆ PyDoc_STRVAR() [1/38]

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/38]

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/38]

PyDoc_STRVAR ( C_Vector_Range_doc ,
".. classmethod:: Range(start, 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/38]

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 vector: The vector to draw values from.\n" " :type vector: :class:`mathutils.Vector`\n" " :arg size: The size of the vector to be created.\n" " :type size: int\n"  )

◆ PyDoc_STRVAR() [5/38]

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|Any\n"  )

◆ PyDoc_STRVAR() [6/38]

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|Any\n"  )

◆ PyDoc_STRVAR() [7/38]

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

◆ PyDoc_STRVAR() [8/38]

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

◆ PyDoc_STRVAR() [9/38]

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

◆ PyDoc_STRVAR() [10/38]

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

◆ PyDoc_STRVAR() [11/38]

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/38]

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 as a vector or a float when 2D vectors are used.\n" " :rtype: :class:`Vector` | float\n" "\n" " .. note:: both vectors must be 2D or 3D\n"  )

◆ PyDoc_STRVAR() [13/38]

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

◆ PyDoc_STRVAR() [14/38]

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/38]

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

◆ PyDoc_STRVAR() [16/38]

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

◆ PyDoc_STRVAR() [17/38]

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/38]

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

◆ PyDoc_STRVAR() [19/38]

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/38]

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/38]

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/38]

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/38]

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"  )

◆ PyDoc_STRVAR() [24/38]

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

◆ PyDoc_STRVAR() [25/38]

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

◆ PyDoc_STRVAR() [26/38]

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

◆ PyDoc_STRVAR() [27/38]

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

◆ PyDoc_STRVAR() [28/38]

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/38]

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` | :class:`Matrix`\n"  )

◆ PyDoc_STRVAR() [30/38]

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/38]

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/38]

PyDoc_STRVAR ( Vector_swizzle_doc ,
":type: :class:`Vector`"  )

◆ PyDoc_STRVAR() [33/38]

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() [34/38]

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() [35/38]

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() [36/38]

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: str\n" " :arg up: Up axis in .\n" " :type up: str\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() [37/38]

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][float] )

◆ PyDoc_STRVAR() [38/38]

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 59 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, col, MatrixObject::col_num, double(), float, MATRIX_ITEM, MAX_DIMENSIONS, MatrixObject::row_num, VectorObject::vec_num, and z().

Referenced by Vector_matmul().

◆ vec__apply_to_copy()

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

Definition at line 96 of file mathutils_Vector.cc.

References ret, self, and Vector_copy().

Referenced by Vector_normalized().

◆ Vector_add()

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

Addition: object + object.

Definition at line 1967 of file mathutils_Vector.cc.

References add_vn_vnvn(), BaseMath_ReadCallback, v2, VectorObject::vec_num, Vector_CreatePyObject_alloc(), and VectorObject_Check.

◆ 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,
Py_ssize_t i,
PyObject * value )
static

Sequence accessor (set): object[i] = x.

Definition at line 1822 of file mathutils_Vector.cc.

References self, and 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

Sequence slice accessor (set): object[i:j] = x.

Definition at line 1853 of file mathutils_Vector.cc.

References BaseMath_ReadCallback_ForWrite, BaseMath_WriteCallback, CLAMP, mathutils_array_parse_alloc(), and self.

Referenced by Vector_ass_subscript().

◆ Vector_ass_subscript()

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

Sequence generic subscript (set): object[...] = x.

Definition at line 1928 of file mathutils_Vector.cc.

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 2552 of file mathutils_Vector.cc.

References POINTER_AS_INT, self, and vector_item_internal().

◆ Vector_axis_set()

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

Definition at line 2557 of file mathutils_Vector.cc.

References POINTER_AS_INT, self, and vector_ass_item_internal().

◆ Vector_copy()

static PyObject * Vector_copy ( VectorObject * self)
static

Definition at line 1568 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, self, and Vector_CreatePyObject().

Referenced by vec__apply_to_copy(), and Vector_deepcopy().

◆ Vector_CreatePyObject()

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

Definition at line 3472 of file mathutils_Vector.cc.

References BASE_MATH_FLAG_DEFAULT, BASE_MATH_NEW, copy_vn_fl(), self, 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_delaunay_2d_cdt(), 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_cell_vector(), 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,
int vec_num,
PyTypeObject * base_type )

◆ Vector_CreatePyObject_cb()

◆ Vector_CreatePyObject_wrap()

PyObject * Vector_CreatePyObject_wrap ( float * vec,
int vec_num,
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 1576 of file mathutils_Vector.cc.

References PyC_CheckArgs_DeepCopy(), self, 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

Division in-place: object /= object.

Definition at line 2409 of file mathutils_Vector.cc.

References BaseMath_ReadCallback_ForWrite, BaseMath_WriteCallback, mul_vn_fl(), v2, and VectorObject::vec_num.

◆ Vector_imatmul()

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

Multiplication in-place (matrix multiply): object @= object.

Definition at line 2351 of file mathutils_Vector.cc.

References v2.

◆ Vector_imul()

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

Multiplication in-place (element-wise or scalar): object *= object.

Definition at line 2233 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, BaseMath_ReadCallback_ForWrite, BaseMath_WriteCallback, mul_vn_fl(), mul_vn_vn(), v2, VectorObject::vec_num, and VectorObject_Check.

◆ Vector_isub()

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

Subtraction in-place: object -= object.

Definition at line 2084 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, BaseMath_ReadCallback_ForWrite, BaseMath_WriteCallback, sub_vn_vn(), v2, VectorObject::vec_num, and VectorObject_Check.

◆ Vector_item()

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

Sequence accessor (get): x = object[i].

Definition at line 1774 of file mathutils_Vector.cc.

References self, and 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 1747 of file mathutils_Vector.cc.

References BaseMath_ReadIndexCallback, and self.

Referenced by Vector_axis_get(), and Vector_item().

◆ Vector_len()

static Py_ssize_t Vector_len ( VectorObject * self)
static

Sequence length: len(object).

Definition at line 1742 of file mathutils_Vector.cc.

References self.

◆ Vector_length_get()

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

Definition at line 2570 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, dot_vn_vn(), 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 *  )
static

Definition at line 2630 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, dot_vn_vn(), 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

Multiplication (element-wise or scalar): object * object.

Definition at line 2181 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, v2, VectorObject::vec_num, vector_mul_float(), vector_mul_vec(), and VectorObject_Check.

◆ vector_mul_float()

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

Definition at line 2152 of file mathutils_Vector.cc.

References mul_vn_vn_fl(), VectorObject::vec_num, and Vector_CreatePyObject_alloc().

Referenced by Vector_mul().

◆ vector_mul_vec()

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

Definition at line 2166 of file mathutils_Vector.cc.

References mul_vn_vnvn(), VectorObject::vec_num, and Vector_CreatePyObject_alloc().

Referenced by Vector_mul().

◆ Vector_neg()

static PyObject * Vector_neg ( VectorObject * self)
static

Negative (returns the negative of this object): -object.

Definition at line 2442 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, negate_vn_vn(), self, and Vector_CreatePyObject_alloc().

◆ Vector_negate()

static PyObject * Vector_negate ( VectorObject * self)
static

Definition at line 1538 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, BaseMath_WriteCallback, negate_vn(), and self.

◆ 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 141 of file mathutils_Vector.cc.

References copy_vn_fl(), mathutils_array_parse_alloc(), 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 476 of file mathutils_Vector.cc.

References self, 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 1590 of file mathutils_Vector.cc.

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

◆ Vector_resize()

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

Definition at line 493 of file mathutils_Vector.cc.

References BASE_MATH_FLAG_IS_WRAP, copy_vn_fl(), and self.

◆ Vector_resize_2d()

static PyObject * Vector_resize_2d ( VectorObject * self)
static

Definition at line 583 of file mathutils_Vector.cc.

References BASE_MATH_FLAG_IS_WRAP, and self.

◆ Vector_resize_3d()

static PyObject * Vector_resize_3d ( VectorObject * self)
static

Definition at line 616 of file mathutils_Vector.cc.

References BASE_MATH_FLAG_IS_WRAP, and self.

◆ Vector_resize_4d()

static PyObject * Vector_resize_4d ( VectorObject * self)
static

Definition at line 653 of file mathutils_Vector.cc.

References BASE_MATH_FLAG_IS_WRAP, and self.

◆ Vector_resized()

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

Definition at line 548 of file mathutils_Vector.cc.

References copy_vn_fl(), self, 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

Sequence slice accessor (get): x = object[i:j].

Definition at line 1828 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, CLAMP, count, 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

Subtraction: object - object.

Definition at line 2043 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, sub_vn_vnvn(), v2, VectorObject::vec_num, Vector_CreatePyObject_alloc(), and VectorObject_Check.

◆ Vector_subscript()

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

Sequence generic subscript (get): x = object[...].

Definition at line 1891 of file mathutils_Vector.cc.

References 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] = (
"(({:d} | SWIZZLE_VALID_AXIS) | "
"(({:d} | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS))"
).format(axis_0_pos, axis_1_pos)
if len(axis_chars) <= 2:
continue
for axis_2 in axis_chars:
axis_2_pos = axis_pos[axis_2]
axis_dict[axis_0 + axis_1 + axis_2] = (
"(({:d} | SWIZZLE_VALID_AXIS) | "
"(({:d} | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | "
"(({:d} | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))"
).format(axis_0_pos, axis_1_pos, axis_2_pos)
if len(axis_chars) <= 3:
continue
for axis_3 in axis_chars:
axis_3_pos = axis_pos[axis_3]
axis_dict[axis_0 + axis_1 + axis_2 + axis_3] = (
"(({:d} | SWIZZLE_VALID_AXIS) | "
"(({:d} | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | "
"(({:d} | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)) | "
"(({:d} | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3)))"
).format(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")
)
for size in range(2, 5):
for rw_pass in (True, False):
key_args = ", ".join(list("abcd"[:size]))
print("#define VECTOR_SWIZZLE{:d}_{:s}_DEF(attr, {:s}) \\".format(
size,
"RW" if rw_pass else "RO",
key_args,
))
print(" {{attr, (getter){:s}, (setter){:s}, {:s}, SWIZZLE{:d}({:s}), }}".format(
"Vector_swizzle_get",
"Vector_swizzle_set" if rw_pass else "nullptr",
"Vector_swizzle_doc",
size,
key_args,
))
print()
unique = set()
for key, val in items:
num = eval(val)
key_args = ", ".join(["{:d}".format(axis_pos[c]) for c in key.lower()])
macro = "VECTOR_SWIZZLE{:d}_{:s}_DEF".format(
len(key),
"RW" if len(set(key)) == len(key) else "RO",
)
print(" {:s}(\"{:s}\", {:s}),".format(
macro,
key,
key_args,
))
unique.add(num)
if len(unique) != len(items):
print("ERROR, duplicate values found")
int len

Get a new Vector according to the provided swizzle bits.

Definition at line 2731 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, MAX_DIMENSIONS, 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(destination)) 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 2773 of file mathutils_Vector.cc.

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 702 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, self, and Vector_CreatePyObject().

◆ Vector_to_3d()

static PyObject * Vector_to_3d ( VectorObject * self)
static

Definition at line 719 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, self, and Vector_CreatePyObject().

◆ Vector_to_4d()

static PyObject * Vector_to_4d ( VectorObject * self)
static

Definition at line 739 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, 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 768 of file mathutils_Vector.cc.

References BaseMath_ReadCallback, self, and Vector_to_tuple_ex().

◆ Vector_to_tuple_ex()

static PyObject * Vector_to_tuple_ex ( VectorObject * self,
int ndigits )
static
Note
BaseMath_ReadCallback must be called beforehand.

Definition at line 110 of file mathutils_Vector.cc.

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 Py_ssize_t Vector_len(VectorObject *self)
static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value)
static PyObject * Vector_subscript(VectorObject *self, PyObject *item)

Definition at line 2474 of file mathutils_Vector.cc.

◆ Vector_getseters

PyGetSetDef Vector_getseters[]
static

Definition at line 2906 of file mathutils_Vector.cc.

◆ Vector_methods

PyMethodDef Vector_methods[]
static

Definition at line 3332 of file mathutils_Vector.cc.

◆ Vector_NumMethods

PyNumberMethods Vector_NumMethods
static

Definition at line 2480 of file mathutils_Vector.cc.

◆ Vector_SeqMethods

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

Definition at line 2461 of file mathutils_Vector.cc.

◆ vector_Type

PyTypeObject vector_Type