Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/RangeExtensions.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.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using Microsoft.Research.DynamicDataDisplay.Charts;
7
8namespace Microsoft.Research.DynamicDataDisplay
9{
10  public static class RangeExtensions
11  {
12    public static double GetLength(this Range<Point> range)
13    {
14      Point p1 = range.Min;
15      Point p2 = range.Max;
16
17      return (p1 - p2).Length;
18    }
19
20    public static double GetLength(this Range<double> range)
21    {
22      return range.Max - range.Min;
23    }
24
25    public static int GetLength(this Range<int> range)
26    {
27      return range.Max - range.Min;
28    }
29
30    public static bool FromTheLeft(this Range<int> range, Range<int> other)
31    {
32      return other.Min < range.Min &&
33        other.Max < range.Min;
34    }
35
36    public static bool FromTheRight(this Range<int> range, Range<int> other)
37    {
38      return other.Min > range.Max &&
39        other.Max > range.Max;
40    }
41
42    public static bool IntersectsWith(this Range<int> range, Range<int> other)
43    {
44      return range.IsBetween(other.Min) ||
45        range.IsBetween(other.Max);
46    }
47
48    public static bool IsBetween(this Range<int> range, int value)
49    {
50      return range.Min <= value && value <= range.Max;
51    }
52
53    /// <summary>
54    /// Determines whether specified range contains the specified value.
55    /// </summary>
56    /// <param name="range">The range.</param>
57    /// <param name="value">The value.</param>
58    /// <returns>
59    ///   <c>true</c> if [contains] [the specified range]; otherwise, <c>false</c>.
60    /// </returns>
61    public static bool Contains(this Range<double> range, double value)
62    {
63      return range.Min < value && value < range.Max;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.