PDA

View Full Version : Some small TPA stuff...



n3ss3s
01-07-2008, 05:17 PM
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;

Dumpin
01-07-2008, 06:54 PM
Anyother great function of n3ss3s :) when you get devolper? :D

n3ss3s
01-07-2008, 07:25 PM
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...

Killerdou
01-07-2008, 07:26 PM
this can be done way faster(and without having to give the box paramaters)

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;

n3ss3s
01-07-2008, 07:29 PM
Yes, ofcourse with your functions lol, I didn't make any separate functions for it :) And I wanted to do it that way :p :p :p Thanks...

Killerdou
01-07-2008, 07:35 PM
ah ok:), but it actually uses one of raymonds functions;)

// from the tpointarray functions from mastaraymond
Function TPointArrayToIntegerArray(ThePoints:TPointArray;Re turnX: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:)

n3ss3s
01-08-2008, 02:10 PM
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?

R0b0t1
01-08-2008, 11:53 PM
I need to start thinking inside the box...

n3ss3s
01-09-2008, 05:47 AM
I need to start thinking inside the box...

okay mhmm... what?

bullzeye95
01-09-2008, 06:15 AM
this can be done way faster(and without having to give the box paramaters)

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 :p), 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 :p

Killerdou
01-09-2008, 06:39 AM
it will result an extended, but if bubblesort is slow, its freddy's fault;)

bullzeye95
01-09-2008, 07:00 AM
Well, I meant that, compared to other methods and other sorting algorithms, it's very slow.

n3ss3s
01-09-2008, 10:53 AM
Also Killerdou, you went off the purpose, the purpose wasn't to get the density of the TPA on the area of the TPA :p

R0b0t1
01-12-2008, 05:33 AM
When a floating point is casted to an integer, the decimal is removed completely... But Delphi doesn't let you do that.

n3ss3s
01-12-2008, 11:28 AM
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?