/// <summary> /// Public method to begin the recursive check for if a point is connected to this point object. /// </summary> /// <param name="p">The point to check.</param> /// <returns></returns> internal bool ConnectedTo(GraphPoint p) { return ConnectedTo(p, new List<Segment>()); }
/// <summary> /// Recursive function that checks if the point is connected to this point. /// </summary> /// <param name="p"></param> /// <param name="checkedSegments"></param> /// <returns></returns> private bool ConnectedTo(GraphPoint p, List<Segment> checkedSegments) { //the same point, clearly connected if (Equals(p)) return true; //check all the segments connected to this one foreach (Segment s in Segments) { if (checkedSegments.Contains(s)) continue;//already checked, continue looping if (s.Contains(p)) return true;//point is directly connected through a segment checkedSegments.Add(s);//segment has been checked, don't try it again. if (s.OtherPoint(this).ConnectedTo(p, checkedSegments)) return true;//perform recursion to check if point is connected to the other point on the segment. } return false; }
/// <summary> /// Returns the smaller item based on name. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static GraphPoint Min(GraphPoint a, GraphPoint b) { if (a.Name.CompareTo(b.Name) <= 0) return a; return b; }
/// <summary> /// Returns the distance between this point object and the parameter. /// </summary> /// <param name="p">The point to check.</param> /// <returns></returns> internal double GetDistance(GraphPoint p) { return Math.Abs(Math.Sqrt(Math.Pow((X - p.X), 2) + Math.Pow((Y - p.Y), 2))); }
/// <summary> /// Add a point to the set /// </summary> /// <param name="point"></param> private void AddPoint(GraphPoint point) { //increment the name if it's numeric if (Util.IsNumeric(point.Name)) nextName = Convert.ToInt32(Math.Floor(Convert.ToDouble(point.Name) + 1.0)); foreach (GraphPoint p in points) { if (point.Equals(p)) { return; } } points.Add(point); listBox1.Items.Add(point); }
internal bool Contains(GraphPoint p) { return p.Equals(A) || p.Equals(B); }
public Segment(GraphPoint a, GraphPoint b) { A = a; B = b; }
internal GraphPoint OtherPoint(GraphPoint p) { if (p.Equals(A)) return B; if (p.Equals(B)) return A; return null; }