Rectangle Problem

Alex Tweedly alex at tweedly.net
Wed Apr 6 07:11:06 EDT 2005


David Burgun wrote:

> Ok, yes thanks, I was just about coming to the conclusion that this 
> was the only way to achieve this. I looked at the "within" 
> function/keyword which works on points, seems like it would be good to 
> make this work with two objects, so you could write:
>
>  if within("UserRect","BoundingRect") then
> .........................
> end if
>
For a rectangle to be (wholly) within another, any two opposite corners 
must each be within it ... so

function RectWithinRect UserRect, BoundRect
   return (item 1 to 2 of UserRect is within BoundRect) and (item 3 to 4 
of UserRect is within BoundRect)
end RectWithinRect

or if you want to check for being within objects rather than any rectangle

function RectWithinObj UserRect, Obj
   return within(item 1 to 2 of UserRect, Obj) and within(item 3 to 4 of 
UserRect, Obj)
end RectWithinObj

(BUT - beware that not all objects have rectangular interiors - so this 
can give wrong answers on some polygons, or partially transparent 
images, or .....)

-- 
Alex Tweedly       http://www.tweedly.net




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.2 - Release Date: 05/04/2005



More information about the use-livecode mailing list