public static Rect CGRectApplyAffineTransform(Rect rect, CGAffineTransform transform)
{
float xMin = rect.position.x;
float xMax = rect.position.x + rect.size.x;
float yMin = rect.position.y;
float yMax = rect.position.y + rect.size.y;
Vector2[] points = new Vector2[4]{
CGPointApplyAffineTransform(new Vector2(xMin, yMin), transform),
CGPointApplyAffineTransform(new Vector2(xMin, yMax), transform),
CGPointApplyAffineTransform(new Vector2(xMax, yMin), transform),
CGPointApplyAffineTransform(new Vector2(xMax, yMax), transform),
};
float newXMin = float.MaxValue;
float newXMax = float.MinValue;
float newYMin = float.MaxValue;
float newYMax = float.MinValue;
for (int i = 0; i < 4; i++) {
newXMax = Mathf.Max(newXMax, points[i].x);
newYMax = Mathf.Max(newYMax, points[i].y);
newXMin = Mathf.Min(newXMin, points[i].x);
newYMin = Mathf.Min(newYMin, points[i].y);
}
Rect result = new Rect(newXMin, newYMin, newXMax - newXMin, newYMax - newYMin);
return result;
}
}