//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()); }
//Gets a certain amount of points from the line //according to the distance between the points public Point[] GetLinePoints() { List <Point> pointList = new List <Point>(); Point firstPoint = new Point( src.Location.X + src.Parent.Location.X, src.Location.Y + src.Parent.Location.Y); firstPoint = LinePointUtils.RotatePoint( firstPoint, src.Parent.Location, -src.Parent.Angle); Point currentPoint = firstPoint; foreach (WirePoint wirePoint in Points) { currentPoint = wirePoint.Location; Point[] aux = LinePointUtils.GetMiddlePoints(firstPoint, currentPoint, DISTANCE_SEEK); if (aux != null) { pointList.AddRange(aux); } pointList.Add(firstPoint); firstPoint = currentPoint; } Point lastPoint = new Point( dst.Location.X + dst.Parent.Location.X, dst.Location.Y + dst.Parent.Location.Y); lastPoint = LinePointUtils.RotatePoint( lastPoint, dst.Parent.Location, -dst.Parent.Angle); Point[] array = LinePointUtils.GetMiddlePoints(firstPoint, lastPoint, DISTANCE_SEEK); if (array != null) { pointList.AddRange(array); } return(pointList.ToArray()); }
//Avoid using this. Consumes lots of resources!! public Rectangle[] GetLinePointsVicinities() { 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 currentPoint = firstPoint; foreach (WirePoint wirePoint in Points) { currentPoint = wirePoint.Location; Rectangle[] aux = LinePointUtils.GetMiddlePointsVicinities(firstPoint, currentPoint, DISTANCE_SEEK, RECT_SIZE); if (aux != null) { rectList.AddRange(aux); } firstPoint = currentPoint; } Point lastPoint = new Point( dst.Location.X + dst.Parent.Location.X, dst.Location.Y + dst.Parent.Location.Y); Rectangle[] array = LinePointUtils.GetMiddlePointsVicinities(firstPoint, lastPoint, DISTANCE_SEEK, RECT_SIZE); if (array != null) { rectList.AddRange(array); } 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()); }