SRL Archive - Suggestions

SortATPAFromMidPoint


mormonman

2011-11-30 21:33:13

Please add this function :)
I'm too lazy to do it myself.

{/\
Sorts the T2DPointArray a from the midpoint of each TPA by From.
/\}

procedure SortATPAFromMidPoint(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
MidPt: TPoint;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
begin
MidPt := MiddleTPA(a[i]);
DistArr[i] := Round(Sqr(From.x - MidPt.x) + Sqr(From.y - MidPt.y));
end;
QuickATPASort(DistArr, a, 0, l, True);
end;