/Main/src/DynamicDataDisplay/Common/Auxiliary/RectExtensions.cs
C# | 67 lines | 57 code | 10 blank | 0 comment | 1 complexity | 223d506b0e6c6e38979c0911b0f31ec2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
1using System.Windows; 2using Microsoft.Research.DynamicDataDisplay.Common; 3using System.Diagnostics; 4 5namespace Microsoft.Research.DynamicDataDisplay 6{ 7 public static class RectExtensions 8 { 9 public static Point GetCenter(this Rect rect) 10 { 11 return new Point(rect.Left + rect.Width * 0.5, rect.Top + rect.Height * 0.5); 12 } 13 14 public static Rect FromCenterSize(Point center, Size size) 15 { 16 return FromCenterSize(center, size.Width, size.Height); 17 } 18 19 public static Rect FromCenterSize(Point center, double width, double height) 20 { 21 Rect res = new Rect(center.X - width / 2, center.Y - height / 2, width, height); 22 return res; 23 } 24 25 public static Rect Zoom(this Rect rect, Point to, double ratio) 26 { 27 return CoordinateUtilities.RectZoom(rect, to, ratio); 28 } 29 30 public static Rect ZoomOutFromCenter(this Rect rect, double ratio) 31 { 32 return CoordinateUtilities.RectZoom(rect, rect.GetCenter(), ratio); 33 } 34 35 public static Rect ZoomInToCenter(this Rect rect, double ratio) 36 { 37 return CoordinateUtilities.RectZoom(rect, rect.GetCenter(), 1 / ratio); 38 } 39 40 public static Int32Rect ToInt32Rect(this Rect rect) 41 { 42 Int32Rect intRect = new Int32Rect( 43 (int)rect.X, 44 (int)rect.Y, 45 (int)rect.Width, 46 (int)rect.Height); 47 48 return intRect; 49 } 50 51 [DebuggerStepThrough] 52 public static DataRect ToDataRect(this Rect rect) 53 { 54 return new DataRect(rect); 55 } 56 57 internal static bool IsNaN(this Rect rect) 58 { 59 return !rect.IsEmpty && ( 60 rect.X.IsNaN() || 61 rect.Y.IsNaN() || 62 rect.Width.IsNaN() || 63 rect.Height.IsNaN() 64 ); 65 } 66 } 67}