[mapcode] 01/18: Moved to 1.40 and fixed warnings

Stefan Fritsch sf at moszumanska.debian.org
Wed Nov 2 23:27:20 UTC 2016


This is an automated email from the git hooks/post-receive script.

sf pushed a commit to annotated tag v1.40
in repository mapcode.

commit 94f0021190cbe849a9ccb8ae705fa98f9364f7f2
Author: Rijn Buve <rijn at buve.nl>
Date:   Wed Sep 17 10:51:13 2014 +0200

    Moved to 1.40 and fixed warnings
---
 README                |  28 +++++--------
 example/mapcode.cpp   | 113 +++++++++++++++++++++++---------------------------
 mapcode_library.doc   | Bin 65536 -> 86528 bytes
 mapcodelib/basics.h   |  18 +-------
 mapcodelib/mapcoder.c |  33 ++++++++-------
 mapcodelib/mapcoder.h |  19 ++++++---
 6 files changed, 93 insertions(+), 118 deletions(-)

diff --git a/README b/README
index 5291e09..8e9be4d 100644
--- a/README
+++ b/README
@@ -34,7 +34,7 @@ Documentation, including example snippets of C source code, can be found in
 
 Also see www.mapcode.com for background and reference materials.
 
-Note: this version may be restricted to a particular area of the Earthas!
+Note: this version may be restricted to a particular area of the Earth!
 In that case, basics.h will state a version number of the for:
 	#define mapcode_cversion "1.2xxx"
 where "xxx" states the geographical limitation.
@@ -49,7 +49,7 @@ of how to use the library.
 To build the original Mapcode tool, execute:
 
   cd example
-  gcc mapcode.cpp -o mapcode
+  gcc mapcode.c -o mapcode
 
 For help, simply execute the binary file 'mapcode' without no arguments.
 This tool provides a rather extensive command-line interface to encode and
@@ -60,43 +60,35 @@ decode Mapcodes.
 MAPCODE LIBRARY - RELEASE NOTES
 -------------------------------------------------------------------------------
 
-1.33
+1.40
+    Added extraDigits parameter to allow high-precision mapcodes to be generated.
 
-    Fix to not remove valid results just across the edge of a territory. Improved
-    interface readability and renamed methods to more readable forms. Removed
-    several warnings produced by GCC.
+1.33
+    Fix to not remove valid results just across the edge of a territory. Improved interface readability
+    and renamed methods to more readable forms.
 
 1.32
-
-    Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative is
-    produced in edge cases; prevent FIJI failing to decode at exactly 180 degrees.
+    Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative is produced in edge cases; prevent FIJI failing to
+    decode at exactly 180 degrees.
 
 1.31
-
     Added compareWithMapcodeFormat().
 
 1.30
-
     IUpdated the documentation and extended it with examples and suggestions.
 
 1.29
-
     Also generate country-wide alternative mapcodes for states.
 
 1.28
-
-    Bug fix for the needless generation of 7-letter alternatives to short mapcodes
-    in large states in India.
+    Bug fix for the needless generation of 7-letter alternatives to short mapcodes in large states in India.
 
 1.27
-
     Improved (faster) implementation of the function isInArea.
 
 1.26
-
     Added alias OD ("Odisha") for indian state OR ("Orissa").
 
 1.25
-
     Initial release to the public domain.
 
diff --git a/example/mapcode.cpp b/example/mapcode.cpp
index d78fd4d..d8f8cb9 100644
--- a/example/mapcode.cpp
+++ b/example/mapcode.cpp
@@ -1,17 +1,6 @@
-/*
- * Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/**
+ * Copyright (C) 2014 Stichting Mapcode Foundation
+ * For terms of use refer to http://www.mapcode.com/downloads.html
  */
 
 /**
@@ -42,7 +31,6 @@
 #define my_isnan(x) (false)
 #define my_round(x) ((long) (floor((x) + 0.5)))
 
-
 static const char*  VERSION             = "1";
 static const int    SELF_CHECK          = 1;
 static const int    SELF_CHECK_EXIT     = 0;
@@ -91,7 +79,7 @@ static void usage(const char* appName) {
     printf("       encoding will only succeeed if the lat/lon is located in the territory.\n");
     printf("\n");
     printf("    %s [-b | --boundaries]\n", appName);
-    printf("    %s [-g | --grid] <nrOfPoints>\n", appName);
+    printf("    %s [-g | --grid] <nrOfPoints> [<extraDigits>]\n", appName);
     printf("    %s [-r | --random] <nrOfPoints> [<seed>]\n", appName);
     printf("\n");
     printf("       Create a test set of lat/lon pairs based on the Mapcode boundaries database\n");
@@ -183,12 +171,12 @@ static void convertLatLonToXYZ(double latDeg, double lonDeg, double* x, double*
 /**
  * This methods provides a self check for encoding lat/lon to Mapcode.
  */
-static void selfCheckLatLonToMapcode(const double lat, double lon, const char* territory, const char* mapcode) {
+static void selfCheckLatLonToMapcode(const double lat, double lon, const char* territory, const char* mapcode, int extraDigits) {
     int context = convertTerritoryIsoNameToCode(territory, 0);
     char* results[MAX_NR_OF_MAPCODE_RESULTS];
     const double limitLat = (lat < -90.0) ? -90.0 : ((lat > 90.0) ? 90.0 : lat);
     const double limitLon = (lon < -180.0) ? -180.0 : ((lon > 180.0) ? 180.0 : lon);
-    const int nrResults = encodeLatLonToMapcodes(results, limitLat, limitLon, context);
+    const int nrResults = encodeLatLonToMapcodes(results, limitLat, limitLon, context, extraDigits);
     if (nrResults <= 0) {
         fprintf(stderr, "internal error: encoding lat/lon to Mapcode failure; "
             "cannot encode lat=%f, lon=%f (default territory=%s)\n",
@@ -256,7 +244,7 @@ static void selfCheckMapcodeToLatLon(const char* territory, const char* mapcode,
 
 /**
  * The method asCoordinate() generates and returns a printable coordinate
- * precisely as it would be interpreted internally by Mapcode encoding
+ * precisely as it would be interpreted internally by mapcode encoding
  * (i.e. correctly rounded to the nearest one-millionth of a degree).
  * As target, pass a buffer for at least 12 characters (including zero termination).
  * If target = 0, an internal scratch buffer is used (the THIRD call will
@@ -272,8 +260,8 @@ static const char* asCoordinate(double coord, char* target)
         c = -c;
     }
     if (target == 0) {
-        target = &asCoordinateBuffer[ascoptr];
         ascoptr= ((ascoptr != 0) ? 0 : 12);
+        target = &asCoordinateBuffer[ascoptr];
     }
     sprintf(target,"%s%d.%06d", (negative ? "-" : ""), (int) (c / 1000000), (int) (c % 1000000));
     return target;
@@ -285,25 +273,25 @@ static const char* asCoordinate(double coord, char* target)
  * If iShowError != 0, then encoding errors are output to stderr, otherwise they
  * are ignored.
  */
-static void generateAndOutputMapcodes(double lat, double lon, int iShowError) {
+static void generateAndOutputMapcodes(double lat, double lon, int iShowError, int extraDigits) {
 
     char* results[MAX_NR_OF_MAPCODE_RESULTS];
     int context = 0;
 
-	while (lon > 180) {
-		lon -= 360;
-	}
-	while (lon < -180) {
-		lon += 360;
-	}
-	while (lat > 90) {
-		lat -= 180;
-	}
-	while (lat < -90) {
-		lat += 180;
-	}
-
-    const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context);
+    while (lon > 180) {
+        lon -= 360;
+    }
+    while (lon < -180) {
+        lon += 360;
+    }
+    while (lat > 90) {
+        lat -= 180;
+    }
+    while (lat < -90) {
+        lat += 180;
+    }
+
+    const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context, extraDigits);
     if (nrResults <= 0) {
         if (iShowError) {
             fprintf(stderr, "error: cannot encode lat=%s, lon=%s)\n", asCoordinate(lat, 0), asCoordinate(lon, 0));
@@ -325,7 +313,7 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError) {
 
         // Self-checking code to see if encoder produces this Mapcode for the lat/lon.
         if (SELF_CHECK) {
-            selfCheckLatLonToMapcode(lat, lon, foundTerritory, foundMapcode);
+            selfCheckLatLonToMapcode(lat, lon, foundTerritory, foundMapcode, extraDigits);
             selfCheckMapcodeToLatLon(foundTerritory, foundMapcode, lat, lon);
         }
     }
@@ -387,6 +375,9 @@ static void showProgress(int i) {
  */
 int main(const int argc, const char** argv)
 {
+    // Assume no extra digits (unless overridden later
+    int extraDigits=0;
+
     // Provide usage message if no arguments specified.
     const char* appName = argv[0];
     if (argc < 2) {
@@ -430,7 +421,7 @@ int main(const int argc, const char** argv)
 
             // Self-checking code to see if encoder produces this Mapcode for the lat/lon.
             if (SELF_CHECK) {
-                selfCheckLatLonToMapcode(lat, lon, defaultTerritory, mapcode);
+                selfCheckLatLonToMapcode(lat, lon, defaultTerritory, mapcode, extraDigits);
             }
         }
     }
@@ -462,7 +453,7 @@ int main(const int argc, const char** argv)
 
         // Encode the lat/lon to a set of Mapcodes.
         char* results[MAX_NR_OF_MAPCODE_RESULTS];
-        const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context);
+        const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context, extraDigits);
         if (nrResults <= 0) {
             fprintf(stderr, "error: cannot encode lat=%f, lon=%f (default territory=%s)\n",
                 lat, lon, defaultTerritory);
@@ -516,37 +507,37 @@ int main(const int argc, const char** argv)
             lon = (maxLon - minLon ) / 2.0;
 
             // Try center.
-            generateAndOutputMapcodes(lat, lon, 0);
+            generateAndOutputMapcodes(lat, lon, 0, extraDigits);
 
             // Try corners.
-            generateAndOutputMapcodes(minLat, minLon, 0);
-            generateAndOutputMapcodes(minLat, maxLon, 0);
-            generateAndOutputMapcodes(maxLat, minLon, 0);
-            generateAndOutputMapcodes(maxLat, maxLon, 0);
+            generateAndOutputMapcodes(minLat, minLon, 0, extraDigits);
+            generateAndOutputMapcodes(minLat, maxLon, 0, extraDigits);
+            generateAndOutputMapcodes(maxLat, minLon, 0, extraDigits);
+            generateAndOutputMapcodes(maxLat, maxLon, 0, extraDigits);
 
             // Try JUST inside.
             double factor = 1.0;
             for (int j = 1; j < 6; ++j) {
 
                 double d = 1.0 / factor;
-                generateAndOutputMapcodes(minLat + d, minLon + d, 0);
-                generateAndOutputMapcodes(minLat + d, maxLon - d, 0);
-                generateAndOutputMapcodes(maxLat - d, minLon + d, 0);
-                generateAndOutputMapcodes(maxLat - d, maxLon - d, 0);
+                generateAndOutputMapcodes(minLat + d, minLon + d, 0, extraDigits);
+                generateAndOutputMapcodes(minLat + d, maxLon - d, 0, extraDigits);
+                generateAndOutputMapcodes(maxLat - d, minLon + d, 0, extraDigits);
+                generateAndOutputMapcodes(maxLat - d, maxLon - d, 0, extraDigits);
 
                 // Try JUST outside.
-                generateAndOutputMapcodes(minLat - d, minLon - d, 0);
-                generateAndOutputMapcodes(minLat - d, maxLon + d, 0);
-                generateAndOutputMapcodes(maxLat + d, minLon - d, 0);
-                generateAndOutputMapcodes(maxLat + d, maxLon + d, 0);
+                generateAndOutputMapcodes(minLat - d, minLon - d, 0, extraDigits);
+                generateAndOutputMapcodes(minLat - d, maxLon + d, 0, extraDigits);
+                generateAndOutputMapcodes(maxLat + d, minLon - d, 0, extraDigits);
+                generateAndOutputMapcodes(maxLat + d, maxLon + d, 0, extraDigits);
                 factor = factor * 10.0;
             }
 
             // Try 22m outside.
-            generateAndOutputMapcodes(minLat - 22, (maxLon - minLon) / 2, 0);
-            generateAndOutputMapcodes(minLat - 22, (maxLon - minLon) / 2, 0);
-            generateAndOutputMapcodes(maxLat + 22, (maxLon - minLon) / 2, 0);
-            generateAndOutputMapcodes(maxLat + 22, (maxLon - minLon) / 2, 0);
+            generateAndOutputMapcodes(minLat - 22, (maxLon - minLon) / 2, 0, extraDigits);
+            generateAndOutputMapcodes(minLat - 22, (maxLon - minLon) / 2, 0, extraDigits);
+            generateAndOutputMapcodes(maxLat + 22, (maxLon - minLon) / 2, 0, extraDigits);
+            generateAndOutputMapcodes(maxLat + 22, (maxLon - minLon) / 2, 0, extraDigits);
 
             if ((i % SHOW_PROGRESS) == 0) {
                 showProgress(i);
@@ -558,7 +549,7 @@ int main(const int argc, const char** argv)
         (strcmp(cmd, "-r") == 0) || (strcmp(cmd, "--random") == 0)) {
 
         // ------------------------------------------------------------------
-        // Generate grid test set:    [-g | --grid]   <nrOfPoints>
+        // Generate grid test set:    [-g | --grid]   <nrOfPoints> [<extradigits>]
         // Generate uniform test set: [-r | --random] <nrOfPoints> [<seed>]
         // ------------------------------------------------------------------
         if ((argc < 3) || (argc > 4)) {
@@ -583,10 +574,8 @@ int main(const int argc, const char** argv)
             }
         }
         else {
-            if (argc > 3) {
-                fprintf(stderr, "error: cannot specify seed for -g/--grid\n\n");
-                usage(appName);
-                return NORMAL_ERROR;
+            if (argc == 4) {
+                extraDigits = atoi(argv[3]);
             }
         }
 
@@ -596,7 +585,7 @@ int main(const int argc, const char** argv)
 
         int gridX = 0;
         int gridY = 0;
-        int line = my_round(sqrt((float) totalNrOfPoints));
+        int line = my_round(sqrt(totalNrOfPoints));
         for (int i = 0; i < totalNrOfPoints; ++i) {
             double lat;
             double lon;
@@ -621,7 +610,7 @@ int main(const int argc, const char** argv)
             }
 
             unitToLatLonDeg(unit1, unit2, &lat, &lon);
-            generateAndOutputMapcodes(lat, lon, 1);
+            generateAndOutputMapcodes(lat, lon, 1, extraDigits);
 
             if ((i % SHOW_PROGRESS) == 0) {
                 showProgress(i);
diff --git a/mapcode_library.doc b/mapcode_library.doc
index 78c6f8e..8e0a566 100644
Binary files a/mapcode_library.doc and b/mapcode_library.doc differ
diff --git a/mapcodelib/basics.h b/mapcodelib/basics.h
index 4ebc3df..feb90db 100644
--- a/mapcodelib/basics.h
+++ b/mapcodelib/basics.h
@@ -1,22 +1,6 @@
-/*
- * Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
 #define UWORD unsigned short int // 2-byte unsigned integer
 
-#define mapcode_cversion "1.33"
+#define mapcode_cversion "1.40"
 #define MAXWIDE 10
 #define BASEX 31
 #define MAXFITLONG 6
diff --git a/mapcodelib/mapcoder.c b/mapcodelib/mapcoder.c
index 6984b21..5d8c775 100644
--- a/mapcodelib/mapcoder.c
+++ b/mapcodelib/mapcoder.c
@@ -832,16 +832,16 @@ void setup_country( int newccode )
 
         if ( codex==13 ) { iso_count13++; if ( iso_first13<0 ) iso_first13=i; }
 				if ( codex==21 ) { iso_count21++; if ( iso_first21<0 ) iso_first21=i; }
-				if ( codex==22 ) { if (pipe) {if (iso_firstpipe22<0) iso_firstpipe22=i; if (pipe<2)       iso_pipeletter22[iso_pipecount22++]=pipeletter(i); else if (iso_firststar22<0) iso_firststar22=i;} else { iso_count22++; if ( iso_first22<0 ) iso_first22=i; } }
-				if ( codex==14 ) { if (pipe) {if (iso_firstpipe14<0) iso_firstpipe14=i; if (pipe<2)       iso_pipeletter14[iso_pipecount14++]=pipeletter(i); else if (iso_firststar14<0) iso_firststar14=i;} else { iso_count14++; if ( iso_first14<0 ) iso_first14=i; } }
-				if ( codex==23 ) { if (pipe) {if (iso_firstpipe23<0) iso_firstpipe23=i; if (pipe<2)       iso_pipeletter23[iso_pipecount23++]=pipeletter(i); else if (iso_firststar23<0) iso_firststar23=i;} else { iso_count23++; if ( iso_first23<0 ) iso_first23=i; } }
-				if ( codex==32 ) { if (pipe) {if (iso_firstpipe32<0) iso_firstpipe32=i; if (pipe<2)       iso_pipeletter32[iso_pipecount32++]=pipeletter(i); else if (iso_firststar32<0) iso_firststar32=i;} else { iso_count32++; if ( iso_first32<0 ) iso_first32=i; } }
-				if ( codex==24 ) { if (pipe) {if (iso_firstpipe24<0) iso_firstpipe24=i; if (pipe<2)       iso_pipeletter24[iso_pipecount24++]=pipeletter(i); else if (iso_firststar24<0) iso_firststar24=i;} else { iso_count24++; if ( iso_first24<0 ) iso_first24=i; } }
-				if ( codex==33 ) { if (pipe) {if (iso_firstpipe33<0) iso_firstpipe33=i; if (pipe<2)       iso_pipeletter33[iso_pipecount33++]=pipeletter(i); else if (iso_firststar33<0) iso_firststar33=i;} else { iso_count33++; if ( iso_first33<0 ) iso_first33=i; } }
-				if ( codex==34 ) { if (pipe) {if (iso_firstpipe34<0) iso_firstpipe34=i; if (pipe<2)       iso_pipeletter34[iso_pipecount34++]=pipeletter(i); else if (iso_firststar34<0) iso_firststar34=i;} else { iso_count34++; if ( iso_first34<0 ) iso_first34=i; } }
+				if ( codex==22 ) { if (pipe) { if (iso_firstpipe22<0) iso_firstpipe22=i; if (pipe<2)       iso_pipeletter22[iso_pipecount22++]=pipeletter(i); else if (iso_firststar22<0) iso_firststar22=i;} else { iso_count22++; if ( iso_first22<0 ) iso_first22=i; } }
+				if ( codex==14 ) { if (pipe) { if (iso_firstpipe14<0) iso_firstpipe14=i; if (pipe<2)       iso_pipeletter14[iso_pipecount14++]=pipeletter(i); else if (iso_firststar14<0) iso_firststar14=i;} else { iso_count14++; if ( iso_first14<0 ) iso_first14=i; } }
+				if ( codex==23 ) { if (pipe) { if (iso_firstpipe23<0) iso_firstpipe23=i; if (pipe<2)       iso_pipeletter23[iso_pipecount23++]=pipeletter(i); else if (iso_firststar23<0) iso_firststar23=i;} else { iso_count23++; if ( iso_first23<0 ) iso_first23=i; } }
+				if ( codex==32 ) { if (pipe) { if (iso_firstpipe32<0) iso_firstpipe32=i; if (pipe<2)       iso_pipeletter32[iso_pipecount32++]=pipeletter(i); else if (iso_firststar32<0) iso_firststar32=i;} else { iso_count32++; if ( iso_first32<0 ) iso_first32=i; } }
+				if ( codex==24 ) { if (pipe) { if (iso_firstpipe24<0) iso_firstpipe24=i; if (pipe<2)       iso_pipeletter24[iso_pipecount24++]=pipeletter(i); else if (iso_firststar24<0) iso_firststar24=i;} else { iso_count24++; if ( iso_first24<0 ) iso_first24=i; } }
+				if ( codex==33 ) { if (pipe) { if (iso_firstpipe33<0) iso_firstpipe33=i; if (pipe<2)       iso_pipeletter33[iso_pipecount33++]=pipeletter(i); else if (iso_firststar33<0) iso_firststar33=i;} else { iso_count33++; if ( iso_first33<0 ) iso_first33=i; } }
+				if ( codex==34 ) { if (pipe) { if (iso_firstpipe34<0) iso_firstpipe34=i; if (pipe<2)       iso_pipeletter34[iso_pipecount34++]=pipeletter(i); else if (iso_firststar34<0) iso_firststar34=i;} else { iso_count34++; if ( iso_first34<0 ) iso_first34=i; } }
 				if ( codex==42 ) { iso_count42++; if ( iso_first42<0 ) iso_first42=i; }
 				if ( codex==43 ) { iso_count43++; if ( iso_first43<0 ) iso_first43=i; }
-				if ( codex==44 ) { if (pipe) {if (iso_firstpipe44<0) iso_firstpipe44=i; if (pipe<2)       iso_pipeletter44[iso_pipecount44++]=pipeletter(i); else if (iso_firststar44<0) iso_firststar44=i;} else { iso_count44++; if ( iso_first44<0 ) iso_first44=i; } }
+				if ( codex==44 ) { if (pipe) { if (iso_firstpipe44<0) iso_firstpipe44=i; if (pipe<2)       iso_pipeletter44[iso_pipecount44++]=pipeletter(i); else if (iso_firststar44<0) iso_firststar44=i;} else { iso_count44++; if ( iso_first44<0 ) iso_first44=i; } }
 		  }
     }
 
@@ -1612,7 +1612,7 @@ void master_encode( char *resultbuffer, int the_ctry, long x, long y, int forcec
     if ( ! (miny<=y && y<maxy && isInRange(x,minx,maxx) ) )
     {
       i=iso_end+1; // skip to "Earth" (if supported)
-      if (!allow_world && skip_parentstate) return;
+      if (!allow_world /*&& skip_parentstate*/) return;
     }
   }
 
@@ -2348,7 +2348,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
   char *p;
   int sign=1;
 
-  while (*i && (p=(char*)strchr(winds,*i))!=NULL) { { if ( (p-(char*)winds) & 1 ) sign*=-1; } i++; }
+  while (*i && (p=strchr(winds,*i))!=NULL) { { if ( (p-winds) & 1 ) sign*=-1; } i++; }
 
   // we are now at a lead digit, or there is an error
   if (!isdig(*i))
@@ -2381,7 +2381,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
   }
 
   // allow all posisble final endsigns
-  { while (*i && (p=(char*)strchr(winds,*i))!=NULL) { if ( (p-(char*)winds) & 1 ) sign*=-1; i++; } }
+  { while (*i && (p=strchr(winds,*i))!=NULL) { if ( (p-winds) & 1 ) sign*=-1; i++; } }
 
   // we now MUST be at the end of the string!
   if (*i)
@@ -2513,12 +2513,13 @@ int convertTerritoryIsoNameToCode(const char *string,int optional_tc) // optiona
 
 // pass point to an array of pointers (at least 64), will be made to point to result strings...
 // returns nr of results;
-int encodeLatLonToMapcodes_full( char **v, double lat, double lon, int tc, int stop_with_one_result ) // 1.31 allow to stop after one result
+int encodeLatLonToMapcodes_full( char **v, double lat, double lon, int tc, int stop_with_one_result, int extraDigits ) // 1.31 allow to stop after one result
 {
   int ccode=tc-1;
   if (tc==0) ccode=0;
   if (ccode<0 || ccode>=MAX_MAPCODE_TERRITORY_CODE) return 0;
   if (lat<-90 || lat>90 || lon<-180 || lon>180) return 0;
+  if (extraDigits<0) extraDigits=0; else if (extraDigits>2) extraDigits=2; use_high_precision=extraDigits;
   lat*=1000000; if (lat<0) lat-=0.5; else lat+=0.5;
   lon*=1000000; if (lon<0) lon-=0.5; else lon+=0.5;
   nr_global_results=0;
@@ -2575,15 +2576,15 @@ const UWORD* encodeToAlphabet(const char *mapcode,int alphabet) // 0=roman, 2=cy
 
 #endif
 
-int encodeLatLonToMapcodes( char **v, double lat, double lon, int tc )
+int encodeLatLonToMapcodes( char **v, double lat, double lon, int tc, int extraDigits )
 {
-  return encodeLatLonToMapcodes_full(v,lat,lon,tc,0);
+  return encodeLatLonToMapcodes_full(v,lat,lon,tc,0,extraDigits);
 }
 
-int encodeLatLonToSingleMapcode( char *result, double lat, double lon, int tc )
+int encodeLatLonToSingleMapcode( char *result, double lat, double lon, int tc, int extraDigits )
 {
   char *v[2];
-  int ret=encodeLatLonToMapcodes_full(v,lat,lon,tc,1);
+  int ret=encodeLatLonToMapcodes_full(v,lat,lon,tc,1,extraDigits);
   *result=0;
   if (ret>0) {
     if (strcmp(v[1],"AAA")!=0) {
diff --git a/mapcodelib/mapcoder.h b/mapcodelib/mapcoder.h
index a889ba1..7970e5c 100644
--- a/mapcodelib/mapcoder.h
+++ b/mapcodelib/mapcoder.h
@@ -35,6 +35,9 @@
  *      lon             - Longitude, in degrees. Range: -180..180.
  *      territoryCode   - Territory code (obtained from convertTerritoryIsoNameToCode), used as encoding context.
  *                        Pass 0 to get Mapcodes for all territories.
+ *      extraDigits     - Number of extra "digits" to add to the generated mapcode. The preferred default is 0.
+ *                        Other valid values are 1 and 2, which will add extra letters to the mapcodes to
+ *                        make them represent the coordinate more accurately.
  *
  * Returns:
  *      Number of results stored in parameter results. Always >= 0 (0 if no encoding was possible or an error occurred).
@@ -45,7 +48,8 @@ int encodeLatLonToMapcodes(
     char**  results,
     double  lat,
     double  lon,
-    int     territoryCode);
+    int     territoryCode,
+    int     extraDigits);
 
 /**
  * Encode a latitude, longitude pair (in degrees) to a single Mapcode: the shortest possible for the given territory
@@ -60,6 +64,9 @@ int encodeLatLonToMapcodes(
  *      lon             - Longitude, in degrees. Range: -180..180.
  *      territoryCode   - Territory code (obtained from convertTerritoryIsoNameToCode), used as encoding context.
  *                        Pass 0 to get the shortest Mapcode for all territories.
+ *      extraDigits     - Number of extra "digits" to add to the generated mapcode. The preferred default is 0.
+ *                        Other valid values are 1 and 2, which will add extra letters to the mapcodes to
+ *                        make them represent the coordinate more accurately.
  *
  * Returns:
  *      0 if encoding failed, or >0 if it succeeded.
@@ -68,7 +75,8 @@ int encodeLatLonToSingleMapcode(
     char* result,
     double lat,
     double lon,
-    int territoryCode);
+    int territoryCode,
+    int extraDigits);
 
 /**
  * Decode a Mapcode to  a latitude, longitude pair (in degrees).
@@ -79,8 +87,9 @@ int encodeLatLonToSingleMapcode(
  *      mapcode         - Mapcode to decode.
  *      territoryCode   - Territory code (obtained from convertTerritoryIsoNameToCode), used as decoding context.
  *                        Pass 0 if not available.
+ *
  * Returns:
- *      0 if encoding failed, or >0 if it succeeded.
+ *      0 if encoding succeeded, nonzero in case of error
  */
 int decodeMapcodeToLatLon(
     double*     lat,
@@ -208,8 +217,8 @@ const UWORD* encodeToAlphabet(const char* mapcode, int alphabet);
 /**
  * list of #defines to support legacy systems
  */
-#define coord2mc encodeLatLonToMapcodes
-#define coord2mc1 encodeLatLonToSingleMapcode
+#define coord2mc(results,lat,lon,territoryCode)  encodeLatLonToMapcodes(results,lat,lon,territoryCode,0)
+#define coord2mc1(results,lat,lon,territoryCode) encodeLatLonToSingleMapcode(results,lat,lon,territoryCode,0)
 #define mc2coord decodeMapcodeToLatLon
 #define lookslikemapcode compareWithMapcodeFormat
 #define text2tc convertTerritoryIsoNameToCode

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git



More information about the Pkg-grass-devel mailing list