Example #1
0
        public static Rectangle?GetClosestRectangleThatDoesNotIntersectWithOthers(
            Point possibleLocation, Size size, Point center, IEnumerable <Rectangle> rectangles)
        {
            var currentRectangles = GetPossibleRectangles(possibleLocation, size)
                                    .Where(r1 => !rectangles.Select(r2 => RectangleUtils.RectanglesAreIntersected(r1, r2)).Any(t => t)).ToList();
            Rectangle?closest = null;

            while (true)
            {
                var newClosest = DistanceUtils.GetClosestToThePointRectangle(center, currentRectangles);
                if (newClosest == null)
                {
                    return(closest);
                }
                closest           = newClosest;
                currentRectangles = GetRectanglesThatCloserToPoint(center, closest.Value, 1)
                                    .Where(r1 => !rectangles.Select(r2 => RectangleUtils.RectanglesAreIntersected(r1, r2)).Any(t => t)).ToList();
            }
        }
Example #2
0
 public static double GetRectangleDiagonal(Rectangle rectangle)
 {
     return(DistanceUtils.GetDistanceFromPointToPoint(
                rectangle.Location,
                new PointF(rectangle.Right, rectangle.Bottom)));
 }
Example #3
0
 public static bool ShiftedRectangleIsCloserToPoint(Point point, Rectangle originalRectangle, Rectangle shiftedRectangle)
 {
     return(DistanceUtils.GetDistanceFromRectangleToPoint(point, shiftedRectangle) <
            DistanceUtils.GetDistanceFromRectangleToPoint(point, originalRectangle));
 }