package e2;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import jn.o;
import kotlin.jvm.internal.k;
import rm.t;

/* loaded from: classes.dex */
public final class c {

    /* renamed from: a, reason: collision with root package name */
    private final boolean f16766a;

    /* renamed from: b, reason: collision with root package name */
    private final a f16767b;

    /* renamed from: c, reason: collision with root package name */
    private final int f16768c;

    /* renamed from: d, reason: collision with root package name */
    private final e2.a[] f16769d;

    /* renamed from: e, reason: collision with root package name */
    private int f16770e;

    /* renamed from: f, reason: collision with root package name */
    private final float[] f16771f;

    /* renamed from: g, reason: collision with root package name */
    private final float[] f16772g;

    /* renamed from: h, reason: collision with root package name */
    private final float[] f16773h;

    /* loaded from: classes.dex */
    public enum a {
        Lsq2,
        Impulse
    }

    /* loaded from: classes.dex */
    public /* synthetic */ class b {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f16774a;

        static {
            int[] iArr = new int[a.values().length];
            try {
                iArr[a.Impulse.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[a.Lsq2.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f16774a = iArr;
        }
    }

    public c(boolean z10, a aVar) {
        this.f16766a = z10;
        this.f16767b = aVar;
        if (z10 && aVar.equals(a.Lsq2)) {
            throw new IllegalStateException("Lsq2 not (yet) supported for differential axes");
        }
        int i10 = b.f16774a[aVar.ordinal()];
        int i11 = 2;
        if (i10 != 1) {
            if (i10 != 2) {
                throw new t();
            }
            i11 = 3;
        }
        this.f16768c = i11;
        this.f16769d = new e2.a[20];
        this.f16771f = new float[20];
        this.f16772g = new float[20];
        this.f16773h = new float[3];
    }

    private final float b(float[] fArr, float[] fArr2, int i10) {
        try {
            return e.i(fArr2, fArr, i10, 2, this.f16773h)[1];
        } catch (IllegalArgumentException unused) {
            return BitmapDescriptorFactory.HUE_RED;
        }
    }

    public final void a(long j10, float f10) {
        int i10 = (this.f16770e + 1) % 20;
        this.f16770e = i10;
        e.j(this.f16769d, i10, j10, f10);
    }

    public final float c() {
        float f10;
        float[] fArr = this.f16771f;
        float[] fArr2 = this.f16772g;
        int i10 = this.f16770e;
        e2.a aVar = this.f16769d[i10];
        if (aVar == null) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        int i11 = 0;
        e2.a aVar2 = aVar;
        while (true) {
            e2.a aVar3 = this.f16769d[i10];
            if (aVar3 != null) {
                float b10 = (float) (aVar.b() - aVar3.b());
                float abs = (float) Math.abs(aVar3.b() - aVar2.b());
                e2.a aVar4 = (this.f16767b == a.Lsq2 || this.f16766a) ? aVar3 : aVar;
                if (b10 > 100.0f || abs > 40.0f) {
                    break;
                }
                fArr[i11] = aVar3.a();
                fArr2[i11] = -b10;
                if (i10 == 0) {
                    i10 = 20;
                }
                i10--;
                i11++;
                if (i11 >= 20) {
                    break;
                }
                aVar2 = aVar4;
            } else {
                break;
            }
        }
        if (i11 < this.f16768c) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        int i12 = b.f16774a[this.f16767b.ordinal()];
        if (i12 == 1) {
            f10 = e.f(fArr, fArr2, i11, this.f16766a);
        } else {
            if (i12 != 2) {
                throw new t();
            }
            f10 = b(fArr, fArr2, i11);
        }
        return f10 * 1000;
    }

    public final float d(float f10) {
        float c10;
        float f11;
        if (!(f10 > BitmapDescriptorFactory.HUE_RED)) {
            g2.a.b("maximumVelocity should be a positive value. You specified=" + f10);
        }
        float c11 = c();
        if ((c11 == BitmapDescriptorFactory.HUE_RED) || Float.isNaN(c11)) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        if (c11 > BitmapDescriptorFactory.HUE_RED) {
            f11 = o.f(c11, f10);
            return f11;
        }
        c10 = o.c(c11, -f10);
        return c10;
    }

    public final void e() {
        sm.o.y(this.f16769d, null, 0, 0, 6, null);
        this.f16770e = 0;
    }

    public /* synthetic */ c(boolean z10, a aVar, int i10, k kVar) {
        this((i10 & 1) != 0 ? false : z10, (i10 & 2) != 0 ? a.Lsq2 : aVar);
    }
}
