, , , , ; . , O(n).
, , LINQ .Any(), , ( , O(1)).
- " ", , , . .
, , Rect newRect, :
if (coordinates.Any(c => c.IntersectsWith(newRect)))
{
}
, " " , Rectangle Windows.Shapes, . Rectangle , .
Rect , :
IEnumerable<Rect> coordinates = rectCollection.Select(r => new Rect(Canvas.GetLeft(r), Canvas.GetTop(r), r.Width, r.Height));
, ( , ifs lamdas ):
public static class Extensions
{
public static bool InteriorIntersectsWith(this Rect rect, Rect other)
{
return rect.IntersectsWith(other) && IsIntersectingInside(rect, other);
}
private static bool IsIntersectingInside(Rect rect, Rect other)
{
Rect intersectionArea = Rect.Intersect(rect, other);
return intersectionArea.Width > 0 && intersectionArea.Height > 0;
}
}
, , , , . , , .
,
if (coordinates.Any(c => c.InteriorIntersectsWith(newRect)))
{
}