Skip to content

Commit bce27b4

Browse files
2.2. Solved 1-microdegree gap in a few spots on Earth, noticable now extreme precision is possible
1 parent 6d52362 commit bce27b4

File tree

7 files changed

+16748
-16735
lines changed

7 files changed

+16748
-16735
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ decode Mapcodes.
5959

6060
# Release Notes
6161

62+
* 2.2
63+
64+
Solved 1-microdegree gap in a few spots on Earth, noticable now extreme precision is possible
65+
6266
* 2.1.5
6367

6468
Added stricter unit tests

mapcodelib/basics.h

Lines changed: 16492 additions & 16469 deletions
Large diffs are not rendered by default.

mapcodelib/mapcode_fast_encode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
// *** GENERATED FILE, DO NOT CHANGE OR PRETTIFY ***
1718
static int redivar[2924] = {
1819
27984500, 1383,
1920
2537718, 676,
@@ -712,4 +713,4 @@ static int redivar[2924] = {
712713
125763055, 2914,
713714
7, 468, 469, 476, 478, 485, 494, 496,
714715
8, 393, 410, 486, 487, 488, 492, 494, 496,
715-
0}; //2924
716+
0}; // 2924 records, data version 2.2

mapcodelib/mapcoder.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,10 +1346,8 @@ static void encoderEngine(const int ccode, const encodeRec *enc, const int stop_
13461346
from = firstrec(ccode);
13471347
upto = lastrec(ccode);
13481348

1349-
if (ccode != ccode_earth) {
1350-
if (!fitsInside(&enc->coord32, upto)) {
1351-
return;
1352-
}
1349+
if (!fitsInside(&enc->coord32, upto)) {
1350+
return;
13531351
}
13541352

13551353
///////////////////////////////////////////////////////////
@@ -1393,7 +1391,7 @@ static void encoderEngine(const int ccode, const encodeRec *enc, const int stop_
13931391

13941392
if (requiredEncoder < 0 || requiredEncoder == i) {
13951393
const int cc = (ccode_override >= 0 ? ccode_override : ccode);
1396-
if (*result && enc->mapcodes && enc->mapcodes->count < MAX_NR_OF_MAPCODE_RESULTS) {
1394+
if (*result && enc->mapcodes && (enc->mapcodes->count < MAX_NR_OF_MAPCODE_RESULTS)) {
13971395
char *s = enc->mapcodes->mapcode[enc->mapcodes->count++];
13981396
if (cc == ccode_earth) {
13991397
strcpy(s, result);
@@ -1584,11 +1582,7 @@ static int decoderEngine(decodeRec *dec) {
15841582
err = decodeGrid(dec, i, 0);
15851583

15861584
// first of all, make sure the zone fits the country
1587-
if ((err == 0) && (ccode != ccode_earth)) {
1588-
if (!restrictZoneTo(&dec->zone, &dec->zone, boundaries(upto))) {
1589-
err = -2999;
1590-
}
1591-
}
1585+
restrictZoneTo(&dec->zone, &dec->zone, boundaries(upto));
15921586

15931587
if ((err == 0) && isRestricted(i)) {
15941588
int nrZoneOverlaps = 0;
@@ -1659,9 +1653,7 @@ static int decoderEngine(decodeRec *dec) {
16591653
} // for
16601654
}
16611655

1662-
if (ccode != ccode_earth) {
1663-
restrictZoneTo(&dec->zone, &dec->zone, boundaries(lastrec(ccode)));
1664-
}
1656+
restrictZoneTo(&dec->zone, &dec->zone, boundaries(lastrec(ccode)));
16651657

16661658
if (isEmpty(&dec->zone)) {
16671659
err = -2222;
@@ -1990,24 +1982,23 @@ static int encodeLatLonToMapcodes_internal(char **v, Mapcodes *mapcodes, double
19901982
if (tc <= 0) // ALL results?
19911983
{
19921984
#ifdef FAST_ENCODE
1993-
int HOR = 1;
1985+
const int sum = enc.coord32.lon + enc.coord32.lat;
1986+
int coord = enc.coord32.lon;
19941987
int i = 0; // pointer into redivar
19951988
for (; ;) {
1996-
const int v2 = redivar[i++];
1997-
HOR = 1 - HOR;
1998-
if (v2 >= 0 && v2 < 1024) { // leaf?
1989+
const int r = redivar[i++];
1990+
if (r >= 0 && r < 1024) { // leaf?
19991991
int j;
2000-
const int nr = v2;
2001-
for (j = 0; j <= nr; j++) {
2002-
int ctry = (j == nr ? ccode_earth : redivar[i + j]);
1992+
for (j = 0; j <= r; j++) {
1993+
const int ctry = (j == r ? ccode_earth : redivar[i + j]);
20031994
encoderEngine(ctry, &enc, stop_with_one_result, extraDigits, requiredEncoder, -1);
20041995
if ((stop_with_one_result || requiredEncoder >= 0) && enc.mapcodes->count > 0) { break; }
20051996
}
20061997
break;
20071998
}
20081999
else {
2009-
const int coord = (HOR ? enc.coord32.lon : enc.coord32.lat);
2010-
if (coord > v2) {
2000+
coord = sum - coord;
2001+
if (coord > r) {
20112002
i = redivar[i];
20122003
}
20132004
else {

mapcodelib/mapcoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
extern "C" {
1919
#endif
2020

21-
#define mapcode_cversion "2.1.5"
21+
#define mapcode_cversion "2.2"
2222

2323
#define UWORD unsigned short int // 2-byte unsigned integer.
2424

2525
#define SUPPORT_FOREIGN_ALPHABETS // Define to support additional alphabets.
2626
#define SUPPORT_HIGH_PRECISION // Define to enable high-precision extension logic.
2727
#define FORCE_RECODE // Define to enforce that encode(decode(M)) generates M
2828

29-
#define MAX_NR_OF_MAPCODE_RESULTS 21 // Max. number of results ever returned by encoder (e.g. for 26.904899, 95.138515).
29+
#define MAX_NR_OF_MAPCODE_RESULTS 22 // Max. number of results ever returned by encoder (e.g. for 26.904899, 95.138515).
3030
#define MAX_PROPER_MAPCODE_LEN 10 // Max. number of characters in a proper mapcode (including the dot).
3131
#define MAX_PRECISION_DIGITS 8 // Max. number of extension characters (excluding the hyphen). Must be even.
3232
#define MAX_PRECISION_FACTOR 810000 // 30 to the power (MAX_PRECISION_DIGITS/2)

0 commit comments

Comments
 (0)