package com.google.android.material.shape;

import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import java.util.ArrayList;
import java.util.BitSet;

/* JADX INFO: loaded from: classes2.dex */
public final class w {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final e0[] f23168a = new e0[4];

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final e0 f23174g = new e0();

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

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final boolean f23179l = true;

    public w() {
        for (int i10 = 0; i10 < 4; i10++) {
            this.f23168a[i10] = new e0();
            this.f23169b[i10] = new Matrix();
            this.f23170c[i10] = new Matrix();
        }
    }

    public static d a(int i10, s sVar) {
        return i10 != 1 ? i10 != 2 ? i10 != 3 ? sVar.f23156f : sVar.f23155e : sVar.f23158h : sVar.f23157g;
    }

    private void setCornerPathAndTransform(@NonNull v vVar, int i10, @Nullable float[] fArr) {
        d dVarA = fArr == null ? a(i10, vVar.f23164a) : new c(fArr[i10]);
        s sVar = vVar.f23164a;
        com.bumptech.glide.h hVar = i10 != 1 ? i10 != 2 ? i10 != 3 ? sVar.f23152b : sVar.f23151a : sVar.f23154d : sVar.f23153c;
        e0 e0Var = this.f23168a[i10];
        hVar.getClass();
        RectF rectF = vVar.f23166c;
        hVar.m(vVar.f23167d, dVarA.a(rectF), e0Var);
        float f10 = ((i10 + 1) % 4) * 90;
        Matrix[] matrixArr = this.f23169b;
        matrixArr[i10].reset();
        PointF pointF = this.f23171d;
        if (i10 == 1) {
            pointF.set(rectF.right, rectF.bottom);
        } else if (i10 == 2) {
            pointF.set(rectF.left, rectF.bottom);
        } else if (i10 != 3) {
            pointF.set(rectF.right, rectF.top);
        } else {
            pointF.set(rectF.left, rectF.top);
        }
        matrixArr[i10].setTranslate(pointF.x, pointF.y);
        matrixArr[i10].preRotate(f10);
    }

    public final boolean b(Path path, int i10) {
        Path path2 = this.f23178k;
        path2.reset();
        this.f23168a[i10].c(this.f23169b[i10], path2);
        RectF rectF = new RectF();
        path.computeBounds(rectF, true);
        path2.computeBounds(rectF, true);
        path.op(path2, Path.Op.INTERSECT);
        path.computeBounds(rectF, true);
        if (rectF.isEmpty()) {
            return rectF.width() > 1.0f && rectF.height() > 1.0f;
        }
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r4v1 */
    /* JADX WARN: Type inference failed for: r4v11 */
    /* JADX WARN: Type inference failed for: r4v2, types: [boolean] */
    @RestrictTo({RestrictTo.Scope.f556b})
    public void calculatePath(@NonNull s sVar, @Nullable float[] fArr, float f10, RectF rectF, u uVar, @NonNull Path path) {
        char c6;
        int i10;
        Matrix[] matrixArr;
        Matrix[] matrixArr2;
        float[] fArr2;
        e0[] e0VarArr;
        char c10;
        boolean z10;
        path.rewind();
        Path path2 = this.f23172e;
        path2.rewind();
        Path path3 = this.f23173f;
        path3.rewind();
        path3.addRect(rectF, Path.Direction.CW);
        v vVar = new v(sVar, f10, rectF, uVar, path);
        ?? r42 = 0;
        int i11 = 0;
        while (true) {
            c6 = 1;
            matrixArr = this.f23170c;
            matrixArr2 = this.f23169b;
            fArr2 = this.f23175h;
            e0VarArr = this.f23168a;
            if (i11 >= 4) {
                break;
            }
            setCornerPathAndTransform(vVar, i11, fArr);
            e0 e0Var = e0VarArr[i11];
            fArr2[0] = e0Var.f23060c;
            fArr2[1] = e0Var.f23061d;
            matrixArr2[i11].mapPoints(fArr2);
            matrixArr[i11].reset();
            matrixArr[i11].setTranslate(fArr2[0], fArr2[1]);
            matrixArr[i11].preRotate((r7 % 4) * 90);
            i11++;
        }
        int i12 = 0;
        for (i10 = 4; i12 < i10; i10 = 4) {
            e0 e0Var2 = e0VarArr[i12];
            fArr2[r42] = e0Var2.f23058a;
            fArr2[c6] = e0Var2.f23059b;
            matrixArr2[i12].mapPoints(fArr2);
            Path path4 = vVar.f23165b;
            if (i12 == 0) {
                path4.moveTo(fArr2[r42], fArr2[c6]);
            } else {
                path4.lineTo(fArr2[r42], fArr2[c6]);
            }
            e0VarArr[i12].c(matrixArr2[i12], path4);
            u uVar2 = vVar.pathListener;
            if (uVar2 != null) {
                e0 e0Var3 = e0VarArr[i12];
                Matrix matrix = matrixArr2[i12];
                e.y yVar = (e.y) uVar2;
                BitSet bitSet = ((k) yVar.f25365a).f23099e;
                e0Var3.getClass();
                bitSet.set(i12, (boolean) r42);
                d0[] d0VarArr = ((k) yVar.f25365a).f23097c;
                e0Var3.b(e0Var3.f23063f);
                d0VarArr[i12] = new x(new ArrayList(e0Var3.f23065h), new Matrix(matrix));
            }
            int i13 = i12 + 1;
            int i14 = i13 % 4;
            e0 e0Var4 = e0VarArr[i12];
            fArr2[r42] = e0Var4.f23060c;
            fArr2[c6] = e0Var4.f23061d;
            matrixArr2[i12].mapPoints(fArr2);
            e0 e0Var5 = e0VarArr[i14];
            float f11 = e0Var5.f23058a;
            float[] fArr3 = this.f23176i;
            fArr3[r42] = f11;
            fArr3[1] = e0Var5.f23059b;
            matrixArr2[i14].mapPoints(fArr3);
            int i15 = i12;
            float fMax = Math.max(((float) Math.hypot(fArr2[r42] - fArr3[r42], fArr2[1] - fArr3[1])) - 0.001f, 0.0f);
            e0 e0Var6 = e0VarArr[i15];
            fArr2[0] = e0Var6.f23060c;
            fArr2[1] = e0Var6.f23061d;
            matrixArr2[i15].mapPoints(fArr2);
            RectF rectF2 = vVar.f23166c;
            float fAbs = (i15 == 1 || i15 == 3) ? Math.abs(rectF2.centerX() - fArr2[0]) : Math.abs(rectF2.centerY() - fArr2[1]);
            e0 e0Var7 = this.f23174g;
            e0Var7.e(0.0f, 0.0f, 270.0f, 0.0f);
            s sVar2 = vVar.f23164a;
            f fVar = i15 != 1 ? i15 != 2 ? i15 != 3 ? sVar2.f23160j : sVar2.f23159i : sVar2.f23162l : sVar2.f23161k;
            fVar.e(fMax, fAbs, vVar.f23167d, e0Var7);
            Path path5 = this.f23177j;
            path5.reset();
            e0Var7.c(matrixArr[i15], path5);
            if (this.f23179l && (fVar.d() || b(path5, i15) || b(path5, i14))) {
                path5.op(path5, path3, Path.Op.DIFFERENCE);
                fArr2[0] = e0Var7.f23058a;
                c10 = 1;
                fArr2[1] = e0Var7.f23059b;
                matrixArr[i15].mapPoints(fArr2);
                path2.moveTo(fArr2[0], fArr2[1]);
                e0Var7.c(matrixArr[i15], path2);
            } else {
                c10 = 1;
                e0Var7.c(matrixArr[i15], path4);
            }
            u uVar3 = vVar.pathListener;
            if (uVar3 != null) {
                Matrix matrix2 = matrixArr[i15];
                e.y yVar2 = (e.y) uVar3;
                z10 = false;
                ((k) yVar2.f25365a).f23099e.set(i15 + 4, false);
                d0[] d0VarArr2 = ((k) yVar2.f25365a).f23098d;
                e0Var7.b(e0Var7.f23063f);
                d0VarArr2[i15] = new x(new ArrayList(e0Var7.f23065h), new Matrix(matrix2));
            } else {
                z10 = false;
            }
            c6 = c10;
            r42 = z10;
            i12 = i13;
        }
        path.close();
        path2.close();
        if (path2.isEmpty()) {
            return;
        }
        path.op(path2, Path.Op.UNION);
    }
}
