package D0;

import E3.v;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f933a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final c f934b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f935c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final a[] f936d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f937e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float[] f938f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final float[] f939g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final float[] f940h;

    public d(boolean z6, c cVar) {
        int i6;
        this.f933a = z6;
        this.f934b = cVar;
        if (z6 && cVar.equals(c.f930a)) {
            throw new IllegalStateException("Lsq2 not (yet) supported for differential axes");
        }
        int iOrdinal = cVar.ordinal();
        if (iOrdinal == 0) {
            i6 = 3;
        } else {
            if (iOrdinal != 1) {
                throw new v();
            }
            i6 = 2;
        }
        this.f935c = i6;
        this.f936d = new a[20];
        this.f938f = new float[20];
        this.f939g = new float[20];
        this.f940h = new float[3];
    }

    public final void a(float f6, long j4) {
        int i6 = (this.f937e + 1) % 20;
        this.f937e = i6;
        a[] aVarArr = this.f936d;
        a aVar = aVarArr[i6];
        if (aVar != null) {
            aVar.f925a = j4;
            aVar.f926b = f6;
        } else {
            a aVar2 = new a();
            aVar2.f925a = j4;
            aVar2.f926b = f6;
            aVarArr[i6] = aVar2;
        }
    }

    public final float b(float f6) {
        c cVar;
        float[] fArr;
        float[] fArr2;
        float f7;
        boolean z6;
        int i6;
        float fSignum;
        float f8 = f6;
        float f9 = 0.0f;
        if (f8 <= 0.0f) {
            F0.a.b("maximumVelocity should be a positive value. You specified=" + f8);
        }
        int i7 = this.f937e;
        a[] aVarArr = this.f936d;
        a aVar = aVarArr[i7];
        if (aVar == null) {
            f7 = 0.0f;
        } else {
            int i8 = 0;
            a aVar2 = aVar;
            while (true) {
                a aVar3 = aVarArr[i7];
                boolean z7 = this.f933a;
                cVar = this.f934b;
                fArr = this.f938f;
                fArr2 = this.f939g;
                if (aVar3 == null) {
                    f7 = f9;
                    z6 = z7;
                    i6 = 1;
                    break;
                }
                long j4 = aVar.f925a;
                f7 = f9;
                int i9 = i7;
                long j6 = aVar3.f925a;
                float f10 = j4 - j6;
                z6 = z7;
                i6 = 1;
                float fAbs = Math.abs(j6 - aVar2.f925a);
                aVar2 = (cVar == c.f930a || z6) ? aVar3 : aVar;
                if (f10 > 100.0f || fAbs > 40.0f) {
                    break;
                }
                fArr[i8] = aVar3.f926b;
                fArr2[i8] = -f10;
                i7 = (i9 == 0 ? 20 : i9) - 1;
                i8++;
                if (i8 >= 20) {
                    break;
                }
                f9 = f7;
            }
            if (i8 >= this.f935c) {
                int iOrdinal = cVar.ordinal();
                if (iOrdinal == 0) {
                    try {
                        float[] fArr3 = this.f940h;
                        android.support.v4.media.session.b.C(fArr2, fArr, i8, fArr3);
                        fSignum = fArr3[1];
                    } catch (IllegalArgumentException unused) {
                        fSignum = f7;
                    }
                } else {
                    if (iOrdinal != i6) {
                        throw new v();
                    }
                    int i10 = i8 - i6;
                    float f11 = fArr2[i10];
                    int i11 = i10;
                    float fAbs2 = f7;
                    while (i11 > 0) {
                        int i12 = i11 - 1;
                        float f12 = fArr2[i12];
                        if (f11 != f12) {
                            float f13 = (z6 ? -fArr[i12] : fArr[i11] - fArr[i12]) / (f11 - f12);
                            fAbs2 += Math.abs(f13) * (f13 - (Math.signum(fAbs2) * ((float) Math.sqrt(Math.abs(fAbs2) * 2))));
                            if (i11 == i10) {
                                fAbs2 *= 0.5f;
                            }
                        }
                        i11--;
                        f11 = f12;
                    }
                    fSignum = Math.signum(fAbs2) * ((float) Math.sqrt(Math.abs(fAbs2) * 2));
                }
                f9 = fSignum * 1000;
            } else {
                f9 = f7;
            }
        }
        if (f9 == f7 || Float.isNaN(f9)) {
            return f7;
        }
        if (f9 <= f7) {
            f8 = -f8;
            if (f9 >= f8) {
                return f9;
            }
        } else if (f9 <= f8) {
            f8 = f9;
        }
        return f8;
    }

    public /* synthetic */ d() {
        this(false, c.f930a);
    }

    public d(int i6) {
        this(true, c.f931b);
    }
}
