SRL Archive - SRL Archives

Symbol.scar FindClosestSymbol(...);


NCDS

2010-02-26 16:10:08

Thought it might be useful. Pretty simple but I figured I would post.


{*******************************************************************************
function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
By: NCDS & Naum
Description: Finds closest symbol defined by 'Name'. Returns true if found.
Returns x and y coord for closest symbol.
*******************************************************************************}
function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
x := Arr[High(Arr) * Integer(Not Closest)].x;
y := Arr[High(Arr) * Integer(Not Closest)].y;
end;
end;

Thoughts?

void_hatred

2010-02-26 16:30:12


var
Arr: array of TPoint;

any reason for not using TPointArray?

other than that, very nice, would be good for a few scripts I'm working on :)

void_hatred

NCDS

2010-02-26 16:32:42

From: void_hatred

var
Arr: array of TPoint;

any reason for not using TPointArray?

other than that, very nice, would be good for a few scripts I'm working on :)

void_hatred


I've just declared them like that for a long time. I think it looks better honestly.

Not anything that's hard to change though if it is a problem.

Bionicle

2010-02-26 16:36:33

{*******************************************************************************
function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
By: NCDS
Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
Returns x and y coord for closest symbol.
*******************************************************************************}
function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
I; integer
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
case Closest of
true: I := Low(Arr);
false: I := High(Arr);
end;
x := Arr[I].x;
y := Arr[I].y;
end;
end;

Would be more useful imo :p
Good idea though

NCDS

2010-02-26 17:29:00

From: bionicle1800
{*******************************************************************************
function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
By: NCDS
Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
Returns x and y coord for closest symbol.
*******************************************************************************}
function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
I; integer
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
case Closest of
true: I := Low(Arr);
false: I := High(Arr);
end;
x := Arr[I].x;
y := Arr[I].y;
end;
end;

Would be more useful imo :p
Good idea though


You could do that. if..then..else is quicker than case statements though generally so:

{*******************************************************************************
function FindClosestSymbol(var x, y: Integer; Name: string): Boolean;
By: NCDS
Description: Finds closest or furthest symbol defined by 'Name'. Returns true if found.
Closest or furthest defined by 'Closest'. Closest = true, furthest = false.
Returns x and y coord for closest symbol.
*******************************************************************************}
function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
I; integer
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
if Closest then
I := 0
else
I := High(Arr);
x := Arr[I].x;
y := Arr[I].y;
end;
end;
would be the way to go if you wanted to do that.

Naum

2010-02-26 18:03:28

Meh:

function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
x := Arr[High(Arr) * Integer(Not Closest)].x;
y := Arr[High(Arr) * Integer(Not Closest)].y;
end;
end;

NCDS

2010-02-26 18:06:06

From: Naum
Meh:

function FindClosestSymbol(var x, y: Integer; Closest: Boolean; Name: string): Boolean;
var
Arr: array of TPoint;
begin
Result := FindSymbols(Arr, Name);
if Result then
begin
SortTPAFrom(Arr, Point(MMCx, MMCy));
x := Arr[High(Arr) * Integer(Not Closest)].x;
y := Arr[High(Arr) * Integer(Not Closest)].y;
end;
end;


Didn't even think of that, I like it though :)