Files
nothoughts/node_modules/pixi.js/lib/maths/shapes/RoundedRectangle.mjs.map
2025-08-04 18:57:35 +02:00

1 line
13 KiB
Plaintext

{"version":3,"file":"RoundedRectangle.mjs","sources":["../../../src/maths/shapes/RoundedRectangle.ts"],"sourcesContent":["import { Rectangle } from './Rectangle';\n\nimport type { ShapePrimitive } from './ShapePrimitive';\n\n// Check corner within stroke width\nconst isCornerWithinStroke = (\n pX: number,\n pY: number,\n cornerX: number,\n cornerY: number,\n radius: number,\n halfStrokeWidth: number\n) =>\n{\n const dx = pX - cornerX;\n const dy = pY - cornerY;\n const distance = Math.sqrt((dx * dx) + (dy * dy));\n\n return distance >= radius - halfStrokeWidth && distance <= radius + halfStrokeWidth;\n};\n\n/**\n * The `RoundedRectangle` object is an area defined by its position, as indicated by its top-left corner\n * point (`x`, `y`) and by its `width` and its `height`, including a `radius` property that\n * defines the radius of the rounded corners.\n * @memberof maths\n */\nexport class RoundedRectangle implements ShapePrimitive\n{\n /**\n * The X coordinate of the upper-left corner of the rounded rectangle\n * @default 0\n */\n public x: number;\n\n /**\n * The Y coordinate of the upper-left corner of the rounded rectangle\n * @default 0\n */\n public y: number;\n\n /**\n * The overall width of this rounded rectangle\n * @default 0\n */\n public width: number;\n\n /**\n * The overall height of this rounded rectangle\n * @default 0\n */\n public height: number;\n\n /**\n * Controls the radius of the rounded corners\n * @default 20\n */\n public radius: number;\n\n /**\n * The type of the object, mainly used to avoid `instanceof` checks\n * @default 'roundedRectangle'\n */\n public readonly type = 'roundedRectangle';\n\n /**\n * @param x - The X coordinate of the upper-left corner of the rounded rectangle\n * @param y - The Y coordinate of the upper-left corner of the rounded rectangle\n * @param width - The overall width of this rounded rectangle\n * @param height - The overall height of this rounded rectangle\n * @param radius - Controls the radius of the rounded corners\n */\n constructor(x = 0, y = 0, width = 0, height = 0, radius = 20)\n {\n this.x = x;\n this.y = y;\n this.width = width;\n this.height = height;\n this.radius = radius;\n }\n\n /**\n * Returns the framing rectangle of the rounded rectangle as a Rectangle object\n * @param out - optional rectangle to store the result\n * @returns The framing rectangle\n */\n public getBounds(out?: Rectangle): Rectangle\n {\n out = out || new Rectangle();\n\n out.x = this.x;\n out.y = this.y;\n out.width = this.width;\n out.height = this.height;\n\n return out;\n }\n\n /**\n * Creates a clone of this Rounded Rectangle.\n * @returns - A copy of the rounded rectangle.\n */\n public clone(): RoundedRectangle\n {\n return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);\n }\n\n /**\n * Copies another rectangle to this one.\n * @param rectangle - The rectangle to copy from.\n * @returns Returns itself.\n */\n public copyFrom(rectangle: RoundedRectangle): this\n {\n this.x = rectangle.x;\n this.y = rectangle.y;\n this.width = rectangle.width;\n this.height = rectangle.height;\n\n return this;\n }\n\n /**\n * Copies this rectangle to another one.\n * @param rectangle - The rectangle to copy to.\n * @returns Returns given parameter.\n */\n public copyTo(rectangle: RoundedRectangle): RoundedRectangle\n {\n rectangle.copyFrom(this);\n\n return rectangle;\n }\n\n /**\n * Checks whether the x and y coordinates given are contained within this Rounded Rectangle\n * @param x - The X coordinate of the point to test.\n * @param y - The Y coordinate of the point to test.\n * @returns - Whether the x/y coordinates are within this Rounded Rectangle.\n */\n public contains(x: number, y: number): boolean\n {\n if (this.width <= 0 || this.height <= 0)\n {\n return false;\n }\n if (x >= this.x && x <= this.x + this.width)\n {\n if (y >= this.y && y <= this.y + this.height)\n {\n const radius = Math.max(0, Math.min(this.radius, Math.min(this.width, this.height) / 2));\n\n if ((y >= this.y + radius && y <= this.y + this.height - radius)\n || (x >= this.x + radius && x <= this.x + this.width - radius))\n {\n return true;\n }\n let dx = x - (this.x + radius);\n let dy = y - (this.y + radius);\n const radius2 = radius * radius;\n\n if ((dx * dx) + (dy * dy) <= radius2)\n {\n return true;\n }\n dx = x - (this.x + this.width - radius);\n if ((dx * dx) + (dy * dy) <= radius2)\n {\n return true;\n }\n dy = y - (this.y + this.height - radius);\n if ((dx * dx) + (dy * dy) <= radius2)\n {\n return true;\n }\n dx = x - (this.x + radius);\n if ((dx * dx) + (dy * dy) <= radius2)\n {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /**\n * Checks whether the x and y coordinates given are contained within this rectangle including the stroke.\n * @param pX - The X coordinate of the point to test\n * @param pY - The Y coordinate of the point to test\n * @param strokeWidth - The width of the line to check\n * @returns Whether the x/y coordinates are within this rectangle\n */\n public strokeContains(pX: number, pY: number, strokeWidth: number): boolean\n {\n const { x, y, width, height, radius } = this;\n\n const halfStrokeWidth = strokeWidth / 2;\n const innerX = x + radius;\n const innerY = y + radius;\n const innerWidth = width - (radius * 2);\n const innerHeight = height - (radius * 2);\n const rightBound = x + width;\n const bottomBound = y + height;\n\n // Check if point is within the vertical edges (excluding corners)\n if (((pX >= x - halfStrokeWidth && pX <= x + halfStrokeWidth)\n || (pX >= rightBound - halfStrokeWidth && pX <= rightBound + halfStrokeWidth))\n && pY >= innerY && pY <= innerY + innerHeight)\n {\n return true;\n }\n\n // Check if point is within the horizontal edges (excluding corners)\n if (((pY >= y - halfStrokeWidth && pY <= y + halfStrokeWidth)\n || (pY >= bottomBound - halfStrokeWidth && pY <= bottomBound + halfStrokeWidth))\n && pX >= innerX && pX <= innerX + innerWidth)\n {\n return true;\n }\n\n // Top-left, top-right, bottom-right, bottom-left corners\n return (\n // Top-left\n (pX < innerX && pY < innerY\n && isCornerWithinStroke(pX, pY, innerX, innerY, radius, halfStrokeWidth))\n // top-right\n || (pX > rightBound - radius && pY < innerY\n && isCornerWithinStroke(pX, pY, rightBound - radius, innerY, radius, halfStrokeWidth))\n // bottom-right\n || (pX > rightBound - radius && pY > bottomBound - radius\n && isCornerWithinStroke(pX, pY, rightBound - radius, bottomBound - radius, radius, halfStrokeWidth))\n // bottom-left\n || (pX < innerX && pY > bottomBound - radius\n && isCornerWithinStroke(pX, pY, innerX, bottomBound - radius, radius, halfStrokeWidth)));\n }\n\n // #if _DEBUG\n public toString(): string\n {\n return `[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}`\n + `width=${this.width}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