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.94 kB
{"version":3,"file":"updateQuadBounds.mjs","sources":["../../../src/utils/data/updateQuadBounds.ts"],"sourcesContent":["import type { ObservablePoint } from '../../maths/point/ObservablePoint';\nimport type { Texture } from '../../rendering/renderers/shared/texture/Texture';\nimport type { BoundsData } from '../../scene/container/bounds/Bounds';\n\n/**\n * Updates the bounds of a quad (a rectangular area) based on the provided texture and anchor point.\n *\n * This function calculates the minimum and maximum x and y coordinates of the bounds, taking into\n * account the texture's original dimensions and any trimming that may have been applied to it.\n * @param {BoundsData} bounds - The bounds object to be updated. It contains minX, maxX, minY, and maxY properties.\n * @param {ObservablePoint} anchor - The anchor point of the texture, which affects the positioning of the bounds.\n * @param {Texture} texture - The texture whose dimensions and trimming information are used to update the bounds.\n * @internal\n */\nexport function updateQuadBounds(\n bounds: BoundsData,\n anchor: ObservablePoint,\n texture: Texture\n): void\n{\n const { width, height } = texture.orig;\n const trim = texture.trim;\n\n // If the texture has trimming information, adjust the bounds accordingly\n if (trim)\n {\n // Calculate the source width and height from the trim\n const sourceWidth = trim.width;\n const sourceHeight = trim.height;\n\n // Update the bounds using the trim's x and y offsets and the anchor point\n bounds.minX = trim.x - (anchor._x * width);\n bounds.maxX = bounds.minX + sourceWidth;\n\n bounds.minY = trim.y - (anchor._y * height);\n bounds.maxY = bounds.minY + sourceHeight;\n }\n // If there is no trimming, calculate the bounds based solely on the texture's original dimensions\n else\n {\n bounds.minX = -anchor._x * width;\n bounds.maxX = bounds.minX + width;\n\n bounds.minY = -anchor._y * height;\n bounds.maxY = bounds.minY + height;\n }\n}\n"],"names":[],"mappings":";AAcgB,SAAA,gBAAA,CACZ,MACA,EAAA,MAAA,EACA,OAEJ,EAAA;AACI,EAAA,MAAM,EAAE,KAAA,EAAO,MAAO,EAAA,GAAI,OAAQ,CAAA,IAAA,CAAA;AAClC,EAAA,MAAM,OAAO,OAAQ,CAAA,IAAA,CAAA;AAGrB,EAAA,IAAI,IACJ,EAAA;AAEI,IAAA,MAAM,cAAc,IAAK,CAAA,KAAA,CAAA;AACzB,IAAA,MAAM,eAAe,IAAK,CAAA,MAAA,CAAA;AAG1B,IAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAK,CAAK,GAAA,MAAA,CAAO,EAAK,GAAA,KAAA,CAAA;AACpC,IAAO,MAAA,CAAA,IAAA,GAAO,OAAO,IAAO,GAAA,WAAA,CAAA;AAE5B,IAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAK,CAAK,GAAA,MAAA,CAAO,EAAK,GAAA,MAAA,CAAA;AACpC,IAAO,MAAA,CAAA,IAAA,GAAO,OAAO,IAAO,GAAA,YAAA,CAAA;AAAA,GAIhC,MAAA;AACI,IAAO,MAAA,CAAA,IAAA,GAAO,CAAC,MAAA,CAAO,EAAK,GAAA,KAAA,CAAA;AAC3B,IAAO,MAAA,CAAA,IAAA,GAAO,OAAO,IAAO,GAAA,KAAA,CAAA;AAE5B,IAAO,MAAA,CAAA,IAAA,GAAO,CAAC,MAAA,CAAO,EAAK,GAAA,MAAA,CAAA;AAC3B,IAAO,MAAA,CAAA,IAAA,GAAO,OAAO,IAAO,GAAA,MAAA,CAAA;AAAA,GAChC;AACJ;;;;"}