Vec2

class Vec2(*args, **kwargs)

A structure capable of holding a vector with two dimensions, x and y.

The contents of the Vec2 structure are private and should never be accessed directly.

Constructors

class Vec2
classmethod alloc() Vec2

Allocates a new Vec2 structure.

The contents of the returned structure are undefined.

Use init() to initialize the vector.

Added in version 1.0.

Methods

class Vec2
add(b: Vec2) Vec2

Adds each component of the two passed vectors and places each result into the components of res.

Added in version 1.0.

Parameters:

b – a Vec2

divide(b: Vec2) 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.

Added in version 1.0.

Parameters:

b – a Vec2

dot(b: Vec2) float

Computes the dot product of the two given vectors.

Added in version 1.0.

Parameters:

b – a Vec2

equal(v2: Vec2) bool

Checks whether the two given Vec2 are equal.

Added in version 1.2.

Parameters:

v2 – a Vec2

free() None

Frees the resources allocated by v

Added in version 1.0.

get_x() float

Retrieves the X component of the Vec2.

Added in version 1.0.

get_y() float

Retrieves the Y component of the Vec2.

Added in version 1.0.

init(x: float, y: float) Vec2

Initializes a Vec2 using the given values.

This function can be called multiple times.

Added in version 1.0.

Parameters:
  • x – the X field of the vector

  • y – the Y field of the vector

init_from_float(src: Sequence[float]) Vec2

Initializes v with the contents of the given array.

Added in version 1.0.

Parameters:

src – an array of floating point values with at least two elements

init_from_vec2(src: Vec2) Vec2

Copies the contents of src into v.

Added in version 1.0.

Parameters:

src – a Vec2

interpolate(v2: Vec2, factor: float) Vec2

Linearly interpolates v1 and v2 using the given factor.

Added in version 1.10.

Parameters:
  • v2 – a Vec2

  • factor – the interpolation factor

length() float

Computes the length of the given vector.

Added in version 1.0.

max(b: Vec2) Vec2

Compares the two given vectors and places the maximum values of each component into res.

Added in version 1.0.

Parameters:

b – a Vec2

min(b: Vec2) Vec2

Compares the two given vectors and places the minimum values of each component into res.

Added in version 1.0.

Parameters:

b – a Vec2

multiply(b: Vec2) Vec2

Multiplies each component of the two passed vectors and places each result into the components of res.

Added in version 1.0.

Parameters:

b – a Vec2

near(v2: Vec2, epsilon: float) bool

Compares the two given Vec2 vectors and checks whether their values are within the given epsilon.

Added in version 1.2.

Parameters:
  • v2 – a Vec2

  • epsilon – the threshold between the two vectors

negate() Vec2

Negates the given Vec2.

Added in version 1.2.

normalize() Vec2

Computes the normalized vector for the given vector v.

Added in version 1.0.

one() Vec2

Retrieves a constant vector with (1, 1) components.

Added in version 1.0.

scale(factor: float) Vec2

Multiplies all components of the given vector with the given scalar factor.

Added in version 1.2.

Parameters:

factor – the scalar factor

subtract(b: Vec2) 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.

Added in version 1.0.

Parameters:

b – a Vec2

to_float() list[float]

Stores the components of v into an array.

Added in version 1.0.

x_axis() Vec2

Retrieves a constant vector with (1, 0) components.

Added in version 1.0.

y_axis() Vec2

Retrieves a constant vector with (0, 1) components.

Added in version 1.0.

zero() Vec2

Retrieves a constant vector with (0, 0) components.

Added in version 1.0.

Fields

class Vec2
value