Example #1
0
 private static RectangleF CalculateBoundingBox(RectangleF rectangle, Matrix transformation)
 {
   PointF tl = rectangle.Location;
   PointF tr = new PointF(rectangle.Right, rectangle.Top);
   PointF bl = new PointF(rectangle.Left, rectangle.Bottom);
   PointF br = new PointF(rectangle.Right, rectangle.Bottom);
   transformation.Transform(ref tl);
   transformation.Transform(ref tr);
   transformation.Transform(ref bl);
   transformation.Transform(ref br);
   PointF rtl = new PointF(
       Math.Min(tl.X, Math.Min(tr.X, Math.Min(bl.X, br.X))),
       Math.Min(tl.Y, Math.Min(tr.Y, Math.Min(bl.Y, br.Y))));
   PointF rbr = new PointF(
       Math.Max(tl.X, Math.Max(tr.X, Math.Max(bl.X, br.X))),
       Math.Max(tl.Y, Math.Max(tr.Y, Math.Max(bl.Y, br.Y))));
   return SharpDXExtensions.CreateRectangleF(rtl, new SizeF(rbr.X - rtl.X, rbr.Y - rtl.Y));
 }
Example #2
0
 private static Rect RectTransform( Rect rect, Matrix matrix )
 {
     // WPF equivalent of following code:
     // Rect rectTransformed = Rect.Transform(rect, matrix);
     var leftTop = matrix.Transform( new Point( rect.Left, rect.Top ) );
     var rightTop = matrix.Transform( new Point( rect.Right, rect.Top ) );
     var leftBottom = matrix.Transform( new Point( rect.Left, rect.Bottom ) );
     var rightBottom = matrix.Transform( new Point( rect.Right, rect.Bottom ) );
     var left = Math.Min( Math.Min( leftTop.X, rightTop.X ), Math.Min( leftBottom.X, rightBottom.X ) );
     var top = Math.Min( Math.Min( leftTop.Y, rightTop.Y ), Math.Min( leftBottom.Y, rightBottom.Y ) );
     var right = Math.Max( Math.Max( leftTop.X, rightTop.X ), Math.Max( leftBottom.X, rightBottom.X ) );
     var bottom = Math.Max( Math.Max( leftTop.Y, rightTop.Y ), Math.Max( leftBottom.Y, rightBottom.Y ) );
     var rectTransformed = new Rect( left, top, right - left, bottom - top );
     return rectTransformed;
 }