package lj;

import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes3.dex */
public class l {

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

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

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

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

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

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

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

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

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

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

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

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

    /* loaded from: classes3.dex */
    private static class a {

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

    /* loaded from: classes3.dex */
    public interface b {
        void a(m mVar, Matrix matrix, int i10);

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

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public static final class c {

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

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

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

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

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

        c(k kVar, float f10, RectF rectF, b bVar, Path path) {
            this.f28398d = bVar;
            this.f28395a = kVar;
            this.f28399e = f10;
            this.f28397c = rectF;
            this.f28396b = path;
        }
    }

    public l() {
        for (int i10 = 0; i10 < 4; i10++) {
            this.f28382a[i10] = new m();
            this.f28383b[i10] = new Matrix();
            this.f28384c[i10] = new Matrix();
        }
    }

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

    private void b(c cVar, int i10) {
        this.f28389h[0] = this.f28382a[i10].k();
        this.f28389h[1] = this.f28382a[i10].l();
        this.f28383b[i10].mapPoints(this.f28389h);
        if (i10 == 0) {
            Path path = cVar.f28396b;
            float[] fArr = this.f28389h;
            path.moveTo(fArr[0], fArr[1]);
        } else {
            Path path2 = cVar.f28396b;
            float[] fArr2 = this.f28389h;
            path2.lineTo(fArr2[0], fArr2[1]);
        }
        this.f28382a[i10].d(this.f28383b[i10], cVar.f28396b);
        b bVar = cVar.f28398d;
        if (bVar != null) {
            bVar.b(this.f28382a[i10], this.f28383b[i10], i10);
        }
    }

    private void c(c cVar, int i10) {
        int i11 = (i10 + 1) % 4;
        this.f28389h[0] = this.f28382a[i10].i();
        this.f28389h[1] = this.f28382a[i10].j();
        this.f28383b[i10].mapPoints(this.f28389h);
        this.f28390i[0] = this.f28382a[i11].k();
        this.f28390i[1] = this.f28382a[i11].l();
        this.f28383b[i11].mapPoints(this.f28390i);
        float f10 = this.f28389h[0];
        float[] fArr = this.f28390i;
        float max = Math.max(((float) Math.hypot(f10 - fArr[0], r1[1] - fArr[1])) - 0.001f, BitmapDescriptorFactory.HUE_RED);
        float i12 = i(cVar.f28397c, i10);
        this.f28388g.n(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED);
        f j10 = j(i10, cVar.f28395a);
        j10.b(max, i12, cVar.f28399e, this.f28388g);
        this.f28391j.reset();
        this.f28388g.d(this.f28384c[i10], this.f28391j);
        if (this.f28393l && (j10.a() || l(this.f28391j, i10) || l(this.f28391j, i11))) {
            Path path = this.f28391j;
            path.op(path, this.f28387f, Path.Op.DIFFERENCE);
            this.f28389h[0] = this.f28388g.k();
            this.f28389h[1] = this.f28388g.l();
            this.f28384c[i10].mapPoints(this.f28389h);
            Path path2 = this.f28386e;
            float[] fArr2 = this.f28389h;
            path2.moveTo(fArr2[0], fArr2[1]);
            this.f28388g.d(this.f28384c[i10], this.f28386e);
        } else {
            this.f28388g.d(this.f28384c[i10], cVar.f28396b);
        }
        b bVar = cVar.f28398d;
        if (bVar != null) {
            bVar.a(this.f28388g, this.f28384c[i10], i10);
        }
    }

    private void f(int i10, RectF rectF, PointF pointF) {
        if (i10 == 1) {
            pointF.set(rectF.right, rectF.bottom);
            return;
        }
        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);
        }
    }

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

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

    private float i(RectF rectF, int i10) {
        float[] fArr = this.f28389h;
        m mVar = this.f28382a[i10];
        fArr[0] = mVar.f28402c;
        fArr[1] = mVar.f28403d;
        this.f28383b[i10].mapPoints(fArr);
        return (i10 == 1 || i10 == 3) ? Math.abs(rectF.centerX() - this.f28389h[0]) : Math.abs(rectF.centerY() - this.f28389h[1]);
    }

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

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

    private boolean l(Path path, int i10) {
        this.f28392k.reset();
        this.f28382a[i10].d(this.f28383b[i10], this.f28392k);
        RectF rectF = new RectF();
        path.computeBounds(rectF, true);
        this.f28392k.computeBounds(rectF, true);
        path.op(this.f28392k, 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 i10) {
        h(i10, cVar.f28395a).b(this.f28382a[i10], 90.0f, cVar.f28399e, cVar.f28397c, g(i10, cVar.f28395a));
        float a10 = a(i10);
        this.f28383b[i10].reset();
        f(i10, cVar.f28397c, this.f28385d);
        Matrix matrix = this.f28383b[i10];
        PointF pointF = this.f28385d;
        matrix.setTranslate(pointF.x, pointF.y);
        this.f28383b[i10].preRotate(a10);
    }

    private void n(int i10) {
        this.f28389h[0] = this.f28382a[i10].i();
        this.f28389h[1] = this.f28382a[i10].j();
        this.f28383b[i10].mapPoints(this.f28389h);
        float a10 = a(i10);
        this.f28384c[i10].reset();
        Matrix matrix = this.f28384c[i10];
        float[] fArr = this.f28389h;
        matrix.setTranslate(fArr[0], fArr[1]);
        this.f28384c[i10].preRotate(a10);
    }

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

    public void e(k kVar, float f10, RectF rectF, b bVar, Path path) {
        path.rewind();
        this.f28386e.rewind();
        this.f28387f.rewind();
        this.f28387f.addRect(rectF, Path.Direction.CW);
        c cVar = new c(kVar, f10, rectF, bVar, path);
        for (int i10 = 0; i10 < 4; i10++) {
            m(cVar, i10);
            n(i10);
        }
        for (int i11 = 0; i11 < 4; i11++) {
            b(cVar, i11);
            c(cVar, i11);
        }
        path.close();
        this.f28386e.close();
        if (this.f28386e.isEmpty()) {
            return;
        }
        path.op(this.f28386e, Path.Op.UNION);
    }
}
