Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/FakePointList.cs @ 13376

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

#2283 added GUI and charts; fixed MCTS

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Windows;
5
6namespace Microsoft.Research.DynamicDataDisplay
7{
8  [DebuggerDisplay("Count = {Count}")]
9  public sealed class FakePointList : IList<Point> {
10    private int first;
11    private int last;
12    private int count;
13    private Point startPoint;
14    private bool hasPoints;
15
16    private double leftBound;
17    private double rightBound;
18    private readonly List<Point> points;
19
20    internal FakePointList(List<Point> points, double left, double right) {
21      this.points = points;
22      this.leftBound = left;
23      this.rightBound = right;
24
25      Calc();
26    }
27
28    internal void SetXBorders(double left, double right) {
29      this.leftBound = left;
30      this.rightBound = right;
31      Calc();
32    }
33
34    private void Calc() {
35      Debug.Assert(leftBound <= rightBound);
36
37      first = points.FindIndex(p => p.X > leftBound);
38      if (first > 0)
39        first--;
40
41      last = points.FindLastIndex(p => p.X < rightBound);
42
43      if (last < points.Count - 1)
44        last++;
45      count = last - first;
46      hasPoints = first >= 0 && last > 0;
47
48      if (hasPoints) {
49        startPoint = points[first];
50      }
51    }
52
53    public Point StartPoint {
54      get { return startPoint; }
55    }
56
57    public bool HasPoints {
58      get { return hasPoints; }
59    }
60
61    #region IList<Point> Members
62
63    public int IndexOf(Point item) {
64      throw new NotSupportedException();
65    }
66
67    public void Insert(int index, Point item) {
68      throw new NotSupportedException();
69    }
70
71    public void RemoveAt(int index) {
72      throw new NotSupportedException();
73    }
74
75    public Point this[int index] {
76      get {
77        return points[first + 1 + index];
78      }
79      set {
80        throw new NotSupportedException();
81      }
82    }
83
84    #endregion
85
86    #region ICollection<Point> Members
87
88    public void Add(Point item) {
89      throw new NotSupportedException();
90    }
91
92    public void Clear() {
93      throw new NotSupportedException();
94    }
95
96    public bool Contains(Point item) {
97      throw new NotSupportedException();
98    }
99
100    public void CopyTo(Point[] array, int arrayIndex) {
101      throw new NotSupportedException();
102    }
103
104    public int Count {
105      get { return count; }
106    }
107
108    public bool IsReadOnly {
109      get { throw new NotSupportedException(); }
110    }
111
112    public bool Remove(Point item) {
113      throw new NotSupportedException();
114    }
115
116    #endregion
117
118    #region IEnumerable<Point> Members
119
120    public IEnumerator<Point> GetEnumerator() {
121      for (int i = first + 1; i <= last; i++) {
122        yield return points[i];
123      }
124    }
125
126    #endregion
127
128    #region IEnumerable Members
129
130    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
131      return GetEnumerator();
132    }
133
134    #endregion
135  }
136}
Note: See TracBrowser for help on using the repository browser.