import { q, P } from './path-428ebac9.esm.js';
import { av as An, aw as u1, ax as p1, ay as Po, az as Ro, U as m1, aA as g1, aB as d1, aC as h1, aD as c1, aE as f1, aF as _1, aG as y1 } from './index.esm2.js';

function cn(l) {
    return l.innerRadius;
}
function yn(l) {
    return l.outerRadius;
}
function gn(l) {
    return l.startAngle;
}
function mn(l) {
    return l.endAngle;
}
function pn(l) {
    return l && l.padAngle;
}
function dn(l, h, z, E, v, A, I, a) {
    var B = z - l, i = E - h, n = I - v, m = a - A, r = m * B - n * i;
    if (!(r * r < Ro)) return r = (n * (h - A) - m * (l - v)) / r, [
        l + r * B,
        h + r * i
    ];
}
function W(l, h, z, E, v, A, I) {
    var a = l - z, B = h - E, i = (I ? A : -A) / g1(a * a + B * B), n = i * B, m = -i * a, r = l + n, s = h + m, f = z + n, c = E + m, O = (r + f) / 2, o = (s + c) / 2, p = f - r, g = c - s, R = p * p + g * g, T = v - A, w = r * c - f * s, C = (g < 0 ? -1 : 1) * g1(f1(0, T * T * R - w * w)), F = (w * g - p * C) / R, G = (-w * p - g * C) / R, P = (w * g + p * C) / R, d = (-w * p + g * C) / R, x = F - O, e = G - o, u = P - O, S = d - o;
    return x * x + e * e > u * u + S * S && (F = P, G = d), {
        cx: F,
        cy: G,
        x01: -n,
        y01: -m,
        x11: F * (v / T - 1),
        y11: G * (v / T - 1)
    };
}
function vn() {
    var l = cn, h = yn, z = P(0), E = null, v = gn, A = mn, I = pn, a = null, B = q(i);
    function i() {
        var n, m, r = +l.apply(this, arguments), s = +h.apply(this, arguments), f = v.apply(this, arguments) - Po, c = A.apply(this, arguments) - Po, O = h1(c - f), o = c > f;
        if (a || (a = n = B()), s < r && (m = s, s = r, r = m), !(s > Ro)) a.moveTo(0, 0);
        else if (O > m1 - Ro) a.moveTo(s * u1(f), s * p1(f)), a.arc(0, 0, s, f, c, !o), r > Ro && (a.moveTo(r * u1(c), r * p1(c)), a.arc(0, 0, r, c, f, o));
        else {
            var p = f, g = c, R = f, T = c, w = O, C = O, F = I.apply(this, arguments) / 2, G = F > Ro && (E ? +E.apply(this, arguments) : g1(r * r + s * s)), P = d1(h1(s - r) / 2, +z.apply(this, arguments)), d = P, x = P, e, u;
            if (G > Ro) {
                var S = _1(G / r * p1(F)), L = _1(G / s * p1(F));
                (w -= S * 2) > Ro ? (S *= o ? 1 : -1, R += S, T -= S) : (w = 0, R = T = (f + c) / 2), (C -= L * 2) > Ro ? (L *= o ? 1 : -1, p += L, g -= L) : (C = 0, p = g = (f + c) / 2);
            }
            var j = s * u1(p), J = s * p1(p), M = r * u1(T), N = r * p1(T);
            if (P > Ro) {
                var Q = s * u1(g), U = s * p1(g), X = r * u1(R), Y = r * p1(R), q;
                if (O < An) if (q = dn(j, J, X, Y, Q, U, M, N)) {
                    var Z = j - q[0], $ = J - q[1], k = Q - q[0], b = U - q[1], nn = 1 / p1(y1((Z * k + $ * b) / (g1(Z * Z + $ * $) * g1(k * k + b * b))) / 2), en = g1(q[0] * q[0] + q[1] * q[1]);
                    d = d1(P, (r - en) / (nn - 1)), x = d1(P, (s - en) / (nn + 1));
                } else d = x = 0;
            }
            C > Ro ? x > Ro ? (e = W(X, Y, j, J, s, x, o), u = W(Q, U, M, N, s, x, o), a.moveTo(e.cx + e.x01, e.cy + e.y01), x < P ? a.arc(e.cx, e.cy, x, c1(e.y01, e.x01), c1(u.y01, u.x01), !o) : (a.arc(e.cx, e.cy, x, c1(e.y01, e.x01), c1(e.y11, e.x11), !o), a.arc(0, 0, s, c1(e.cy + e.y11, e.cx + e.x11), c1(u.cy + u.y11, u.cx + u.x11), !o), a.arc(u.cx, u.cy, x, c1(u.y11, u.x11), c1(u.y01, u.x01), !o))) : (a.moveTo(j, J), a.arc(0, 0, s, p, g, !o)) : a.moveTo(j, J), !(r > Ro) || !(w > Ro) ? a.lineTo(M, N) : d > Ro ? (e = W(M, N, Q, U, r, -d, o), u = W(j, J, X, Y, r, -d, o), a.lineTo(e.cx + e.x01, e.cy + e.y01), d < P ? a.arc(e.cx, e.cy, d, c1(e.y01, e.x01), c1(u.y01, u.x01), !o) : (a.arc(e.cx, e.cy, d, c1(e.y01, e.x01), c1(e.y11, e.x11), !o), a.arc(0, 0, r, c1(e.cy + e.y11, e.cx + e.x11), c1(u.cy + u.y11, u.cx + u.x11), o), a.arc(u.cx, u.cy, d, c1(u.y11, u.x11), c1(u.y01, u.x01), !o))) : a.arc(0, 0, r, T, R, o);
        }
        if (a.closePath(), n) return a = null, n + "" || null;
    }
    return i.centroid = function() {
        var n = (+l.apply(this, arguments) + +h.apply(this, arguments)) / 2, m = (+v.apply(this, arguments) + +A.apply(this, arguments)) / 2 - An / 2;
        return [
            u1(m) * n,
            p1(m) * n
        ];
    }, i.innerRadius = function(n) {
        return arguments.length ? (l = typeof n == "function" ? n : P(+n), i) : l;
    }, i.outerRadius = function(n) {
        return arguments.length ? (h = typeof n == "function" ? n : P(+n), i) : h;
    }, i.cornerRadius = function(n) {
        return arguments.length ? (z = typeof n == "function" ? n : P(+n), i) : z;
    }, i.padRadius = function(n) {
        return arguments.length ? (E = n == null ? null : typeof n == "function" ? n : P(+n), i) : E;
    }, i.startAngle = function(n) {
        return arguments.length ? (v = typeof n == "function" ? n : P(+n), i) : v;
    }, i.endAngle = function(n) {
        return arguments.length ? (A = typeof n == "function" ? n : P(+n), i) : A;
    }, i.padAngle = function(n) {
        return arguments.length ? (I = typeof n == "function" ? n : P(+n), i) : I;
    }, i.context = function(n) {
        return arguments.length ? (a = n !== null && n !== void 0 ? n : null, i) : a;
    }, i;
}

export { vn as v };
