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) -> boolafloat-
First value
bfloat-
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) -> floatvaluefloat-
The value to clamp
lowfloat-
The lower bound of the range. Defaults to 0.0.
highfloat-
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,
) -> floatvaluefloat-
The value to scale
lowfloat-
Lower bound of the value range
highfloat-
Upper bound of the value range
low_rescalefloat-
Lower bound of the scaled value range
high_rescalefloat-
Upper bound of the scaled value range
Returns
The value scaled to the range [low_rescale, high_rescale]