Despite the fact that this question is older than a year, I have recently encountered a similar problem. Thanks to a small amount of research in TRectF (used by FMX and FM2 Primitives), I got the following very simple function:
var aRect1, aRect2 : TRectF; begin aRect1 := Selection1.AbsoluteRect; aRect2 := Selection2.AbsoluteRect; if System.Types.IntersectRect(aRect1,aRect2) then Result := True else Result := False; end;
It is not clear, but if two rectangles / objects intersect or overlap, then the result is correct.
An alternative is the same procedure, but the code is refined
var aRect1, aRect2 : TRectF; begin aRect1 := Selection1.AbsoluteRect; aRect2 := Selection2.AbsoluteRect; result := System.Types.IntersectRect(aRect1,aRect2); end;
You will need to work on it to accept some input objects (in my case, I used TSelection , known as Selection1 and Selection2) and maybe found a way to add an offset (see TControl.GetAbsoluteRect in FMX.Types ), but theoretically it should work with almost any primitive or any control.
As an additional note, there are many TRectF for such objects;
AbsoluteRectBoundsRectLocalRectUpdateRect (May not apply to this situation, investigation required)ParentedRectClipRectChildrenRect
It is important to use the most appropriate for your situation (as the results will vary greatly in each case). In my example, TSelection were children of the form, so using AbsoluteRect was a very good choice (since LocalRect did not return the correct values).
Actually, you can scroll through each child component of your parent to be able to find out if there is a conflict between any and potentially, you could build a function that tells you which ones are facing (although this will probably require a recursive function) .
If you ever need to deal with “basic physics” in which collision detection is considered one (at least in this case, at a basic level) in Firemonkey, then working with TRectF is where you need to look. There’s a lot routines built into System.Types (XE3, and most likely XE2) automatically process this material, and as such you can avoid the large amount of math usually associated with this problem.
Additional notes
Something that I noticed was that the procedure described above was not very accurate and had several pixels. One solution is to put your shape in the parent container with alClient aligned, and then 5 pixels for all sides. Then, instead of measuring on TSelection.AbsoluteRect , the child AbsoluteRect is measured.
For example, I put a TCircle inside each TSelection, set the alignment of the circles to alClient , alClient to 5 on each side and a modified routine to work with Circle1 and Circle2 , unlike Selection1 and Selection2 . This turned out to be accurate to such an extent that if the circles themselves did not intersect (more precisely, their area did not overlap), then they would not be seen as colliding until the edges touch. Obviously, the angles of the circles themselves are a problem, but you could add another child component inside each circle, while its visibility is set to false, and it is slightly smaller in size to mimic the old collision method "Bounding Box" detection .
Application example
I added an example application with the source showing above. The 1 tab is a useful example, and the second tab gives a brief explanation of how TRectF works (and shows some limitations using the radar visual interface). The third tab demonstrates the use of TBitmapListAnimation to create animated images.
FMX Collision Detection - Example and Source