SRL Archive - OSR Help

TPA sorting


purerange86

2014-10-19 23:36:32

So I am trying to sort an ATPA by each entry's first tile's proximity to a given tiles (c,d), and eventually click the closest one. Any ideas on how to do this?

right now i have:

function clickbankminimap: boolean;
var
c,d,dist,fails: Integer;
TPA,TPA2: TPointArray;
ATPA,ATPA2: T2DPointArray;
mapbox: TBox;
begin

FindColorsTolerance(TPA, floorcolor, 599, 75, MMX2, MMY2, 3);
atpa:= splittpa(tpa,2); //i want to find the entry in atpa that is closest to tile (c,d)

dist := distance(c,d,what the heck do i put here)
SortATPASize(atpa2,true); //maybe I could use the sortatpasize function in combination with the distance(x1,y1,x2,y2) function?

tpa2:=atpa[0];
mapbox := gettpabounds(tpa2); //eventually I would want to output the box to mapbox
end;

Just learned how to use arrays yesterday, please excuse my mistakes. Thanks in advance for everything :)

Olly

2014-10-20 00:00:51

SortATPAFromMidPoint(ATPA, Point(c, d));

I can only assume that's what you want.

Flight

2014-10-20 01:07:29

Olly is correct. Here's how I would do it based on your code:


function clickbankminimap: boolean;
var
mapbox : TBox;
c,d : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
begin
if not findColorsTolerance(tpa, floorcolor, 599, 75, MMX2, MMY2, 3) then Exit; // Colors not found
splittpawrap(tpa,2,atpa);

SortATPAFromMidPoint(atpa, point(c,d)); // Sort each TPA from "point(c,d)"
mapbox := gettpabounds(atpa[0]); //The closest tpa
end;

If you'd like to get some very detailed information on TPAs/ATPAs check out this tutorial:
https://villavu.com/forum/showthread.php?t=49067

purerange86

2014-10-20 16:39:55

Thanks guys, both helped lots!