Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/RectExtensions.cs @ 13792

Last change on this file since 13792 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.6 KB
Line 
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}
Note: See TracBrowser for help on using the repository browser.