SRL Archive - SRL Suggestions

A little TPointArray function...


Pure1993

2009-04-26 21:15:03

While designing a fishing spot locating function, I am accross this idea…
It works similar to AMax and Max, but instead of returning the length, it is returning the entire TPA with the biggest length… Might be helpfull to some… Using this in my fisher… :)
I haven't tested it yet, but it should work…

{*******************************************************************************
function ReturnHighestTPArray(TPAs : T2DPointArray): TPointArray;
By: Pure1993
Description: Returns the TPA with the highest length.
*******************************************************************************}
function ReturnHighestTPArray(TPAs : T2DPointArray): TPointArray;
var
carry, i : integer;
begin
carry := Max( length(TPAs[0]), length(TPAs[1]));
if (High(TPAs) > 1) then
begin
for i := 2 to high(TPAs) do
begin
carry := Max(carry, length(TPAs[i]));
end;
end;
for i := 0 to high(TPAs) do
begin
if carry = Length(TPAs[i]) then
Result := TPAs[i];
end;
end;
I know the name is "clumsy"… I just couldn't think of a better one… :o

Didn't know where to put this, so I just followed RM's example and posted this in the suggestion part… :D

PS. Sorry if something like this already exists… but I didn't find anything like this while searching for it…

marpis

2009-04-26 23:20:41

InIntArrayEx(Array: TIntegerArray; var where: integer; number: integer): boolean;
Array is the array of integers you are inspecting
where is a variable. It tells wheter the number is found in Array[0], [1], [2] and so on.
number is the number you are looking for.

Try this, Highest=true returns the longest tpa, false returns the shortest tpa
i didn't try if it works ^^ you have a good idea there anyways!

EDIT: Added SetLength to TIA. Now it works :) I tried it, works 100%.

function TPALengths(ATPA : T2DPointArray; Highest: boolean): TPointArray;
var
TIA: TIntegerArray;
i, w: integer;
begin
SetLength(TIA, Length(ATPA));
for i:= 0 to High(ATPA) do
TIA[i]:= Length(ATPA[i]);
if Highest then
InIntArrayEx(TIA, w, AMax(TIA))
else
InIntArrayEx(TIA, w, AMin(TIA));
result := ATPA[w]
end;

Nava2

2009-04-26 23:33:03

SortATPASize, anyone?

Pure1993

2009-04-26 23:46:32

oh, wasn't aware of that one… go ahead and close/delete this…

ShowerThoughts

2009-04-27 00:16:07

Devs - Pure
4 - 0

Nava2

2009-04-27 02:00:42

Closed, thanks for your attempt! :)

<3