Treefrog.Framework.Model.ObjectInstance.CalculateRectangleBounds C# (CSharp) Метод

CalculateRectangleBounds() приватный статический Метод

private static CalculateRectangleBounds ( Rectangle rect, float angle ) : Rectangle
rect Treefrog.Framework.Imaging.Rectangle
angle float
Результат Treefrog.Framework.Imaging.Rectangle
        private static Rectangle CalculateRectangleBounds(Rectangle rect, float angle)
        {
            float st = (float)Math.Sin(angle);
            float ct = (float)Math.Cos(angle);

            float x1 = rect.Left * ct - rect.Top * st;
            float y1 = rect.Left * st + rect.Top * ct;
            float x2 = rect.Right * ct - rect.Top * st;
            float y2 = rect.Right * st + rect.Top * ct;
            float x3 = rect.Left * ct - rect.Bottom * st;
            float y3 = rect.Left * st + rect.Bottom * ct;
            float x4 = rect.Right * ct - rect.Bottom * st;
            float y4 = rect.Right * st + rect.Bottom * ct;

            int xmin = (int)Math.Floor(Math.Min(x1, Math.Min(x2, Math.Min(x3, x4))));
            int xmax = (int)Math.Ceiling(Math.Max(x1, Math.Max(x2, Math.Max(x3, x4))));
            int ymin = (int)Math.Floor(Math.Min(y1, Math.Min(y2, Math.Min(y3, y4))));
            int ymax = (int)Math.Ceiling(Math.Max(y1, Math.Max(y2, Math.Max(y3, y4))));

            return new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin);
        }