SRL Archive - SRL Archives

FindSymbolsIn Fix


Bad Boy JH

2010-02-03 01:02:35

Through some clever working, myself and frement both figured out that PointInTPA is the issue, so i created a replacement functoin IsPointInTPA, which if I understand PointInTPA, should do the same thing…


Function IsPointInTPA(Point:TPoint; TPA:TPointArray):Boolean;
var I:integer;
begin
for i := 0 to high(TPA)-1 do
begin
if (TPA[i].x = Point.x) and (TPA[i].x = Point.y) then
begin
Result:= True
Exit;
end;
end;
Result := False
end;

and FindSymbolsIn also needs to be slightly modified…

{*******************************************************************************
function FindSymbolsIn(var AnsTPA: TPointArray; SymbolName: string; x1, y1, x2, y2: integer): Boolean;
By: lordsaturn
Description: Finds a symbol in multiple places within the search coords. Results
true if at least 1 symbol is found.
*******************************************************************************}
function FindSymbolsIn(var AnsTPA: TPointArray; SymbolName: string; x1, y1, x2, y2: integer): Boolean;
var
CTS, Col, Hi, i, x, y, fx, fy, L: integer;
aP: T2DPointArray;
P: TPointArray;
Pt: TPoint;
acc: Extended;
begin
Col := GetSymbolColorIn(fx, fy, SymbolName, x1, y1, x2, y2);
if Col = 0 then
Exit;
FindColorsTolerance(P, Col, x1, y1, x2, y2, 0);
aP := TPAtoATPA(P, 10);
Hi := High(aP);
LoadSymbolBitmapColor(LowerCase(SymbolName));
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
SetLength(AnsTPA, Hi+1);
for i := 0 to Hi do
begin
Pt := MiddleTPA(aP[i]);
if IsPointInTPA(Point(fx, fy), aP[i]) then
acc := 1
else
FindDeformedBitmapToleranceIn(SymbolBitmap, x, y, Pt.x-15, Pt.y-5, Pt.x+15, Pt.y+5, 70, 0, True, acc);
if (acc > SymbolAccuracy) then
begin
AnsTPA[L] := Pt;
Inc(L);
end;
end;
Result := L > 0;
SetLength(AnsTPA, L);
try
FreeBitmap(SymbolBitmap);
finally
ColorToleranceSpeed(CTS);
end;
end;

I just changed
if PointInTPA(Point(fx, fy), aP) then
to
if IsPointInTPA(Point(fx, fy), aP) then
which should fix the issue

Frement

2010-02-03 01:04:56

The problem was that scar kept crashing while executing FindSymbolsIn function.

marpis

2010-02-03 03:07:29

Oh THAT'S why my autocoloring crashes SCAR all the time yesterday!
btw:

function IsPointInTPA(P: TPoint; TPA: TPointArray): boolean;
var
I, H: Integer;
begin
Result := True;
H := High(TPA);
for I := 0 to H do
if (P.X = TPA[I].X) then
if (P.Y = TPA[I].Y) then
Exit;
Result := False;
end;

EDIT: Holy cow, you fixed it! :) Committing now…
EDIT: Oh, has it been already committed or is my SVN fooling around with me?

mixster

2010-02-03 08:42:25

If you wanted a faster method, you could sort the TPA from the point you're trying to find then only compare the first point - as SortTPA is in WizzyPlugin it should be a lot faster than a Scar version of manual point checking.

Naum

2010-02-04 15:53:33

Yet no one notices that this line:

if (TPA[i].x = Point.x) and (TPA[i].x = Point.y) then

should be

if (TPA[i].x = Point.x) and (TPA[i].y = Point.y) then
.

Frement

2010-02-06 01:07:38

From: Naum
Yet no one notices that this line:

if (TPA[i].x = Point.x) and (TPA[i].x = Point.y) then

should be

if (TPA[i].x = Point.x) and (TPA[i].y = Point.y) then
.


Whats the difference?

i luffs yeww

2010-02-06 01:22:32

From: Frement
Whats the difference?



if (TPA[i].x = Point.x) and (TPA[i].x = Point.y) then

if (TPA[i].x = Point.x) and (TPA[i].y = Point.y) then

TPA.x = Point.x and TPA.x = Point.y

the second TPA.x should be TPA.y ;)

Frement

2010-02-06 01:25:49

Haha, yeah now i see it! :D