Math
Math related functions
From Polar
from_polar(angle: float, radius: float) → Vec2Convert polar coordinates to a Cartesian vector.
Args
angle: The angle in radians.radius: The radius/distance from origin.
Returns
Vec2 : The equivalent Cartesian vector.
Clamp
clamp(vec: Vec2, min_vec: Vec2, max_vec: Vec2) → Vec2Clamp a vector between two boundary vectors.
Args
vec: The vector to clamp.min_vec: The minimum boundary vector.max_vec: The maximum boundary vector.
Returns
Vec2 : A new vector with components clamped between min and max.
clamp(
value: float,
min_val: float,
max_val: float
) → floatClamp a value between two boundaries.
Args
value: The value to clamp.min_val: The minimum boundary.max_val: The maximum boundary.
Returns
float : The clamped value.
Lerp
lerp(a: Vec2, b: Vec2, t: float) → Vec2Linearly interpolate between two Vec2s.
Args
a: The start vector.b: The end vector.t: The interpolation factor [0.0, 1.0].
Returns
Vec2 : The interpolated vector.
lerp(a: float, b: float, t: float) → floatLinearly interpolate between two values.
Args
a: The start value.b: The end value.t: The interpolation factor [0.0, 1.0].
Returns
float : The interpolated value.
Remap
remap(
in_min: float,
in_max: float,
out_min: float,
out_max: float,
value: float
) → floatRemap a value from one range to another.
Args
in_min: Input range minimum.in_max: Input range maximum.out_min: Output range minimum.out_max: Output range maximum.value: The value to remap.
Returns
float : The remapped value in the output range.
Raises
ValueError: If in_min equals in_max.
Dot
dot(a: Vec2, b: Vec2) → floatCalculate the dot product of two vectors.
Args
a: The first vector.b: The second vector.
Returns
float : The dot product (a.x * b.x + a.y * b.y).
Cross
cross(a: Vec2, b: Vec2) → floatCalculate the 2D cross product of two vectors. (a.x * b.y - a.y * b.x)
Args
a: The first vector.b: The second vector.
Returns
float : The 2D cross product.