1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 09:12:19 -05:00

SRL is working (correctly) now.. Added shitload of Wrappers for any function that returns an Array.. (PS fails on these kind of functions).

Fixed bug in FindDTM(s). Might want to optimze the function though. Replaced all the fSqrt with Sqrt..

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@529 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-02-06 21:01:35 +00:00
parent 108bf37d6f
commit 354ab2aab9
7 changed files with 3222 additions and 3134 deletions

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,10 @@ end;
function ps_pow(base,exponent : extended) : extended; extdecl;
begin
result := power(base,exponent);
if (exponent=0) then
result := 1
else
result := power(base,exponent);
end;
function ps_Max(a,b : integer) : integer; extdecl;

View File

@ -0,0 +1,66 @@
procedure SplitTPAExWrap(arr: TPointArray; w, h: Integer; out res : T2DPointArray);
begin
res := SplitTPAEx(arr,w,h);
end;
procedure SplitTPAWrap(arr: TPointArray; Dist: Integer; out res: T2DPointArray);
begin
res := SplitTPA(arr,dist);
end;
procedure FindGapsTPAWrap(TPA: TPointArray; MinPixels: Integer; out Res : T2DPointArray); extdecl;
begin
Res := FindGapsTPA(TPA,MinPixels);
end;
procedure RemoveDistTPointArrayWrap(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean; out Res : TPointArray);extdecl;
begin
Res := RemoveDistTPointArray(x,y,dist,thepoints,removehigher);
end;
procedure CombineTPAWrap(Ar1, Ar2: TPointArray; out Res : TPointArray);extdecl;
begin
Res := CombineTPA(Ar1,Ar2);
end;
procedure ReArrangeandShortenArrayExWrap(a: TPointArray; w, h: Integer; out Res : TPointArray);extdecl;
begin
Res := ReArrangeandShortenArrayEx(a,w,h);
end;
procedure ReArrangeandShortenArrayWrap(a: TPointArray; Dist: Integer; out Res : TPointArray);extdecl;
begin
Res := ReArrangeandShortenArray(a,dist);
end;
procedure TPAtoATPAExWrap(TPA: TPointArray; w, h: Integer; out Res : T2DPointArray);extdecl;
begin
Res := TPAtoATPAEx(TPA,w,h);
end;
procedure TPAtoATPAWrap(TPA: TPointArray; Dist: Integer; out Res : T2DPointArray);extdecl;
begin
Res := TPAtoATPA(TPA,Dist);
end;
procedure CombineIntArrayWrap(Ar1, Ar2: TIntegerArray; out Res : TIntegerArray);extdecl;
begin
Res := CombineIntArray(Ar1,Ar2);
end;
procedure MergeATPAWrap(ATPA : T2DPointArray; out Res: TPointArray); extdecl;
begin
Res := MergeATPA(ATPA);
end;
procedure TPAFromBoxWrap(const Box : TBox; out Res : TPointArray);extdecl;
begin
Res := TPAFromBox(Box);
end;
procedure RotatePointsWrap(Const P: TPointArray; A, cx, cy: Extended; out Res : TPointArray);extdecl;
begin
Res := RotatePoints(P,a,cx,cy);
end;
procedure FindTPAEdgesWrap(p: TPointArray; out Res : TPointArray);extdecl;
begin
Res := FindTPAEdges(p);
end;
procedure ClearTPAFromTPAWrap(arP, ClearPoints: TPointArray; out Res : TPointArray);extdecl;
begin
Res := ClearTPAFromTPA(arP, clearpoints);
end;
procedure ReturnPointsNotInTPAWrap(Const TotalTPA: TPointArray; const Box: TBox; out Res : TPointArray);extdecl;
begin
Res := ReturnPointsNotInTPA(TotalTPA,box);
end;

View File

@ -274,10 +274,6 @@ AddFunction(@RAaSTPAEx,'procedure RAaSTPAEx(var a: TPointArray; const w, h: Inte
AddFunction(@RAaSTPA,'procedure RAaSTPA(var a: TPointArray; const Dist: Integer);');
AddFunction(@NearbyPointInArrayEx,'function NearbyPointInArrayEx(const P: TPoint; w, h:Integer; a: TPointArray): Boolean;');
AddFunction(@NearbyPointInArray,'function NearbyPointInArray(const P: TPoint; Dist:Integer; a: TPointArray): Boolean;');
AddFunction(@ReArrangeandShortenArrayEx,'function ReArrangeandShortenArrayEx(a: TPointArray; w, h: Integer): TPointArray;');
AddFunction(@ReArrangeandShortenArray,'function ReArrangeandShortenArray(a: TPointArray; Dist: Integer): TPointArray;');
AddFunction(@TPAtoATPAEx,'function TPAtoATPAEx(TPA: TPointArray; w, h: Integer): T2DPointArray;');
AddFunction(@TPAtoATPA,'function TPAtoATPA(TPA: TPointArray; Dist: Integer): T2DPointArray;');
AddFunction(@QuickTPASort,'procedure QuickTPASort(var A: TIntegerArray; var B: TPointArray; iLo, iHi: Integer; SortUp: Boolean);');
AddFunction(@QuickATPASort,'procedure QuickATPASort(var A: TIntegerArray; var B: T2DPointArray; iLo, iHi: Integer; SortUp: Boolean);');
AddFunction(@SortTPAFrom,'procedure SortTPAFrom(var a: TPointArray; const From: TPoint);');
@ -289,8 +285,6 @@ AddFunction(@MiddleTPAEx,'function MiddleTPAEx(TPA: TPointArray; var x, y: Integ
AddFunction(@MiddleTPA,'function MiddleTPA(tpa: TPointArray): TPoint;');
AddFunction(@SortATPASize,'procedure SortATPASize(var a: T2DPointArray; const BigFirst: Boolean);');
AddFunction(@SortATPAFromSize,'procedure SortATPAFromSize(var a: T2DPointArray; const Size: Integer; CloseFirst: Boolean);');
AddFunction(@CombineTPA,'function CombineTPA(Ar1, Ar2: TPointArray): TPointArray;');
AddFunction(@CombineIntArray,'function CombineIntArray(Ar1, Ar2: TIntegerArray): TIntegerArray;');
AddFunction(@InIntArrayEx,'function InIntArrayEx(a: TIntegerArray; var Where: Integer; const Number: Integer): Boolean;');
AddFunction(@InIntArray,'function InIntArray(a: TIntegerArray; Number: Integer): Boolean;');
AddFunction(@ClearSameIntegers,'procedure ClearSameIntegers(var a: TIntegerArray);');
@ -298,26 +292,48 @@ AddFunction(@ClearSameIntegersAndTPA,'procedure ClearSameIntegersAndTPA(var a: T
AddFunction(@SplitTPAEx,'function SplitTPAEx(arr: TPointArray; w, h: Integer): T2DPointArray;');
AddFunction(@SplitTPA,'function SplitTPA(arr: TPointArray; Dist: Integer): T2DPointArray;');
AddFunction(@FilterPointsPie,'procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);');
AddFunction(@RemoveDistTPointArray,'function RemoveDistTPointArray(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;');
AddFunction(@GetATPABounds,'function GetATPABounds(ATPA: T2DPointArray): TBox;');
AddFunction(@GetTPABounds,'function GetTPABounds(TPA: TPointArray): TBox;');
AddFunction(@FindTPAinTPA,'function FindTPAinTPA(SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;');
AddFunction(@FindTextTPAinTPA,'function FindTextTPAinTPA(Height : integer; SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;');
AddFunction(@FindGapsTPA,'function FindGapsTPA(TPA: TPointArray; MinPixels: Integer): T2DPointArray;');
AddFunction(@SortCircleWise,'procedure SortCircleWise(var tpa: TPointArray; const cx, cy, StartDegree: Integer; SortUp, ClockWise: Boolean);');
AddFunction(@LinearSort,'procedure LinearSort(var tpa: TPointArray; cx, cy, sd: Integer; SortUp: Boolean);');
AddFunction(@RotatePoint,'Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;');
AddFunction(@FindGapsTPA,'function FindGapsTPA(TPA: TPointArray; MinPixels: Integer): T2DPointArray;');
AddFunction(@RemoveDistTPointArray,'function RemoveDistTPointArray(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;');
AddFunction(@CombineTPA,'function CombineTPA(Ar1, Ar2: TPointArray): TPointArray;');
AddFunction(@ReArrangeandShortenArrayEx,'function ReArrangeandShortenArrayEx(a: TPointArray; w, h: Integer): TPointArray;');
AddFunction(@ReArrangeandShortenArray,'function ReArrangeandShortenArray(a: TPointArray; Dist: Integer): TPointArray;');
AddFunction(@TPAtoATPAEx,'function TPAtoATPAEx(TPA: TPointArray; w, h: Integer): T2DPointArray;');
AddFunction(@TPAtoATPA,'function TPAtoATPA(TPA: TPointArray; Dist: Integer): T2DPointArray;');
AddFunction(@CombineIntArray,'function CombineIntArray(Ar1, Ar2: TIntegerArray): TIntegerArray;');
AddFunction(@MergeATPA,'Function MergeATPA(ATPA : T2DPointArray) : TPointArray;');
AddFunction(@TPAFromBox,'function TPAFromBox(const Box : TBox) : TPointArray;');
AddFunction(@RotatePoints,'Function RotatePoints(Const P: TPointArray; A, cx, cy: Extended): TPointArray ;');
AddFunction(@RotatePoint,'Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;');
AddFunction(@FindTPAEdges,'function FindTPAEdges(p: TPointArray): TPointArray;');
AddFunction(@PointInTPA,'function PointInTPA(p: TPoint; arP: TPointArray): Boolean;');
AddFunction(@ClearTPAFromTPA,'function ClearTPAFromTPA(arP, ClearPoints: TPointArray): TPointArray;');
AddFunction(@ClearDoubleTPA,'procedure ClearDoubleTPA(var TPA: TPointArray);');
AddFunction(@ReturnPointsNotInTPA,'Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; const Box: TBox): TPointArray;');
AddFunction(@PointInTPA,'function PointInTPA(p: TPoint; arP: TPointArray): Boolean;');
AddFunction(@ClearDoubleTPA,'procedure ClearDoubleTPA(var TPA: TPointArray);');
AddFunction(@TPACountSort,'Procedure TPACountSort(Var TPA: TPointArray;const max: TPoint;Const SortOnX : Boolean);');
AddFunction(@TPACountSortBase,'Procedure TPACountSortBase(Var TPA: TPointArray;const maxx, base: TPoint; const SortOnX : Boolean);');
AddFunction(@InvertTIA,'procedure InvertTIA(var tI: TIntegerArray);');
AddFunction(@SumIntegerArray,'function SumIntegerArray(Ints : TIntegerArray): Integer;');
AddFunction(@AverageTIA,'function AverageTIA(tI: TIntegerArray): Integer;');
AddFunction(@AverageExtended,'function AverageExtended(tE: TExtendedArray): Extended;');
AddFunction(@SplitTPAExWrap,'procedure SplitTPAExWrap(arr: TPointArray; w, h: Integer; out res : T2DPointArray);');
AddFunction(@SplitTPAWrap,'procedure SplitTPAWrap(arr: TPointArray; Dist: Integer; out res: T2DPointArray);');
AddFunction(@FindGapsTPAWrap,'procedure FindGapsTPAWrap(TPA: TPointArray; MinPixels: Integer; out Res : T2DPointArray);');
AddFunction(@RemoveDistTPointArrayWrap,'procedure RemoveDistTPointArrayWrap(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean; out Res : TPointArray);');
AddFunction(@CombineTPAWrap,'procedure CombineTPAWrap(Ar1, Ar2: TPointArray; out Res : TPointArray);');
AddFunction(@ReArrangeandShortenArrayExWrap,'procedure ReArrangeandShortenArrayExWrap(a: TPointArray; w, h: Integer; out Res : TPointArray);');
AddFunction(@ReArrangeandShortenArrayWrap,'procedure ReArrangeandShortenArrayWrap(a: TPointArray; Dist: Integer; out Res : TPointArray);');
AddFunction(@TPAtoATPAExWrap,'procedure TPAtoATPAExWrap(TPA: TPointArray; w, h: Integer; out Res : T2DPointArray);');
AddFunction(@TPAtoATPAWrap,'procedure TPAtoATPAWrap(TPA: TPointArray; Dist: Integer; out Res : T2DPointArray);');
AddFunction(@CombineIntArrayWrap, 'procedure CombineIntArrayWrap(Ar1, Ar2: TIntegerArray; out Res : TIntegerArray);');
AddFunction(@ReturnPointsNotInTPAWrap,'procedure ReturnPointsNotInTPAWrap(Const TotalTPA: TPointArray; const Box: TBox; out Res : TPointArray);');
AddFunction(@MergeATPAWrap,'procedure MergeATPAWrap(ATPA : T2DPointArray; out Res: TPointArray);');
AddFunction(@TPAFromBoxWrap,'procedure TPAFromBoxWrap(const Box : TBox; out Res : TPointArray);');
AddFunction(@RotatePointsWrap,'procedure RotatePointsWrap(Const P: TPointArray; A, cx, cy: Extended; out Res : TPointArray);');
AddFunction(@FindTPAEdgesWrap,'procedure FindTPAEdgesWrap(p: TPointArray; out Res : TPointArray);');
AddFunction(@ClearTPAFromTPAWrap,'procedure ClearTPAFromTPAWrap(arP, ClearPoints: TPointArray; out Res : TPointArray);');

View File

@ -390,6 +390,7 @@ end;
{$I PSInc/Wrappers/other.inc}
{$I PSInc/Wrappers/bitmap.inc}
{$I PSInc/Wrappers/window.inc}
{$I PSInc/Wrappers/tpa.inc}
{$I PSInc/Wrappers/strings.inc}
{$I PSInc/Wrappers/colour.inc}
{$I PSInc/Wrappers/math.inc}

View File

@ -1930,9 +1930,9 @@ begin
end;
// Get the area we should search in for the Main Point.
//writeln(Format('%d, %d, %d, %d', [x1,y1,x2,y2]));
// writeln(Format('%d, %d, %d, %d', [x1,y1,x2,y2]));
MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
//writeln(Format('%d, %d, %d, %d', [MA.x1,MA.y1,MA.x2,MA.y2]));
// writeln(Format('%d, %d, %d, %d', [MA.x1,MA.y1,MA.x2,MA.y2]));
DefaultOperations(MA.x1, MA.y1, MA.x2, MA.y2);
@ -1943,15 +1943,15 @@ begin
// Init data structure B.
W := x2 - x1;
H := y2 - y1;
setlength(b, (W + 1) * 2);
setlength(b, (W + 1));
for i := 0 to W do
begin
setlength(b[i], (H + 1) * 2);
setlength(b[i], (H + 1));
{ does setlength init already? if it doesn't, do we want to init here?
or do we want to init in the loop, as we loop over every b anyway? }
// init
FillChar(b[i][0], SizeOf(Integer) * H * 2, 0);
FillChar(b[i][0], SizeOf(Integer) * (H+1), 0);
end;
// C = DTM.C
@ -1967,14 +1967,12 @@ begin
SetLength(rgbs, dtm.l);
for i := 0 to dtm.l - 1 do
ColorToRGB(dtm.c[i], rgbs[i].r, rgbs[i].g, rgbs[i].b);
for yy := MA.y1 to MA.y2 do
for xx := MA.x1 to MA.x2 do
for yy := MA.y1 -y1 to MA.y2 - y1 do
for xx := MA.x1 -x1 to MA.x2 - x1 do
begin
// Checking main point now; store that we have checked it.
// (Main point is point 1)
b[xx][yy] := B[xx][yy] or 1;
// if Sqrt(sqr(rgbs[0].r - cd[yy][xx].R) + sqr(rgbs[0].g - cd[yy][xx].G) + sqr(rgbs[0].b - cd[yy][xx].B)) > dtm.t[0] then
if not SimilarColors(dtm.c[0], RGBToColor(cd[yy][xx].R, cd[yy][xx].G, cd[yy][xx].B), dtm.t[0]) then
goto AnotherLoopEnd;
@ -2006,7 +2004,7 @@ begin
end;
end;
//writeln(Format('Found point: (%d, %d)', [xx,yy]));
ClientTPA[pc] := Point(xx, yy);
ClientTPA[pc] := Point(xx + x1, yy + y1);
Inc(pc);
if(pc = maxToFind) then
goto theEnd;

View File

@ -202,7 +202,7 @@ const
flnC=545947;
fsqrtA:single=0.5;
{$ASMMODE INTEL}
{{$ASMMODE INTEL}
function fsqrt(x: Single): Single;
begin
asm
@ -213,7 +213,8 @@ begin
add dword ptr x,($3F800000-flnC)
fld x
end;
end;
end; }
procedure tSwap(var a, b: TPoint);
var
@ -280,10 +281,11 @@ var
begin
NoTP := 0;
l := High(a);
Writeln('wat');
for i := 0 to l do
begin
for c := 0 to NoTP - 1 do
if (Round(fSqrt(Sqr(a[i].x - a[c].x) + Sqr(a[i].y - a[c].y))) <= Dist) then
if (Round(sqrt(Sqr(a[i].x - a[c].x) + Sqr(a[i].y - a[c].y))) <= Dist) then
Break;
if (c >= NoTP) then
begin
@ -325,7 +327,7 @@ begin
Result := False;
l := High(a);
for i := 0 to l do
if (Round(fSqrt(Sqr(P.x - a[i].x) + Sqr(P.y - a[i].y))) <= Dist) then
if (Round(sqrt(Sqr(P.x - a[i].x) + Sqr(P.y - a[i].y))) <= Dist) then
begin
Result := True;
Exit;
@ -371,7 +373,7 @@ begin
for i := 0 to l do
begin
for t := 0 to c -1 do
if (Round(fSqrt(Sqr(Result[t].x - a[i].x) + Sqr(Result[t].y - a[i].y))) <= Dist) then
if (Round(sqrt(Sqr(Result[t].x - a[i].x) + Sqr(Result[t].y - a[i].y))) <= Dist) then
Break;
if (t >= c) then
begin
@ -426,7 +428,7 @@ begin
for a := 0 to l do
begin
for b := 0 to c -1 do
if (Round(fSqrt(Sqr(TPA[a].X - Result[b][0].X) + Sqr(TPA[a].Y - Result[b][0].Y))) <= Dist) then
if (Round(sqrt(Sqr(TPA[a].X - Result[b][0].X) + Sqr(TPA[a].Y - Result[b][0].Y))) <= Dist) then
Break;
if (b < c) then
begin
@ -654,11 +656,14 @@ var
i, l: Integer;
SizeArr: TIntegerArray;
begin
Writeln('yo man!');
l := High(a);
Writeln(inttostr(l));
if (l < 0) then Exit;
SetLength(SizeArr, l + 1);
for i := 0 to l do
SizeArr[i] := Length(a[i]);
Writeln('Yo');
QuickATPASort(SizeArr, a, 0, l, not BigFirst);
end;
@ -878,7 +883,7 @@ begin
t2 := 0;
while (t2 <= (l - ec)) do
begin
if (Round(fSqrt(Sqr(Result[c][t1].x - tpa[t2].x) + Sqr(Result[c][t1].y - tpa[t2].y))) <= Dist) then
if (Round(sqrt(Sqr(Result[c][t1].x - tpa[t2].x) + Sqr(Result[c][t1].y - tpa[t2].y))) <= Dist) then
begin
SetLength(Result[c], tc +1);
Result[c][tc] := tpa[t2];
@ -930,7 +935,7 @@ begin
SwapE(StartD, EndD);
for I := 0 to T do
begin
D := fSqrt(Sqr(Points[I].X - Mx) + Sqr(Points[I].Y - My));
D := sqrt(Sqr(Points[I].X - Mx) + Sqr(Points[I].Y - My));
if( D <= MinR) or (D >= MaxR) then
Continue;
D := (ArcTan2(Points[I].Y - My, Points[I].X - Mx) * i180Pi) + 90;
@ -959,7 +964,7 @@ begin;
if RemoveHigher then
begin;
for I := 0 to LL do
if not (Round(fSqrt(sqr(ThePoints[i].x - x)+sqr(ThePoints[i].y - y))) > Dist) then
if not (Round(sqrt(sqr(ThePoints[i].x - x)+sqr(ThePoints[i].y - y))) > Dist) then
begin;
Result[L] := ThePoints[i];
L := L + 1;
@ -967,7 +972,7 @@ begin;
end else
begin;
for I := 0 to LL do
if not (Round(fSqrt(sqr(ThePoints[i].x - x)+sqr(ThePoints[i].y - y))) < Dist) then
if not (Round(sqrt(sqr(ThePoints[i].x - x)+sqr(ThePoints[i].y - y))) < Dist) then
begin;
Result[L] := ThePoints[i];
L := L + 1;