Results 1 to 7 of 7

Thread: Symbol.scar FindClosestSymbol(...);

  1. #1
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default Symbol.scar FindClosestSymbol(...);

    Thought it might be useful. Pretty simple but I figured I would post.

    SCAR Code:
    {*******************************************************************************
    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    By: NCDS & Naum
    Description: Finds closest symbol defined by 'Name'. Returns true if found.
    Returns x and y coord for closest symbol.
    *******************************************************************************}

    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        x := Arr[High(Arr) * Integer(Not Closest)].x;
        y := Arr[High(Arr) * Integer(Not Closest)].y;
      end;
    end;

    Thoughts?
    Last edited by NCDS; 02-26-2010 at 11:07 PM.

  2. #2
    Join Date
    Feb 2010
    Location
    England
    Posts
    56
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    var
      Arr: array of TPoint;

    any reason for not using TPointArray?

    other than that, very nice, would be good for a few scripts I'm working on

    void_hatred

  3. #3
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by void_hatred View Post
    SCAR Code:
    var
      Arr: array of TPoint;

    any reason for not using TPointArray?

    other than that, very nice, would be good for a few scripts I'm working on

    void_hatred
    I've just declared them like that for a long time. I think it looks better honestly.

    Not anything that's hard to change though if it is a problem.

  4. #4
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    {*******************************************************************************
    function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
    By: NCDS
    Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
    Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
    Returns x and y coord for closest symbol.
    *******************************************************************************}

    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      I; integer
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        case Closest of
          true: I := Low(Arr);
          false: I := High(Arr);
        end;
        x := Arr[I].x;
        y := Arr[I].y;
      end;
    end;

    Would be more useful imo
    Good idea though
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by bionicle1800 View Post
    SCAR Code:
    {*******************************************************************************
    function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
    By: NCDS
    Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
    Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
    Returns x and y coord for closest symbol.
    *******************************************************************************}

    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      I; integer
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        case Closest of
          true: I := Low(Arr);
          false: I := High(Arr);
        end;
        x := Arr[I].x;
        y := Arr[I].y;
      end;
    end;

    Would be more useful imo
    Good idea though
    You could do that. if..then..else is quicker than case statements though generally so:
    SCAR Code:
    {*******************************************************************************
    function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
    By: NCDS
    Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
    Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
    Returns x and y coord for closest symbol.
    *******************************************************************************}

    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      I; integer
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        if Closest then
          I := 0
        else
          I := High(Arr);
        x := Arr[I].x;
        y := Arr[I].y;
      end;
    end;
    would be the way to go if you wanted to do that.

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

    Default

    Meh:

    SCAR Code:
    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        x := Arr[High(Arr) * Integer(Not Closest)].x;
        y := Arr[High(Arr) * Integer(Not Closest)].y;
      end;
    end;

  7. #7
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Naum View Post
    Meh:

    SCAR Code:
    function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
    var
      Arr: array of TPoint;
    begin
      Result :=  FindSymbols(Arr, Name);
      if Result then
      begin
        SortTPAFrom(Arr, Point(MMCx, MMCy));
        x := Arr[High(Arr) * Integer(Not Closest)].x;
        y := Arr[High(Arr) * Integer(Not Closest)].y;
      end;
    end;
    Didn't even think of that, I like it though

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
  •