Files
Foundry-VTT-Docker/resources/app/node_modules/@pixi/graphics-smooth/lib/shapes/CircleBuilder.mjs.map

1 line
18 KiB
Plaintext
Raw Normal View History

2025-01-04 00:34:03 +01:00
{"version":3,"file":"CircleBuilder.mjs","sources":["../../src/shapes/CircleBuilder.ts"],"sourcesContent":["// for type only\r\nimport { SHAPES } from '@pixi/core';\r\n\r\nimport type { Circle, Ellipse, RoundedRectangle } from '@pixi/core';\r\nimport type { IShapeBuilder } from '../core/IShapeBuilder';\r\nimport { SmoothGraphicsData } from '../core/SmoothGraphicsData';\r\nimport { BuildData } from '../core/BuildData';\r\nimport { JOINT_TYPE } from '../core/const';\r\n\r\n/**\r\n * @memberof PIXI.smooth\r\n */\r\nexport class CircleBuilder implements IShapeBuilder\r\n{\r\n path(graphicsData: SmoothGraphicsData, _target: BuildData)\r\n {\r\n // need to convert points to a nice regular data\r\n const points = graphicsData.points;\r\n\r\n let x;\r\n let y;\r\n let dx;\r\n let dy;\r\n let rx;\r\n let ry;\r\n\r\n if (graphicsData.type === SHAPES.CIRC)\r\n {\r\n const circle = graphicsData.shape as Circle;\r\n\r\n x = circle.x;\r\n y = circle.y;\r\n rx = ry = circle.radius;\r\n dx = dy = 0;\r\n }\r\n else if (graphicsData.type === SHAPES.ELIP)\r\n {\r\n const ellipse = graphicsData.shape as Ellipse;\r\n\r\n x = ellipse.x;\r\n y = ellipse.y;\r\n rx = ellipse.width;\r\n ry = ellipse.height;\r\n dx = dy = 0;\r\n }\r\n else\r\n {\r\n const roundedRect = graphicsData.shape as RoundedRectangle;\r\n const halfWidth = roundedRect.width / 2;\r\n const halfHeight = roundedRect.height / 2;\r\n\r\n x = roundedRect.x + halfWidth;\r\n y = roundedRect.y + halfHeight;\r\n rx = ry = Math.max(0, Math.min(roundedRect.radius, Math.min(halfWidth, halfHeight)));\r\n dx = halfWidth - rx;\r\n dy = halfHeight - ry;\r\n }\r\n\r\n if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0))\r\n {\r\n points.length = 0;\r\n\r\n return;\r\n }\r\n\r\n // Choose a number of segments such that the maximum absolute deviation from the circle is approximately 0.029\r\n const n = Math.ceil(2.3 * Math.sqrt(rx + ry));\r\n const m = (n * 8) + (dx ? 4 : 0) + (dy ? 4 : 0);\r\n\r\n points.length = m;\r\n\r\n if (m === 0)\r\n {\r\n return;\r\n }\r\n\r\n if (n === 0)\r\n {\r\n points.length = 8;\r\n points[0] = points[6] = x + dx;\r\n points[1] = points[3] = y + dy;\r\n points[2] = points[4] = x - dx;\r\n points[5] = points[7] = y - dy;\r\n\r\n return;\r\n }\r\n\r\n let j1 = 0;\r\n let j2 = (n * 4) + (dx ? 2 : 0) + 2;\r\n let j3 = j2;\r\n let j4 = m;\r\n\r\n {\r\n const x0 = dx + rx;\r\n const y0 = dy;\r\n const x1 = x + x0;\r\n const x2 = x - x0;\r\n const y1 = y + y0;\r\n\r\n points[j1++] = x1;\r\n points[j1++] = y1;\r\n points[--j2] = y1;\r\n points[--j2] = x2;\r\n\r\n if (dy)\r\n {\r\n const y2 = y - y0;\r\n\r\n points[j3++] = x2;\r\n points[j3++] = y2;\r\n points[--j4] = y2;\r\n points[--j4] = x1;\r\n }\r\n }\r\n\r\n for (let i = 1; i < n; i++)\r\n {\r\n const a = Math.PI / 2 * (i / n);\r\n const x0 = dx + (Math.cos(a) * rx);\r\n const y0 = dy + (Math.sin(a) * ry);\r\n const x1 = x + x0;\r\n const x2 = x - x0;\r\n const y1 = y + y0;\r\n const y2 = y - y0;\r\n\r\n points[j1++] = x1;\r\n points[j1++] = y1;\r\n points[--j2] = y1;\r\n points[--j2] = x2;\r\n points[j3++] = x2;\r\n points[j3++] = y2;\r\n points[--j4] = y2;\r\n points[--j4] = x1;\r\n