public ShapeAABB(Rectangle r, float rotation = 0)
{
Center = new Vector2(r.Center.X, r.Center.Y);
Width = r.Width;
Height = r.Height;
if (rotation == 0) return;
Vector2 topLeft = new Vector2(r.Left, r.Top);
Vector2 topRight = new Vector2(r.Right, r.Top);
Vector2 bottomLeft = new Vector2(topLeft.X, r.Bottom);
Vector2 bottomRight = new Vector2(topRight.X, bottomLeft.Y);
topLeft = ShapeAABB.RotateAroundOrigin(topLeft, Center, rotation);
topRight = ShapeAABB.RotateAroundOrigin(topRight, Center, rotation);
bottomLeft = ShapeAABB.RotateAroundOrigin(bottomLeft, Center, rotation);
bottomRight = ShapeAABB.RotateAroundOrigin(bottomRight, Center, rotation);
float topLeftX = topLeft.X;
float topLeftY = topLeft.Y;
float bottomRightX = bottomRight.X;
float bottomRightY = bottomRight.Y;
if (topRight.X < topLeftX) topLeftX = topRight.X;
if (bottomLeft.X < topLeftX) topLeftX = bottomLeft.X;
if (bottomRight.X < topLeftX) topLeftX = bottomRight.X;
if (topRight.Y < topLeftY) topLeftY = topRight.Y;
if (bottomLeft.Y < topLeftY) topLeftY = bottomLeft.Y;
if (bottomRight.Y < topLeftY) topLeftY = bottomRight.Y;
if (topRight.X > bottomRightX) bottomRightX = topRight.X;
if (bottomLeft.X > bottomRightX) bottomRightX = bottomLeft.X;
if (topLeft.X > bottomRightX) bottomRightX = topLeft.X;
if (topRight.Y > bottomRightY) bottomRightY = topRight.Y;
if (bottomLeft.Y > bottomRightY) bottomRightY = bottomLeft.Y;
if (topLeft.Y > bottomRightY) bottomRightY = topLeft.Y;
Width = (int)(bottomRightX - topLeftX);
Height = (int)(bottomRightY - topLeftY);
Center = new Vector2(topLeftX + Width / 2, topLeftY + Height / 2);
}