Welcome to Python-flavored Magnum! Please note that, while already being
rather stable, this functionality is still considered experimental and
some APIs might get changed without preserving full backwards compatibility.
class
Vector2Two-component float vector
Static methods
- def x_axis(length: float = 1.0) -> Vector2
- Vector in a direction of X axis (right)
- def x_scale(scale: float) -> Vector2
- Scaling vector in a direction of X axis (width)
- def y_axis(length: float = 1.0) -> Vector2
- Vector in a direction of Y axis (up)
- def y_scale(scale: float) -> Vector2
- Scaling vector in a direction of Y axis (height)
- def zero_init() -> Vector2
- Construct a zero vector
Methods
- def aspect_ratio(self, /) -> float
- Aspect ratio
- def dot(self, /) -> float
- Dot product of the vector
- def flipped(self, /) -> Vector2
- Flipped vector
- def is_normalized(self, /) -> bool
- Whether the vector is normalized
- def is_zero(self, /) -> bool
- Whether the vector is zero
- def length(self, /) -> float
- Vector length
- def length_inverted(self, /) -> float
- Inverse vector length
- def max(self, /) -> float
- Maximal value in the vector
- def min(self, /) -> float
- Minimal value in the vector
- def minmax(self, /) -> tuple[float, float]
- Minimal and maximal value in the vector
- def normalized(self, /) -> Vector2
- Normalized vector (of unit length)
- def perpendicular(self, /) -> Vector2
- Perpendicular vector
- def product(self, /) -> float
- Product of values in the vector
- def projected(self, line: Vector2) -> Vector2
- Vector projected onto a line
- def projected_onto_normalized(self, line: Vector2) -> Vector2
- Vector projected onto a normalized line
- def resized(self, length: float) -> Vector2
- Resized vector
- def sum(self, /) -> float
- Sum of values in the vector
Special methods
- def __add__(self, arg0: Vector2, /) -> Vector2
- Add a vector
- def __buffer__(self, flags, /)
- Return a buffer object that exposes the underlying memory of the object.
- def __eq__(self, arg0: Vector2, /) -> bool
- Equality comparison
- def __ge__(self, arg0: Vector2, /) -> BitVector2
- Component-wise greater than or equal comparison
- def __getattr__(self, arg0: str, /) -> object
- Vector swizzle
- def __getitem__(self, arg0: int, /) -> float
- Value at given position
- def __getstate__(self, /) -> bytes
- Dumps the in-memory representation of vector components
- def __gt__(self, arg0: Vector2, /) -> BitVector2
- Component-wise greater than comparison
- def __iadd__(self, arg0: Vector2, /) -> Vector2
- Add and assign a vector
- def __imul__(self, arg0: float, /) -> Vector2
- Multiply with a scalar and assign
- def __imul__(self, arg0: Vector2, /) -> Vector2
- Multiply a vector component-wise and assign
- def __init__(self, arg0: Vector2ui, /) -> None
- Construct from different underlying type
- def __init__(self, arg0: Vector2i, /) -> None
- Construct from different underlying type
- def __init__(self, arg0: Vector2d, /) -> None
- Construct from different underlying type
- def __init__(self, arg0: Buffer, /) -> None
- Construct from a buffer
- def __init__(self, /) -> None
- Default constructor
- def __init__(self, arg0: float, /) -> None
- Construct a vector with one value for all components
- def __init__(self, arg0: float, arg1: float, /) -> None
- Constructor
- def __init__(self, arg0: tuple[float, float], /) -> None
- Construct from a tuple
- def __isub__(self, arg0: Vector2, /) -> Vector2
- Subtract and assign a vector
- def __itruediv__(self, arg0: float, /) -> Vector2
- Divide with a scalar and assign
- def __itruediv__(self, arg0: Vector2, /) -> Vector2
- Divide a vector component-wise and assign
- def __le__(self, arg0: Vector2, /) -> BitVector2
- Component-wise less than or equal comparison
- def __len__() -> int
- Vector size. Returns 2.
- def __lt__(self, arg0: Vector2, /) -> BitVector2
- Component-wise less than comparison
- def __mul__(self, arg0: float, /) -> Vector2
- Multiply with a scalar
- def __mul__(self, arg0: Vector2, /) -> Vector2
- Multiply a vector component-wise
- def __ne__(self, arg0: Vector2, /) -> bool
- Non-equality comparison
- def __neg__(self, /) -> Vector2
- Negated vector
- def __release_buffer__(self, buffer, /)
- Release the buffer object that exposes the underlying memory of the object.
- def __repr__(self, /) -> str
- Object representation
- def __rmul__(self, arg0: float, /) -> Vector2
- Multiply a scalar with a vector
- def __rtruediv__(self, arg0: float, /) -> Vector2
- Divide a vector with a scalar and invert
- def __setattr__(self, arg0: str, arg1: object, /) -> None
- Vector swizzle
- def __setitem__(self, arg0: int, arg1: float, /) -> None
- Set a value at given position
- def __setstate__(self, arg0: bytes, /) -> None
- Treats the data as the in-memory representation of vector components
- def __sub__(self, arg0: Vector2, /) -> Vector2
- Subtract a vector
- def __truediv__(self, arg0: float, /) -> Vector2
- Divide with a scalar
- def __truediv__(self, arg0: Vector2, /) -> Vector2
- Divide a vector component-wise
Properties
Method documentation
def magnum. Vector2. projected_onto_normalized(self,
line: Vector2) -> Vector2
Vector projected onto a normalized line
Exceptions | |
---|---|
ValueError | If line is not normalized |
def magnum. Vector2. __setstate__(self,
arg0: bytes, /) -> None
Treats the data as the in-memory representation of vector components
Exceptions | |
---|---|
ValueError | If the data size doesn’t match type size |