import { N as dn, O, G as hn, P as rn, o as un, h as fn, j as gn, a as on } from "./am-chart.H2jnOzFc.js";
const ln = Math.abs, y = Math.atan2, $ = Math.cos, yn = Math.max, en = Math.min, w = Math.sin, k = Math.sqrt, R = 1e-12, z = Math.PI, Q = z / 2, mn = 2 * z;
function pn(s) {
  return s > 1 ? 0 : s < -1 ? z : Math.acos(s);
}
function cn(s) {
  return s >= 1 ? Q : s <= -1 ? -Q : Math.asin(s);
}
function Rn(s) {
  return s.innerRadius;
}
function xn(s) {
  return s.outerRadius;
}
function An(s) {
  return s.startAngle;
}
function vn(s) {
  return s.endAngle;
}
function Dn(s) {
  return s && s.padAngle;
}
function Mn(s, o, c, g, d, l, f, e) {
  var x = c - s, r = g - o, n = f - d, v = e - l, t = v * x - n * r;
  if (!(t * t < R))
    return t = (n * (o - l) - v * (s - d)) / t, [s + t * x, o + t * r];
}
function L(s, o, c, g, d, l, f) {
  var e = s - c, x = o - g, r = (f ? l : -l) / k(e * e + x * x), n = r * x, v = -r * e, t = s + n, u = o + v, m = c + n, p = g + v, X = (t + m) / 2, h = (u + p) / 2, D = m - t, A = p - u, P = D * D + A * A, I = d - l, N = t * p - m * u, q = (A < 0 ? -1 : 1) * k(yn(0, I * I * P - N * N)), C = (N * A - D * q) / P, G = (-N * D - A * q) / P, S = (N * A + D * q) / P, M = (-N * D + A * q) / P, T = C - X, i = G - h, a = S - X, Y = M - h;
  return T * T + i * i > a * a + Y * Y && (C = S, G = M), {
    cx: C,
    cy: G,
    x01: -n,
    y01: -v,
    x11: C * (d / I - 1),
    y11: G * (d / I - 1)
  };
}
function Tn() {
  var s = Rn, o = xn, c = O(0), g = null, d = An, l = vn, f = Dn, e = null, x = dn(r);
  function r() {
    var n, v, t = +s.apply(this, arguments), u = +o.apply(this, arguments), m = d.apply(this, arguments) - Q, p = l.apply(this, arguments) - Q, X = ln(p - m), h = p > m;
    if (e || (e = n = x()), u < t && (v = u, u = t, t = v), !(u > R)) e.moveTo(0, 0);
    else if (X > mn - R)
      e.moveTo(u * $(m), u * w(m)), e.arc(0, 0, u, m, p, !h), t > R && (e.moveTo(t * $(p), t * w(p)), e.arc(0, 0, t, p, m, h));
    else {
      var D = m, A = p, P = m, I = p, N = X, q = X, C = f.apply(this, arguments) / 2, G = C > R && (g ? +g.apply(this, arguments) : k(t * t + u * u)), S = en(ln(u - t) / 2, +c.apply(this, arguments)), M = S, T = S, i, a;
      if (G > R) {
        var Y = cn(G / t * w(C)), B = cn(G / u * w(C));
        (N -= Y * 2) > R ? (Y *= h ? 1 : -1, P += Y, I -= Y) : (N = 0, P = I = (m + p) / 2), (q -= B * 2) > R ? (B *= h ? 1 : -1, D += B, A -= B) : (q = 0, D = A = (m + p) / 2);
      }
      var j = u * $(D), E = u * w(D), F = t * $(I), H = t * w(I);
      if (S > R) {
        var J = u * $(A), K = u * w(A), U = t * $(P), V = t * w(P), b;
        if (X < z)
          if (b = Mn(j, E, U, V, J, K, F, H)) {
            var W = j - b[0], Z = E - b[1], _ = J - b[0], nn = K - b[1], sn = 1 / w(pn((W * _ + Z * nn) / (k(W * W + Z * Z) * k(_ * _ + nn * nn))) / 2), an = k(b[0] * b[0] + b[1] * b[1]);
            M = en(S, (t - an) / (sn - 1)), T = en(S, (u - an) / (sn + 1));
          } else
            M = T = 0;
      }
      q > R ? T > R ? (i = L(U, V, j, E, u, T, h), a = L(J, K, F, H, u, T, h), e.moveTo(i.cx + i.x01, i.cy + i.y01), T < S ? e.arc(i.cx, i.cy, T, y(i.y01, i.x01), y(a.y01, a.x01), !h) : (e.arc(i.cx, i.cy, T, y(i.y01, i.x01), y(i.y11, i.x11), !h), e.arc(0, 0, u, y(i.cy + i.y11, i.cx + i.x11), y(a.cy + a.y11, a.cx + a.x11), !h), e.arc(a.cx, a.cy, T, y(a.y11, a.x11), y(a.y01, a.x01), !h))) : (e.moveTo(j, E), e.arc(0, 0, u, D, A, !h)) : e.moveTo(j, E), !(t > R) || !(N > R) ? e.lineTo(F, H) : M > R ? (i = L(F, H, J, K, t, -M, h), a = L(j, E, U, V, t, -M, h), e.lineTo(i.cx + i.x01, i.cy + i.y01), M < S ? e.arc(i.cx, i.cy, M, y(i.y01, i.x01), y(a.y01, a.x01), !h) : (e.arc(i.cx, i.cy, M, y(i.y01, i.x01), y(i.y11, i.x11), !h), e.arc(0, 0, t, y(i.cy + i.y11, i.cx + i.x11), y(a.cy + a.y11, a.cx + a.x11), h), e.arc(a.cx, a.cy, M, y(a.y11, a.x11), y(a.y01, a.x01), !h))) : e.arc(0, 0, t, I, P, h);
    }
    if (e.closePath(), n) return e = null, n + "" || null;
  }
  return r.centroid = function() {
    var n = (+s.apply(this, arguments) + +o.apply(this, arguments)) / 2, v = (+d.apply(this, arguments) + +l.apply(this, arguments)) / 2 - z / 2;
    return [$(v) * n, w(v) * n];
  }, r.innerRadius = function(n) {
    return arguments.length ? (s = typeof n == "function" ? n : O(+n), r) : s;
  }, r.outerRadius = function(n) {
    return arguments.length ? (o = typeof n == "function" ? n : O(+n), r) : o;
  }, r.cornerRadius = function(n) {
    return arguments.length ? (c = typeof n == "function" ? n : O(+n), r) : c;
  }, r.padRadius = function(n) {
    return arguments.length ? (g = n == null ? null : typeof n == "function" ? n : O(+n), r) : g;
  }, r.startAngle = function(n) {
    return arguments.length ? (d = typeof n == "function" ? n : O(+n), r) : d;
  }, r.endAngle = function(n) {
    return arguments.length ? (l = typeof n == "function" ? n : O(+n), r) : l;
  }, r.padAngle = function(n) {
    return arguments.length ? (f = typeof n == "function" ? n : O(+n), r) : f;
  }, r.context = function(n) {
    return arguments.length ? (e = n ?? null, r) : e;
  }, r;
}
class tn extends hn {
  constructor() {
    super(...arguments), this.ix = 0, this.iy = 0, this._generator = Tn();
  }
  _getTooltipPoint() {
    let o = this.get("tooltipX"), c = this.get("tooltipY"), g = 0, d = 0;
    on(o) && (g = o), on(c) && (d = c);
    let l = this.get("radius", 0), f = this.get("innerRadius", 0), e = this.get("dRadius", 0), x = this.get("dInnerRadius", 0);
    return l += e, f += x, f < 0 && (f = l + f), o instanceof rn && (g = this.ix * (f + (l - f) * o.value)), c instanceof rn && (d = this.iy * (f + (l - f) * c.value)), this.get("arc") >= 360 && f == 0 && (g = 0, d = 0), { x: g, y: d };
  }
  _beforeChanged() {
    super._beforeChanged(), (this.isDirty("radius") || this.isDirty("arc") || this.isDirty("innerRadius") || this.isDirty("startAngle") || this.isDirty("dRadius") || this.isDirty("dInnerRadius") || this.isDirty("cornerRadius") || this.isDirty("shiftRadius")) && (this._clear = !0);
  }
  _changed() {
    if (super._changed(), this._clear) {
      let o = this.get("startAngle", 0), c = this.get("arc", 0);
      const g = this._generator;
      c < 0 && (o = o + c, c = c * -1), c > 0.1 && g.cornerRadius(this.get("cornerRadius", 0)), g.context(this._display);
      let d = this.get("radius", 0), l = this.get("innerRadius", 0), f = this.get("dRadius", 0), e = this.get("dInnerRadius", 0);
      d += f, l += e, l < 0 && (l = d + l), g({ innerRadius: l, outerRadius: d, startAngle: (o + 90) * un, endAngle: (o + c + 90) * un });
      let x = o + c / 2;
      this.ix = fn(x), this.iy = gn(x);
      const r = this.get("shiftRadius", 0);
      this.setRaw("dx", this.ix * r), this.setRaw("dy", this.iy * r), this.markDirtyPosition();
    }
  }
}
tn.className = "Slice";
tn.classNames = hn.classNames.concat([tn.className]);
export {
  tn as S,
  Tn as a
};
