SRL Archive - SRL Suggestions

Some TPA and ATPA functions


Sabzi

2009-08-31 14:46:35


type
TPAEx = record
Width, Height, AreaSize, Radius, Length: Integer;
MidPoint: TPoint;
end;

function GetTPAEx(var TPA: TPointArray): TPAEx;

var
B: TBox;
x, y, L: Integer;
T: TPoint;

begin
B := GetTPABounds(TPA);
MiddleTPAEx(TPA, x, y);
SortTPAFrom(TPA, Point(x, y));
T := TPA[High(TPA)];
L := Length(TPA);
with Result do
begin
Width := B.x2 - B.x1;
Height := B.y2 - B.y1;
AreaSize := Result.Width * Result.Height;
Radius := Distance(x, y, T.x, T.y);
Midpoint := Point(x, y);
Length := L;
end;
end;

function FilterATPABy(by: string; var ATPA: T2DPointArray; Length, AreaSize, Width, Height, Radius: TIntegerArray): T2DPointArray;

var
H, I, O: Integer;
TE: array of TPAEx;

begin
H := High(ATPA);
SetArrayLength(TE, H + 1);
for I := 0 to H do
TE[I] := GetTPAEx(ATPA[I]);
case Lowercase(by) of
'length':
begin
for I := 0 to H do
begin
if ((TE[I].Length < Length[0]) or (TE[I].Length > Length[1])) then Continue;
SetLength(Result, O + 1);
Result[O] := ATPA[I];
Inc(O);
end;
end;
'wandh':
begin
for I := 0 to H do
begin
if ((TE[I].Width < Width[0]) or (TE[I].Width > Width[1]) or (TE[I].Height < Height[0]) or (TE[I].Height > Height[1])) then Continue;
SetLength(Result, O + 1);
Result[O] := ATPA[I];
Inc(O);
end;
end;
'areasize':
begin
for I := 0 to H do
begin
if ((TE[I].AreaSize < AreaSize[0]) or (TE[I].AreaSize > AreaSize[1])) then Continue;
SetLength(Result, O + 1);
Result[O] := ATPA[I];
Inc(O);
end;
end;
'radius':
begin
for I := 0 to H do
begin
if ((TE[I].Radius < Radius[0]) or (TE[I].Radius > Radius[1])) then Continue;
SetLength(Result, O + 1);
Result[O] := ATPA[I];
Inc(O);
end;
end;
else WriteLn{srlwarnthingy}('you give a baaaad by!');
end;
end;

I did not know to place it here ot the the test corner so move it if you think this fits there more.
Credit to caused because my brain started when I tried to help him and failed due to tiredness. But I have tested these and they are working!
Pretty self explanatory only thing you might not understand the TIntegerArrays in FilterATPABy. First integer in the array is the minimum value second is the maximum one.
I can't write descriptions and can't find good names.(open to these)
Also I must mention that I made these mainly because I want to understand TPAs and ATPAs more. So these might be useless and not effective or just simply bad. But it's always fun playing with TPAs and ATPAs for me.
You will get runtime error for example when you filter by areasize but gives the radius values so be careful with those.

caused

2009-09-04 16:59:17

Hey Sabzi.

Sorry that i didnt reply earlier :'D .. I'm just a lazy ass ;).

I think your function looks good. Too many options for my taste though. For example, i think that you dont need a radius Filter, because there are already functions that can filter points that are within a certain radius.

What is Area size ?. Oh, and you dont seem to filter by minimum box size. I think thats crucial ;).

Anyways good Job. Add some debugging images and you probably get more feedback ;)

~caused

Sabzi

2009-09-04 17:23:49

From: caused
Hey Sabzi.

Sorry that i didnt reply earlier :'D .. I'm just a lazy ass ;).

I think your function looks good. Too many options for my taste though. For example, i think that you dont need a radius Filter, because there are already functions that can filter points that are within a certain radius.

What is Area size ?. Oh, and you dont seem to filter by minimum box size. I think thats crucial ;).

Anyways good Job. Add some debugging images and you probably get more feedback ;)

~caused


I'm a lazy ass too to add debug images XD
But thank you very much! The response. Areasize is areasize :p.
How big the are is in pixels. W*H.
And what about minimum box size, like what?
I don't really understand you, sorry.

caused

2009-09-04 17:34:18

What my function does ;).

It checks if the width or height is larger than a given minimum ;). Before i released my function it did check for areasize too, but when you define min and max widths and heights, you dont need an area size and its even more accurate :).

About the debugging :). SRL got an awesome function for debugging, thats what i generated my images with, its
debugatpabounds(yourATPA,''); in the debug.scar include.

~caused

Sabzi

2009-09-04 17:38:53

Nah, I know almost every srl function but thanks anyway :p. And I knew that you created your images with that. I used that too before. But I'm still lazy to do that.
Mine does that if you chose wandh. Exactly the same as yours. I mean the output.
wandh = Width and Height :p
But you should have seen that from the code :D

caused

2009-09-04 17:52:25

From: Sabzi
Nah, I know almost every srl function but thanks anyway :p. And I knew that you created your images with that. I used that too before. But I'm still lazy to do that.
Mine does that if you chose wandh. Exactly the same as yours. I mean the output.
wandh = Width and Height :p
But you should have seen that from the code :D


Oh, alright :D. I've overseen it ;)

~caused

marpis

2009-09-04 18:50:11

I like it :)

type
TPAEx = record
Points: TPointArray; // add this maybe?
Width, Height, AreaSize, Radius: Integer; //if you add Points:TPointArray, you can take Length away (use Length(TPAExVar.Points)
MidPoint: TPoint;
end;

Sabzi

2009-09-06 14:45:02

From: marpis
I like it :)

type
TPAEx = record
Points: TPointArray; // add this maybe?
Width, Height, AreaSize, Radius: Integer; //if you add Points:TPointArray, you can take Length away (use Length(TPAExVar.Points)
MidPoint: TPoint;
end;


I'm quiet brain died now. I am going to be a zombie in on of the left 4 dead film so …
Can you please explain it more. Or just wait a day and tomorrow I will understand :).


EDIT: I get it. But you may have been confused by the name. It's not really TPAEx but TPAProperties.
So I don't think I want to make it like that. Or I get it wrong?
But I am glad you like it! Nothing more that is bad?