package androidx.core.view;

import android.view.MotionEvent;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes.dex */
class q0 {

    /* renamed from: a, reason: collision with root package name */
    private final float[] f3900a = new float[20];

    /* renamed from: b, reason: collision with root package name */
    private final long[] f3901b = new long[20];

    /* renamed from: c, reason: collision with root package name */
    private float f3902c = BitmapDescriptorFactory.HUE_RED;

    /* renamed from: d, reason: collision with root package name */
    private int f3903d = 0;

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

    private void b() {
        this.f3903d = 0;
        this.f3902c = BitmapDescriptorFactory.HUE_RED;
    }

    private float e() {
        long[] jArr;
        long j10;
        int i10 = this.f3903d;
        if (i10 < 2) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        int i11 = this.f3904e;
        int i12 = ((i11 + 20) - (i10 - 1)) % 20;
        long j11 = this.f3901b[i11];
        while (true) {
            jArr = this.f3901b;
            j10 = jArr[i12];
            if (j11 - j10 <= 100) {
                break;
            }
            this.f3903d--;
            i12 = (i12 + 1) % 20;
        }
        int i13 = this.f3903d;
        if (i13 < 2) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        if (i13 == 2) {
            int i14 = (i12 + 1) % 20;
            long j12 = jArr[i14];
            return j10 == j12 ? BitmapDescriptorFactory.HUE_RED : this.f3900a[i14] / ((float) (j12 - j10));
        }
        float f10 = 0.0f;
        int i15 = 0;
        for (int i16 = 0; i16 < this.f3903d - 1; i16++) {
            int i17 = i16 + i12;
            long[] jArr2 = this.f3901b;
            long j13 = jArr2[i17 % 20];
            int i18 = (i17 + 1) % 20;
            if (jArr2[i18] != j13) {
                i15++;
                float f11 = f(f10);
                float f12 = this.f3900a[i18] / ((float) (this.f3901b[i18] - j13));
                f10 += (f12 - f11) * Math.abs(f12);
                if (i15 == 1) {
                    f10 *= 0.5f;
                }
            }
        }
        return f(f10);
    }

    private static float f(float f10) {
        return (f10 < BitmapDescriptorFactory.HUE_RED ? -1.0f : 1.0f) * ((float) Math.sqrt(Math.abs(f10) * 2.0f));
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(MotionEvent motionEvent) {
        long eventTime = motionEvent.getEventTime();
        if (this.f3903d != 0 && eventTime - this.f3901b[this.f3904e] > 40) {
            b();
        }
        int i10 = (this.f3904e + 1) % 20;
        this.f3904e = i10;
        int i11 = this.f3903d;
        if (i11 != 20) {
            this.f3903d = i11 + 1;
        }
        this.f3900a[i10] = motionEvent.getAxisValue(26);
        this.f3901b[this.f3904e] = eventTime;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void c(int i10, float f10) {
        float e10 = e() * i10;
        this.f3902c = e10;
        if (e10 < (-Math.abs(f10))) {
            this.f3902c = -Math.abs(f10);
        } else if (this.f3902c > Math.abs(f10)) {
            this.f3902c = Math.abs(f10);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public float d(int i10) {
        return i10 != 26 ? BitmapDescriptorFactory.HUE_RED : this.f3902c;
    }
}
