Assume I have the following overlapping rectangles (\"a\" and \"b\"):
aaaaaaaa
aaaaccccbbbbb
aaaaccccbbbbb
aaaaccccbbbbb
bbbbbbbbb
bbbbbbbbb
I used an abstract validator for my project and to check if some layout controls where overlapping I created rectangles out of the layout figures:
RuleFor(p => DoControlsIntersect(p.PageControls.Select(x => new Rectangle(x.Row, x.Column, x.Width, x.Height)).ToList())).Equal(false).WithMessage(OverlappingFields);
private bool DoControlsIntersect(List rectangles)
{
return rectangles.Any(rect => rectangles.Where(r => !r.Equals(rect)).Any(r => r.IntersectsWith(rect)));
}