Skip to content

LinearScale

The LinearScale class maps a numeric value from a specified domain to an output range using a linear transformation.

pydreamplet.scales.LinearScale

LinearScale(
    domain: tuple[float, float],
    output_range: tuple[float, float]
)

Parameters

  • domain (tuple[float, float]): The input domain as a minimum and maximum value.
  • output_range (tuple[float, float]): The target output range.
scale = LinearScale((0, 100), (0, 1))
print(scale.map(50))  # Output: 0.5
print(scale.invert(0.75))  # Output: 75.0

map

map(value: float) -> float

Scales a value from the domain to the output range.

invert

invert(value: float) -> float

Maps a value from the output range back to the domain.

domain

Get or set the input domain.

output_range

Get or set the target output range.