import '../../core/settings.mjs';
import '../../color.mjs';
import '../../constants.mjs';
import '../../extensions.mjs';
import { PI_2 } from '../../math/const.mjs';
import '../../math/groupD8.mjs';
import '../../math/Transform.mjs';
import '../../runner.mjs';
import '../../ticker/settings.mjs';
import '../../ticker/const.mjs';
import '../../ticker/Ticker.mjs';
import '../../ticker/TickerPlugin.mjs';
import '../../utils/settings.mjs';
import '../../utils/is_mobile/index.mjs';
import '../../utils/color/premultiply.mjs';
import '../../utils/media/BoundingBox.mjs';
import '../../core/autoDetectRenderer.mjs';
import '../../core/background/BackgroundSystem.mjs';
import '../../core/batch/BatchRenderer.mjs';
import '../../core/shader/Program.mjs';
import '../../core/batch/BatchSystem.mjs';
import '../../core/context/ContextSystem.mjs';
import '../../core/filters/Filter.mjs';
import '../../core/filters/FilterSystem.mjs';
import '../../core/textures/BaseTexture.mjs';
import '../../core/framebuffer/FramebufferSystem.mjs';
import '../../core/framebuffer/MultisampleSystem.mjs';
import '../../core/geometry/BufferSystem.mjs';
import '../../core/geometry/GeometrySystem.mjs';
import '../../core/mask/MaskSystem.mjs';
import '../../core/mask/ScissorSystem.mjs';
import '../../core/mask/StencilSystem.mjs';
import '../../core/plugin/PluginSystem.mjs';
import '../../core/projection/ProjectionSystem.mjs';
import '../../core/render/ObjectRendererSystem.mjs';
import '../../core/Renderer.mjs';
import '../../core/renderTexture/GenerateTextureSystem.mjs';
import '../../core/renderTexture/RenderTexturePool.mjs';
import '../../core/renderTexture/RenderTextureSystem.mjs';
import '../../core/shader/ShaderSystem.mjs';
import '../../core/startup/StartupSystem.mjs';
import '../../core/state/StateSystem.mjs';
import '../../core/textures/TextureGCSystem.mjs';
import '../../core/textures/TextureSystem.mjs';
import '../../core/transformFeedback/TransformFeedbackSystem.mjs';
import '../../core/view/ViewSystem.mjs';
import '../../core/textures/resources/index.mjs';
import { curves } from '../const.mjs';

class ArcUtils {
  /**
   * Calculate information of the arc for {@link PIXI.Graphics.arcTo}.
   * @private
   * @param x1 - The x-coordinate of the first control point of the arc
   * @param y1 - The y-coordinate of the first control point of the arc
   * @param x2 - The x-coordinate of the second control point of the arc
   * @param y2 - The y-coordinate of the second control point of the arc
   * @param radius - The radius of the arc
   * @param points - Collection of points to add to
   * @returns - If the arc length is valid, return center of circle, radius and other info otherwise `null`.
   */
  static curveTo(x1, y1, x2, y2, radius, points) {
    const fromX = points[points.length - 2];
    const fromY = points[points.length - 1];
    const a1 = fromY - y1;
    const b1 = fromX - x1;
    const a2 = y2 - y1;
    const b2 = x2 - x1;
    const mm = Math.abs(a1 * b2 - b1 * a2);
    if (mm < 1e-8 || radius === 0) {
      if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
        points.push(x1, y1);
      }
      return null;
    }
    const dd = a1 * a1 + b1 * b1;
    const cc = a2 * a2 + b2 * b2;
    const tt = a1 * a2 + b1 * b2;
    const k1 = radius * Math.sqrt(dd) / mm;
    const k2 = radius * Math.sqrt(cc) / mm;
    const j1 = k1 * tt / dd;
    const j2 = k2 * tt / cc;
    const cx = k1 * b2 + k2 * b1;
    const cy = k1 * a2 + k2 * a1;
    const px = b1 * (k2 + j1);
    const py = a1 * (k2 + j1);
    const qx = b2 * (k1 + j2);
    const qy = a2 * (k1 + j2);
    const startAngle = Math.atan2(py - cy, px - cx);
    const endAngle = Math.atan2(qy - cy, qx - cx);
    return {
      cx: cx + x1,
      cy: cy + y1,
      radius,
      startAngle,
      endAngle,
      anticlockwise: b1 * a2 > b2 * a1
    };
  }
  /**
   * The arc method creates an arc/curve (used to create circles, or parts of circles).
   * @private
   * @param _startX - Start x location of arc
   * @param _startY - Start y location of arc
   * @param cx - The x-coordinate of the center of the circle
   * @param cy - The y-coordinate of the center of the circle
   * @param radius - The radius of the circle
   * @param startAngle - The starting angle, in radians (0 is at the 3 o'clock position
   *  of the arc's circle)
   * @param endAngle - The ending angle, in radians
   * @param _anticlockwise - Specifies whether the drawing should be
   *  counter-clockwise or clockwise. False is default, and indicates clockwise, while true
   *  indicates counter-clockwise.
   * @param points - Collection of points to add to
   */
  static arc(_startX, _startY, cx, cy, radius, startAngle, endAngle, _anticlockwise, points) {
    const sweep = endAngle - startAngle;
    const n = curves._segmentsCount(Math.abs(sweep) * radius, Math.ceil(Math.abs(sweep) / PI_2) * 40);
    const theta = sweep / (n * 2);
    const theta2 = theta * 2;
    const cTheta = Math.cos(theta);
    const sTheta = Math.sin(theta);
    const segMinus = n - 1;
    const remainder = segMinus % 1 / segMinus;
    for (let i = 0; i <= segMinus; ++i) {
      const real = i + remainder * i;
      const angle = theta + startAngle + theta2 * real;
      const c = Math.cos(angle);
      const s = -Math.sin(angle);
      points.push((cTheta * c + sTheta * s) * radius + cx, (cTheta * -s + sTheta * c) * radius + cy);
    }
  }
}

export { ArcUtils };
//# sourceMappingURL=ArcUtils.mjs.map
