Zwraca tablicę w postaci:
[ [jednostka, odległość], [jednostka, odległość], ...]
Parametry:
- x,y - koordynaty
- list - lista jednostek
- asc - tryb sortowania: true -> rosnąco, false -> malejąco
Kód: Vybrať všetko
Export Function SortByDistanceXY(x, y, list, asc);
var i, j, tmp;
begin
if not list then
exit;
result := [];
for i in list do
begin
tmp := GetDistUnitXY(i, x, y);
if not result then
result := [[i, tmp]]
else
begin
if result[result][2] < tmp then
result := Insert(result, result+1, [i, tmp])
else
for j = 1 to result do
begin
if tmp < result[j][2] then
begin
result := Insert(result, j, [i, tmp]);
break;
end;
end;
end;
end;
if result and not asc then
begin
tmp := result;
for i = tmp downto 1 do
result := Replace(result, tmp - i + 1, tmp[i]);
end;
End;
Kód: Vybrať všetko
Export Function SortByDistanceUnit(unit, list, asc);
begin
result := SortByDistanceXY(GetX(unit), GetY(unit), list, asc);
End;