Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions mapcodelib/mapcoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static const char *get_entity_iso3(char *entity_iso3_result, int ccode) {

static void makeupper(char *s)
{
for(;*s;*s++) { *s = toupper(*s); }
while(*s) { *s = (char) toupper(*s); s++; }
}

static int disambiguate_str(const char *s, const int len) // returns disambiguation 1-8, or negative if error
Expand Down Expand Up @@ -829,7 +829,7 @@ static int decodeNameless(decodeRec *dec, int m) {
{
const int p = 31 / A;
const int r = 31 % A;
int v;
int v = 0;
int SIDE;
int swapletters = 0;
int xSIDE;
Expand Down Expand Up @@ -1250,7 +1250,8 @@ static void encodeAutoHeader(char *result, const encodeRec *enc, const int m, co
firstindex--;
}

for (i = firstindex; i <= m; i++) {
i = firstindex;
for(;;) {
b = boundaries(i);
// determine how many cells
H = (b->maxy - b->miny + 89) / 90; // multiple of 10m
Expand All @@ -1265,37 +1266,36 @@ static void encodeAutoHeader(char *result, const encodeRec *enc, const int m, co
const int GOODROUNDER = codexm >= 23 ? (961 * 961 * 31) : (961 * 961);
product = ((STORAGE_START + product + GOODROUNDER - 1) / GOODROUNDER) * GOODROUNDER - STORAGE_START;
}
if (i < m) {
STORAGE_START += product;
}
}

{
// encode
const int dividerx = (b->maxx - b->minx + W - 1) / W;
const int vx = (enc->coord32.lon - b->minx) / dividerx;
const int extrax = (enc->coord32.lon - b->minx) % dividerx;
if (i == m) {
// encode
const int dividerx = (b->maxx - b->minx + W - 1) / W;
const int vx = (enc->coord32.lon - b->minx) / dividerx;
const int extrax = (enc->coord32.lon - b->minx) % dividerx;

const int dividery = (b->maxy - b->miny + H - 1) / H;
int vy = (b->maxy - enc->coord32.lat) / dividery;
int extray = (b->maxy - enc->coord32.lat) % dividery;
const int dividery = (b->maxy - b->miny + H - 1) / H;
int vy = (b->maxy - enc->coord32.lat) / dividery;
int extray = (b->maxy - enc->coord32.lat) % dividery;

const int codexlen = (codexm / 10) + (codexm % 10);
int value = (vx / 168) * (H / 176);
const int codexlen = (codexm / 10) + (codexm % 10);
int value = (vx / 168) * (H / 176);

if (extray == 0 && enc->fraclat > 0) {
vy--;
extray += dividery;
}
if (extray == 0 && enc->fraclat > 0) {
vy--;
extray += dividery;
}

value += (vy / 176);
value += (vy / 176);

// PIPELETTER ENCODE
encodeBase31(result, (STORAGE_START / (961 * 31)) + value, codexlen - 2);
result[codexlen - 2] = '.';
encode_triple(result + codexlen - 1, vx % 168, vy % 176);
// PIPELETTER ENCODE
encodeBase31(result, (STORAGE_START / (961 * 31)) + value, codexlen - 2);
result[codexlen - 2] = '.';
encode_triple(result + codexlen - 1, vx % 168, vy % 176);

encodeExtension(result, extrax << 2, extray, dividerx << 2, dividery, extraDigits, -1, enc); // autoheader
encodeExtension(result, extrax << 2, extray, dividerx << 2, dividery, extraDigits, -1, enc); // autoheader
return;
}
STORAGE_START += product;
i++;
}
}

Expand Down Expand Up @@ -1391,7 +1391,7 @@ static int decoderEngine(decodeRec *dec) {
int hasvowels = 0;
int hasletters = 0;
const char *dot = NULL;
int prelen;
int prelen = 0;
int len;
char *w;
// skip whitesace
Expand Down Expand Up @@ -2062,7 +2062,7 @@ int binfindmatch(int parentcode, const char *str) {
char tmp[5];
if (parentcode < 0) { return -1; }
if (parentcode > 0) {
tmp[0] = '0' + parentcode;
tmp[0] = (char) ('0' + parentcode);
memcpy(tmp + 1, str, 3);
} else {
memcpy(tmp, str, 4);
Expand Down
38 changes: 23 additions & 15 deletions unitttest/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,22 @@ static void testEncodeAndDecode(const char *str, double y, double x, int localso
printf("*** ERROR *** encode(%0.8f , %0.8f,%d) does not deliver %d solutions\n", y, x, tc, localsolutions);
printGeneratedMapcodes(&mapcodes);
}
}

// test that EXPECTED solution is there (if requested)
if (str && localsolutions) {
nrTests++;
for (i = 0; i < nrresults; i++) {
const char *m = mapcodes.mapcode[i];
if (strstr(m, clean) == m) {
found = 1;
break;
// test that EXPECTED solution is there (if requested)
if (str) {
nrTests++;
for (i = 0; i < nrresults; i++) {
const char *m = mapcodes.mapcode[i];
if (strstr(m, clean) == m) {
found = 1;
break;
}
}
if (!found) {
nrErrors++;
printf("*** ERROR *** encode(%0.8f , %0.8f) does not deliver \"%s\"\n", y, x, clean);
printGeneratedMapcodes(&mapcodes);
}
}
if (!found) {
nrErrors++;
printf("*** ERROR *** encode(%0.8f , %0.8f) does not deliver \"%s\"\n", y, x, clean);
printGeneratedMapcodes(&mapcodes);
}
}

Expand Down Expand Up @@ -398,6 +398,15 @@ void test_territory(const char *alphaCode, int tc, int isAlias, int needsParent,
char alphacode[8];
int tn;
strcpy(alphacode, alphaCode);
if (!needsParent && i==0) {
tn = convertTerritoryIsoNameToCode(alphacode, 0);
nrTests++;
if (tn != tc) {
nrErrors++;
printf("*** ERROR *** convertTerritoryIsoNameToCode('%s')=%d but expected %d (%s)\n",
alphacode, tn, tc, convertTerritoryCodeToIsoName(tc,0) );
}
}
alphacode[i] = (char) tolower(alphacode[i]);
tn = convertTerritoryIsoNameToCode(alphacode, tcParent);
nrTests++;
Expand Down Expand Up @@ -443,7 +452,6 @@ static void re_encode_tests() {
int nrrecords = lastrec(ccode_earth) + 1;
printf("%d records\n", nrrecords);
for (ccode = 0; ccode <= ccode_earth; ccode++) {
int tc = (ccode + 1);
for (m = firstrec(ccode); m <= lastrec(ccode); m++) {
double y, x, midx, midy;
const mminforec *b = boundaries(m);
Expand Down