Skip to content

XY (2D) Vectors

FloatVector2

FloatVector2(x: float, y: float)

Bases: BaseVector2

2D Float Vector Array.

Create a new 2D, float-based vector array.

PARAMETER DESCRIPTION
x

Coordinate on the X-axis.

TYPE: float

y

Coordinate on the Y-axis.

TYPE: float

x property writable

x: float

Coordinate on the X-axis.

y property writable

y: float

Coordinate on the Y-axis.

copy

copy() -> FloatVector2

Copy this vector into another instance of the same vector.

RETURNS DESCRIPTION
FloatVector2

This vector as another instance.

dot

dot(other: FloatVector2) -> float

Calculate the dot product of this vector with another.

PARAMETER DESCRIPTION
other

The other vector to calculate the dot product with.

TYPE: FloatVector2

RETURNS DESCRIPTION
float

The dot product of these two vectors.

from_iterable classmethod

Create a new 2D, float-based vector array from an iterable with 2 float or int values.

PARAMETER DESCRIPTION
iterable

The iterable with 3 float or int values.

TYPE: FloatVector2 | IntVector2 | numpy.ndarray[numpy.int32] | tuple[int | float, int | float] | list[int | float]

RETURNS DESCRIPTION
FloatVector2

The new 2D, float-based vector array.

RAISES DESCRIPTION
ValueError

If the provided iterable contains more or less than 2 values

normalize

normalize() -> FloatVector2

Normalize this vector.

RETURNS DESCRIPTION
FloatVector2

The normalized vector.

RAISES DESCRIPTION
ZeroDivisionError

If the magnitude of this vector is 0

to_numpy

to_numpy(copy: bool = True) -> NDArray[np.float32]

Return this vector as an instance of a NumPy array.

PARAMETER DESCRIPTION
copy

If this method should return a copy of the internal NumPy array or the array itself

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
numpy.ndarray[numpy.int32]

This vector as an instance of a NumPy array.

Warning

If you return the array itself, any changes to that array will change this vector object.

to_tuple

to_tuple() -> tuple[int, int]

Return this vector as a tuple.

RETURNS DESCRIPTION
tuple[int, int]

This vector as a tuple.

magnitude

magnitude() -> float

Calculate the magnitude of this vector.

RETURNS DESCRIPTION
float

The magnitude of this vector.

IntVector2

IntVector2(x: int, y: int)

Bases: BaseVector2

2D Integer Vector Array.

Create a new 2D, int-based vector array.

PARAMETER DESCRIPTION
x

Coordinate on the X-axis.

TYPE: int

y

Coordinate on the Y-axis.

TYPE: int

x property writable

x: int

Coordinate on the X-axis.

y property writable

y: int

Coordinate on the Y-axis.

copy

copy() -> IntVector2

Copy this vector into another instance of the same vector.

RETURNS DESCRIPTION
IntVector2

This vector as another instance.

dot

dot(other: IntVector2) -> float

Calculate the dot product of this vector with another.

PARAMETER DESCRIPTION
other

The other vector to calculate the dot product with.

TYPE: IntVector2

RETURNS DESCRIPTION
float

The dot product of these two vectors.

from_iterable classmethod

from_iterable(
    iterable: Union[
        IntVector2,
        np.ndarray[np.int32],
        tuple[int, int],
        list[int],
    ],
) -> IntVector2

Create a new 2D, int-based vector array from an iterable with 2 int values.

PARAMETER DESCRIPTION
iterable

The iterable with 2 int values.

TYPE: IntVector2 | numpy.ndarray[numpy.int32] | tuple[int, int] | list[int]

RETURNS DESCRIPTION
IntVector2

The new 2D, int-based vector array.

RAISES DESCRIPTION
ValueError

If the provided iterable contains more or less than 2 values

normalize

normalize() -> FloatVector2

Normalize this vector.

RETURNS DESCRIPTION
FloatVector2

The normalized vector.

RAISES DESCRIPTION
ZeroDivisionError

If the magnitude of this vector is 0

to_numpy

to_numpy(copy: bool = True) -> NDArray[np.int32]

Return this vector as an instance of a NumPy array.

PARAMETER DESCRIPTION
copy

If this method should return a copy of the internal NumPy array or the array itself

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
numpy.ndarray[numpy.int32]

This vector as an instance of a NumPy array.

Warning

If you return the array itself, any changes to that array will change this vector object.

to_tuple

to_tuple() -> tuple[int, int]

Return this vector as a tuple.

RETURNS DESCRIPTION
tuple[int, int]

This vector as a tuple.

magnitude

magnitude() -> float

Calculate the magnitude of this vector.

RETURNS DESCRIPTION
float

The magnitude of this vector.