import '../../core/settings.mjs';
import '../../color.mjs';
import '../../constants.mjs';
import '../../extensions.mjs';
import { SHAPES } 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';

const buildCircle = {
  build(graphicsData) {
    const points = graphicsData.points;
    let x;
    let y;
    let dx;
    let dy;
    let rx;
    let ry;
    if (graphicsData.type === SHAPES.CIRC) {
      const circle = graphicsData.shape;
      x = circle.x;
      y = circle.y;
      rx = ry = circle.radius;
      dx = dy = 0;
    } else if (graphicsData.type === SHAPES.ELIP) {
      const ellipse = graphicsData.shape;
      x = ellipse.x;
      y = ellipse.y;
      rx = ellipse.width;
      ry = ellipse.height;
      dx = dy = 0;
    } else {
      const roundedRect = graphicsData.shape;
      const halfWidth = roundedRect.width / 2;
      const halfHeight = roundedRect.height / 2;
      x = roundedRect.x + halfWidth;
      y = roundedRect.y + halfHeight;
      rx = ry = Math.max(0, Math.min(roundedRect.radius, Math.min(halfWidth, halfHeight)));
      dx = halfWidth - rx;
      dy = halfHeight - ry;
    }
    if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
      points.length = 0;
      return;
    }
    const n = Math.ceil(2.3 * Math.sqrt(rx + ry));
    const m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
    points.length = m;
    if (m === 0) {
      return;
    }
    if (n === 0) {
      points.length = 8;
      points[0] = points[6] = x + dx;
      points[1] = points[3] = y + dy;
      points[2] = points[4] = x - dx;
      points[5] = points[7] = y - dy;
      return;
    }
    let j1 = 0;
    let j2 = n * 4 + (dx ? 2 : 0) + 2;
    let j3 = j2;
    let j4 = m;
    {
      const x0 = dx + rx;
      const y0 = dy;
      const x1 = x + x0;
      const x2 = x - x0;
      const y1 = y + y0;
      points[j1++] = x1;
      points[j1++] = y1;
      points[--j2] = y1;
      points[--j2] = x2;
      if (dy) {
        const y2 = y - y0;
        points[j3++] = x2;
        points[j3++] = y2;
        points[--j4] = y2;
        points[--j4] = x1;
      }
    }
    for (let i = 1; i < n; i++) {
      const a = Math.PI / 2 * (i / n);
      const x0 = dx + Math.cos(a) * rx;
      const y0 = dy + Math.sin(a) * ry;
      const x1 = x + x0;
      const x2 = x - x0;
      const y1 = y + y0;
      const y2 = y - y0;
      points[j1++] = x1;
      points[j1++] = y1;
      points[--j2] = y1;
      points[--j2] = x2;
      points[j3++] = x2;
      points[j3++] = y2;
      points[--j4] = y2;
      points[--j4] = x1;
    }
    {
      const x0 = dx;
      const y0 = dy + ry;
      const x1 = x + x0;
      const x2 = x - x0;
      const y1 = y + y0;
      const y2 = y - y0;
      points[j1++] = x1;
      points[j1++] = y1;
      points[--j4] = y2;
      points[--j4] = x1;
      if (dx) {
        points[j1++] = x2;
        points[j1++] = y1;
        points[--j4] = y2;
        points[--j4] = x2;
      }
    }
  },
  triangulate(graphicsData, graphicsGeometry) {
    const points = graphicsData.points;
    const verts = graphicsGeometry.points;
    const indices = graphicsGeometry.indices;
    if (points.length === 0) {
      return;
    }
    let vertPos = verts.length / 2;
    const center = vertPos;
    let x;
    let y;
    if (graphicsData.type !== SHAPES.RREC) {
      const circle = graphicsData.shape;
      x = circle.x;
      y = circle.y;
    } else {
      const roundedRect = graphicsData.shape;
      x = roundedRect.x + roundedRect.width / 2;
      y = roundedRect.y + roundedRect.height / 2;
    }
    const matrix = graphicsData.matrix;
    verts.push(graphicsData.matrix ? matrix.a * x + matrix.c * y + matrix.tx : x, graphicsData.matrix ? matrix.b * x + matrix.d * y + matrix.ty : y);
    vertPos++;
    verts.push(points[0], points[1]);
    for (let i = 2; i < points.length; i += 2) {
      verts.push(points[i], points[i + 1]);
      indices.push(vertPos++, center, vertPos);
    }
    indices.push(center + 1, center, vertPos);
  }
};

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