//This was optimized. It returns no more than 2 Rectangles //representing the surface that needs to be redrawn //when the respective wirePoint is moved public Rectangle[] GetLinePointsVicinities(WirePoint wirePoint) { List <Rectangle> rectList = new List <Rectangle>(); Point firstPoint = new Point( src.Location.X + src.Parent.Location.X, src.Location.Y + src.Parent.Location.Y); Point lastPoint = new Point( dst.Location.X + dst.Parent.Location.X, dst.Location.Y + dst.Parent.Location.Y); int index = Points.IndexOf(wirePoint); if (index != -1) { Rectangle rect1; Rectangle rect2; if (index > 0 && index < Points.Count - 1) { WirePoint point1 = Points[index - 1]; WirePoint point2 = Points[index + 1]; rect1 = LinePointUtils.GetRectangleWithCorners( point1.Location, wirePoint.Location); rect2 = LinePointUtils.GetRectangleWithCorners( point2.Location, wirePoint.Location); } else { rect1 = LinePointUtils.GetRectangleWithCorners( firstPoint, wirePoint.Location); rect2 = LinePointUtils.GetRectangleWithCorners( lastPoint, wirePoint.Location); } if (rect1 != null) { rectList.Add(rect1); } if (rect2 != null) { rectList.Add(rect2); } } return(rectList.ToArray()); }
//This was optimized. It returns only a rectangle who's corners //are the gate location and the nearest Wire Point in the wire //If no wire points exist the opposite gate's location is used public Rectangle[] GetLinePointsVicinities(Gate gate) { List <Rectangle> rectList = new List <Rectangle>(); Point firstPoint; Point lastPoint; if (gate == src.Parent) { lastPoint = new Point( src.Location.X + src.Parent.Location.X, src.Location.Y + src.Parent.Location.Y); if (Points.Count != 0) { firstPoint = Points[0].Location; } else { firstPoint = new Point( dst.Location.X + dst.Parent.Location.X, dst.Location.Y + dst.Parent.Location.Y); } Rectangle rect = LinePointUtils.GetRectangleWithCorners( lastPoint, firstPoint); if (rect != null) { rectList.Add(rect); } } if (gate == dst.Parent) { lastPoint = new Point( dst.Location.X + dst.Parent.Location.X, dst.Location.Y + dst.Parent.Location.Y); if (Points.Count != 0) { firstPoint = Points[Points.Count - 1].Location; } else { firstPoint = new Point( src.Location.X + src.Parent.Location.X, src.Location.Y + src.Parent.Location.Y); } Rectangle rect = LinePointUtils.GetRectangleWithCorners( lastPoint, firstPoint); if (rect != null) { rectList.Add(rect); } } return(rectList.ToArray()); }