Quote:
Procedure SortTPAFrom(Var a: Array Of TPoint; From: TPoint); //creds to Wizzup?
{ Sort's all points in a TPointArray.
First Value will be closest to From, Last Value most far away.}
Var
I, C: Integer;
Begin
For I := 0 To Length(a) - 2 Do
Begin
If Distance(a[i].x, a[i].y, from.x, from.y) > Distance(a[i + 1].x, a[i + 1].y, from.x, from.y) Then
Begin
C := I;
Repeat
{WriteLn(IntToStr(c) + ' (' + IntToStr(a[c].x) + ', ' + IntToStr(a[c].y) + ') <-> ' +
' (' + IntToStr(a[c + 1].x) + ', ' + IntToStr(a[c + 1].y) + ')');}
tSwap(a[c], a[c + 1]);
if c < 1 then
break;
c := c - 1;
Until Distance(a[c].x, a[c].y, from.x, from.y) < Distance(a[c + 1].x, a[c + 1].y, from.x, from.y)
//writeln('next');
End;
End
End;