utils.math

are_floats_equal

Check if two floating-point values are close enough to be considered equal by this project.

def are_floats_equal(a: float, b: float) -> bool
a float

First value

b float

Second value

Returns

True if values are close enough to be considered equal

clamp

Clamp a value to always be within the range [low, high].

def clamp(value: float, low: float = 0.0, high: float = 1.0) -> float
value float

The value to clamp

low float

The lower bound of the range. Defaults to 0.0.

high float

The upper bound of the range. Defaults to 1.0.

Returns

The value clamped to the range [low, high]

clamped_rescale

Scales values from low to high to the range low_rescale to high_rescale using linear interpolation. Values outside low and high are clamped to low_rescale and high_rescale, respectively.

def clamped_rescale(
    value: float,
    low: float,
    high: float,
    low_rescale: float = 0.0,
    high_rescale: float = 1.0,
) -> float
value float

The value to scale

low float

Lower bound of the value range

high float

Upper bound of the value range

low_rescale float

Lower bound of the scaled value range

high_rescale float

Upper bound of the scaled value range

Returns

The value scaled to the range [low_rescale, high_rescale]