Día de Muertos is an ofrenda: papel picado for the battery, a calavera with the speed in a ring of marigolds for the power, candles for the range, a path of petals for the last two minutes of power. Halloween is a graveyard hill: a jack-o'-lantern with the speed in its grin, embers for the power, a potion flask for the battery, a tombstone and bats for the range. Each has its own palette; Tally counts what a value lights. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
28 lines
1.1 KiB
Java
28 lines
1.1 KiB
Java
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)));
|
|
}
|
|
}
|