package com.evsuite.abrp; /** * How many of a row of things a value lights: flags, candles, petals, embers, bats. An unread * value lights none, never a made-up amount. Android-free and unit-tested. */ final class Tally { private Tally() {} /** One thing per {@code step} of the value, rounded, from 0 to {@code max}; null or NaN is 0. */ static int lit(Float value, float step, int max) { if (value == null || value.isNaN() || step <= 0f || value <= 0f) return 0; return Math.min(max, Math.round(value / step)); } /** * Of {@code count} things round a gauge, how many the power lights: all of them at * {@code fullDraw} kW drawn, or at {@code fullRegen} kW regenerated (negative power). * Any real power lights at least one, so the gauge never looks idle while it is not. */ static int ofPower(Float kw, float fullDraw, float fullRegen, int count) { if (kw == null || kw.isNaN() || Math.abs(kw) < 0.1f) return 0; float share = Math.abs(kw) / (kw < 0f ? fullRegen : fullDraw); return Math.max(1, Math.min(count, Math.round(share * count))); } }