PDA

View Full Version : Multi Color Distance Function- Untested



Enslaved
05-26-2013, 03:15 PM
This is my untested function of finding a TPA of a color which is only surrounded by other all other given colors within a distance:
This is also an example of how to use multidimensional arrays

Function TPDist(P1,P2:TPoint):Integer;
begin
Result := Distance(P1.x,P1.y,P2.x,P2.y);
end;


Function MultiColorDist(Colors,Tol,Maxdist:Array of LongInt;x1,y1,x2,y2:Integer):Variant; // Main Color to look for followed by surrounding colors
//Written by Enslaved
Var
i,j,k:integer;
TPAMain, ReturnTPA: TPointArray;
ColTPAA: Array of TPointArray;
TPACount : Array of Integer;
Begin
If High(Colors) <> High(tol) then
Begin
Writeln('Uneven array lengths');
Result := -1;
Exit;
end;
If (High(Colors) <> (High(MaxDist) + 1)) then
Begin
Writeln('Make sure that the length of Max Dist is 1 less that of the colors');
Writeln('Current MaxDist Length:' + IntToStr(Length(MaxDist)));
Writeln('Current Color Items:' + IntToStr(Length(Colors)));
Result := -1;
Exit;
end;
If (High(colors) = 0) then
begin
Writeln('Please search for more than 1 color');
result := -1
Exit;
End;

If FindColorsSpiralTolerance(Round((X1+x2)/2),Round((Y1+Y2)/2),TPAMain,Colors[0],x1,y1,x2,y2,Tol[0]) then
Begin
SetLength(TPACount,Length(TPAMain));
SetLength(ColTPAA,Length(Colors));
For i := 1 To High(Colors) do
FindColorsSpiralTolerance(Round((X1+x2)/2),Round((Y1+Y2)/2),ColTPAA[i],Colors[i],x1,y1,x2,y2,Tol[i]);

For i := 0 To High(TPAMain) do
Begin
For j := 1 to High(ColTPAA) do
Begin
For k := 0 to High(ColTPAA[j]) do
Begin
If (TPDist(ColTPAA[j][k],TPAMain[i]) <= MaxDist[j-1]) then
Begin
TPACount[i] := TPACount[i] + 1;
Break;
End;
End;
End;
If (TPACount[i] = High(ColTPAA)) Then
begin
TPACount[i] := 1;
end else
TPACount[i] := 0;
end;
End;
j := 0;
For i := 1 to High(TPAMain) do
Begin
If (TPACount[i] = 1) then
Begin
SetLength(ReturnTPA,(j + 1));
ReturnTPA[j] := TPAMain[i];
end;
End;
Result := ReturnTPA;
End;