package com.b.a.a;

import android.os.SystemClock;
import com.b.a.a.u.b;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.smtt.sdk.TbsMediaPlayer$TbsMediaPlayerListener;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;

class u$f {
    final /* synthetic */ u bHP;
    private ArrayList<b> bIc;
    private a[] bId;
    private int bIe;
    private float[][] bIf;
    private float[][] bIg;
    private float[][] bIh;
    private int[] bIi;
    private int bIj;
    private int bIk;
    private int bIl;

    private u$f(u uVar) {
        this.bHP = uVar;
        AppMethodBeat.i(55634);
        this.bIc = new ArrayList();
        this.bId = new a[5];
        this.bIe = 0;
        this.bIf = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
        this.bIg = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
        this.bIh = (float[][]) Array.newInstance(Float.TYPE, new int[]{3, 3});
        this.bIi = new int[6];
        this.bIj = 5;
        this.bIk = -1;
        this.bIl = 0;
        AppMethodBeat.o(55634);
    }

    /* synthetic */ u$f(u uVar, byte b) {
        this(uVar);
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized void reset() {
        AppMethodBeat.i(55635);
        this.bIc.clear();
        this.bId = new a[5];
        this.bIe = 0;
        this.bIf = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
        this.bIg = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
        this.bIh = (float[][]) Array.newInstance(Float.TYPE, new int[]{3, 3});
        this.bIi = new int[6];
        this.bIj = 5;
        AppMethodBeat.o(55635);
    }

    private synchronized boolean wy() {
        boolean z;
        AppMethodBeat.i(55636);
        if (this.bIe >= 20) {
            float[] fArr = this.bIf[0];
            fArr[2] = fArr[2] / 20.0f;
            fArr = this.bIf[1];
            fArr[2] = fArr[2] / 20.0f;
            fArr = this.bIf[2];
            fArr[2] = fArr[2] / 20.0f;
            fArr = this.bIg[0];
            fArr[2] = fArr[2] / 20.0f;
            fArr = this.bIg[1];
            fArr[2] = fArr[2] / 20.0f;
            fArr = this.bIg[2];
            fArr[2] = fArr[2] / 20.0f;
            float f = this.bIg[0][2];
            float f2 = this.bIf[0][0] - this.bIf[0][2];
            float f3 = this.bIf[0][2] - this.bIf[0][1];
            float f4 = this.bIg[1][2];
            float f5 = this.bIf[1][0] - this.bIf[1][2];
            float f6 = this.bIf[1][2] - this.bIf[1][1];
            float f7 = this.bIg[2][2];
            float f8 = this.bIf[2][0] - this.bIf[2][2];
            float f9 = this.bIf[2][2] - this.bIf[2][1];
            this.bIh[0][0] = (f * 0.32999998f) + (0.67f * this.bIh[0][0]);
            this.bIh[0][1] = (f2 * 0.32999998f) + (0.67f * this.bIh[0][1]);
            this.bIh[0][2] = (f3 * 0.32999998f) + (0.67f * this.bIh[0][2]);
            this.bIh[1][0] = (0.67f * this.bIh[1][0]) + (f4 * 0.32999998f);
            this.bIh[1][1] = (0.67f * this.bIh[1][1]) + (0.32999998f * f5);
            this.bIh[1][2] = (0.67f * this.bIh[1][2]) + (0.32999998f * f6);
            this.bIh[2][0] = (0.67f * this.bIh[2][0]) + (0.32999998f * f7);
            this.bIh[2][1] = (0.67f * this.bIh[2][1]) + (0.32999998f * f8);
            this.bIh[2][2] = (0.67f * this.bIh[2][2]) + (0.32999998f * f9);
            a(wz());
            this.bIe = 0;
            this.bIf = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
            this.bIg = new float[][]{new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}, new float[]{Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f}};
            if (this.bIc.size() >= 100) {
                this.bIc.subList(0, 20).clear();
                this.bIc.trimToSize();
            }
            z = true;
            AppMethodBeat.o(55636);
        } else {
            z = false;
            AppMethodBeat.o(55636);
        }
        return z;
    }

    private synchronized a wz() {
        a aVar;
        Object obj;
        float abs;
        float abs2;
        float abs3;
        float f;
        int i;
        int i2;
        AppMethodBeat.i(55637);
        Object obj2 = this.bIl == 0 ? 1 : null;
        if (obj2 != null) {
            this.bIj = ((double) Math.abs(this.bIh[2][0])) < 9.3d ? 5 : 2;
            this.bIi = new int[6];
            obj = null;
        } else {
            Object obj3 = (Math.abs(this.bIh[0][0]) < 7.0f || (this.bIh[1][1] < 2.3f && this.bIh[1][2] < 2.3f)) ? null : 1;
            if (obj3 != null) {
                this.bIj = 2;
                this.bIi = new int[6];
                obj = obj3;
            } else {
                int i3;
                abs = Math.abs(this.bIh[0][0]);
                abs2 = Math.abs(this.bIh[1][0]);
                abs3 = Math.abs(this.bIh[2][0]);
                if (abs > abs2) {
                    if (abs > abs3) {
                        i3 = 0;
                    } else {
                        i3 = 2;
                    }
                } else if (abs2 > abs3) {
                    i3 = 1;
                } else {
                    i3 = 2;
                }
                f = 0.0f;
                int i4 = 0;
                i = 0;
                for (i2 = 0; i2 < 3; i2++) {
                    if (i2 != i3) {
                        for (int i5 = 1; i5 < 3; i5++) {
                            if (this.bIh[i2][i5] > f) {
                                f = this.bIh[i2][i5];
                                i = i5;
                                i4 = i2;
                            }
                        }
                    }
                }
                i3 = ((i4 * 2) + i) - 1;
                int[] iArr = this.bIi;
                iArr[i3] = iArr[i3] + 1;
                i3 = 0;
                while (i3 <= 5) {
                    if (i3 != this.bIj && this.bIi[i3] > this.bIi[this.bIj]) {
                        this.bIj = i3;
                    }
                    i3++;
                }
                obj = obj3;
            }
        }
        if (this.bIk >= 0 && this.bIk <= 5) {
            this.bIj = this.bIk;
        }
        aVar = new a(this, (byte) 0);
        aVar = new a(this, (byte) 0);
        if (this.bId[0] != null) {
            aVar.bIq = this.bId[0].bIq;
            aVar.bIn = this.bId[0].bIn;
        }
        if (this.bId[4] != null) {
            aVar.bIq = this.bId[4].bIq;
            aVar.bIn = this.bId[4].bIn;
        }
        if (!this.bIc.isEmpty()) {
            b bVar;
            i2 = this.bIc.size();
            float[] fArr = new float[6];
            float[] fArr2 = new float[6];
            Iterator it = this.bIc.iterator();
            abs3 = 0.0f;
            float f2 = 0.0f;
            while (it.hasNext()) {
                bVar = (b) it.next();
                if (obj == null) {
                    abs2 = bVar.bHB;
                } else {
                    abs2 = bVar.bHE;
                }
                f2 += abs2;
                if (obj == null) {
                    abs2 = bVar.bHJ;
                } else {
                    abs2 = (float) Math.sqrt((double) (((bVar.bHC * bVar.bHC) + (bVar.bHD * bVar.bHD)) + (bVar.bHE * bVar.bHE)));
                    bVar.bHI = abs2;
                }
                abs3 += abs2;
                for (i = 0; i <= 5; i++) {
                    fArr[i] = fArr[i] + bVar.bHN[i];
                    fArr2[i] = fArr2[i] + bVar.bHO[i];
                }
            }
            float f3 = f2 / ((float) i2);
            float f4 = abs3 / ((float) i2);
            float f5 = obj == null ? f3 : f4;
            float[] fArr3 = new float[]{(float) Math.atan2((double) fArr[0], (double) fArr2[0]), (float) Math.atan2((double) fArr[1], (double) fArr2[1]), (float) Math.atan2((double) fArr[2], (double) fArr2[2]), (float) Math.atan2((double) fArr[3], (double) fArr2[3]), (float) Math.atan2((double) fArr[4], (double) fArr2[4]), (float) Math.atan2((double) fArr[5], (double) fArr2[5])};
            float f6 = obj == null ? f3 : f4;
            abs2 = 0.0f;
            float f7 = obj == null ? 1.2f : 1.0f;
            float f8 = obj2 != null ? 0.08726647f : 0.2617994f;
            Iterator it2 = this.bIc.iterator();
            f2 = f4;
            float f9 = 0.0f;
            float f10 = 0.0f;
            int i6 = 0;
            while (it2.hasNext()) {
                float f11;
                bVar = (b) it2.next();
                if (obj == null) {
                    f11 = bVar.bHB;
                } else {
                    f11 = bVar.bHI;
                }
                if (obj == null) {
                    abs3 = bVar.bHJ;
                } else {
                    abs3 = bVar.bHI;
                }
                float f12 = obj == null ? f3 : f4;
                if (i6 > 0) {
                    float f13;
                    if (f6 < f11) {
                        if (obj2 == null) {
                            f = f11 - f12;
                            if (f > 2.0f * f7) {
                                f13 = f / 2.0f;
                                f6 = f11;
                            }
                        }
                        f13 = f7;
                        f6 = f11;
                    } else {
                        f13 = f7;
                    }
                    if (f2 < abs3) {
                        f = abs3;
                    } else {
                        f = f2;
                    }
                    if (f11 > f12) {
                        f7 = f13;
                        f2 = f;
                        i6++;
                    } else {
                        if (i6 <= 10) {
                            Object obj4 = 1;
                            if (aVar.bIq != 0 && bVar.time - aVar.bIq < 250) {
                                obj4 = null;
                            }
                            if (obj4 != null && f - f4 < 0.3f) {
                                obj4 = null;
                            }
                            if (obj4 != null) {
                                aVar.bIm++;
                                abs2 += f6;
                                f2 = (float) Math.atan2((double) (bVar.bHN[this.bIj] + f10), (double) (bVar.bHO[this.bIj] + f9));
                                abs3 = Math.abs(f2 - fArr3[this.bIj]);
                                if (abs3 > 3.1415927f) {
                                    abs3 = 6.2831855f - abs3;
                                }
                                Object obj5 = abs3 >= f8 ? 1 : null;
                                abs3 = 1.0f;
                                if (obj5 != null) {
                                    abs3 = 0.93f;
                                } else {
                                    f2 = fArr3[this.bIj];
                                }
                                f7 = (float) (Math.sin((double) f2) * ((double) abs3));
                                abs3 = (float) (((double) abs3) * Math.cos((double) f2));
                                aVar.x += f7;
                                aVar.y += abs3;
                                if (bVar.time - aVar.bIq > 250) {
                                    aVar.x -= f7;
                                    aVar.y -= abs3;
                                    aVar.bIm++;
                                }
                            }
                            aVar.bIq = bVar.time;
                        }
                        abs3 = bVar.bHN[this.bIj];
                        f7 = f13;
                        f2 = f;
                        f9 = bVar.bHO[this.bIj];
                        f10 = abs3;
                        i6 = 0;
                    }
                } else if (f11 <= f12) {
                    abs3 = bVar.bHN[this.bIj];
                    f9 = bVar.bHO[this.bIj];
                    f10 = abs3;
                } else if (f11 - f12 >= f7) {
                    f2 = abs3;
                    f6 = f11;
                    i6 = 1;
                }
            }
            if (aVar.bIm > 0) {
                if (obj == null) {
                    abs = 0.0f;
                } else {
                    abs = 0.08f;
                }
                abs2 /= (float) aVar.bIm;
                abs3 = aVar.bIn;
                abs += ((abs2 - f5) / 15.0f) + 0.537f;
                if (abs3 != 0.0f) {
                    abs = (abs * 0.67f) + (0.33f * abs3);
                }
                aVar.bIn = abs;
                aVar.x *= aVar.bIn;
                aVar.y *= aVar.bIn;
                aVar.bIo = ((float) aVar.bIm) * aVar.bIn;
            }
        }
        aVar.bIp = aVar.bIo / ((float) (this.bIc.size() / 20));
        if (this.bId[0] != null) {
            aVar.x += this.bId[0].x;
            aVar.y += this.bId[0].y;
            aVar.z += this.bId[0].z;
            aVar.bIm += this.bId[0].bIm;
            aVar.bIo += this.bId[0].bIo;
        }
        if (this.bId[4] != null && aVar.bIm > 0) {
            this.bId[4].x = ((this.bId[4].x + aVar.x) + (aVar.x * aVar.bIn)) / 2.0f;
            this.bId[4].y = ((this.bId[4].y + aVar.y) + (aVar.y * aVar.bIn)) / 2.0f;
        }
        AppMethodBeat.o(55637);
        return aVar;
    }

    private synchronized void a(a aVar) {
        AppMethodBeat.i(55638);
        System.arraycopy(this.bId, 1, this.bId, 0, 4);
        if (this.bId[4] == null || SystemClock.elapsedRealtime() - aVar.bIq <= 1000) {
            this.bId[4] = aVar;
            AppMethodBeat.o(55638);
        } else {
            a aVar2 = this.bId[4];
            aVar2.x = (aVar2.x + aVar.x) / 2.0f;
            aVar2.y = (aVar2.y + aVar.y) / 2.0f;
            aVar2.z = (aVar2.z + aVar.z) / 2.0f;
            aVar2.bIm = Math.round(((float) (aVar2.bIm + aVar.bIm)) / 2.0f);
            aVar2.bIn = (aVar2.bIn + aVar.bIn) / 2.0f;
            aVar2.bIo = (aVar2.bIo + aVar.bIo) / 2.0f;
            aVar2.bIq = aVar.bIq;
            aVar2.bIp = aVar.bIp;
            AppMethodBeat.o(55638);
        }
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized void a(b bVar) {
        AppMethodBeat.i(55639);
        if (this.bIl > 0 && this.bIl < TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_EXTRA_SUBTITLE_COUNT) {
            this.bIl--;
        }
        this.bIc.add(bVar);
        this.bIe++;
        if (bVar.bHC > this.bIf[0][0]) {
            this.bIf[0][0] = bVar.bHC;
        }
        if (bVar.bHC < this.bIf[0][1]) {
            this.bIf[0][1] = bVar.bHC;
        }
        float[] fArr = this.bIf[0];
        fArr[2] = fArr[2] + bVar.bHC;
        if (bVar.bHD > this.bIf[1][0]) {
            this.bIf[1][0] = bVar.bHD;
        }
        if (bVar.bHD < this.bIf[1][1]) {
            this.bIf[1][1] = bVar.bHD;
        }
        fArr = this.bIf[1];
        fArr[2] = fArr[2] + bVar.bHD;
        if (bVar.bHE > this.bIf[2][0]) {
            this.bIf[2][0] = bVar.bHE;
        }
        if (bVar.bHE < this.bIf[2][1]) {
            this.bIf[2][1] = bVar.bHE;
        }
        fArr = this.bIf[2];
        fArr[2] = fArr[2] + bVar.bHE;
        if (bVar.bHF > this.bIg[0][0]) {
            this.bIg[0][0] = bVar.bHF;
        }
        if (bVar.bHF < this.bIg[0][1]) {
            this.bIg[0][1] = bVar.bHF;
        }
        fArr = this.bIg[0];
        fArr[2] = fArr[2] + bVar.bHF;
        if (bVar.bHG > this.bIg[1][0]) {
            this.bIg[1][0] = bVar.bHG;
        }
        if (bVar.bHG < this.bIg[1][1]) {
            this.bIg[1][1] = bVar.bHG;
        }
        fArr = this.bIg[1];
        fArr[2] = fArr[2] + bVar.bHG;
        if (bVar.bHH > this.bIg[2][0]) {
            this.bIg[2][0] = bVar.bHH;
        }
        if (bVar.bHH < this.bIg[2][1]) {
            this.bIg[2][1] = bVar.bHH;
        }
        fArr = this.bIg[2];
        fArr[2] = fArr[2] + bVar.bHH;
        if (wy()) {
            u.b(this.bHP);
        }
        AppMethodBeat.o(55639);
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized a wA() {
        a wB;
        AppMethodBeat.i(55640);
        if (this.bId[4] != null) {
            wB = this.bId[4].wB();
            AppMethodBeat.o(55640);
        } else {
            wB = null;
            AppMethodBeat.o(55640);
        }
        return wB;
    }
}
