package p9;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.util.Pair;
import com.google.android.gms.measurement.internal.c2;
import java.util.ArrayList;
import kotlinx.coroutines.y;

/* JADX INFO: loaded from: classes2.dex */
public final class e extends p {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public float f31800f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float f31801g;

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public float f31804j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public float f31805k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f31806l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public float f31807m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f31808n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public float f31809o;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final Pair f31811q;

    public e(j jVar) {
        super(jVar);
        this.f31810p = new RectF();
        this.f31811q = new Pair(new o(), new o());
    }

    @Override // p9.p
    public final void a(Canvas canvas, Rect rect, float f10, boolean z10, boolean z11) {
        float fWidth = rect.width() / k();
        float fHeight = rect.height() / k();
        d dVar = this.f31875a;
        float f11 = (((j) dVar).f31843p / 2.0f) + ((j) dVar).f31844q;
        canvas.translate((f11 * fWidth) + rect.left, (f11 * fHeight) + rect.top);
        canvas.rotate(-90.0f);
        canvas.scale(fWidth, fHeight);
        if (((j) dVar).f31845r != 0) {
            canvas.scale(1.0f, -1.0f);
            if (Build.VERSION.SDK_INT == 29) {
                canvas.rotate(0.1f);
            }
        }
        float f12 = -f11;
        canvas.clipRect(f12, f12, f11, f11);
        this.f31800f = ((j) dVar).f31786a * f10;
        this.f31801g = Math.min(((j) dVar).f31786a / 2, ((j) dVar).a()) * f10;
        this.f31802h = ((j) dVar).f31797l * f10;
        float f13 = (((j) dVar).f31843p - ((j) dVar).f31786a) / 2.0f;
        this.f31803i = f13;
        if (z10 || z11) {
            float f14 = ((1.0f - f10) * ((j) dVar).f31786a) / 2.0f;
            if ((z10 && ((j) dVar).f31792g == 2) || (z11 && ((j) dVar).f31793h == 1)) {
                this.f31803i = f13 + f14;
            } else if ((z10 && ((j) dVar).f31792g == 1) || (z11 && ((j) dVar).f31793h == 2)) {
                this.f31803i = f13 - f14;
            }
        }
        if (z11 && ((j) dVar).f31793h == 3) {
            this.f31809o = f10;
        } else {
            this.f31809o = 1.0f;
        }
    }

    @Override // p9.p
    public final void b(int i10, int i11, Canvas canvas, Paint paint) {
    }

    @Override // p9.p
    public final void c(Canvas canvas, Paint paint, n nVar, int i10) {
        int iA = h9.a.a(nVar.f31866c, i10);
        canvas.save();
        canvas.rotate(nVar.f31870g);
        this.f31808n = nVar.f31871h;
        float f10 = nVar.f31864a;
        float f11 = nVar.f31865b;
        int i11 = nVar.f31867d;
        i(canvas, paint, f10, f11, iA, i11, i11, nVar.f31868e, nVar.f31869f, true);
        canvas.restore();
    }

    @Override // p9.p
    public final void d(Canvas canvas, Paint paint, float f10, float f11, int i10, int i11, int i12) {
        int iA = h9.a.a(i10, i11);
        this.f31808n = false;
        i(canvas, paint, f10, f11, iA, i12, i12, 0.0f, 0.0f, false);
    }

    @Override // p9.p
    public final int e() {
        return k();
    }

    @Override // p9.p
    public final int f() {
        return k();
    }

    @Override // p9.p
    public final void g() {
        Path path = this.f31876b;
        path.rewind();
        path.moveTo(1.0f, 0.0f);
        for (int i10 = 0; i10 < 2; i10++) {
            path.cubicTo(1.0f, 0.5522848f, 0.5522848f, 1.0f, 0.0f, 1.0f);
            path.cubicTo(-0.5522848f, 1.0f, -1.0f, 0.5522848f, -1.0f, 0.0f);
            path.cubicTo(-1.0f, -0.5522848f, -0.5522848f, -1.0f, 0.0f, -1.0f);
            path.cubicTo(0.5522848f, -1.0f, 1.0f, -0.5522848f, 1.0f, 0.0f);
        }
        Matrix matrix = this.f31879e;
        matrix.reset();
        float f10 = this.f31803i;
        matrix.setScale(f10, f10);
        path.transform(matrix);
        boolean zB = ((j) this.f31875a).b(this.f31808n);
        PathMeasure pathMeasure = this.f31878d;
        if (zB) {
            pathMeasure.setPath(path, false);
            float f11 = this.f31805k;
            path.rewind();
            float length = pathMeasure.getLength();
            int iMax = Math.max(3, (int) ((length / (this.f31808n ? r2.f31795j : r2.f31796k)) / 2.0f)) * 2;
            this.f31804j = length / iMax;
            ArrayList arrayList = new ArrayList();
            for (int i11 = 0; i11 < iMax; i11++) {
                o oVar = new o();
                float f12 = i11;
                pathMeasure.getPosTan(this.f31804j * f12, oVar.f31872a, oVar.f31873b);
                o oVar2 = new o();
                float f13 = this.f31804j;
                pathMeasure.getPosTan((f13 / 2.0f) + (f12 * f13), oVar2.f31872a, oVar2.f31873b);
                arrayList.add(oVar);
                oVar2.a(f11 * 2.0f);
                arrayList.add(oVar2);
            }
            arrayList.add((o) arrayList.get(0));
            o oVar3 = (o) arrayList.get(0);
            float[] fArr = oVar3.f31872a;
            path.moveTo(fArr[0], fArr[1]);
            int i12 = 1;
            while (i12 < arrayList.size()) {
                o oVar4 = (o) arrayList.get(i12);
                float f14 = (this.f31804j / 2.0f) * 0.48f;
                o oVar5 = new o(oVar3.f31872a, oVar3.f31873b);
                o oVar6 = new o(oVar4.f31872a, oVar4.f31873b);
                oVar5.b(f14);
                oVar6.b(-f14);
                float[] fArr2 = oVar5.f31872a;
                float f15 = fArr2[0];
                float f16 = fArr2[1];
                float[] fArr3 = oVar6.f31872a;
                float f17 = fArr3[0];
                float f18 = fArr3[1];
                float[] fArr4 = oVar4.f31872a;
                path.cubicTo(f15, f16, f17, f18, fArr4[0], fArr4[1]);
                i12++;
                oVar3 = oVar4;
            }
        }
        pathMeasure.setPath(path, false);
    }

    public final void i(Canvas canvas, Paint paint, float f10, float f11, int i10, int i11, int i12, float f12, float f13, boolean z10) {
        Pair pair;
        float f14;
        Pair pair2;
        float f15 = f11 >= f10 ? f11 - f10 : (f11 + 1.0f) - f10;
        float f16 = f10 % 1.0f;
        if (f16 < 0.0f) {
            f16 += 1.0f;
        }
        float f17 = f16;
        if (this.f31809o < 1.0f) {
            float f18 = f17 + f15;
            if (f18 > 1.0f) {
                i(canvas, paint, f17, 1.0f, i10, i11, 0, f12, f13, z10);
                i(canvas, paint, 1.0f, f18, i10, 0, i12, f12, f13, z10);
                return;
            }
        }
        float degrees = (float) Math.toDegrees(this.f31801g / this.f31803i);
        float f19 = f15 - 0.99f;
        if (f19 >= 0.0f) {
            float f20 = ((f19 * degrees) / 180.0f) / 0.01f;
            f15 += f20;
            if (!z10) {
                f17 -= f20 / 2.0f;
            }
        }
        float fJ = c2.j(1.0f - this.f31809o, 1.0f, f17);
        float fJ2 = c2.j(0.0f, this.f31809o, f15);
        float degrees2 = (float) Math.toDegrees(i11 / this.f31803i);
        float degrees3 = ((fJ2 * 360.0f) - degrees2) - ((float) Math.toDegrees(i12 / this.f31803i));
        float f21 = (fJ * 360.0f) + degrees2;
        if (degrees3 <= 0.0f) {
            return;
        }
        j jVar = (j) this.f31875a;
        boolean z11 = jVar.b(this.f31808n) && z10 && f12 > 0.0f;
        paint.setAntiAlias(true);
        paint.setColor(i10);
        paint.setStrokeWidth(this.f31800f);
        float f22 = this.f31801g * 2.0f;
        float f23 = degrees * 2.0f;
        PathMeasure pathMeasure = this.f31878d;
        if (degrees3 < f23) {
            float f24 = degrees3 / f23;
            float f25 = (degrees * f24) + f21;
            o oVar = new o();
            if (z11) {
                float length = (pathMeasure.getLength() * (f25 / 360.0f)) / 2.0f;
                float f26 = this.f31802h * f12;
                float f27 = this.f31803i;
                if (f27 != this.f31807m || f26 != this.f31805k) {
                    this.f31805k = f26;
                    this.f31807m = f27;
                    g();
                }
                pathMeasure.getPosTan(length, oVar.f31872a, oVar.f31873b);
            } else {
                oVar.d(f25 + 90.0f);
                oVar.a(-this.f31803i);
            }
            paint.setStyle(Paint.Style.FILL);
            j(canvas, paint, oVar, f22, this.f31800f, f24);
            return;
        }
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeCap(jVar.c() ? Paint.Cap.ROUND : Paint.Cap.BUTT);
        float f28 = degrees + f21;
        float f29 = degrees3 - f23;
        Pair pair3 = this.f31811q;
        ((o) pair3.first).c();
        ((o) pair3.second).c();
        if (z11) {
            Path path = this.f31877c;
            float f30 = f28 / 360.0f;
            float f31 = f29 / 360.0f;
            float f32 = this.f31802h * f12;
            int i13 = this.f31808n ? jVar.f31795j : jVar.f31796k;
            float f33 = this.f31803i;
            if (f33 != this.f31807m || f32 != this.f31805k || i13 != this.f31806l) {
                this.f31805k = f32;
                this.f31806l = i13;
                this.f31807m = f33;
                g();
            }
            path.rewind();
            float f34 = y.f(f31, 0.0f, 1.0f);
            if (jVar.b(this.f31808n)) {
                pair = pair3;
                float f35 = f13 / ((float) ((((double) this.f31803i) * 6.283185307179586d) / ((double) this.f31804j)));
                f30 += f35;
                f14 = 0.0f - (f35 * 360.0f);
            } else {
                pair = pair3;
                f14 = 0.0f;
            }
            float f36 = f30 % 1.0f;
            float length2 = (pathMeasure.getLength() * f36) / 2.0f;
            float length3 = (pathMeasure.getLength() * (f36 + f34)) / 2.0f;
            pathMeasure.getSegment(length2, length3, path, true);
            pair2 = pair;
            o oVar2 = (o) pair2.first;
            oVar2.c();
            pathMeasure.getPosTan(length2, oVar2.f31872a, oVar2.f31873b);
            o oVar3 = (o) pair2.second;
            oVar3.c();
            pathMeasure.getPosTan(length3, oVar3.f31872a, oVar3.f31873b);
            Matrix matrix = this.f31879e;
            matrix.reset();
            matrix.setRotate(f14);
            oVar2.d(f14);
            oVar3.d(f14);
            path.transform(matrix);
            canvas.drawPath(path, paint);
        } else {
            ((o) pair3.first).d(f28 + 90.0f);
            ((o) pair3.first).a(-this.f31803i);
            ((o) pair3.second).d(f28 + f29 + 90.0f);
            ((o) pair3.second).a(-this.f31803i);
            RectF rectF = this.f31810p;
            float f37 = this.f31803i;
            float f38 = -f37;
            rectF.set(f38, f38, f37, f37);
            canvas.drawArc(rectF, f28, f29, false, paint);
            pair2 = pair3;
        }
        if (jVar.c() || this.f31801g <= 0.0f) {
            return;
        }
        paint.setStyle(Paint.Style.FILL);
        j(canvas, paint, (o) pair2.first, f22, this.f31800f, 1.0f);
        j(canvas, paint, (o) pair2.second, f22, this.f31800f, 1.0f);
    }

    public final void j(Canvas canvas, Paint paint, o oVar, float f10, float f11, float f12) {
        float fMin = Math.min(f11, this.f31800f);
        float f13 = f10 / 2.0f;
        float fMin2 = Math.min(f13, (this.f31801g * fMin) / this.f31800f);
        RectF rectF = new RectF((-f10) / 2.0f, (-fMin) / 2.0f, f13, fMin / 2.0f);
        canvas.save();
        float[] fArr = oVar.f31872a;
        canvas.translate(fArr[0], fArr[1]);
        canvas.rotate(p.h(oVar.f31873b));
        canvas.scale(f12, f12);
        canvas.drawRoundRect(rectF, fMin2, fMin2, paint);
        canvas.restore();
    }

    public final int k() {
        d dVar = this.f31875a;
        return (((j) dVar).f31844q * 2) + ((j) dVar).f31843p;
    }
}
