Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/DataRectExtensions.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: 4.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using System.Windows.Media.TextFormatting;
7using Microsoft.Research.DynamicDataDisplay.Common;
8
9namespace Microsoft.Research.DynamicDataDisplay
10{
11    public static class DataRectExtensions
12    {
13        internal static bool IsNaN( this DataRect rect )
14        {
15            return !rect.IsEmpty &&
16                (
17                rect.XMin.IsNaN() ||
18                rect.YMin.IsNaN() ||
19                rect.XMax.IsNaN() ||
20                rect.YMax.IsNaN()
21                );
22        }
23
24        /// <summary>
25        /// Gets the center of specified rectangle.
26        /// </summary>
27        /// <param name="rect">The rect.</param>
28        /// <returns></returns>
29        public static Point GetCenter( this DataRect rect )
30        {
31            return new Point( rect.XMin + rect.Width * 0.5, rect.YMin + rect.Height * 0.5 );
32        }
33
34        public static DataRect Zoom( this DataRect rect, Point to, double ratio )
35        {
36            return CoordinateUtilities.RectZoom( rect, to, ratio );
37        }
38
39        /// <summary>
40        /// Zooms out from center.
41        /// </summary>
42        /// <param name="rect">The rect.</param>
43        /// <param name="ratio">The ratio.</param>
44        /// <returns></returns>
45        public static DataRect ZoomOutFromCenter( this DataRect rect, double ratio )
46        {
47            return CoordinateUtilities.RectZoom( rect, rect.GetCenter(), ratio );
48        }
49
50        /// <summary>
51        /// Zooms in to center.
52        /// </summary>
53        /// <param name="rect">The rect.</param>
54        /// <param name="ratio">The ratio.</param>
55        /// <returns></returns>
56        public static DataRect ZoomInToCenter( this DataRect rect, double ratio )
57        {
58            return CoordinateUtilities.RectZoom( rect, rect.GetCenter(), 1 / ratio );
59        }
60
61        public static DataRect ZoomX( this DataRect rect, Point to, double ratio )
62        {
63            return CoordinateUtilities.RectZoomX( rect, to, ratio );
64        }
65
66        public static DataRect ZoomY( this DataRect rect, Point to, double ratio )
67        {
68            return CoordinateUtilities.RectZoomY( rect, to, ratio );
69        }
70
71        /// <summary>
72        /// Gets the square of specified DataRect.
73        /// </summary>
74        /// <param name="rect">The rect.</param>
75        /// <returns></returns>
76        public static double GetSquare( this DataRect rect )
77        {
78            if ( rect.IsEmpty )
79                return 0;
80
81            return rect.Width * rect.Height;
82        }
83
84        /// <summary>
85        /// Determines whether one DataRect is close to another DataRect.
86        /// </summary>
87        /// <param name="rect1">The rect1.</param>
88        /// <param name="rect2">The rect2.</param>
89        /// <param name="difference">The difference.</param>
90        /// <returns>
91        ///   <c>true</c> if [is close to] [the specified rect1]; otherwise, <c>false</c>.
92        /// </returns>
93        public static bool IsCloseTo( this DataRect rect1, DataRect rect2, double difference )
94        {
95            DataRect intersection = DataRect.Intersect( rect1, rect2 );
96            double square1 = rect1.GetSquare();
97            double square2 = rect2.GetSquare();
98            double intersectionSquare = intersection.GetSquare();
99
100            bool areClose = MathHelper.AreClose( square1, intersectionSquare, difference ) &&
101                MathHelper.AreClose( square2, intersectionSquare, difference );
102            return areClose;
103        }
104
105        public static DataRect WithX( this DataRect rect, double xmin, double xmax )
106        {
107            return DataRect.Create( xmin, rect.YMin, xmax, rect.YMax );
108        }
109
110        public static DataRect WithY( this DataRect rect, double ymin, double ymax )
111        {
112            return DataRect.Create( rect.XMin, ymin, rect.XMax, ymax );
113        }
114    }
115}
Note: See TracBrowser for help on using the repository browser.