Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/BoundsHelper.cs @ 13757

Last change on this file since 13757 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows;
4using Microsoft.Research.DynamicDataDisplay.Common;
5
6namespace Microsoft.Research.DynamicDataDisplay
7{
8  public static class BoundsHelper
9  {
10    /// <summary>Computes bounding rectangle for sequence of points</summary>
11    /// <param name="points">Points sequence</param>
12    /// <returns>Minimal axis-aligned bounding rectangle</returns>
13    public static DataRect GetViewportBounds(IEnumerable<Point> viewportPoints)
14    {
15      DataRect bounds = DataRect.Empty;
16
17      double xMin = Double.PositiveInfinity;
18      double xMax = Double.NegativeInfinity;
19
20      double yMin = Double.PositiveInfinity;
21      double yMax = Double.NegativeInfinity;
22
23      foreach (Point p in viewportPoints)
24      {
25        xMin = Math.Min(xMin, p.X);
26        xMax = Math.Max(xMax, p.X);
27
28        yMin = Math.Min(yMin, p.Y);
29        yMax = Math.Max(yMax, p.Y);
30      }
31
32      // were some points in collection
33      if (!Double.IsInfinity(xMin))
34      {
35        bounds = DataRect.Create(xMin, yMin, xMax, yMax);
36      }
37
38      return bounds;
39    }
40
41    public static DataRect GetViewportBounds(IEnumerable<Point> dataPoints, DataTransform transform)
42    {
43      return GetViewportBounds(dataPoints.DataToViewport(transform));
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.