package androidx.constraintlayout.motion.widget;

import android.view.View;
import android.view.animation.Interpolator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import p.c;
import p.d;
import p.e;

/* JADX INFO: compiled from: MotionController.java */
/* JADX INFO: loaded from: classes.dex */
public class g {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private k f1156b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private k f1157c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private f f1158d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private f f1159e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private l.a[] f1160f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private l.a f1161g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    float f1162h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    float f1163i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private int[] f1164j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private double[] f1165k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private double[] f1166l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private String[] f1167m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private float[] f1168n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private ArrayList<k> f1169o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private HashMap<String, p.e> f1170p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private HashMap<String, p.d> f1171q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private HashMap<String, p.c> f1172r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private e[] f1173s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private int f1174t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private View f1175u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private int f1176v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private float f1177w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private Interpolator f1178x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private boolean f1179y;

    private float a(float f3, float[] fArr) {
        float f4 = 0.0f;
        if (fArr != null) {
            fArr[0] = 1.0f;
        } else {
            float f5 = this.f1163i;
            if (f5 != 1.0d) {
                float f6 = this.f1162h;
                if (f3 < f6) {
                    f3 = 0.0f;
                }
                if (f3 > f6 && f3 < 1.0d) {
                    f3 = Math.min((f3 - f6) * f5, 1.0f);
                }
            }
        }
        l.b bVar = this.f1156b.f1216e;
        float f7 = Float.NaN;
        for (k kVar : this.f1169o) {
            l.b bVar2 = kVar.f1216e;
            if (bVar2 != null) {
                float f8 = kVar.f1218g;
                if (f8 < f3) {
                    bVar = bVar2;
                    f4 = f8;
                } else if (Float.isNaN(f7)) {
                    f7 = kVar.f1218g;
                }
            }
        }
        if (bVar == null) {
            return f3;
        }
        float f9 = (Float.isNaN(f7) ? 1.0f : f7) - f4;
        double d3 = (f3 - f4) / f9;
        float fA = f4 + (((float) bVar.a(d3)) * f9);
        if (fArr != null) {
            fArr[0] = (float) bVar.b(d3);
        }
        return fA;
    }

    public void b(double d3, float[] fArr, float[] fArr2) {
        double[] dArr = new double[4];
        double[] dArr2 = new double[4];
        this.f1160f[0].b(d3, dArr);
        this.f1160f[0].d(d3, dArr2);
        Arrays.fill(fArr2, 0.0f);
        this.f1156b.b(d3, this.f1164j, dArr, fArr, dArr2, fArr2);
    }

    boolean c(View view, float f3, long j3, l.c cVar) {
        e.a aVar;
        boolean zC;
        int i3;
        double d3;
        float fA = a(f3, null);
        int i4 = this.f1176v;
        if (i4 != d.f1152a) {
            float f4 = 1.0f / i4;
            float fFloor = ((float) Math.floor(fA / f4)) * f4;
            float f5 = (fA % f4) / f4;
            if (!Float.isNaN(this.f1177w)) {
                f5 = (f5 + this.f1177w) % 1.0f;
            }
            Interpolator interpolator = this.f1178x;
            fA = ((interpolator != null ? interpolator.getInterpolation(f5) : ((double) f5) > 0.5d ? 1.0f : 0.0f) * f4) + fFloor;
        }
        float f6 = fA;
        HashMap<String, p.d> map = this.f1171q;
        if (map != null) {
            Iterator<p.d> it = map.values().iterator();
            while (it.hasNext()) {
                it.next().b(view, f6);
            }
        }
        HashMap<String, p.e> map2 = this.f1170p;
        if (map2 != null) {
            e.a aVar2 = null;
            boolean zB = false;
            for (p.e eVar : map2.values()) {
                if (eVar instanceof e.a) {
                    aVar2 = (e.a) eVar;
                } else {
                    zB |= eVar.b(view, f6, j3, cVar);
                }
            }
            zC = zB;
            aVar = aVar2;
        } else {
            aVar = null;
            zC = false;
        }
        l.a[] aVarArr = this.f1160f;
        if (aVarArr != null) {
            double d4 = f6;
            aVarArr[0].b(d4, this.f1165k);
            this.f1160f[0].d(d4, this.f1166l);
            l.a aVar3 = this.f1161g;
            if (aVar3 != null) {
                double[] dArr = this.f1165k;
                if (dArr.length > 0) {
                    aVar3.b(d4, dArr);
                    this.f1161g.d(d4, this.f1166l);
                }
            }
            if (this.f1179y) {
                d3 = d4;
            } else {
                d3 = d4;
                this.f1156b.c(f6, view, this.f1164j, this.f1165k, this.f1166l, null, this.f1155a);
                this.f1155a = false;
            }
            if (this.f1174t != d.f1152a) {
                if (this.f1175u == null) {
                    this.f1175u = ((View) view.getParent()).findViewById(this.f1174t);
                }
                if (this.f1175u != null) {
                    float top = (r1.getTop() + this.f1175u.getBottom()) / 2.0f;
                    float left = (this.f1175u.getLeft() + this.f1175u.getRight()) / 2.0f;
                    if (view.getRight() - view.getLeft() > 0 && view.getBottom() - view.getTop() > 0) {
                        view.setPivotX(left - view.getLeft());
                        view.setPivotY(top - view.getTop());
                    }
                }
            }
            HashMap<String, p.d> map3 = this.f1171q;
            if (map3 != null) {
                for (p.d dVar : map3.values()) {
                    if (dVar instanceof d.a) {
                        double[] dArr2 = this.f1166l;
                        if (dArr2.length > 1) {
                            ((d.a) dVar).c(view, f6, dArr2[0], dArr2[1]);
                        }
                    }
                }
            }
            if (aVar != null) {
                double[] dArr3 = this.f1166l;
                i3 = 1;
                zC |= aVar.c(view, cVar, f6, j3, dArr3[0], dArr3[1]);
            } else {
                i3 = 1;
            }
            int i5 = i3;
            while (true) {
                l.a[] aVarArr2 = this.f1160f;
                if (i5 >= aVarArr2.length) {
                    break;
                }
                aVarArr2[i5].c(d3, this.f1168n);
                p.a.b(this.f1156b.f1228q.get(this.f1167m[i5 - 1]), view, this.f1168n);
                i5++;
            }
            f fVar = this.f1158d;
            if (fVar.f1153e == 0) {
                if (f6 <= 0.0f) {
                    view.setVisibility(fVar.f1154f);
                } else if (f6 >= 1.0f) {
                    view.setVisibility(this.f1159e.f1154f);
                } else if (this.f1159e.f1154f != fVar.f1154f) {
                    view.setVisibility(0);
                }
            }
            if (this.f1173s != null) {
                int i6 = 0;
                while (true) {
                    e[] eVarArr = this.f1173s;
                    if (i6 >= eVarArr.length) {
                        break;
                    }
                    eVarArr[i6].a(f6, view);
                    i6++;
                }
            }
        } else {
            i3 = 1;
            k kVar = this.f1156b;
            float f7 = kVar.f1220i;
            k kVar2 = this.f1157c;
            float f8 = f7 + ((kVar2.f1220i - f7) * f6);
            float f9 = kVar.f1221j;
            float f10 = f9 + ((kVar2.f1221j - f9) * f6);
            float f11 = kVar.f1222k;
            float f12 = kVar2.f1222k;
            float f13 = kVar.f1223l;
            float f14 = kVar2.f1223l;
            float f15 = f8 + 0.5f;
            int i7 = (int) f15;
            float f16 = f10 + 0.5f;
            int i8 = (int) f16;
            int i9 = (int) (f15 + ((f12 - f11) * f6) + f11);
            int i10 = (int) (f16 + ((f14 - f13) * f6) + f13);
            int i11 = i9 - i7;
            int i12 = i10 - i8;
            if (f12 != f11 || f14 != f13 || this.f1155a) {
                view.measure(View.MeasureSpec.makeMeasureSpec(i11, 1073741824), View.MeasureSpec.makeMeasureSpec(i12, 1073741824));
                this.f1155a = false;
            }
            view.layout(i7, i8, i9, i10);
        }
        HashMap<String, p.c> map4 = this.f1172r;
        if (map4 != null) {
            for (p.c cVar2 : map4.values()) {
                if (cVar2 instanceof c.a) {
                    double[] dArr4 = this.f1166l;
                    ((c.a) cVar2).c(view, f6, dArr4[0], dArr4[i3]);
                } else {
                    cVar2.b(view, f6);
                }
            }
        }
        return zC;
    }

    public String toString() {
        return " start: x: " + this.f1156b.f1220i + " y: " + this.f1156b.f1221j + " end: x: " + this.f1157c.f1220i + " y: " + this.f1157c.f1221j;
    }
}
