:right-sidebar: True Vec2 =================================================================== .. currentmodule:: gi.repository.Graphene .. class:: Vec2(*args, **kwargs) :no-contents-entry: A structure capable of holding a vector with two dimensions, x and y. The contents of the :obj:`~gi.repository.Graphene.Vec2` structure are private and should never be accessed directly. Constructors ------------ .. rst-class:: interim-class .. class:: Vec2 :no-index: .. classmethod:: alloc() -> ~gi.repository.Graphene.Vec2 Allocates a new :obj:`~gi.repository.Graphene.Vec2` structure. The contents of the returned structure are undefined. Use :func:`~gi.repository.Graphene.Vec2.init` to initialize the vector. .. versionadded:: 1.0 Methods ------- .. rst-class:: interim-class .. class:: Vec2 :no-index: .. method:: add(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Adds each component of the two passed vectors and places each result into the components of ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: divide(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Divides each component of the first operand ``a`` by the corresponding component of the second operand ``b``\, and places the results into the vector ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: dot(b: ~gi.repository.Graphene.Vec2) -> float Computes the dot product of the two given vectors. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: equal(v2: ~gi.repository.Graphene.Vec2) -> bool Checks whether the two given :obj:`~gi.repository.Graphene.Vec2` are equal. .. versionadded:: 1.2 :param v2: a :obj:`~gi.repository.Graphene.Vec2` .. method:: free() -> None Frees the resources allocated by ``v`` .. versionadded:: 1.0 .. method:: get_x() -> float Retrieves the X component of the :obj:`~gi.repository.Graphene.Vec2`\. .. versionadded:: 1.0 .. method:: get_y() -> float Retrieves the Y component of the :obj:`~gi.repository.Graphene.Vec2`\. .. versionadded:: 1.0 .. method:: init(x: float, y: float) -> ~gi.repository.Graphene.Vec2 Initializes a :obj:`~gi.repository.Graphene.Vec2` using the given values. This function can be called multiple times. .. versionadded:: 1.0 :param x: the X field of the vector :param y: the Y field of the vector .. method:: init_from_float(src: list[float]) -> ~gi.repository.Graphene.Vec2 Initializes ``v`` with the contents of the given array. .. versionadded:: 1.0 :param src: an array of floating point values with at least two elements .. method:: init_from_vec2(src: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Copies the contents of ``src`` into ``v``\. .. versionadded:: 1.0 :param src: a :obj:`~gi.repository.Graphene.Vec2` .. method:: interpolate(v2: ~gi.repository.Graphene.Vec2, factor: float) -> ~gi.repository.Graphene.Vec2 Linearly interpolates ``v1`` and ``v2`` using the given ``factor``\. .. versionadded:: 1.10 :param v2: a :obj:`~gi.repository.Graphene.Vec2` :param factor: the interpolation factor .. method:: length() -> float Computes the length of the given vector. .. versionadded:: 1.0 .. method:: max(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Compares the two given vectors and places the maximum values of each component into ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: min(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Compares the two given vectors and places the minimum values of each component into ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: multiply(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Multiplies each component of the two passed vectors and places each result into the components of ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: near(v2: ~gi.repository.Graphene.Vec2, epsilon: float) -> bool Compares the two given :obj:`~gi.repository.Graphene.Vec2` vectors and checks whether their values are within the given ``epsilon``\. .. versionadded:: 1.2 :param v2: a :obj:`~gi.repository.Graphene.Vec2` :param epsilon: the threshold between the two vectors .. method:: negate() -> ~gi.repository.Graphene.Vec2 Negates the given :obj:`~gi.repository.Graphene.Vec2`\. .. versionadded:: 1.2 .. method:: normalize() -> ~gi.repository.Graphene.Vec2 Computes the normalized vector for the given vector ``v``\. .. versionadded:: 1.0 .. classmethod:: one() -> ~gi.repository.Graphene.Vec2 Retrieves a constant vector with (1, 1) components. .. versionadded:: 1.0 .. method:: scale(factor: float) -> ~gi.repository.Graphene.Vec2 Multiplies all components of the given vector with the given scalar ``factor``\. .. versionadded:: 1.2 :param factor: the scalar factor .. method:: subtract(b: ~gi.repository.Graphene.Vec2) -> ~gi.repository.Graphene.Vec2 Subtracts from each component of the first operand ``a`` the corresponding component of the second operand ``b`` and places each result into the components of ``res``\. .. versionadded:: 1.0 :param b: a :obj:`~gi.repository.Graphene.Vec2` .. method:: to_float() -> list[float] Stores the components of ``v`` into an array. .. versionadded:: 1.0 .. classmethod:: x_axis() -> ~gi.repository.Graphene.Vec2 Retrieves a constant vector with (1, 0) components. .. versionadded:: 1.0 .. classmethod:: y_axis() -> ~gi.repository.Graphene.Vec2 Retrieves a constant vector with (0, 1) components. .. versionadded:: 1.0 .. classmethod:: zero() -> ~gi.repository.Graphene.Vec2 Retrieves a constant vector with (0, 0) components. .. versionadded:: 1.0 Fields ------ .. rst-class:: interim-class .. class:: Vec2 :no-index: .. attribute:: value