using RioJoy.Core.Calibration;

namespace RioJoy.Core.Editing;

/// <summary>
/// Pure math for the editor's live encoder gauges: converts a calibrated axis
/// value (<c>0..32766</c>, center 16383) into a normalized fill fraction or a
/// signed center deflection, clamped so out-of-range values can't overdraw a
/// gauge. UI-free so the conversions are unit-tested; the panel renderer only
/// scales these to pixels.
/// </summary>
public static class AxisGauges
{
    /// <summary>Fill fraction <c>0..1</c> of an axis value (0 = empty, Max = full).</summary>
    public static double Fraction(int value) =>
        Math.Min(1.0, Math.Max(0.0, value / (double)AxisOutputs.Max));

    /// <summary>Signed deflection <c>-1..+1</c> from the axis center (0 = centered).</summary>
    public static double Deflection(int value) =>
        Math.Min(1.0, Math.Max(-1.0, (value - AxisOutputs.Center) / (double)AxisOutputs.Center));
}
