Results 1 to 8 of 8

Thread: FindSymbolsIn Fix

  1. #1
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default FindSymbolsIn Fix

    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...

    SCAR Code:
    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...
    SCAR Code:
    {*******************************************************************************
    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[i]) then
    to
    if IsPointInTPA(Point(fx, fy), aP[i]) then
    which should fix the issue
    Last edited by Bebe; 02-03-2010 at 03:23 PM.

  2. #2
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    The problem was that scar kept crashing while executing FindSymbolsIn function.
    There used to be something meaningful here.

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Oh THAT'S why my autocoloring crashes SCAR all the time yesterday!
    btw:
    SCAR Code:
    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?
    Last edited by marpis; 02-03-2010 at 08:18 AM.

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  5. #5
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Yet no one notices that this line:

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

    should be

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

  6. #6
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Naum View Post
    Yet no one notices that this line:

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

    should be

    SCAR Code:
    if (TPA[i].x = Point.x) and (TPA[i].y = Point.y) then
    .
    Whats the difference?
    There used to be something meaningful here.

  7. #7
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    Whats the difference?
    SCAR Code:
    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[i].x = Point.x and TPA[i].x = Point.y

    the second TPA[i].x should be TPA[i].y

  8. #8
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Haha, yeah now i see it!
    There used to be something meaningful here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •