package a0;

import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.view.View;
import androidx.constraintlayout.motion.widget.MotionLayout;

/* JADX INFO: loaded from: classes.dex */
public final class u {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public float[] f198a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int[] f199b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final float[] f200c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Path f201d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Paint f203f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Paint f204g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Paint f205h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final Paint f206i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final float[] f207j;

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final Rect f209l = new Rect();

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final int f210m = 1;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final /* synthetic */ MotionLayout f211n;

    public u(MotionLayout motionLayout) {
        this.f211n = motionLayout;
        Paint paint = new Paint();
        this.f202e = paint;
        paint.setAntiAlias(true);
        paint.setColor(-21965);
        paint.setStrokeWidth(2.0f);
        Paint.Style style = Paint.Style.STROKE;
        paint.setStyle(style);
        Paint paint2 = new Paint();
        this.f203f = paint2;
        paint2.setAntiAlias(true);
        paint2.setColor(-2067046);
        paint2.setStrokeWidth(2.0f);
        paint2.setStyle(style);
        Paint paint3 = new Paint();
        this.f204g = paint3;
        paint3.setAntiAlias(true);
        paint3.setColor(-13391360);
        paint3.setStrokeWidth(2.0f);
        paint3.setStyle(style);
        Paint paint4 = new Paint();
        this.f205h = paint4;
        paint4.setAntiAlias(true);
        paint4.setColor(-13391360);
        paint4.setTextSize(motionLayout.getContext().getResources().getDisplayMetrics().density * 12.0f);
        this.f207j = new float[8];
        Paint paint5 = new Paint();
        this.f206i = paint5;
        paint5.setAntiAlias(true);
        paint3.setPathEffect(new DashPathEffect(new float[]{4.0f, 8.0f}, 0.0f));
        this.f200c = new float[100];
        this.f199b = new int[50];
    }

    public final void a(Canvas canvas, int i10, int i11, q qVar) {
        int width;
        int height;
        Paint paint;
        float f10;
        float f11;
        int i12;
        int[] iArr = this.f199b;
        int i13 = 4;
        if (i10 == 4) {
            boolean z10 = false;
            boolean z11 = false;
            for (int i14 = 0; i14 < this.f208k; i14++) {
                int i15 = iArr[i14];
                if (i15 == 1) {
                    z10 = true;
                }
                if (i15 == 0) {
                    z11 = true;
                }
            }
            if (z10) {
                float[] fArr = this.f198a;
                canvas.drawLine(fArr[0], fArr[1], fArr[fArr.length - 2], fArr[fArr.length - 1], this.f204g);
            }
            if (z11) {
                b(canvas);
            }
        }
        if (i10 == 2) {
            float[] fArr2 = this.f198a;
            canvas.drawLine(fArr2[0], fArr2[1], fArr2[fArr2.length - 2], fArr2[fArr2.length - 1], this.f204g);
        }
        if (i10 == 3) {
            b(canvas);
        }
        canvas.drawLines(this.f198a, this.f202e);
        View view = qVar.f167b;
        if (view != null) {
            width = view.getWidth();
            height = qVar.f167b.getHeight();
        } else {
            width = 0;
            height = 0;
        }
        int i16 = 1;
        while (i16 < i11 - 1) {
            if (i10 == i13 && iArr[i16 - 1] == 0) {
                i12 = i16;
            } else {
                int i17 = i16 * 2;
                float[] fArr3 = this.f200c;
                float f12 = fArr3[i17];
                float f13 = fArr3[i17 + 1];
                this.f201d.reset();
                this.f201d.moveTo(f12, f13 + 10.0f);
                this.f201d.lineTo(f12 + 10.0f, f13);
                this.f201d.lineTo(f12, f13 - 10.0f);
                this.f201d.lineTo(f12 - 10.0f, f13);
                this.f201d.close();
                int i18 = i16 - 1;
                Paint paint2 = this.f206i;
                if (i10 == i13) {
                    int i19 = iArr[i18];
                    if (i19 == 1) {
                        d(canvas, f12 - 0.0f, f13 - 0.0f);
                    } else if (i19 == 0) {
                        c(canvas, f12 - 0.0f, f13 - 0.0f);
                    } else {
                        if (i19 == 2) {
                            paint = paint2;
                            f10 = f13;
                            f11 = f12;
                            i12 = i16;
                            e(canvas, f12 - 0.0f, f13 - 0.0f, width, height);
                        }
                        canvas.drawPath(this.f201d, paint);
                    }
                    paint = paint2;
                    f10 = f13;
                    f11 = f12;
                    i12 = i16;
                    canvas.drawPath(this.f201d, paint);
                } else {
                    paint = paint2;
                    f10 = f13;
                    f11 = f12;
                    i12 = i16;
                }
                if (i10 == 2) {
                    d(canvas, f11 - 0.0f, f10 - 0.0f);
                }
                if (i10 == 3) {
                    c(canvas, f11 - 0.0f, f10 - 0.0f);
                }
                if (i10 == 6) {
                    e(canvas, f11 - 0.0f, f10 - 0.0f, width, height);
                }
                canvas.drawPath(this.f201d, paint);
            }
            i16 = i12 + 1;
            i13 = 4;
        }
        float[] fArr4 = this.f198a;
        if (fArr4.length > 1) {
            float f14 = fArr4[0];
            float f15 = fArr4[1];
            Paint paint3 = this.f203f;
            canvas.drawCircle(f14, f15, 8.0f, paint3);
            float[] fArr5 = this.f198a;
            canvas.drawCircle(fArr5[fArr5.length - 2], fArr5[fArr5.length - 1], 8.0f, paint3);
        }
    }

    public final void b(Canvas canvas) {
        float[] fArr = this.f198a;
        float f10 = fArr[0];
        float f11 = fArr[1];
        float f12 = fArr[fArr.length - 2];
        float f13 = fArr[fArr.length - 1];
        float fMin = Math.min(f10, f12);
        float fMax = Math.max(f11, f13);
        float fMax2 = Math.max(f10, f12);
        float fMax3 = Math.max(f11, f13);
        Paint paint = this.f204g;
        canvas.drawLine(fMin, fMax, fMax2, fMax3, paint);
        canvas.drawLine(Math.min(f10, f12), Math.min(f11, f13), Math.min(f10, f12), Math.max(f11, f13), paint);
    }

    public final void c(Canvas canvas, float f10, float f11) {
        float[] fArr = this.f198a;
        float f12 = fArr[0];
        float f13 = fArr[1];
        float f14 = fArr[fArr.length - 2];
        float f15 = fArr[fArr.length - 1];
        float fMin = Math.min(f12, f14);
        float fMax = Math.max(f13, f15);
        float fMin2 = f10 - Math.min(f12, f14);
        float fMax2 = Math.max(f13, f15) - f11;
        String str = "" + (((int) (((double) ((fMin2 * 100.0f) / Math.abs(f14 - f12))) + 0.5d)) / 100.0f);
        Paint paint = this.f205h;
        paint.getTextBounds(str, 0, str.length(), this.f209l);
        Rect rect = this.f209l;
        canvas.drawText(str, ((fMin2 / 2.0f) - (rect.width() / 2)) + fMin, f11 - 20.0f, paint);
        float fMin3 = Math.min(f12, f14);
        Paint paint2 = this.f204g;
        canvas.drawLine(f10, f11, fMin3, f11, paint2);
        String str2 = "" + (((int) (((double) ((fMax2 * 100.0f) / Math.abs(f15 - f13))) + 0.5d)) / 100.0f);
        paint.getTextBounds(str2, 0, str2.length(), this.f209l);
        canvas.drawText(str2, f10 + 5.0f, fMax - ((fMax2 / 2.0f) - (rect.height() / 2)), paint);
        canvas.drawLine(f10, f11, f10, Math.max(f13, f15), paint2);
    }

    public final void d(Canvas canvas, float f10, float f11) {
        float[] fArr = this.f198a;
        float f12 = fArr[0];
        float f13 = fArr[1];
        float f14 = fArr[fArr.length - 2];
        float f15 = fArr[fArr.length - 1];
        float fHypot = (float) Math.hypot(f12 - f14, f13 - f15);
        float f16 = f14 - f12;
        float f17 = f15 - f13;
        float f18 = (((f11 - f13) * f17) + ((f10 - f12) * f16)) / (fHypot * fHypot);
        float f19 = f12 + (f16 * f18);
        float f20 = f13 + (f18 * f17);
        Path path = new Path();
        path.moveTo(f10, f11);
        path.lineTo(f19, f20);
        float fHypot2 = (float) Math.hypot(f19 - f10, f20 - f11);
        String str = "" + (((int) ((fHypot2 * 100.0f) / fHypot)) / 100.0f);
        Paint paint = this.f205h;
        paint.getTextBounds(str, 0, str.length(), this.f209l);
        canvas.drawTextOnPath(str, path, (fHypot2 / 2.0f) - (this.f209l.width() / 2), -20.0f, paint);
        canvas.drawLine(f10, f11, f19, f20, this.f204g);
    }

    public final void e(Canvas canvas, float f10, float f11, int i10, int i11) {
        StringBuilder sb = new StringBuilder("");
        MotionLayout motionLayout = this.f211n;
        sb.append(((int) (((double) (((f10 - (i10 / 2)) * 100.0f) / (motionLayout.getWidth() - i10))) + 0.5d)) / 100.0f);
        String string = sb.toString();
        Paint paint = this.f205h;
        paint.getTextBounds(string, 0, string.length(), this.f209l);
        Rect rect = this.f209l;
        canvas.drawText(string, ((f10 / 2.0f) - (rect.width() / 2)) + 0.0f, f11 - 20.0f, paint);
        float fMin = Math.min(0.0f, 1.0f);
        Paint paint2 = this.f204g;
        canvas.drawLine(f10, f11, fMin, f11, paint2);
        String str = "" + (((int) (((double) (((f11 - (i11 / 2)) * 100.0f) / (motionLayout.getHeight() - i11))) + 0.5d)) / 100.0f);
        paint.getTextBounds(str, 0, str.length(), this.f209l);
        canvas.drawText(str, f10 + 5.0f, 0.0f - ((f11 / 2.0f) - (rect.height() / 2)), paint);
        canvas.drawLine(f10, f11, f10, Math.max(0.0f, 1.0f), paint2);
    }
}
