public override int GetHashCode() { Debug.Assert(Label != null); if (Pt1 != null) { if (Pt2 != null) { return(Pt1.GetHashCode() ^ Pt2.GetHashCode() ^ Label.GetHashCode()); } else { return(Pt1.GetHashCode() ^ Label.GetHashCode()); } } else { if (Pt2 != null) { return(Pt2.GetHashCode() ^ Label.GetHashCode()); } else { return(Label.GetHashCode()); } } }
public override bool Equals(Shape other) { if (other == null) { return(false); } if (other is LineSegment) { var lineSeg = other as LineSegment; bool equalPt1 = Pt1.Equals(lineSeg.Pt1); bool equalPt2 = Pt2.Equals(lineSeg.Pt2); if (!(equalPt1 || equalPt2)) { return(false); } } return(base.Equals(other)); }
private void GraphOne_Click(object sender, EventArgs e) { Tables.Clear(); g.Clip = new Region(new Rectangle(0, 0, 1500, 1000)); g.Clear(Color.White); finalPoints.Clear(); List <double> Pt1 = new List <double> { 1 }, Pt2; // P(t)1..P(t)n, P(t+1)1..P(t+1)n for (int i = 1; i < levels; i++) { Pt1.Add(0); } Pt2 = Pt1.ToList(); SetStartValue(Pt1, probabilities[0][0].From - 1); if (probabilities.Last().Count == 0) { probabilities.Remove(probabilities.Last()); } g = this.CreateGraphics(); g.Clip = new Region(new Rectangle(0, 0, 1000, 1000)); g.Clear(Color.White); int wMulti = 1, hMulti = 15, startX = 70, startY = 750, stepCounter; for (int i = 1; i < levels + 1; i++) { g.DrawString($"{i}", Font, brush, startX - 20, startY - 2 - hMulti * i); g.DrawLine(new Pen(brush), startX, startY - hMulti * i - 4, startX + image.Width + 100, startY - hMulti * i - 4); } font = new Font("Arial", 10); for (int i = 0; i < image.Width / step; i += image.Width / step / 5) { g.DrawString($"{i * step}", font, brush, startX - 10 + i * step, startY + 7); } g.DrawRectangle(new Pen(brush.Color), startX, startY, image.Width + 100, 1); g.DrawRectangle(new Pen(brush.Color), startX, startY - expectedLevel(Pt1) * hMulti, wMulti, 3 * wMulti); finalPoints.Add(expectedLevel(Pt1)); for (int s = 0; s < probabilities.Count; s++) { //Pt1 = SetStartValue(Pt1, probabilities[s][0].From - 1); stepCounter = 0; while (stepCounter < StepsCount(s)) { for (int i = 0; i < levels; i++) { double res = probabilities[s].FindAll(x => x.From.Equals(i + 1) && !x.To.Equals(i + 1)).Sum(x => x.probability); Pt2[i] = Pt1[i] - Pt1[i] * probabilities[s].FindAll(x => x.From.Equals(i + 1) && !x.To.Equals(i + 1)).Sum(x => x.probability); for (int j = 0; j < levels; j++) { if (i == j) { continue; } Pt2[i] += Pt1[j] * probabilities[s].FindAll(x => x.From.Equals(j + 1) && x.To.Equals(i + 1)).Sum(x => x.probability); } } Tables.Add(Pt1); Pt1 = Pt2.ToList(); g.DrawRectangle(new Pen(brush.Color), startX += step, startY - expectedLevel(Pt1) * hMulti, wMulti, 3 * wMulti); stepCounter++; finalPoints.Add(expectedLevel(Pt1)); } } Tables.Add(Pt1); }