SRL Archive - SRL Positioning System

function SPS_PathToAreas(Path : TPointArray) : TStringArray;


putonajonny

2012-01-14 16:23:33

Returns The Areas that any path uses,
function SPS_PathToAreas(Path : TPointArray) : TStringArray;
Var Xs, Ys, Xss, Yss, i, j : Integer; Areas : TPointArray; DoNot : Boolean;
begin
for i := 0 to high(Path) do
begin
Xs := Floor(Path[i].x/400);
Ys := Floor(Path[i].y/400);
if(GetArrayLength(Areas) = 0) then
begin
SetLength(Areas,GetArrayLength(Areas)+9)
Areas[0].x := Xs-1;
Areas[0].y := Ys-1;
Areas[1].x := Xs;
Areas[1].y := Ys-1;
Areas[2].x := Xs+1;
Areas[2].y := Ys-1;
Areas[3].x := Xs-1;
Areas[3].y := Ys;
Areas[4].x := Xs;
Areas[4].y := Ys;
Areas[5].x := Xs+1;
Areas[5].y := Ys;
Areas[6].x := Xs-1;
Areas[6].y := Ys+1;
Areas[7].x := Xs;
Areas[7].y := Ys+1;
Areas[8].x := Xs+1;
Areas[8].y := Ys+1;
end else
begin
for Yss := Ys-1 to Ys+1 do
begin
for Xss := Xs-1 to Xs+1 do
begin
for j := 0 to high(Areas) do
begin
if((Xss = Areas[j].x) and (Yss = Areas[j].y)) then
begin
DoNot := True;
end;
end;
if(not DoNot) then
begin
SetLength(Areas,GetArrayLength(Areas)+1)
Areas[High(Areas)].x := Xss;
Areas[High(Areas)].y := Yss;
end;
end;
end;
end;
Status(IntToStr(Floor(i*100/high(Path)))+'% Complete')
end;
SetLength(Result,GetArrayLength(Areas))
for i := 0 to high(Areas) do
Result[i] := IntToStr(Areas[i].x)+'_'+IntToStr(Areas[i].y);
end;

So something like:
SPS_Areas := SPS_PathToAreas(myPath)
can be called, fairly pointless function because I got frustrated with having to work out new areas every time I changed paths. Probably not the most efficient/best way of doing it but it does include nearby tiles.

Note this probably includes too many tiles and you may want to reduce the number.

Coh3n

2012-01-16 20:48:55

Nice. :) I know marpis planned to include something like this in SPS2, so maybe it'll be of some use to him.

marpis

2012-01-17 09:44:42


function SPS_PathToAreas(Path : TPointArray) : TStringArray;
var
s: string;
i, x, y, L: integer;
begin
for i := high(Path) downto 0 do
begin
x := Path[i].x mod 500;
y := Path[i].y mod 500;
s := ToStr(x) + '_' + ToStr(y);
if not InStrArr(s, Result, true) then
begin
Inc(L);
SetLength(Result, L);
Result[L - 1] := s;
end;
end;
end;

I'm pretty sure this would work.

Shuttleu

2012-01-17 10:14:59

From: marpis

function SPS_PathToAreas(Path : TPointArray) : TStringArray;
var
s: string;
i, x, y, L: integer;
begin
for i := high(Path) downto 0 do
begin
x := Path[i].x mod 500;
y := Path[i].y mod 500;
s := ToStr(x) + '_' + ToStr(y);
if not InStrArr(s, Result, true) then
begin
Inc(L);
SetLength(Result, L);
Result[L - 1] := s;
end;
end;
end;

I'm pretty sure this would work.

but the first image is 0_1 not 0_0

so it should be
s := ToStr(x) + '_' + ToStr(y+1)

~shut

EDIT: it doesnt work

this is one of the points i use (4685, 2640), it should return 11_6 but instead it returns 185_140


EDIT: this does work though
function SPS_PathToAreas(Path : TPointArray) : TStringArray;
var
s: string;
i, x, y, L: integer;
begin
for i := high(Path) downto 0 do
begin
x := Path[i].x div 400;
y := Path[i].y div 400;
s := ToStr(x) + '_' + ToStr(y);
if not InStrArr(s, Result, true) then
begin
Inc(L);
SetLength(Result, L);
Result[L - 1] := s;
end;
end;
end;

marpis

2012-01-18 05:55:35

From: Shuttleu
but the first image is 0_1 not 0_0

so it should be
s := ToStr(x) + '_' + ToStr(y+1)

~shut

EDIT: it doesnt work

this is one of the points i use (4685, 2640), it should return 11_6 but instead it returns 185_140


EDIT: this does work though
function SPS_PathToAreas(Path : TPointArray) : TStringArray;
var
s: string;
i, x, y, L: integer;
begin
for i := high(Path) downto 0 do
begin
x := Path[i].x div 400;
y := Path[i].y div 400;
s := ToStr(x) + '_' + ToStr(y);
if not InStrArr(s, Result, true) then
begin
Inc(L);
SetLength(Result, L);
Result[L - 1] := s;
end;
end;
end;


Blagh yea, of course it's not mod 500… I made it hastely.