xecs.Vec2#

class xecs.Vec2[source]#

Bases: Struct

A set of 2D vector values.

Methods

angle_between_vec2

Return the angles between some other vectors.

angle_between_xy

Return the angles between another vector.

clamp_length

Ensure lengths are no less than min and no more than max.

dot_vec2

Get the element wise dot products with some other vectors.

dot_xy

Get the dot products between the vectors and another vector.

fill

Set the values of the vectors.

from_numpy

Create the vectors from a NumPy array.

from_xy

Create the vectors from x and y values.

length_squared

Get the squared lengths of the vectors.

numpy

Return a copy of the vectors as a NumPy array.

perp_dot_vec2

Get the perpendicular dot products with some other vectors.

perp_dot_xy

Get the perpendicular dot products with the vectors and another.

to_str

Return a string representation.

Attributes

x

The x values.

y

The y values.

angle_between_vec2(other)[source]#

Return the angles between some other vectors.

The returned angles are in radians and in the range [-pi, pi].

Parameters:

other (Vec2) – The other vectors.

Returns:

The angles.

Return type:

ndarray[Any, dtype[float32]]

angle_between_xy(x, y)[source]#

Return the angles between another vector.

The returned angles are in radians and in the range [-pi, pi].

Parameters:
  • x (float) – The x value of the other vector.

  • y (float) – The y value of the other vector.

Returns:

The angles.

Return type:

ndarray[Any, dtype[float32]]

clamp_length(min, max)[source]#

Ensure lengths are no less than min and no more than max.

Parameters:
  • min (float) – The minimum length.

  • max (float) – The maximum length.

Returns:

Itself.

Return type:

Self

dot_vec2(other)[source]#

Get the element wise dot products with some other vectors.

Parameters:

other (Vec2) – The other vectors.

Returns:

The dot products.

Return type:

ndarray[Any, dtype[float32]]

dot_xy(x, y)[source]#

Get the dot products between the vectors and another vector.

Parameters:
  • x (float) – The x value of the other vector.

  • y (float) – The y value of the other vector.

Returns:

The dot products.

Return type:

ndarray[Any, dtype[float32]]

fill(value)[source]#

Set the values of the vectors.

Parameters:

value (float | list[float]) – The values to set the vectors to.

Return type:

None

static from_numpy(array)[source]#

Create the vectors from a NumPy array.

Parameters:

array (ndarray[Any, dtype[float32]]) – The NumPy array.

Returns:

The vectors.

Return type:

Vec2

static from_xy(x, y, num)[source]#

Create the vectors from x and y values.

Parameters:
  • x (float) – The x value of the vectors.

  • y (float) – The y value of the vectors.

  • num (int) – The number of vectors to create.

Returns:

The vectors.

Return type:

Vec2

length_squared()[source]#

Get the squared lengths of the vectors.

Returns:

The squared lengths.

Return type:

ndarray[Any, dtype[float32]]

numpy()[source]#

Return a copy of the vectors as a NumPy array.

Returns:

The vectors.

Return type:

ndarray[Any, dtype[float32]]

perp_dot_vec2(other)[source]#

Get the perpendicular dot products with some other vectors.

Also known as the 2D cross product.

Parameters:

other (Vec2) – The other vectors.

Returns:

The perpendicular dot products.

Return type:

ndarray[Any, dtype[float32]]

perp_dot_xy(x, y)[source]#

Get the perpendicular dot products with the vectors and another.

Also known as the 2D cross product.

Parameters:
  • x (float) – The x value of the other vector.

  • y (float) – The y value of the other vector.

Returns:

The perpendicular dot products.

Return type:

ndarray[Any, dtype[float32]]

to_str(nesting)#

Return a string representation.

Parameters:

nesting (int) – How deeply nested the struct is in the component.

Returns:

The string representation.

Return type:

str

x: Float32#

The x values.

y: Float32#

The y values.