For a LiveCoder it is never too late
You take the rectangle, for example "20,30,100,120". This is (left,top,right,bottom)
[LC awaits points and treats these four items as (left,top) & cr & (right, bottom) -- usually wrong because leaving out bottomleft and topright.].
But you have to take the four extreme points topleft, topright, bottomleft and bottomright
of each field's rectangle.
A point (x,y) has two items, the x-coord and the y-coord. You can say, for example.
'put (10,20) into myPoint' or 'put "10,20" into myPoint'. And the function convexHull needs lines of points as input. Now this works:
Code: Select all
lock screen; lock messages
put fld "myFields" into myFields
--repeat with i=1 to the num of flds
--put the short name of fld i into line i of myFields
repeat with x=1 to the num of lines of myFields
put line x of myFields into lalin
repeat for each item elit in lalin
put the rect of fld elit into r -- is (r1,r2,r3,r4)
put cr & (item 1 of r, item 2 of r) & cr & \ -- topleft = (left,top)
(item 3 of r ,item 2 of r) & cr & \ -- topright = (right, top)
(item 3 of r, item 4 of r) & cr & \ -- bottomright = (right, bottom)
(item 1 of r, item 4 of r) after losPoints -- bottomleft = (left, bottom)
put "convexHullOfFlds" into g
if there is no grc g then create grc g
set style of grc g to "polygon"
set forecolor of grc g to "red"
set points of grc g to convexHull(losPoints)
unlock screen; unlock messages
[Edit. Corrected wrong order in explanation in the first paragraph.]