Results 1 to 13 of 13

Thread: SortTPADist

  1. #1
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default SortTPADist

    Sorts TPA by it's Distance from (Cx, Cy). It's got a wide range of uses, I developed this with the intention of finding the closest rock to your RS character but I've envisioned many more possibilities, and I'm sure the great minds of SRL will think of even more!

    SCAR Code:
    procedure SortTPADist(var TPA: TPointArray; Cx, Cy: Integer);
    var
      ID: TPointArray;
      i, ArrL: Byte;
    begin
      ArrL:= GetArrayLength(TPA);
      SetArrayLength(ID, ArrL);
      for i:= 0 to ArrL - 1 do
      begin
        ID[i].x:= Distance(Cx, Cy, TPA[i].x, TPA[i].y);
        ID[i].y:= i;
      end;
      ID:= RearrangeTPA(ID, 0, ArrL, True, False);
      for i:= 0 to ArrL - 1 do TPA[i]:= TPA[ID[ArrL - 1 - i].y];
    end;

    From what I've seen there isn't anything like it... there are things that are similar but nothing I've found can do this. Although, I'm pretty unobservant so who knows
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Uhm, it doesn't seem to work for me =/

    So... I got bored and made one with quicksort, if you want to look at that.
    SCAR Code:
    procedure QuickSortTPADist(var A: TPointArray; cx, cy, iLo, iHi: Integer);
    var
      Lo, Hi, Pivot, N: Integer;
      T: TPoint;
    begin
      Lo := iLo;
      Hi := iHi;
      N:= (Lo + Hi) div 2;
      Pivot := Distance(cx, cy, A[N].x, A[N].y);
      repeat
        while Distance(cx, cy, A[Lo].x, A[Lo].y) < Pivot do Inc(Lo);
        while Distance(cx, cy, A[Hi].x, A[Hi].y) > Pivot do Dec(Hi);
        if Lo <= Hi then
        begin
          T := A[Lo];
          A[Lo] := A[Hi];
          A[Hi] := T;
          Inc(Lo);
          Dec(Hi);
        end;
      until Lo > Hi;
      if Hi > iLo then QuickSortTPADist(A, cx, cy, iLo, Hi) ;
      if Lo < iHi then QuickSortTPADist(A, cx, cy, Lo, iHi) ;
    end;
    (not a planned hijack, I just can't stand to leave things nonfunctional )

  3. #3
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    SortTPAFrom...?
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    WizzyPlugin's End User "from" sorting functions:

    // * procedure SortTPAFrom(var a: TPointArray; const From: TPoint);
    // * procedure SortATPAFrom(var a: T2DPointArray; const From: TPoint);
    // * procedure SortATPAFromFirstPoint(var a: T2DPointArray; const From: TPoint);
    Yes, it has a wide range of uses, the better something sounds the more likely it's already made =]

  5. #5
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    WizzyPlugin's End User "from" sorting functions:



    Yes, it has a wide range of uses, the better something sounds the more likely it's already made =]
    I knew it sounded really familiar... but I just assumed that since he made it, that it must just be in one of the other few plugins I've managed to get my hands on.

  6. #6
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ahh... I had looked through wizzups plugin and hadn't seen those. Like I said, I tend to miss things

    I would like to know though, why wasn't it working for you bullzeye? What did it return?
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  7. #7
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    It seemed that it didn't sort it at all.

  8. #8
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    It seemed that it didn't sort it at all.
    Hmmm... works / worked fine for me... Lemme test it again.

    EDIT: Huh... weird... It doesn't work for me either now. I know it was working fine yesterday because I was testing in on rocks. Anything you see that is wrong?
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  9. #9
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Well, I see that RearrangeTPA is a function that RETURNS a new TPA, instead of EDITING the passed TPA =]

  10. #10
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    I'm weird that way

  11. #11
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ahhh... When I tested it the rocks must've just been found in the correct order so my procedure did nothing... but it looked like it did. Thanks for the fix! Jeeze Boreas you made it like that on purpose didn't you? Just to throw me off
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  12. #12
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Quote Originally Posted by Special Ed View Post
    Ahhh... When I tested it the rocks must've just been found in the correct order so my procedure did nothing... but it looked like it did. Thanks for the fix! Jeeze Boreas you made it like that on purpose didn't you? Just to throw me off
    I don't doubt a bit that you didn't use FindColorsSpiralTolerance =D

  13. #13
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It wasn't using FindColorsSpiralTolerance. I was using Benlands "FindRock" procedure. Which for some reason will return doubles of some rocks and doesn't always return the rocks in order of distance. Although it may be because the colors need updating... regardless it was still needed.
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

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
  •