Skip to content

sonolus.script.numtools

make_comparable_float(*values: tuple[int, int]) -> float

Convert a series of non-negative integer values into a float that compares the same way as the original series.

This is useful for z-indexes, since Sonolus only supports a single float for z-index.

The product of all maximum values must be less than 2^31.

Usage
make_comparable_float(
    quantize_to_step(time, -100, 100, 0.001),
    quantize_to_step(abs(lane), 0, 16, 0.01),
)

Parameters:

Name Type Description Default
*values tuple[int, int]

A series of tuples (value, max_value) where value falls in the range [0, max_value).

()

Returns:

Type Description
float

A single float that can be used for comparison.

product(values: Iterable[float]) -> float

Calculate the product of an iterable of floats.

quantize_to_step(value: float, start: float, stop: float, step: float) -> tuple[int, int]

Quantize a float value by step size within a range and return the step number and total steps in the range.

If value is between start and stop, start + step_number * step will be approximately equal to value, where step_number is the first element of the returned tuple.

Parameters:

Name Type Description Default
value float

The float value to quantize.

required
start float

The start of the range. The range is inclusive of this value.

required
stop float

The end of the range. The range is exclusive of this value. Must be strictly greater than start.

required
step float

The step size. Must be positive.

required

Returns:

Type Description
tuple[int, int]

A tuple containing the quantized step number and the total number of steps in the range.