package o;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.mj0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1886mj0 {
    public final boolean a;
    public final int b;
    public final int c;
    public final C1230fp[] d;
    public int e;
    public final float[] f;
    public final float[] g;
    public final float[] h;

    public /* synthetic */ C1886mj0() {
        this(false, 1);
    }

    public final void a(float f, long j) {
        int i = (this.e + 1) % 20;
        this.e = i;
        C1230fp[] c1230fpArr = this.d;
        C1230fp c1230fp = c1230fpArr[i];
        if (c1230fp != null) {
            c1230fp.a = j;
            c1230fp.b = f;
        } else {
            C1230fp c1230fp2 = new C1230fp();
            c1230fp2.a = j;
            c1230fp2.b = f;
            c1230fpArr[i] = c1230fp2;
        }
    }

    public final float b(float f) {
        int i;
        float[] fArr;
        float[] fArr2;
        float f2;
        boolean z;
        float fSignum;
        float f3 = f;
        float f4 = 0.0f;
        if (f3 <= 0.0f) {
            AbstractC2133pH.b("maximumVelocity should be a positive value. You specified=" + f3);
        }
        int i2 = this.e;
        C1230fp[] c1230fpArr = this.d;
        C1230fp c1230fp = c1230fpArr[i2];
        if (c1230fp == null) {
            f2 = 0.0f;
        } else {
            int i3 = 0;
            C1230fp c1230fp2 = c1230fp;
            while (true) {
                C1230fp c1230fp3 = c1230fpArr[i2];
                boolean z2 = this.a;
                i = this.b;
                fArr = this.f;
                fArr2 = this.g;
                if (c1230fp3 == null) {
                    f2 = f4;
                    z = z2;
                    break;
                }
                long j = c1230fp.a;
                f2 = f4;
                int i4 = i2;
                long j2 = c1230fp3.a;
                float f5 = j - j2;
                z = z2;
                float fAbs = Math.abs(j2 - c1230fp2.a);
                c1230fp2 = (i == 1 || z) ? c1230fp3 : c1230fp;
                if (f5 > 100.0f || fAbs > 40.0f) {
                    break;
                }
                fArr[i3] = c1230fp3.b;
                fArr2[i3] = -f5;
                i2 = (i4 == 0 ? 20 : i4) - 1;
                i3++;
                if (i3 >= 20) {
                    break;
                }
                f4 = f2;
            }
            if (i3 >= this.c) {
                int iW = AbstractC2462sn.w(i);
                if (iW == 0) {
                    try {
                        float[] fArr3 = this.h;
                        AbstractC0249Jp.Z(fArr2, fArr, i3, fArr3);
                        fSignum = fArr3[1];
                    } catch (IllegalArgumentException unused) {
                        fSignum = f2;
                    }
                } else {
                    if (iW != 1) {
                        throw new C2170pj();
                    }
                    int i5 = i3 - 1;
                    float f6 = fArr2[i5];
                    int i6 = i5;
                    float fAbs2 = f2;
                    while (i6 > 0) {
                        int i7 = i6 - 1;
                        float f7 = fArr2[i7];
                        if (f6 != f7) {
                            float f8 = (z ? -fArr[i7] : fArr[i6] - fArr[i7]) / (f6 - f7);
                            fAbs2 += Math.abs(f8) * (f8 - (Math.signum(fAbs2) * ((float) Math.sqrt(Math.abs(fAbs2) * 2))));
                            if (i6 == i5) {
                                fAbs2 *= 0.5f;
                            }
                        }
                        i6--;
                        f6 = f7;
                    }
                    fSignum = Math.signum(fAbs2) * ((float) Math.sqrt(Math.abs(fAbs2) * 2));
                }
                f4 = fSignum * 1000;
            } else {
                f4 = f2;
            }
        }
        if (f4 == f2 || Float.isNaN(f4)) {
            return f2;
        }
        if (f4 <= f2) {
            f3 = -f3;
            if (f4 >= f3) {
                return f4;
            }
        } else if (f4 <= f3) {
            f3 = f4;
        }
        return f3;
    }

    public C1886mj0(boolean z, int i) {
        int i2;
        this.a = z;
        this.b = i;
        if (z && AbstractC2462sn.b(i, 1)) {
            throw new IllegalStateException("Lsq2 not (yet) supported for differential axes");
        }
        int iW = AbstractC2462sn.w(i);
        if (iW == 0) {
            i2 = 3;
        } else {
            if (iW != 1) {
                throw new C2170pj();
            }
            i2 = 2;
        }
        this.c = i2;
        this.d = new C1230fp[20];
        this.f = new float[20];
        this.g = new float[20];
        this.h = new float[3];
    }

    public C1886mj0(int i) {
        this(true, 2);
    }
}
