I have a class that contains a Rectangle, and I fill up a list with these objects. Here’s an example of what I’m trying to do:
class Foo
{
Rectangle rect;
public Foo(Rectangle r) { rect = r; }
}
List<Foo> listFoo = new List<Foo>();
// Call the next three Rectangles 'A' 'B' and 'C'.
listFoo.Add(new Foo(new Rectangle(0, 0, 5, 5))); // Rect 'A' intersects with B
listFoo.Add(new Foo(new Rectangle(3, 3, 5, 5))); // Rect 'B' intersects with A & C
listFoo.Add(new Foo(new Rectangle(6, 6, 5, 5))); // Rect 'C' intersects with B
var query = ???;
foreach (Rectangle r in query)
{
// Should give two results
// Rectangle(3, 3, 2, 2); A & B
// Rectangle(6, 6, 2, 2); B & C
}
Can I write a single query that will use Rectangle.Intersect() to return a list of unique intersections in listFoo, with no duplicates from things like .Intersect(A,B) and .Intersect(B,A)?
1 Answer