Nilu
Nilu

Reputation: 245

Check for overlapping shapes in WPF

I have a set of shapes which need to be drawn on top of each other. I need to re-order them such that the smallest shape gets drawn last (i.e. it will be closest to the user). Is there any way to check whether a shape overlappes (encloses and/or intersects) another shape. I know there is a method in Rect structure called Contains which checks whether there is an object within it. Is there a similar method or a way to simulate it on Shapes in WPF? Thanks in advance for any help.

Cheers,

Nilu

Upvotes: 3

Views: 2984

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292465

You could probably use the Geometry.FillContainsWithDetail method. Its name is ill-chosen IMHO, but the description is clear :

Returns a value that describes the intersection between the current geometry and the specified geometry.

I have successfully used it for collision testing before, so it should work for you too...

Upvotes: 5

Related Questions