public static IEnumerable <Point> GetCorners(this Rect rect) { return(new[] { rect.GetTopLeft(), rect.GetTopRight(), rect.GetBottomLeft(), rect.GetBottomRight() }); }
public static Rect Transform(this Rect rect, Matrix matrix) { if (matrix.IsIdentity) { return(rect); } Point topLeft = rect.GetTopLeft() * matrix; Point topRight = rect.GetTopRight() * matrix; Point bottomLeft = rect.GetBottomLeft() * matrix; Point bottomRight = rect.GetBottomRight() * matrix; Point location = new Point( topLeft.X.Min(topRight.X).Min(bottomLeft.X).Min(bottomRight.X), topLeft.Y.Min(topRight.Y).Min(bottomLeft.Y).Min(bottomRight.Y)); Size size = new Size( topLeft.X.Max(topRight.X).Max(bottomLeft.X).Max(bottomRight.X) - location.X, topLeft.Y.Max(topRight.Y).Max(bottomLeft.Y).Max(bottomRight.Y) - location.Y); return(new Rect(location, size)); }