UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 2.93 kB
{"version":3,"file":"fillOperations.mjs","sources":["../../../../../../src/scene/graphics/shared/svg/utils/fillOperations.ts"],"sourcesContent":["import type {\n FillInstruction,\n GraphicsContext,\n} from '../../GraphicsContext';\n\n/**\n * Determines if subpaths represent nested shapes or multiple holes pattern.\n * @param subpathsWithArea - Array of subpaths with their calculated areas\n * @returns True if nested pattern, false if multiple holes pattern\n * @internal\n */\nexport function checkForNestedPattern(subpathsWithArea: Array<{path: string, area: number}>): boolean\n{\n if (subpathsWithArea.length <= 2)\n {\n return true;\n }\n\n const areas = subpathsWithArea.map((s) => s.area).sort((a, b) => b - a);\n\n const [largestArea, secondArea] = areas;\n const smallestArea = areas[areas.length - 1];\n\n const largestToSecondRatio = largestArea / secondArea;\n const secondToSmallestRatio = secondArea / smallestArea;\n\n // If the largest shape is significantly bigger than the second (3x+)\n // AND the smaller shapes are similar in size (2x or less difference),\n // it suggests multiple holes pattern rather than nested shapes\n if (largestToSecondRatio > 3 && secondToSmallestRatio < 2)\n {\n return false; // Multiple holes\n }\n\n return true; // Default to nested\n}\n\n/**\n * Gets fill instruction data from a graphics context.\n * @param context - The graphics context\n * @param index - Index of the fill instruction (default: 0)\n * @returns The fill instruction data\n * @throws Error if instruction at index is not a fill instruction\n * @internal\n */\nexport function getFillInstructionData(context: GraphicsContext, index: number = 0)\n{\n const instruction = context.instructions[index];\n\n if (!instruction || instruction.action !== 'fill')\n {\n throw new Error(`Expected fill instruction at index ${index}, got ${instruction?.action || 'undefined'}`);\n }\n\n return (instruction as FillInstruction).data;\n}\n"],"names":[],"mappings":";AAWO,SAAS,sBAAsB,gBAAA,EACtC;AACI,EAAA,IAAI,gBAAA,CAAiB,UAAU,CAAA,EAC/B;AACI,IAAA,OAAO,IAAA;AAAA,EACX;AAEA,EAAA,MAAM,KAAA,GAAQ,gBAAA,CAAiB,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,IAAI,CAAC,CAAA;AAEtE,EAAA,MAAM,CAAC,WAAA,EAAa,UAAU,CAAA,GAAI,KAAA;AAClC,EAAA,MAAM,YAAA,GAAe,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA;AAE3C,EAAA,MAAM,uBAAuB,WAAA,GAAc,UAAA;AAC3C,EAAA,MAAM,wBAAwB,UAAA,GAAa,YAAA;AAK3C,EAAA,IAAI,oBAAA,GAAuB,CAAA,IAAK,qBAAA,GAAwB,CAAA,EACxD;AACI,IAAA,OAAO,KAAA;AAAA,EACX;AAEA,EAAA,OAAO,IAAA;AACX;AAUO,SAAS,sBAAA,CAAuB,OAAA,EAA0B,KAAA,GAAgB,CAAA,EACjF;AACI,EAAA,MAAM,WAAA,GAAc,OAAA,CAAQ,YAAA,CAAa,KAAK,CAAA;AAE9C,EAAA,IAAI,CAAC,WAAA,IAAe,WAAA,CAAY,MAAA,KAAW,MAAA,EAC3C;AACI,IAAA,MAAM,IAAI,MAAM,CAAA,mCAAA,EAAsC,KAAK,SAAS,WAAA,EAAa,MAAA,IAAU,WAAW,CAAA,CAAE,CAAA;AAAA,EAC5G;AAEA,EAAA,OAAQ,WAAA,CAAgC,IAAA;AAC5C;;;;"}