Skip to content

Commit

Permalink
tab to space
Browse files Browse the repository at this point in the history
  • Loading branch information
taisukef committed Jan 7, 2025
1 parent 36203a9 commit 829213d
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions geo3x3.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ implementation
sysutils,
math;


function Geo3x3_encode(lat: real; lng: real; level: integer): string;
var
unitsize: real;
i: integer;
x: integer;
y: integer;
begin
if level < 1 then
result := ''
if level < 1 then
result := ''
else
begin
result := 'E';
Expand All @@ -33,17 +32,17 @@ function Geo3x3_encode(lat: real; lng: real; level: integer): string;
result := 'W';
lng := lng + 180.0;
end;
lat := lat + 90.0; { 180:the North Pole, 0:the South Pole }
unitsize := 180.0;
for i := 1 to level - 1 do
lat := lat + 90.0; { 180:the North Pole, 0:the South Pole }
unitsize := 180.0;
for i := 1 to level - 1 do
begin
unitsize := unitsize / 3.0;
x := Floor(lng / unitsize);
y := Floor(lat / unitsize);
result := result + IntToStr(x + y * 3 + 1);
lng := lng - x * unitsize;
lat := lat - y * unitsize;
end
unitsize := unitsize / 3.0;
x := Floor(lng / unitsize);
y := Floor(lat / unitsize);
result := result + IntToStr(x + y * 3 + 1);
lng := lng - x * unitsize;
lat := lat - y * unitsize;
end
end
end;

Expand All @@ -62,23 +61,23 @@ function Geo3x3_decode(code: string): latlnglevelunit; static;
else
begin
flg := integer(code[1]) = 87; { ascii code of "W" }
unitsize := 180.0;
lat := 0.0;
lng := 0.0;
level := 1;
for i := 1 to length(code) - 1 do
unitsize := 180.0;
lat := 0.0;
lng := 0.0;
level := 1;
for i := 1 to length(code) - 1 do
begin
n := integer(code[i + 1]) - 49; { ascii code of "1" }
n := integer(code[i + 1]) - 49; { ascii code of "1" }
if (n < 0) or (n > 9) then
break;
unitsize := unitsize / 3.0;
lng := lng + (n mod 3) * unitsize;
lat := lat + Floor(n / 3) * unitsize;
level := level + 1;
unitsize := unitsize / 3.0;
lng := lng + (n mod 3) * unitsize;
lat := lat + Floor(n / 3) * unitsize;
level := level + 1;
end;
lat := lat + unitsize / 2.0;
lng := lng + unitsize / 2.0;
lat := lat - 90.0;
lat := lat + unitsize / 2.0;
lng := lng + unitsize / 2.0;
lat := lat - 90.0;
if flg then
lng := lng - 180.0;
result := [ lat, lng, level, unitsize];
Expand Down

0 comments on commit 829213d

Please sign in to comment.