1 line
8.7 KiB
Plaintext
1 line
8.7 KiB
Plaintext
|
|
{"version":3,"file":"buildCircle.mjs","sources":["../../src/utils/buildCircle.ts"],"sourcesContent":["// for type only\nimport { SHAPES } from '@pixi/core';\n\nimport type { Circle, Ellipse, RoundedRectangle } from '@pixi/core';\nimport type { IShapeBuildCommand } from './IShapeBuildCommand';\n\n/**\n * Builds a circle to draw\n *\n * Ignored from docs since it is not directly exposed.\n * @ignore\n * @private\n * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object to draw\n * @param {object} webGLData - an object containing all the WebGL-specific information to create this shape\n * @param {object} webGLDataNativeLines - an object containing all the WebGL-specific information to create nativeLines\n */\nexport const buildCircle: IShapeBuildCommand = {\n\n build(graphicsData)\n {\n // need to convert points to a nice regular data\n const points = graphicsData.points;\n\n let x;\n let y;\n let dx;\n let dy;\n let rx;\n let ry;\n\n if (graphicsData.type === SHAPES.CIRC)\n {\n const circle = graphicsData.shape as Circle;\n\n x = circle.x;\n y = circle.y;\n rx = ry = circle.radius;\n dx = dy = 0;\n }\n else if (graphicsData.type === SHAPES.ELIP)\n {\n const ellipse = graphicsData.shape as Ellipse;\n\n x = ellipse.x;\n y = ellipse.y;\n rx = ellipse.width;\n ry = ellipse.height;\n dx = dy = 0;\n }\n else\n {\n const roundedRect = graphicsData.shape as RoundedRectangle;\n const halfWidth = roundedRect.width / 2;\n const halfHeight = roundedRect.height / 2;\n\n x = roundedRect.x + halfWidth;\n y = roundedRect.y + halfHeight;\n rx = ry = Math.max(0, Math.min(roundedRect.radius, Math.min(halfWidth, halfHeight)));\n dx = halfWidth - rx;\n dy = halfHeight - ry;\n }\n\n if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0))\n {\n points.length = 0;\n\n return;\n }\n\n // Choose a number of segments such that the maximum absolute deviation from the circle is approximately 0.029\n const n = Math.ceil(2.3 * Math.sqrt(rx + ry));\n const m = (n * 8) + (dx ? 4 : 0) + (dy ? 4 : 0);\n\n points.length = m;\n\n if (m === 0)\n {\n return;\n }\n\n if (n === 0)\n {\n points.length = 8;\n points[0] = points[6] = x + dx;\n points[1] = points[3] = y + dy;\n points[2] = points[4] = x - dx;\n points[5] = points[7] = y - dy;\n\n return;\n }\n\n let j1 = 0;\n let j2 = (n * 4) + (dx ? 2 : 0) + 2;\n let j3 = j2;\n let j4 = m;\n\n {\n const x0 = dx + rx;\n const y0 = dy;\n const x1 = x + x0;\n const x2 = x - x0;\n const y1 = y + y0;\n\n points[j1++] = x1;\n points[j1++] = y1;\n points[--j2] = y1;\n points[--j2] = x2;\n\n if (dy)\n {\n const y2 = y - y0;\n\n points[j3++] = x2;\n points[j3++] = y2;\n points[--j4] = y2;\n points[--j4] = x1;\n }\n }\n\n for (let i = 1; i < n; i++)\n {\n const a = Math.PI / 2 * (i / n);\n const x0 = dx + (Math.cos(a) * rx);\n const y0 = dy + (Math.sin(a) * ry);\n const x1 = x + x0;\n const x2 = x - x0;\n const y1 = y + y0;\n const y2 = y - y0;\n\n points[j1++] = x1;\n points[j1++] = y1;\n points[--j2] = y1;\n points[--j2] = x2;\n points[j3++] = x2;\n points[j3++] = y2;\n points[--j4] = y2;\n points[--j4] = x1;\n }\n\n {\n const x0 = dx;\n const y0 =
|