package c1;

import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;

/* JADX INFO: compiled from: ShapeAppearancePathProvider.java */
/* JADX INFO: loaded from: classes.dex */
public class l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final m[] f3454a = new m[4];

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final Matrix[] f3455b = new Matrix[4];

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final Matrix[] f3456c = new Matrix[4];

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final PointF f3457d = new PointF();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final Path f3458e = new Path();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final Path f3459f = new Path();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final m f3460g = new m();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final float[] f3461h = new float[2];

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private final float[] f3462i = new float[2];

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final Path f3463j = new Path();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final Path f3464k = new Path();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private boolean f3465l = true;

    /* JADX INFO: compiled from: ShapeAppearancePathProvider.java */
    private static class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        static final l f3466a = new l();
    }

    /* JADX INFO: compiled from: ShapeAppearancePathProvider.java */
    public interface b {
        void a(m mVar, Matrix matrix, int i3);

        void b(m mVar, Matrix matrix, int i3);
    }

    /* JADX INFO: compiled from: ShapeAppearancePathProvider.java */
    static final class c {

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

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

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

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

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final float f3471e;

        c(k kVar, float f3, RectF rectF, b bVar, Path path) {
            this.f3470d = bVar;
            this.f3467a = kVar;
            this.f3471e = f3;
            this.f3469c = rectF;
            this.f3468b = path;
        }
    }

    public l() {
        for (int i3 = 0; i3 < 4; i3++) {
            this.f3454a[i3] = new m();
            this.f3455b[i3] = new Matrix();
            this.f3456c[i3] = new Matrix();
        }
    }

    private float a(int i3) {
        return (i3 + 1) * 90;
    }

    private void b(c cVar, int i3) {
        this.f3461h[0] = this.f3454a[i3].k();
        this.f3461h[1] = this.f3454a[i3].l();
        this.f3455b[i3].mapPoints(this.f3461h);
        if (i3 == 0) {
            Path path = cVar.f3468b;
            float[] fArr = this.f3461h;
            path.moveTo(fArr[0], fArr[1]);
        } else {
            Path path2 = cVar.f3468b;
            float[] fArr2 = this.f3461h;
            path2.lineTo(fArr2[0], fArr2[1]);
        }
        this.f3454a[i3].d(this.f3455b[i3], cVar.f3468b);
        b bVar = cVar.f3470d;
        if (bVar != null) {
            bVar.b(this.f3454a[i3], this.f3455b[i3], i3);
        }
    }

    private void c(c cVar, int i3) {
        int i4 = (i3 + 1) % 4;
        this.f3461h[0] = this.f3454a[i3].i();
        this.f3461h[1] = this.f3454a[i3].j();
        this.f3455b[i3].mapPoints(this.f3461h);
        this.f3462i[0] = this.f3454a[i4].k();
        this.f3462i[1] = this.f3454a[i4].l();
        this.f3455b[i4].mapPoints(this.f3462i);
        float f3 = this.f3461h[0];
        float[] fArr = this.f3462i;
        float fMax = Math.max(((float) Math.hypot(f3 - fArr[0], r1[1] - fArr[1])) - 0.001f, 0.0f);
        float fI = i(cVar.f3469c, i3);
        this.f3460g.n(0.0f, 0.0f);
        f fVarJ = j(i3, cVar.f3467a);
        fVarJ.b(fMax, fI, cVar.f3471e, this.f3460g);
        this.f3463j.reset();
        this.f3460g.d(this.f3456c[i3], this.f3463j);
        if (this.f3465l && Build.VERSION.SDK_INT >= 19 && (fVarJ.a() || l(this.f3463j, i3) || l(this.f3463j, i4))) {
            Path path = this.f3463j;
            path.op(path, this.f3459f, Path.Op.DIFFERENCE);
            this.f3461h[0] = this.f3460g.k();
            this.f3461h[1] = this.f3460g.l();
            this.f3456c[i3].mapPoints(this.f3461h);
            Path path2 = this.f3458e;
            float[] fArr2 = this.f3461h;
            path2.moveTo(fArr2[0], fArr2[1]);
            this.f3460g.d(this.f3456c[i3], this.f3458e);
        } else {
            this.f3460g.d(this.f3456c[i3], cVar.f3468b);
        }
        b bVar = cVar.f3470d;
        if (bVar != null) {
            bVar.a(this.f3460g, this.f3456c[i3], i3);
        }
    }

    private void f(int i3, RectF rectF, PointF pointF) {
        if (i3 == 1) {
            pointF.set(rectF.right, rectF.bottom);
            return;
        }
        if (i3 == 2) {
            pointF.set(rectF.left, rectF.bottom);
        } else if (i3 != 3) {
            pointF.set(rectF.right, rectF.top);
        } else {
            pointF.set(rectF.left, rectF.top);
        }
    }

    private c1.c g(int i3, k kVar) {
        return i3 != 1 ? i3 != 2 ? i3 != 3 ? kVar.t() : kVar.r() : kVar.j() : kVar.l();
    }

    private d h(int i3, k kVar) {
        return i3 != 1 ? i3 != 2 ? i3 != 3 ? kVar.s() : kVar.q() : kVar.i() : kVar.k();
    }

    private float i(RectF rectF, int i3) {
        float[] fArr = this.f3461h;
        m[] mVarArr = this.f3454a;
        fArr[0] = mVarArr[i3].f3474c;
        fArr[1] = mVarArr[i3].f3475d;
        this.f3455b[i3].mapPoints(fArr);
        return (i3 == 1 || i3 == 3) ? Math.abs(rectF.centerX() - this.f3461h[0]) : Math.abs(rectF.centerY() - this.f3461h[1]);
    }

    private f j(int i3, k kVar) {
        return i3 != 1 ? i3 != 2 ? i3 != 3 ? kVar.o() : kVar.p() : kVar.n() : kVar.h();
    }

    public static l k() {
        return a.f3466a;
    }

    private boolean l(Path path, int i3) {
        this.f3464k.reset();
        this.f3454a[i3].d(this.f3455b[i3], this.f3464k);
        RectF rectF = new RectF();
        path.computeBounds(rectF, true);
        this.f3464k.computeBounds(rectF, true);
        path.op(this.f3464k, Path.Op.INTERSECT);
        path.computeBounds(rectF, true);
        if (rectF.isEmpty()) {
            return rectF.width() > 1.0f && rectF.height() > 1.0f;
        }
        return true;
    }

    private void m(c cVar, int i3) {
        h(i3, cVar.f3467a).b(this.f3454a[i3], 90.0f, cVar.f3471e, cVar.f3469c, g(i3, cVar.f3467a));
        float fA = a(i3);
        this.f3455b[i3].reset();
        f(i3, cVar.f3469c, this.f3457d);
        Matrix matrix = this.f3455b[i3];
        PointF pointF = this.f3457d;
        matrix.setTranslate(pointF.x, pointF.y);
        this.f3455b[i3].preRotate(fA);
    }

    private void n(int i3) {
        this.f3461h[0] = this.f3454a[i3].i();
        this.f3461h[1] = this.f3454a[i3].j();
        this.f3455b[i3].mapPoints(this.f3461h);
        float fA = a(i3);
        this.f3456c[i3].reset();
        Matrix matrix = this.f3456c[i3];
        float[] fArr = this.f3461h;
        matrix.setTranslate(fArr[0], fArr[1]);
        this.f3456c[i3].preRotate(fA);
    }

    public void d(k kVar, float f3, RectF rectF, Path path) {
        e(kVar, f3, rectF, null, path);
    }

    public void e(k kVar, float f3, RectF rectF, b bVar, Path path) {
        path.rewind();
        this.f3458e.rewind();
        this.f3459f.rewind();
        this.f3459f.addRect(rectF, Path.Direction.CW);
        c cVar = new c(kVar, f3, rectF, bVar, path);
        for (int i3 = 0; i3 < 4; i3++) {
            m(cVar, i3);
            n(i3);
        }
        for (int i4 = 0; i4 < 4; i4++) {
            b(cVar, i4);
            c(cVar, i4);
        }
        path.close();
        this.f3458e.close();
        if (Build.VERSION.SDK_INT < 19 || this.f3458e.isEmpty()) {
            return;
        }
        path.op(this.f3458e, Path.Op.UNION);
    }
}
