Skip to content

Commit 1e74c13

Browse files
committed
Fixed issue with AAA codes; v1.61
1 parent 9d66565 commit 1e74c13

File tree

2 files changed

+81
-84
lines changed

2 files changed

+81
-84
lines changed

mapcodelib/basics.h

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
@@ -16,15 +16,11 @@
1616

1717
#define UWORD unsigned short int // 2-byte unsigned integer
1818

19-
#ifdef VERSION160
20-
#define mapcode_cversion "1.60"
21-
#else
22-
#define mapcode_cversion "1.55"
23-
#endif
19+
#define mapcode_cversion "1.61"
2420
#define MAXWIDE 10
2521
#define BASEX 31
2622
#define MAXFITLONG 6
27-
#define XSIDE3 168
23+
#define XSIDE3 168
2824
#define YSIDE3 176
2925

3026
#define ALIASES "2UK=2UT,2CG=2CT,1GU=GUM,1UM=UMI,1VI=VIR,1PR=PRI,1AS=ASM,1MP=MNP,4CX=CXR,4CC=CCK,4NF=NFK,4HM=HMD,COL=5CL,5ME=5MX,MEX=5MX,5TM=TAM,5AG=AGU,5BC=BCN,5BS=BCS,5CM=CAM,5CS=CHP,5CH=CHH,5CO=COA,5DF=DIF,5DG=DUR,5GT=GUA,5GR=GRO,5HG=HID,5JA=JAL,5MI=MIC,5MO=MOR,5NA=NAY,5NL=NLE,5OA=OAX,5PB=PUE,5QE=QUE,5QR=ROO,5SL=SLP,5SI=SIN,5SO=SON,5TB=TAB,5TL=TLA,5VE=VER,5YU=YUC,5ZA=ZAC,811=8BJ,812=8TJ,813=8HE,814=8SX,815=8NM,821=8LN,822=8JL,823=8HL,831=8SH,832=8JS,833=8ZJ,834=8AH,835=8FJ,836=8JX,837=8SD,841=8HA,842=8HB,843=8HN,844=8GD,845=8GX,846=8HI,850=8CQ,851=8SC,852=8GZ,853=8YN,854=8XZ,861=8SN,862=8GS,863=8QH,864=8NX,865=8XJ,871=TWN,891=HKG,892=MAC,8TW=TWN,8HK=HKG,8MC=MAC,BEL=7BE,KIR=7KI,PRI=7PO,CHE=7CH,KHM=7KM,PER=7PM,TAM=7TT,0US=USA,0AU=AUS,0RU=RUS,0CN=CHN,TAA=SHN,ASC=SHN,DGA=IOT,WAK=MHL,JTN=UMI,MID=1HI,2OD=2OR,"
@@ -172,63 +168,63 @@ static const char encode_chars[34] = {
172168

173169

174170
static const UWORD data_start[MAX_CCODE+1] = {
175-
0, 3, 6, 9, 13, 16, 18, 19, 30, 31,
176-
33, 35, 37, 42, 44, 47, 51, 54, 56, 58,
177-
60, 62, 64, 68, 71, 79, 81, 116, 121, 131,
178-
133, 135, 138, 143, 155, 159, 165, 167, 169, 173,
179-
176, 183, 185, 187, 189, 193, 195, 202, 208, 212,
180-
216, 219, 221, 223, 250, 252, 259, 261, 266, 284,
181-
288, 292, 296, 298, 303, 311, 315, 325, 327, 332,
182-
336, 342, 356, 360, 365, 369, 385, 391, 396, 404,
183-
412, 428, 432, 436, 443, 454, 491, 495, 521, 527,
184-
545, 557, 593, 659, 694, 733, 745, 754, 782, 798,
185-
832, 848, 882, 918, 932, 956, 967, 1022, 1080, 1094,
186-
1155, 1179, 1208, 1276, 1353, 1405, 1484, 1569, 1621, 1696,
187-
1772, 1833, 1875, 1900, 1948, 1991, 2036, 2097, 2183, 2270,
188-
2319, 2382, 2467, 2558, 2643, 2702, 2815, 2912, 3004, 3088,
189-
3186, 3248, 3350, 3416, 3511, 3602, 3688, 3776, 3866, 3973,
190-
4119, 4221, 4325, 4356, 4393, 4468, 4504, 4538, 4574, 4626,
191-
4690, 4741, 4756, 4791, 4931, 5017, 5067, 5143, 5168, 5236,
192-
5293, 5328, 5408, 5459, 5530, 5623, 5658, 5736, 5795, 5861,
193-
5918, 5971, 6028, 6065, 6156, 6285, 6335, 6365, 6417, 6513,
194-
6546, 6627, 6675, 6755, 6798, 6892, 6926, 6971, 7078, 7082,
195-
7154, 7198, 7282, 7322, 7346, 7403, 7489, 7563, 7602, 7689,
196-
7765, 7873, 7951, 8025, 8095, 8152, 8234, 8316, 8375, 8402,
197-
8440, 8494, 8570, 8680, 8760, 8824, 8881, 8935, 9013, 9084,
198-
9170, 9220, 9281, 9425, 9429, 9434, 9439, 9444, 9450, 9455,
199-
9463, 9471, 9482, 9490, 9505, 9514, 9525, 9558, 9567, 9575,
200-
9590, 9600, 9610, 9618, 9626, 9642, 9650, 9660, 9671, 9681,
201-
9691, 9700, 9709, 9720, 9761, 9802, 9820, 9917, 10068, 10159,
202-
10241, 10436, 10439, 10442, 10445, 10455, 10460, 10463, 10475, 10488,
203-
10499, 10515, 10524, 10530, 10564, 10592, 10611, 10679, 10771, 10786,
204-
10790, 10826, 10913, 10924, 10942, 10959, 11023, 11055, 11096, 11116,
205-
11221, 11301, 11365, 11419, 11478, 11534, 11594, 11600, 11642, 11646,
206-
11649, 11659, 11674, 11685, 11723, 11786, 11832, 11837, 11844, 11849,
207-
11868, 11878, 11885, 11893, 11907, 11923, 11930, 11938, 11946, 11994,
208-
12003, 12014, 12064, 12075, 12085, 12104, 12120, 12133, 12145, 12164,
209-
12198, 12207, 12219, 12231, 12235, 12241, 12247, 12259, 12270, 12279,
210-
12285, 12299, 12317, 12328, 12370, 12421, 12471, 12527, 12540, 12553,
211-
12616, 12676, 12737, 12802, 12873, 12938, 13007, 13082, 13149, 13228,
212-
13302, 13316, 13331, 13376, 13389, 13417, 13431, 13444, 13460, 13476,
213-
13488, 13530, 13542, 13553, 13588, 13603, 13615, 13632, 13640, 13678,
214-
13691, 13706, 13826, 13872, 13916, 13956, 13980, 14021, 14060, 14080,
215-
14096, 14114, 14126, 14140, 14148, 14159, 14176, 14189, 14244, 14245,
216-
14246, 14247, 14286, 14292, 14297, 14302, 14307, 14313, 14320, 14326,
217-
14335, 14341, 14349, 14355, 14362, 14371, 14379, 14388, 14400, 14409,
218-
14417, 14428, 14439, 14448, 14458, 14465, 14515, 14549, 14558, 14570,
219-
14581, 14620, 14631, 14645, 14662, 14674, 14687, 14701, 14716, 14729,
220-
14750, 14758, 14777, 14786, 14798, 14809, 14823, 14838, 14851, 14865,
221-
14878, 14892, 14907, 14925, 14945, 14957, 14977, 14990, 15005, 15019,
222-
15037, 15053, 15067, 15080, 15097, 15117, 15134, 15152, 15167, 15181,
223-
15197, 15208, 15224, 15237, 15252, 15267, 15313, 15327, 15336, 15346,
224-
15359, 15373, 15384, 15397, 15413, 15428, 15429, 15456, 15462, 15470,
225-
15476, 15492, 15529, 15546, 15570, 15593, 15610, 15630, 15656, 15682,
226-
15701, 15718, 15771, 15812, 15834, 15861, 15881, 15902, 15920, 15950,
227-
15976, 15996, 16017, 16035, 16053, 16072, 16088, 16104, 16132, 16158,
228-
16165, 16167, 16168, 16200
171+
0, 3, 6, 9, 13, 16, 18, 19, 30, 31,
172+
33, 35, 37, 42, 44, 47, 51, 54, 56, 58,
173+
60, 62, 64, 68, 71, 79, 81, 116, 121, 131,
174+
133, 135, 138, 143, 155, 159, 165, 167, 169, 173,
175+
176, 183, 185, 187, 189, 193, 195, 202, 208, 212,
176+
216, 219, 221, 223, 250, 252, 259, 261, 266, 284,
177+
288, 292, 296, 298, 303, 311, 315, 325, 327, 332,
178+
336, 342, 356, 360, 365, 369, 385, 391, 396, 404,
179+
412, 428, 432, 436, 443, 454, 491, 495, 521, 527,
180+
545, 557, 593, 659, 694, 733, 745, 754, 782, 798,
181+
832, 848, 882, 918, 932, 956, 967, 1022, 1080, 1094,
182+
1155, 1179, 1208, 1276, 1353, 1405, 1484, 1569, 1621, 1696,
183+
1772, 1833, 1875, 1900, 1948, 1991, 2036, 2097, 2183, 2270,
184+
2319, 2382, 2467, 2558, 2643, 2702, 2815, 2912, 3004, 3088,
185+
3186, 3248, 3350, 3416, 3511, 3602, 3688, 3776, 3866, 3973,
186+
4119, 4221, 4325, 4356, 4393, 4468, 4504, 4538, 4574, 4626,
187+
4690, 4741, 4756, 4791, 4931, 5017, 5067, 5143, 5168, 5236,
188+
5293, 5328, 5408, 5459, 5530, 5623, 5658, 5736, 5795, 5861,
189+
5918, 5971, 6028, 6065, 6156, 6285, 6335, 6365, 6417, 6513,
190+
6546, 6627, 6675, 6755, 6798, 6892, 6926, 6971, 7078, 7083,
191+
7155, 7199, 7283, 7323, 7347, 7404, 7490, 7564, 7603, 7690,
192+
7766, 7874, 7952, 8026, 8096, 8153, 8235, 8317, 8376, 8403,
193+
8441, 8495, 8571, 8681, 8761, 8825, 8882, 8936, 9014, 9085,
194+
9171, 9221, 9282, 9426, 9430, 9435, 9440, 9445, 9451, 9456,
195+
9464, 9472, 9483, 9491, 9506, 9515, 9526, 9559, 9568, 9576,
196+
9591, 9601, 9611, 9619, 9627, 9643, 9651, 9661, 9672, 9682,
197+
9692, 9701, 9710, 9721, 9762, 9803, 9821, 9918, 10069, 10160,
198+
10242, 10437, 10440, 10443, 10446, 10456, 10461, 10464, 10476, 10489,
199+
10500, 10516, 10525, 10531, 10565, 10593, 10612, 10680, 10772, 10787,
200+
10791, 10827, 10914, 10925, 10943, 10960, 11024, 11056, 11097, 11117,
201+
11222, 11302, 11366, 11420, 11479, 11535, 11595, 11601, 11643, 11647,
202+
11650, 11660, 11675, 11686, 11724, 11787, 11833, 11838, 11845, 11850,
203+
11869, 11879, 11886, 11894, 11908, 11924, 11931, 11939, 11947, 11995,
204+
12004, 12015, 12065, 12076, 12086, 12105, 12121, 12134, 12146, 12165,
205+
12199, 12208, 12220, 12232, 12236, 12242, 12248, 12260, 12271, 12280,
206+
12286, 12300, 12318, 12329, 12371, 12422, 12472, 12528, 12541, 12554,
207+
12617, 12677, 12738, 12803, 12874, 12939, 13008, 13083, 13150, 13229,
208+
13303, 13317, 13332, 13377, 13390, 13418, 13432, 13445, 13461, 13477,
209+
13489, 13531, 13543, 13554, 13589, 13604, 13616, 13633, 13641, 13679,
210+
13692, 13707, 13827, 13873, 13917, 13957, 13981, 14022, 14061, 14081,
211+
14097, 14115, 14127, 14141, 14149, 14160, 14177, 14190, 14245, 14246,
212+
14247, 14248, 14287, 14293, 14298, 14303, 14308, 14314, 14321, 14327,
213+
14336, 14342, 14350, 14356, 14363, 14372, 14380, 14389, 14401, 14410,
214+
14418, 14429, 14440, 14449, 14459, 14466, 14516, 14550, 14559, 14571,
215+
14582, 14621, 14632, 14646, 14663, 14675, 14688, 14702, 14717, 14730,
216+
14751, 14759, 14778, 14787, 14799, 14810, 14824, 14839, 14852, 14866,
217+
14879, 14893, 14908, 14926, 14946, 14958, 14978, 14991, 15006, 15020,
218+
15038, 15054, 15068, 15081, 15098, 15118, 15135, 15153, 15168, 15182,
219+
15198, 15209, 15225, 15238, 15253, 15268, 15314, 15328, 15337, 15347,
220+
15360, 15374, 15385, 15398, 15414, 15429, 15430, 15457, 15463, 15471,
221+
15477, 15493, 15530, 15547, 15571, 15594, 15611, 15631, 15657, 15683,
222+
15702, 15719, 15772, 15813, 15835, 15862, 15882, 15903, 15921, 15951,
223+
15977, 15997, 16018, 16036, 16054, 16073, 16089, 16105, 16133, 16159,
224+
16166, 16168, 16169, 16201
229225
};
230226

231-
#define NR_RECS 16200
227+
#define NR_RECS 16201
232228
#define WORST_RECS_PER_CCODE 195 // 8 Argentina @43
233229

234230
typedef struct { long minx; long miny; long maxx; long maxy; unsigned long flags; } mminforec;
@@ -242,7 +238,7 @@ static const mminforec mminfo[NR_RECS+1] = {
242238
{-5200000, 41310000, 9600000, 53557000, 0x0010216},
243239
{7404110, 43723932, 7444472, 43752762, 0x003021c},
244240
{-5384925, 36107682, -5321499, 36159576, 0x001000b},
245-
{-6703000, 35867000, -3426000, 38475972, 0x0a63091},
241+
{-6703000, 35867000, -3426000, 38475972, 0x0a63291},
246242
{-5384925, 36107682, -5321499, 36159576, 0x003021c},
247243
{-172537866, -8601181, -172450415, -8514691, 0x001000a},
248244
{-171996267, -9340159, -171646464, -8994200, 0xf04004b},
@@ -415,7 +411,7 @@ static const mminforec mminfo[NR_RECS+1] = {
415411
{14043750, 78045711, 14328250, 78106820, 0x2a7004a},
416412
{-9164930, 70754480, -7779602, 71245520, 0x001000c},
417413
{10400000, 76889405, 22024500, 79500000, 0x0a50011},
418-
{-9154000, 68600000, 33625000, 80843100, 0x0970012},
414+
{-9154000, 68600000, 33625000, 80843100, 0x0970212},
419415
{10000000, 74300000, 33624989, 80843000, 0x0010016},
420416
{-9165000, 70754400, 33625000, 80843100, 0x003021c},
421417
{-61257000, 13122000, -61139000, 13183000, 0x016000a},
@@ -449,7 +445,7 @@ static const mminforec mminfo[NR_RECS+1] = {
449445
{144875000, 14080000, 146076000, 20560000, 0x18d0011},
450446
{1482182, 42461955, 1598463, 42548445, 0x001000a},
451447
{1404864, 42394488, 1795464, 42694568, 0x001000c},
452-
{348000, 40191933, 3820000, 42873123, 0x0a90091},
448+
{348000, 40191933, 3820000, 42873123, 0x0a90291},
453449
{1404864, 42394488, 1795464, 42694568, 0x003021c},
454450
{144826158, 13521379, 144888964, 13582488, 0x2a7004a},
455451
{144737755, 13449545, 144800561, 13510654, 0x2a7004a},
@@ -500,7 +496,7 @@ static const mminforec mminfo[NR_RECS+1] = {
500496
{50575813, 26194782, 50623592, 26281272, 0x2a7044a},
501497
{50310000, 25788000, 50745000, 26338000, 0x023000c},
502498
{50448000, 25557000, 50825000, 25967000, 0x0bd0010},
503-
{50310000, 25557000, 50825000, 26338000, 0x0da0211},
499+
{50300000, 25557000, 50825000, 26338000, 0x0d80211},
504500
{172918000, 1324000, 173080000, 1365000, 0x00f000a},
505501
{172778000, 1323000, 173172000, 1974000, 0x026000c},
506502
{-157502976, 1911168, -157353217, 2060927, 0x680004b},
@@ -7315,6 +7311,7 @@ static const mminforec mminfo[NR_RECS+1] = {
73157311
{-5200000, 41310000, 9600000, 51100000, 0x003021c},
73167312
{19474000, 59973000, 20400000, 60464000, 0x001000c},
73177313
{20400000, 59900000, 21118800, 60536000, 0x0e40010},
7314+
{-9154000, 68600000, 33625000, 80843100, 0x0970012},
73187315
{4490000, 54544000, 31600000, 68600000, 0x3770016},
73197316
{19100000, 59675750, 21134000, 60671833, 0x003021c},
73207317
{36798377, -1311622, 36884867, -1225132, 0x001000a},

mapcodelib/mapcoder.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ static double extrax,extray;
323323
static void decodeExtension(long *nx,long *ny, long dividerx4,long dividery,int ydirection) // add extra precision to a coordinate based on extra chars
324324
{
325325
#ifndef VERSION160 // old integer-arithmetic version
326-
// long extrax,extray;
326+
long extrax,extray;
327327
if (*extrapostfix) {
328328
int column1,row1,column2,row2,c1,c2;
329329
c1 = extrapostfix[0];
330-
c1 = decode_chars[c1];
330+
c1 = decode_chars[(unsigned int)c1];
331331
if (c1<0) c1=0; else if (c1>29) c1=29;
332332
row1 =(c1/5); column1 = (c1%5);
333333
c2 = (extrapostfix[1]) ? extrapostfix[1] : 72; // 72='H'=code 15=(3+2*6)
334-
c2 = decode_chars[c2];
334+
c2 = decode_chars[(unsigned int)c2];
335335
if (c2<0) c2=0; else if (c2>29) c2=29;
336336
row2 =(c2/6); column2 = (c2%6);
337337

@@ -356,11 +356,11 @@ static void decodeExtension(long *nx,long *ny, long dividerx4,long dividery,int
356356
int column1,row1,column2,row2;
357357
double halfcolumn=0;
358358
int c1 = *extrapostfix++;
359-
c1 = decode_chars[c1];
359+
c1 = decode_chars[(unsigned int)c1];
360360
if (c1<0) c1=0; else if (c1>29) c1=29;
361361
row1 =(c1/5); column1 = (c1%5);
362362
if (*extrapostfix) {
363-
int c2 = decode_chars[(int)*extrapostfix++];
363+
int c2 = decode_chars[(unsigned int)*extrapostfix++];
364364
if (c2<0) c2=0; else if (c2>29) c2=29;
365365
row2 =(c2/6); column2 = (c2%6);
366366
}
@@ -458,7 +458,7 @@ static long decodeBase31( const char *code )
458458
long value=0;
459459
while (*code!='.' && *code!=0 )
460460
{
461-
value = value*31 + decode_chars[(int)*code++];
461+
value = value*31 + decode_chars[(unsigned int)*code++];
462462
}
463463
return value;
464464
}
@@ -488,7 +488,7 @@ static void encode_triple( char *result, long difx,long dify )
488488
static void decode_triple( const char *result, long *difx, long *dify )
489489
{
490490
// decode the first character
491-
int c1 = decode_chars[(int)*result++];
491+
int c1 = decode_chars[(unsigned int)*result++];
492492
if ( c1<24 )
493493
{
494494
long m = decodeBase31(result);
@@ -999,7 +999,7 @@ static int decodeNameless( const char *orginput, long *x, long *y, int i
999999
// now determine X = index of first area, and SIDE
10001000
if ( codex!=21 && A<=31 )
10011001
{
1002-
int offset = decode_chars[(int)*result];
1002+
int offset = decode_chars[(unsigned int)*result];
10031003

10041004
if ( offset < r*(p+1) )
10051005
{
@@ -1014,7 +1014,7 @@ static int decodeNameless( const char *orginput, long *x, long *y, int i
10141014
else if ( codex!=21 && A<62 )
10151015
{
10161016

1017-
X = decode_chars[(int)*result];
1017+
X = decode_chars[(unsigned int)*result];
10181018
if ( X < (62-A) )
10191019
{
10201020
swapletters=(codex==22);
@@ -1165,15 +1165,15 @@ static int unpack_if_alldigits(char *input) // returns 1 if unpacked, 0 if left
11651165
break;
11661166
else if (*s=='.' && !dotpos)
11671167
dotpos=s;
1168-
else if ( decode_chars[(int)*s]<0 || decode_chars[(int)*s]>9 )
1168+
else if ( decode_chars[(unsigned int)*s]<0 || decode_chars[(unsigned int)*s]>9 )
11691169
return 0; // nondigit, so stop
11701170
}
11711171

11721172
if (dotpos)
11731173
{
11741174
if (aonly) // v1.50 encoded only with A's
11751175
{
1176-
int v = (s[0]=='A' || s[0]=='a' ? 31 : decode_chars[(int)s[0]]) * 32 + (s[1]=='A' || s[1]=='a' ? 31 : decode_chars[(int)s[1]]);
1176+
int v = (s[0]=='A' || s[0]=='a' ? 31 : decode_chars[(unsigned int)s[0]]) * 32 + (s[1]=='A' || s[1]=='a' ? 31 : decode_chars[(unsigned int)s[1]]);
11771177
*input = '0'+(v/100);
11781178
s[0]= '0'+((v/10)%10);
11791179
s[1]= '0'+(v%10);
@@ -1191,13 +1191,13 @@ static int unpack_if_alldigits(char *input) // returns 1 if unpacked, 0 if left
11911191
if (*e=='a' || *e=='A') v+=31;
11921192
else if (*e=='e' || *e=='E') v+=32;
11931193
else if (*e=='u' || *e=='U') v+=33;
1194-
else if (decode_chars[(int)*e]<0) return -9; // invalid last character!
1195-
else v+=decode_chars[(int)*e];
1194+
else if (decode_chars[(unsigned int)*e]<0) return -9; // invalid last character!
1195+
else v+=decode_chars[(unsigned int)*e];
11961196

11971197
if (v<100)
11981198
{
1199-
*s = encode_chars[(int)v/10];
1200-
*e = encode_chars[(int)v%10];
1199+
*s = encode_chars[(unsigned int)v/10];
1200+
*e = encode_chars[(unsigned int)v%10];
12011201
}
12021202
return 1;
12031203
}
@@ -1430,9 +1430,9 @@ static int master_decode( long *nx,long *ny, // <- store result in nx,ny
14301430
{
14311431
if (*s=='.')
14321432
{ if (dot) return -5; else dot=s; }
1433-
else if ( decode_chars[(int)*s]<0 )
1433+
else if ( decode_chars[(unsigned int)*s]<0 )
14341434
return -4; // invalid char
1435-
else if ( decode_chars[(int)*s]<10 ) // digit?
1435+
else if ( decode_chars[(unsigned int)*s]<10 ) // digit?
14361436
nrd++;
14371437
}
14381438
if (dot==NULL)
@@ -2721,7 +2721,7 @@ int encodeLatLonToMapcodes_full( char **v, double lat, double lon, int tc, int s
27212721
int i;
27222722
for(i=0;i<MAX_MAPCODE_TERRITORY_CODE;i++) {
27232723
master_encode(NULL,i,lon32,lat32,-1,stop_with_one_result,0,0); // 1.29 - also add parents recursively
2724-
if ((stop_with_one_result||debugStopAt) && nr_global_results>0) break;
2724+
if ((stop_with_one_result||debugStopAt>=0) && nr_global_results>0) break;
27252725
}
27262726
}
27272727
else

0 commit comments

Comments
 (0)