Skip to content

Commit 560369c

Browse files
committed
Updated
1 parent 570a3e8 commit 560369c

4 files changed

Lines changed: 18135 additions & 18136 deletions

File tree

mapcode_api.php

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,16 @@ function isInRange($x, $minx, $maxx)
256256

257257
function fitsInside($p, $mm)
258258
{
259-
return ($mm->miny <= $p->y && $p->y < $mm->maxy && isInRange($p->x, $mm->minx, $mm->maxx));
259+
return ($mm->miny <= $p->lat && $p->lat < $mm->maxy && isInRange($p->lon, $mm->minx, $mm->maxx));
260260
}
261261

262262
function fitsInsideWithRoom($p, $mm)
263263
{
264-
if ((($mm->miny - 45) > $p->y) || ($p->y >= ($mm->maxy + 45))) {
264+
if ((($mm->miny - 45) > $p->lat) || ($p->lat >= ($mm->maxy + 45))) {
265265
return false;
266266
}
267267
$xroom = xDivider4($mm->miny, $mm->maxy) >> 2;
268-
return isInRange($p->x, $mm->minx - $xroom, $mm->maxx + $xroom);
268+
return isInRange($p->lon, $mm->minx - $xroom, $mm->maxx + $xroom);
269269
}
270270

271271
function startsdigit($n)
@@ -334,20 +334,17 @@ function hasSubdivision($territory)
334334

335335
class Coord
336336
{
337-
public $x, $y;
337+
public $lat, $lon;
338338

339339
public function __construct($lat, $lon)
340340
{
341-
$this->y = $lat;
342-
$this->x = $lon;
341+
$this->lat = $lat;
342+
$this->lon = $lon;
343343
}
344344

345345
public function __toString()
346346
{
347-
if ($this->x > 360 || $this->y > 360 || $this->x < -360 || $this->y < -360) {
348-
return sprintf('[%0.9f,%0.9f]', $this->y / 1000000.0, $this->x / 1000000.0);
349-
}
350-
return sprintf('[%0.9f,%0.9f]', $this->y, $this->x);
347+
return sprintf('[%0.9f,%0.9f]', $this->lat, $this->lon);
351348
}
352349
}
353350

@@ -439,7 +436,7 @@ public function __construct($lat, $lon)
439436

440437
public function __toString()
441438
{
442-
return sprintf('[%0.9f,%0.9f]', ($this->coord32->y + $this->fraclat) / 1000000.0, ($this->coord32->x + $this->fraclon) / 1000000.0);
439+
return sprintf('[%0.9f,%0.9f]', ($this->coord32->lat + $this->fraclat) / 1000000.0, ($this->coord32->lon + $this->fraclon) / 1000000.0);
443440
}
444441
}
445442

@@ -554,7 +551,7 @@ function decodeSixWide($v, $width, $height)
554551
return new Coord($height - 1 - floor($w / $D), ($col * 6) + ($w % $D));
555552
}
556553

557-
function decodeExtension($extensionchars, $Coord, $dividerx4, $dividery, $ydirection, $orginput)
554+
function decodeExtension($extensionchars, $Coord, $dividerx4, $dividery, $ydirection)
558555
{
559556
$dividerx = $dividerx4 / 4.0;
560557
$processor = 1.0;
@@ -593,12 +590,12 @@ function decodeExtension($extensionchars, $Coord, $dividerx4, $dividery, $ydirec
593590
$extray += (0.5 / $processor);
594591
$extrax *= $dividerx;
595592
$extray *= $dividery;
596-
$Coord->x += $extrax;
597-
$Coord->y += $extray * $ydirection;
593+
$Coord->lon += $extrax;
594+
$Coord->lat += $extray * $ydirection;
598595
return $Coord;
599596
}
600597

601-
function decodeGrid($input, $extensionchars, $headerletter, $territoryNumber, $m)
598+
function decodeGrid($input, $extensionchars, $headerletter, $m)
602599
{
603600
$orgresult = $input;
604601
$prefixlength = strpos($input, '.');
@@ -632,8 +629,8 @@ function decodeGrid($input, $extensionchars, $headerletter, $territoryNumber, $m
632629

633630
if ($divx != $divy && $prefixlength > 2) {
634631
$d = decodeSixWide($v, $divx, $divy);
635-
$relx = $d->x;
636-
$rely = $d->y;
632+
$relx = $d->lon;
633+
$rely = $d->lat;
637634
} else {
638635
$relx = floor($v / $divy);
639636
$rely = $divy - 1 - ($v % $divy);
@@ -662,8 +659,8 @@ function decodeGrid($input, $extensionchars, $headerletter, $territoryNumber, $m
662659
if ($d == 0) {
663660
return 0;
664661
}
665-
$difx = $d->x;
666-
$dify = $d->y;
662+
$difx = $d->lon;
663+
$dify = $d->lat;
667664
} else {
668665
if ($postfixlength == 4) {
669666
$rest = $rest[0] . $rest[2] . $rest[1] . $rest[3];
@@ -682,7 +679,7 @@ function decodeGrid($input, $extensionchars, $headerletter, $territoryNumber, $m
682679
$corner = new Coord($rely + ($dify * $dividery), $relx + ($difx * $dividerx));
683680

684681

685-
return decodeExtension($extensionchars, $corner, ($dividerx) << 2, $dividery, 1, $headerletter + $input);
682+
return decodeExtension($extensionchars, $corner, ($dividerx) << 2, $dividery, 1);
686683
}
687684

688685
function firstNamelessRecord($index, $firstcode)
@@ -805,8 +802,8 @@ function decodeNameless($input, $extensionchars, $m, $firstindex)
805802

806803
if (isSpecialShape($m)) {
807804
$d = decodeSixWide($v, $XSIDE, $SIDE);
808-
$dx = $d->x;
809-
$dy = $SIDE - 1 - $d->y;
805+
$dx = $d->lon;
806+
$dy = $SIDE - 1 - $d->lat;
810807
} else {
811808
$dy = ($v % $SIDE);
812809
$dx = floor($v / $SIDE);
@@ -820,9 +817,9 @@ function decodeNameless($input, $extensionchars, $m, $firstindex)
820817
$dividery = 90;
821818

822819
$corner = new Coord($mm->maxy - ($dy * $dividery), $mm->minx + floor(($dx * $dividerx4) / 4));
823-
$ret = decodeExtension($extensionchars, $corner, $dividerx4, $dividery, -1, $input);
820+
$ret = decodeExtension($extensionchars, $corner, $dividerx4, $dividery, -1);
824821
if ($ret != 0) {
825-
$ret->x += (($dx * $dividerx4) % 4) / 4.0;
822+
$ret->lon += (($dx * $dividerx4) % 4) / 4.0;
826823
}
827824
return $ret;
828825
}
@@ -865,15 +862,15 @@ function decodeAutoHeader($input, $extensionchars, $m)
865862
$value -= $STORAGE_START;
866863
$value = floor($value / (961 * 31));
867864

868-
$vx = $triple->x + 168 * (floor($value / floor($H / 176)));
869-
$vy = $triple->y + 176 * ($value % floor($H / 176));
865+
$vx = $triple->lon + 168 * (floor($value / floor($H / 176)));
866+
$vy = $triple->lat + 176 * ($value % floor($H / 176));
870867

871868
$corner = new Coord($mm->maxy - $vy * $dividery, $mm->minx + $vx * $dividerx);
872869

873-
if ($corner->x < $mm->minx || $corner->x >= $mm->maxx || $corner->y < $mm->miny || $corner->y > $mm->maxy) {
870+
if ($corner->lon < $mm->minx || $corner->lon >= $mm->maxx || $corner->lat < $mm->miny || $corner->lat > $mm->maxy) {
874871
return 0;
875872
}
876-
return decodeExtension($extensionchars, $corner, $dividerx << 2, $dividery, -1, $input);
873+
return decodeExtension($extensionchars, $corner, $dividerx << 2, $dividery, -1);
877874
}
878875
$STORAGE_START += $product;
879876
}
@@ -1010,7 +1007,7 @@ function aeu_pack($r, $short = 0)
10101007
"Hebrew",
10111008
"Hindi",
10121009
"Malai",
1013-
"Georgisch",
1010+
"Georgian",
10141011
"Katakana",
10151012
"Thai",
10161013
"Lao",
@@ -1205,7 +1202,7 @@ function master_decode($mapcode, $territoryNumber = -1)
12051202

12061203
if (($incodex == $codexm || ($incodex == 22 && $codexm == 21)) && recType($m) == 0 && isNameless($m) == 0) {
12071204

1208-
$result = decodeGrid($mapcode, $extensionchars, '', $territoryNumber, $m);
1205+
$result = decodeGrid($mapcode, $extensionchars, '', $m);
12091206
if ($result != 0 && isRestricted($m)) {
12101207
$fitssomewhere = 0;
12111208
for ($j = $upto - 1; $j >= $from; $j--) {
@@ -1223,7 +1220,7 @@ function master_decode($mapcode, $territoryNumber = -1)
12231220
break;
12241221
} else {
12251222
if ($codexm + 10 == $incodex && recType($m) == 1 && headerLetter($m) == $mapcode[0]) {
1226-
$result = decodeGrid(substr($mapcode, 1), $extensionchars, substr($mapcode, 0, 1), $territoryNumber, $m);
1223+
$result = decodeGrid(substr($mapcode, 1), $extensionchars, substr($mapcode, 0, 1), $m);
12271224
break;
12281225
} else {
12291226
if (isNameless($m) && (($codexm == 21 && $incodex == 22) || ($codexm == 22 && $incodex == 32) || ($codexm == 13 && $incodex == 23))) {
@@ -1233,18 +1230,20 @@ function master_decode($mapcode, $territoryNumber = -1)
12331230
if ($postfixlength == 3 && recType($m) > 1 && CodexLen($m) == $prefixlength + 2) {
12341231
$result = decodeAutoHeader($mapcode, $extensionchars, $m);
12351232
break;
1233+
} else {
1234+
$result = 0;
12361235
}
12371236
}
12381237
}
12391238
}
12401239
}
12411240

12421241
if ($result) {
1243-
if ($result->x > 180000000) {
1244-
$result->x -= 360000000;
1242+
if ($result->lon > 180000000) {
1243+
$result->lon -= 360000000;
12451244
} else {
1246-
if ($result->x < -180000000) {
1247-
$result->x += 360000000;
1245+
if ($result->lon < -180000000) {
1246+
$result->lon += 360000000;
12481247
}
12491248
}
12501249

@@ -1254,10 +1253,10 @@ function master_decode($mapcode, $territoryNumber = -1)
12541253
}
12551254
}
12561255

1257-
$result->x /= 1000000.0;
1258-
$result->y /= 1000000.0;
1259-
if ($result->y > 90) {
1260-
$result->y = 90;
1256+
$result->lon /= 1000000.0;
1257+
$result->lat /= 1000000.0;
1258+
if ($result->lat > 90) {
1259+
$result->lat = 90;
12611260
}
12621261
}
12631262
return $result;
@@ -1364,7 +1363,7 @@ function encodeExtension($result, $enc, $extrax4, $extray, $dividerx4, $dividery
13641363
}
13651364

13661365

1367-
function encodeGrid($enc, $m, $mm, $headerletter, $territoryNumber, $extraDigits)
1366+
function encodeGrid($enc, $m, $mm, $headerletter, $extraDigits)
13681367
{
13691368
$orgcodex = Codex($m);
13701369
$codexm = $orgcodex;
@@ -1387,10 +1386,10 @@ function encodeGrid($enc, $m, $mm, $headerletter, $territoryNumber, $extraDigits
13871386
$divx = floor($GLOBALS['nc'][$prefixlength] / $divy);
13881387
}
13891388
$ygridsize = floor(($mm->maxy - $mm->miny + $divy - 1) / $divy);
1390-
$rely = $enc->coord32->y - $mm->miny;
1389+
$rely = $enc->coord32->lat - $mm->miny;
13911390
$rely = floor($rely / $ygridsize);
13921391
$xgridsize = floor(($mm->maxx - $mm->minx + $divx - 1) / $divx);
1393-
$x = $enc->coord32->x;
1392+
$x = $enc->coord32->lon;
13941393
$relx = $x - $mm->minx;
13951394
if ($relx < 0) {
13961395
$x += 360000000;
@@ -1429,7 +1428,7 @@ function encodeGrid($enc, $m, $mm, $headerletter, $territoryNumber, $extraDigits
14291428
$result .= '.';
14301429

14311430
$difx = $x - $relx;
1432-
$dify = $enc->coord32->y - $rely;
1431+
$dify = $enc->coord32->lat - $rely;
14331432
$extrax = $difx % $dividerx;
14341433
$extray = $dify % $dividery;
14351434
$difx = floor($difx / $dividerx);
@@ -1506,12 +1505,12 @@ function encodeNameless($enc, $m, $firstcode, $extraDigits)
15061505

15071506
$dividerx4 = xDivider4($mm->miny, $mm->maxy);
15081507
$xFracture = floor(4 * $enc->fraclon);
1509-
$dx = floor((4 * ($enc->coord32->x - $mm->minx) + $xFracture) / $dividerx4);
1510-
$extrax4 = ($enc->coord32->x - $mm->minx) * 4 - $dx * $dividerx4;
1508+
$dx = floor((4 * ($enc->coord32->lon - $mm->minx) + $xFracture) / $dividerx4);
1509+
$extrax4 = ($enc->coord32->lon - $mm->minx) * 4 - $dx * $dividerx4;
15111510

15121511
$dividery = 90;
1513-
$dy = floor(($mm->maxy - $enc->coord32->y) / $dividery);
1514-
$extray = ($mm->maxy - $enc->coord32->y) % $dividery;
1512+
$dy = floor(($mm->maxy - $enc->coord32->lat) / $dividery);
1513+
$extray = ($mm->maxy - $enc->coord32->lat) % $dividery;
15151514

15161515
if ($extray == 0 && $enc->fraclat > 0) {
15171516
$dy--;
@@ -1546,7 +1545,7 @@ function encodeNameless($enc, $m, $firstcode, $extraDigits)
15461545
return encodeExtension($result, $enc, $extrax4, $extray, $dividerx4, $dividery, $extraDigits, -1);
15471546
}
15481547

1549-
function encodeAutoHeader($enc, $m, $territoryNumber, $extraDigits)
1548+
function encodeAutoHeader($enc, $m, $extraDigits)
15501549
{
15511550
$STORAGE_START = 0;
15521551

@@ -1576,12 +1575,12 @@ function encodeAutoHeader($enc, $m, $territoryNumber, $extraDigits)
15761575

15771576
if ($i == $m && fitsInside($enc->coord32, $mm)) {
15781577
$dividerx = floor(($mm->maxx - $mm->minx + $W - 1) / $W);
1579-
$vx = floor(($enc->coord32->x - $mm->minx) / $dividerx);
1580-
$extrax = (($enc->coord32->x - $mm->minx) % $dividerx);
1578+
$vx = floor(($enc->coord32->lon - $mm->minx) / $dividerx);
1579+
$extrax = (($enc->coord32->lon - $mm->minx) % $dividerx);
15811580

15821581
$dividery = floor(($mm->maxy - $mm->miny + $H - 1) / $H);
1583-
$vy = floor(($mm->maxy - $enc->coord32->y) / $dividery);
1584-
$extray = (($mm->maxy - $enc->coord32->y) % $dividery);
1582+
$vy = floor(($mm->maxy - $enc->coord32->lat) / $dividery);
1583+
$extray = (($mm->maxy - $enc->coord32->lat) % $dividery);
15851584

15861585
$spx = $vx % 168;
15871586
$spy = $vy % 176;
@@ -1646,7 +1645,7 @@ function mapcoderEngine($enc, $tn, $getshortest, $isrecursive, $state_override,
16461645
$r = encodeNameless($enc, $i, $from, $extraDigits);
16471646
} else {
16481647
if (recType($i) > 1) {
1649-
$r = encodeAutoHeader($enc, $i, $territoryNumber, $extraDigits);
1648+
$r = encodeAutoHeader($enc, $i, $extraDigits);
16501649
} else {
16511650
if (isRestricted($i) && $i == $upto && getParentOf($territoryNumber) >= 0) {
16521651
$results = array_merge($results, mapcoderEngine($enc, getParentOf($territoryNumber), $getshortest, 1/*recursive*/, $territoryNumber, $extraDigits));
@@ -1655,7 +1654,7 @@ function mapcoderEngine($enc, $tn, $getshortest, $isrecursive, $state_override,
16551654
if (isRestricted($i) && count($results) == $original_length) {
16561655
$r = '';
16571656
} else {
1658-
$r = encodeGrid($enc, $i, $mm, headerLetter($i), $territoryNumber, $extraDigits);
1657+
$r = encodeGrid($enc, $i, $mm, headerLetter($i), $extraDigits);
16591658
}
16601659
}
16611660
}

0 commit comments

Comments
 (0)