[mapcode] 07/18: Added std basics.h and added XYZ option

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 2d8e47b0bfe3968dce7e68353143bddd2659d970
Author: Rijn Buve <rijn at buve.nl>
Date:   Thu Sep 18 15:36:48 2014 +0200

    Added std basics.h and added XYZ option
---
 example/mapcode.cpp | 80 ++++++++++++++++++++++++++++-------------------------
 mapcodelib/basics.h | 18 ++++++------
 2 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/example/mapcode.cpp b/example/mapcode.cpp
index 4319a76..68983ae 100644
--- a/example/mapcode.cpp
+++ b/example/mapcode.cpp
@@ -88,9 +88,9 @@ static void usage(const char* appName) {
     printf("       Encode a lat/lon to a Mapcode. If the territory code is specified, the\n");
     printf("       encoding will only succeeed if the lat/lon is located in the territory.\n");
     printf("\n");
-    printf("    %s [-b | --boundaries] [<extraDigits>]\n", appName);
-    printf("    %s [-g | --grid] <nrOfPoints> [<extraDigits>]\n", appName);
-    printf("    %s [-r | --random] <nrOfPoints> [<extraDigits>] [<seed>]\n", appName);
+    printf("    %s [-b[XYZ] | --boundaries[XYZ]] [<extraDigits>]\n", appName);
+    printf("    %s [-g[XYZ] | --grid[XYZ]]   <nrOfPoints> [<extraDigits>]\n", appName);
+    printf("    %s [-r[XYZ] | --random[XYZ]] <nrOfPoints> [<extraDigits>] [<seed>]\n", appName);
     printf("\n");
     printf("       Create a test set of lat/lon pairs based on the Mapcode boundaries database\n");
     printf("       as a fixed 3D grid or random uniformly distributed set of lat/lons with their\n");
@@ -101,7 +101,7 @@ static void usage(const char* appName) {
     printf("       (You may wish to specify a specific seed to regenerate test cases).\n");
     printf("\n");
     printf("       The output format is:\n");
-    printf("           <number-of-aliases> <lat-deg> <lon-deg> <x> <y> <z>\n");
+    printf("           <number-of-aliases> <lat-deg> <lon-deg> [<x> <y> <z>]\n");
     printf("           <territory> <mapcode>      (repeated 'number-of-aliases' times)\n");
     printf("                                      (empty lines and next record)\n");
     printf("       Ranges:\n");
@@ -287,7 +287,7 @@ 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, int extraDigits) {
+static void generateAndOutputMapcodes(double lat, double lon, int iShowError, int extraDigits, int useXYZ) {
 
     char* results[MAX_NR_OF_MAPCODE_RESULTS];
     int context = 0;
@@ -313,11 +313,16 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
         }
     }
 
-    double x;
-    double y;
-    double z;
-    convertLatLonToXYZ(lat, lon, &x, &y, &z);
-    printf("%d %s %s %lf %lf %lf\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0), x, y, z);
+    if (useXYZ) {
+        double x;
+        double y;
+        double z;
+        convertLatLonToXYZ(lat, lon, &x, &y, &z);
+        printf("%d %s %s %lf %lf %lf\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0), x, y, z);
+    }
+    else {
+        printf("%d %s %s\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0));
+    }
     for (int j = 0; j < nrResults; ++j) {
         const char* foundMapcode = results[(j * 2)];
         const char* foundTerritory = results[(j * 2) + 1];
@@ -392,6 +397,9 @@ int main(const int argc, const char** argv)
     // Assume no extra digits (unless overridden later.
     int extraDigits = 0;
 
+    // If XYZ is added to -b, -r or -g, print x, y, z coordinates
+    int useXYZ = 0;
+
     // Provide usage message if no arguments specified.
     const char* appName = argv[0];
     if (argc < 2) {
@@ -486,7 +494,8 @@ int main(const int argc, const char** argv)
             }
         }
     }
-    else if ((strcmp(cmd, "-b") == 0) || (strcmp(cmd, "--boundaries") == 0)) {
+    else if ((strcmp(cmd, "-b") == 0) || (strcmp(cmd, "-bXYZ") == 0) ||
+        (strcmp(cmd, "--boundaries") == 0) || (strcmp(cmd, "--boundariesXYZ") == 0)) {
 
         // ------------------------------------------------------------------
         // Generate a test set based on the Mapcode boundaries.
@@ -499,6 +508,7 @@ int main(const int argc, const char** argv)
         if (argc == 3) {
             extraDigits = atoi(argv[2]);
         }
+        useXYZ = (strstr(cmd, "XYZ") != 0);
 
         resetStatistics(NR_BOUNDARY_RECS);
         for (int i = 0; i < totalNrOfPoints; ++i) {
@@ -522,33 +532,26 @@ int main(const int argc, const char** argv)
             // Try center.
             lat = (maxLat - minLat ) / 2.0;
             lon = (maxLon - minLon ) / 2.0;
-
-            // Try center.
-            generateAndOutputMapcodes(lat, lon, 0, extraDigits);
+            generateAndOutputMapcodes(lat, lon, 0, extraDigits, useXYZ);
 
             // Try corners.
-            generateAndOutputMapcodes(minLat, minLon, 0, extraDigits);
-            generateAndOutputMapcodes(minLat, maxLon, 0, extraDigits);
-            generateAndOutputMapcodes(maxLat, minLon, 0, extraDigits);
-            generateAndOutputMapcodes(maxLat, maxLon, 0, extraDigits);
+            generateAndOutputMapcodes(minLat, minLon, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(minLat, maxLon, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat, minLon, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat, maxLon, 0, extraDigits, useXYZ);
 
             // Try JUST inside.
-            double factor = 10.0;
-            for (int j = 1; j < 2; ++j) {
-
-                double d = 1.0 / factor;
-                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, 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;
-            }
+            const double d = 0.000001;
+            generateAndOutputMapcodes(minLat + d, minLon + d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(minLat + d, maxLon - d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat - d, minLon + d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat - d, maxLon - d, 0, extraDigits, useXYZ);
+
+            // Try JUST outside.
+            generateAndOutputMapcodes(minLat - d, minLon - d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(minLat - d, maxLon + d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat + d, minLon - d, 0, extraDigits, useXYZ);
+            generateAndOutputMapcodes(maxLat + d, maxLon + d, 0, extraDigits, useXYZ);
 
             if ((i % SHOW_PROGRESS) == 0) {
                 showProgress(i);
@@ -556,8 +559,10 @@ int main(const int argc, const char** argv)
         }
         outputStatistics();
     }
-    else if ((strcmp(cmd, "-g") == 0) || (strcmp(cmd, "--grid") == 0) ||
-        (strcmp(cmd, "-r") == 0) || (strcmp(cmd, "--random") == 0)) {
+    else if ((strcmp(cmd, "-g") == 0) || (strcmp(cmd, "-gXYZ") == 0) ||
+        (strcmp(cmd, "--grid") == 0) || (strcmp(cmd, "--gridXYZ") == 0) ||
+        (strcmp(cmd, "-r") == 0) || (strcmp(cmd, "-rXYZ") == 0) ||
+        (strcmp(cmd, "--random") == 0) || (strcmp(cmd, "--randomXYZ") == 0)) {
 
         // ------------------------------------------------------------------
         // Generate grid test set:    [-g | --grid]   <nrOfPoints> [<extradigits>]
@@ -592,6 +597,7 @@ int main(const int argc, const char** argv)
                 extraDigits = atoi(argv[3]);
             }
         }
+        useXYZ = (strstr(cmd, "XYZ") != 0);
 
         // Statistics.
         resetStatistics(nrOfPoints);
@@ -624,7 +630,7 @@ int main(const int argc, const char** argv)
             }
 
             unitToLatLonDeg(unit1, unit2, &lat, &lon);
-            generateAndOutputMapcodes(lat, lon, 1, extraDigits);
+            generateAndOutputMapcodes(lat, lon, 1, extraDigits, useXYZ);
 
             if ((i % SHOW_PROGRESS) == 0) {
                 showProgress(i);
diff --git a/mapcodelib/basics.h b/mapcodelib/basics.h
index 47ca841..4040e4a 100644
--- a/mapcodelib/basics.h
+++ b/mapcodelib/basics.h
@@ -1,6 +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
@@ -115,7 +115,7 @@ static const char *entity_iso = ""
 
 
 
-static UWORD xdivider19[172] = {
+static const UWORD xdivider19[172] = {
 	  360,  360,  360,  360,  360,  360,  361,  361,  361,  361,
 	  362,  362,  362,  363,  363,  363,  364,  364,  365,  366,
 	  366,  367,  367,  368,  369,  370,  370,  371,  372,  373,
@@ -136,13 +136,13 @@ static UWORD xdivider19[172] = {
 	23681,59485
 };
 
-static long nc[MAXFITLONG+1] = { 1, 31, 961, 29791, 923521, 28629151, 887503681 };
+static const long nc[MAXFITLONG+1] = { 1, 31, 961, 29791, 923521, 28629151, 887503681 };
 
-static long xside[MAXWIDE] = { 0, 5,  31,  168,    961,    168*31,     29791,       165869,         923521,        5141947};
+static const long xside[MAXWIDE] = { 0, 5,  31,  168,    961,    168*31,     29791,       165869,         923521,        5141947};
 
-static long yside[MAXWIDE] = { 0, 6,  31,  176,    961,    176*31,     29791,       165869,         923521,        5141947};
+static const long yside[MAXWIDE] = { 0, 6,  31,  176,    961,    176*31,     29791,       165869,         923521,        5141947};
 
-static signed char decode_chars[256] = {
+static const signed char decode_chars[256] = {
 	 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 	 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 	 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -161,14 +161,14 @@ static signed char decode_chars[256] = {
 	 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 };
 
-static char encode_chars[31] = {
+static const char encode_chars[31] = {
 	'0','1','2','3','4','5','6','7','8','9',
 	'B','C','D','F','G','H','J','K','L','M',
 	'N','P','Q','R','S','T','V','W','X','Y','Z'
 };
 
 
-static UWORD data_start[MAX_CCODE+1] = {
+static const UWORD data_start[MAX_CCODE+1] = {
 	    0,    3,    6,    9,   13,   16,   18,   19,   30,   31,
 	   33,   35,   37,   42,   44,   47,   51,   54,   56,   58,
 	   60,   62,   64,   68,   71,   79,   81,  116,  121,  131,
@@ -232,7 +232,7 @@ static UWORD data_start[MAX_CCODE+1] = {
 typedef struct { long minx; long miny; long maxx; long maxy; unsigned long flags; } mminforec;
 
 #ifndef MAKE_SOURCE_DIGITAL
-static mminforec mminfo[NR_RECS+1] = {
+static const mminforec mminfo[NR_RECS+1] = {
 	{  12433114,  41851944,  12548434,  41938434,0x001002b},
 	{   5850000,  35450000,  18560000,  55080000,0x50a0636},
 	{  12444000,  41899000,  12460000,  41908000,0x003063c},

-- 
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