Flight
2011-04-19 23:01:03
Is there a simple bit of code already out there that finds the DTM nearest to the center of MS?
Thanks in advance.
Thanks in advance.
2011-04-19 23:01:03
2011-04-19 23:01:38
2011-04-19 23:52:14
2011-04-20 01:27:23
{***
function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
By: TomTuff
Desc: Finds all the DTMs in the TIA within the SearchBox, then finds the closest one
to point "P". Point is stored in ResultPoint as well.
***}
function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
var
ATPA: T2DPointArray;
i: Integer;
TPA: TPointArray;
begin
SetLength(ATPA, Length(DTMs));
for i := 0 to High(DTMs) do
FindDTMs(DTMs[i], ATPA[i], SearchBox.X1, SearchBox.Y1, SearchBox.X2, SearchBox.X2);
Result := (Length(TPA) > 0);
if not(Result) then
Exit;
TPA := MergeATPA(ATPA);
SortTPAFrom(TPA, P);
ResultPoint := TPA[0];
end;
2011-04-20 01:40:36
2011-04-20 01:43:05
2011-04-20 01:55:05
From: Flight
P (TPoint) would be the center of your search box, or do we leave that bank to get defined later in the function?
Looks awesome by the way, I really appreciate it. I'll test it in a while and see what I come up with.
2011-04-20 04:16:05
2011-04-20 04:18:59
From: Bonfield
i would use the tpoint of the middle of the screen, create an array of DTMs then sort by length and go from there, i would handle it the same as searching for TPAs
sorry i didnt post any code, but i dont see how that wont work
2011-04-20 04:21:27
2011-04-20 10:56:54
2011-04-20 12:26:45
From: Flight
Wouldn't you need to free the DTMs within this procedure?
2011-04-20 12:55:28
From: pur3b100d
the DTM's are loaded externally from the Function so would there be any reason to free them internally?
function Example: boolean;
var
DTMa, DTMb: Integer;
begin
DTMa := ...
DTMb := ...
FindClosestDTM
FreeDTM(DTMa);
FreeDTM(DTMb);
end;
2011-04-20 13:59:43
2011-04-20 20:58:24
Function GetClosestDTM(DTMs: TIntegerArray): Boolean;
Var
i: Integer;
TPA: TPointArray;
ResultPoint: TPoint;
ATPA: T2DPointArray;
begin
SetLength(ATPA, Length(DTMs));
for i := 0 to High(DTMs) do
FindDTMs(DTMs[i], ATPA[i], MSX1, MSY1, MSX2, MSY2);
Result := (Length(TPA) > 0);
if not(Result) then
Exit;
TPA := MergeATPA(ATPA);
SortTPAFrom(TPA, Point(MSCX,MSCY));
ResultPoint := TPA[0];
end;
X := GetClosestDTM(RockDTM).ResultPoint.x;
Y := GetClosestDTM(RockDTM).ResultPoint.y;