Results 1 to 15 of 15

Thread: Some small TPA stuff...

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

    Default Some small TPA stuff...

    SCAR Code:
    Function DensityTPA(TPA: TPointArray; x1, y1, x2, y2: Integer; Percent: Boolean): Extended;
    Begin
      TB := IntToBox(x1, y1, x2, y2);
      L := High(TPA);
      For I := 0 To L Do
        If PointInBox(TPA[i], TB) Then
          M := M + 1;
      AW := x2 - x1;
      AH := y2 - y1;
      Pixels := (AW + 1) * (AH + 1);
      Result := M / Pixels;
      If Percent Then
        Result := Result * 100;
    End;


    Function ColorDensityAt(Var TPA: TPointArray; Color, Tolerance, x1, y1, x2,
     y2: Integer; Percent: Boolean): Extended;
    Begin
      FindColorsTolerance(TPA, Color, x1, y1, x2, y2, Tolerance);
      Result := DensityTPA(TPA, x1, y1, x2, y2, Percent);
    End;

  2. #2
    Join Date
    Jun 2007
    Posts
    785
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Anyother great function of n3ss3s when you get devolper?

    [22:20] <[-jesus-]> freddy, go uninstall yourself

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

    Default

    Lol, thanks, the more people say that the more I'm starting to have 'hope', even though I kinda feel/know it ain't gonna be very soon somewhy...

  4. #4
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    this can be done way faster(and without having to give the box paramaters)
    SCAR Code:
    Function Density(A : TPointArray) : Extended;
      var
        B, C : Array of Integer;
        D, E : Integer;
      Begin
        B := TPointArrayToIntegerArray(A, True);
        C := TPointArrayToIntegerArray(A, False);
        BubbleSort(B);
        BubbleSort(C);
        D := GetArrayLength(A);
        E := (B[D - 1] - B[0] + 1)*(C[D - 1] - C[0] + 1)
        Result := 1 / (E / D);
      end;
    Infractions, reputation, reflection, the dark side of scripting, they are.

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

    Default

    Yes, ofcourse with your functions lol, I didn't make any separate functions for it And I wanted to do it that way Thanks...

  6. #6
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    ah ok, but it actually uses one of raymonds functions
    SCAR Code:
    // from the tpointarray functions from mastaraymond
    Function TPointArrayToIntegerArray(ThePoints:TPointArray;ReturnX:Boolean): TIntegerArray;
    var
      I:integer;
    begin;
      Try
      SetArrayLength(Result,Length(ThePoints));
      For I:= 0  to Length(ThePoints)-1 do
        If ReturnX then Result[I]:=ThePoints[I].x
        else Result[I]:=ThePoints[I].y;
      Except
      Writeln('There is an error, sorry!');
      end;
    end;
    ow and good job btw
    Infractions, reputation, reflection, the dark side of scripting, they are.

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

    Default

    Oh, okay, but I very rarely use other people's code, (I mean code like that which isn't in SRL etc)

    Thanks anyway, would save me a for loop.

    EDIT: and time?

  8. #8
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    I need to start thinking inside the box...
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

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

    Default

    I need to start thinking inside the box...
    okay mhmm... what?

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

    Default

    Quote Originally Posted by Killerdou View Post
    this can be done way faster(and without having to give the box paramaters)
    SCAR Code:
    Function Density(A : TPointArray) : Extended;
      var
        B, C : Array of Integer;
        D, E : Integer;
      Begin
        B := TPointArrayToIntegerArray(A, True);
        C := TPointArrayToIntegerArray(A, False);
        BubbleSort(B);
        BubbleSort(C);
        D := GetArrayLength(A);
        E := (B[D - 1] - B[0] + 1)*(C[D - 1] - C[0] + 1)
        Result := 1 / (E / D);
      end;
    You have Result := 1 / (E / D);. When working with integers like that, isn't the quotient ceil'd (whatever I should call it ), or floored? So I don't think it would return a float.
    Also, if you used Ray's GetTPABounds, that could be faster. BubbleSort is WAY slow. Sorry, I'm a critic of everything

  11. #11
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    it will result an extended, but if bubblesort is slow, its freddy's fault
    Infractions, reputation, reflection, the dark side of scripting, they are.

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

    Default

    Well, I meant that, compared to other methods and other sorting algorithms, it's very slow.

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

    Default

    Also Killerdou, you went off the purpose, the purpose wasn't to get the density of the TPA on the area of the TPA

  14. #14
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    When a floating point is casted to an integer, the decimal is removed completely... But Delphi doesn't let you do that.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

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

    Default

    When a floating point is casted to an integer, the decimal is removed completely... But Delphi doesn't let you do that.
    What's that got to do with anything?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help (only small)
    By poolikemax in forum OSR Help
    Replies: 5
    Last Post: 08-27-2008, 10:09 AM
  2. Small Help.
    By faster789 in forum OSR Help
    Replies: 11
    Last Post: 04-19-2008, 02:52 PM

Posting Permissions

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