Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Solve - do 2 rectangles overlap
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01455826
Message ID:
01455975
Views:
59
>Hi John,
>
>>I need the algorithm (in VFP) to determine if two containers on a form overlap at any point. The code I did now has 8 Between() statements and still does not cover all possibilities.
>
>That's the same problem as figuring out whether two date ranges overlap (http://www.foxpert.com/knowlbits_200711_1.htm). The key is that it's much easier to find out when there's no overlap, rather when there's an overlap. Therefore you need to approach this from the opposite direction:
>
>Local llxAxis, llyAxis, lo1, lo2
>
>lo1 = Thisform.Container1
>lo2 = Thisform.Container2
>
>llxAxis = (NOT((lo2.Left+lo2.Width < lo1.Left) or (lo2.Left > lo1.Left+lo1.Width)))
>llyAxis = (NOT((lo2.Top+lo2.Height < lo1.Top) or (lo2.Top > lo1.Height+lo1.Height)))
>
>If m.llxAxis and m.llyAxis
>	MessageBox("Overlap")
>Else
>	MessageBox("No overlap")
>EndIf
>
Christof, thanks very much for the code. You had one typo but it was minor. It sure is much simpler that the way I tried to do it.
>
>llxAxis = (NOT((lo2.Left+lo2.Width < lo1.Left) or (lo2.Left > lo1.Left+lo1.Width)))
>llyAxis = (NOT((lo2.Top+lo2.Height < lo1.Top) or (lo2.Top > lo1.Height+lo1.Height)))  <-- Changed:
>llyAxis = (NOT((lo2.Top+lo2.Height < lo1.Top) or (lo2.Top > lo1.Top+lo1.Height)))   <-- To:
>
Beer is proof that God loves man, and wants him to be happy. - Benjamin Franklin
John J. Henn
Previous
Reply
Map
View

Click here to load this message in the networking platform