step 5: complete first gauge catalogue

This commit is contained in:
2026-07-02 14:47:05 +02:00
parent d638c512e9
commit 1a476bc91d
11 changed files with 594 additions and 16 deletions

View File

@@ -56,6 +56,13 @@ def value_to_angle(
return start_angle + (end_angle - start_angle) * fraction
def compass_heading(value: float) -> float:
if not math.isfinite(value):
msg = "heading value must be finite"
raise GaugeValueError(msg)
return value % 360.0
def fill_fraction(value: float, min_value: float, max_value: float, *, clamp: bool = True) -> float:
return normalize_value(value, min_value, max_value, clamp=clamp)
@@ -83,6 +90,16 @@ def normalized_span(
return min(first, second), max(first, second)
def active_segments(
value: float, min_value: float, max_value: float, segments: int, *, clamp: bool = True
) -> int:
if segments <= 0:
msg = "segments must be greater than zero"
raise GaugeConfigError(msg)
fraction = fill_fraction(value, min_value, max_value, clamp=clamp)
return min(max(math.ceil(fraction * segments), 0), segments)
def generate_ticks(min_value: float, max_value: float, count: int) -> list[float]:
validate_range(min_value, max_value)
if count < 2: