Alex, No one would challenge your definition I think, but your solution only takes the corner points into account, right? So this wouldn’t give correct results in case the rectangles have different sizes or are positioned obliquely.
Henk > On 16 Feb 2021, at 03:12, use-livecode-requ...@lists.runrev.com wrote: > > For me, a more precise problem specification is: > > Given two rectangles (in regular Livecode format), the distance between > them is : > > ?- if they touch or overlap, distance is zero. > > ?- otherwise, it's the smallest distance from any point in R1 to any > point in R2. > > Which leads to a simple solution > >> function rdist R1, R2 >> ?? local DX, DY >> ?? put max( item 1 of R1 - item 3 of R2, item 1 of R2 - item 3 of R1, >> 0) into DX >> ?? put max( item 2 of R1 - item 4 of R2, item 2 of R2 - item 4 of R1, >> 0) into DY >> ?? return sqrt( DX*DX + DY * DY) >> end rdist >> > Alex. _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode