@@ -88,9 +88,9 @@ static void usage(const char* appName) {
8888 printf (" Encode a lat/lon to a Mapcode. If the territory code is specified, the\n " );
8989 printf (" encoding will only succeeed if the lat/lon is located in the territory.\n " );
9090 printf (" \n " );
91- printf (" %s [-b | --boundaries] [<extraDigits>]\n " , appName);
92- printf (" %s [-g | --grid] <nrOfPoints> [<extraDigits>]\n " , appName);
93- printf (" %s [-r | --random] <nrOfPoints> [<extraDigits>] [<seed>]\n " , appName);
91+ printf (" %s [-b[XYZ] | --boundaries[XYZ] ] [<extraDigits>]\n " , appName);
92+ printf (" %s [-g[XYZ] | --grid[XYZ]] <nrOfPoints> [<extraDigits>]\n " , appName);
93+ printf (" %s [-r[XYZ] | --random[XYZ] ] <nrOfPoints> [<extraDigits>] [<seed>]\n " , appName);
9494 printf (" \n " );
9595 printf (" Create a test set of lat/lon pairs based on the Mapcode boundaries database\n " );
9696 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) {
101101 printf (" (You may wish to specify a specific seed to regenerate test cases).\n " );
102102 printf (" \n " );
103103 printf (" The output format is:\n " );
104- printf (" <number-of-aliases> <lat-deg> <lon-deg> <x> <y> <z>\n " );
104+ printf (" <number-of-aliases> <lat-deg> <lon-deg> [ <x> <y> <z>] \n " );
105105 printf (" <territory> <mapcode> (repeated 'number-of-aliases' times)\n " );
106106 printf (" (empty lines and next record)\n " );
107107 printf (" Ranges:\n " );
@@ -287,7 +287,7 @@ static const char* asCoordinate(double coord, char* target)
287287 * If iShowError != 0, then encoding errors are output to stderr, otherwise they
288288 * are ignored.
289289 */
290- static void generateAndOutputMapcodes (double lat, double lon, int iShowError, int extraDigits) {
290+ static void generateAndOutputMapcodes (double lat, double lon, int iShowError, int extraDigits, int useXYZ ) {
291291
292292 char * results[MAX_NR_OF_MAPCODE_RESULTS];
293293 int context = 0 ;
@@ -313,11 +313,16 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
313313 }
314314 }
315315
316- double x;
317- double y;
318- double z;
319- convertLatLonToXYZ (lat, lon, &x, &y, &z);
320- printf (" %d %s %s %lf %lf %lf\n " , nrResults, asCoordinate (lat, 0 ), asCoordinate (lon, 0 ), x, y, z);
316+ if (useXYZ) {
317+ double x;
318+ double y;
319+ double z;
320+ convertLatLonToXYZ (lat, lon, &x, &y, &z);
321+ printf (" %d %s %s %lf %lf %lf\n " , nrResults, asCoordinate (lat, 0 ), asCoordinate (lon, 0 ), x, y, z);
322+ }
323+ else {
324+ printf (" %d %s %s\n " , nrResults, asCoordinate (lat, 0 ), asCoordinate (lon, 0 ));
325+ }
321326 for (int j = 0 ; j < nrResults; ++j) {
322327 const char * foundMapcode = results[(j * 2 )];
323328 const char * foundTerritory = results[(j * 2 ) + 1 ];
@@ -392,6 +397,9 @@ int main(const int argc, const char** argv)
392397 // Assume no extra digits (unless overridden later.
393398 int extraDigits = 0 ;
394399
400+ // If XYZ is added to -b, -r or -g, print x, y, z coordinates
401+ int useXYZ = 0 ;
402+
395403 // Provide usage message if no arguments specified.
396404 const char * appName = argv[0 ];
397405 if (argc < 2 ) {
@@ -486,7 +494,8 @@ int main(const int argc, const char** argv)
486494 }
487495 }
488496 }
489- else if ((strcmp (cmd, " -b" ) == 0 ) || (strcmp (cmd, " --boundaries" ) == 0 )) {
497+ else if ((strcmp (cmd, " -b" ) == 0 ) || (strcmp (cmd, " -bXYZ" ) == 0 ) ||
498+ (strcmp (cmd, " --boundaries" ) == 0 ) || (strcmp (cmd, " --boundariesXYZ" ) == 0 )) {
490499
491500 // ------------------------------------------------------------------
492501 // Generate a test set based on the Mapcode boundaries.
@@ -499,6 +508,7 @@ int main(const int argc, const char** argv)
499508 if (argc == 3 ) {
500509 extraDigits = atoi (argv[2 ]);
501510 }
511+ useXYZ = (strstr (cmd, " XYZ" ) != 0 );
502512
503513 resetStatistics (NR_BOUNDARY_RECS);
504514 for (int i = 0 ; i < totalNrOfPoints; ++i) {
@@ -522,42 +532,37 @@ int main(const int argc, const char** argv)
522532 // Try center.
523533 lat = (maxLat - minLat ) / 2.0 ;
524534 lon = (maxLon - minLon ) / 2.0 ;
525-
526- // Try center.
527- generateAndOutputMapcodes (lat, lon, 0 , extraDigits);
535+ generateAndOutputMapcodes (lat, lon, 0 , extraDigits, useXYZ);
528536
529537 // Try corners.
530- generateAndOutputMapcodes (minLat, minLon, 0 , extraDigits);
531- generateAndOutputMapcodes (minLat, maxLon, 0 , extraDigits);
532- generateAndOutputMapcodes (maxLat, minLon, 0 , extraDigits);
533- generateAndOutputMapcodes (maxLat, maxLon, 0 , extraDigits);
538+ generateAndOutputMapcodes (minLat, minLon, 0 , extraDigits, useXYZ );
539+ generateAndOutputMapcodes (minLat, maxLon, 0 , extraDigits, useXYZ );
540+ generateAndOutputMapcodes (maxLat, minLon, 0 , extraDigits, useXYZ );
541+ generateAndOutputMapcodes (maxLat, maxLon, 0 , extraDigits, useXYZ );
534542
535543 // Try JUST inside.
536- double factor = 10.0 ;
537- for (int j = 1 ; j < 2 ; ++j) {
538-
539- double d = 1.0 / factor;
540- generateAndOutputMapcodes (minLat + d, minLon + d, 0 , extraDigits);
541- generateAndOutputMapcodes (minLat + d, maxLon - d, 0 , extraDigits);
542- generateAndOutputMapcodes (maxLat - d, minLon + d, 0 , extraDigits);
543- generateAndOutputMapcodes (maxLat - d, maxLon - d, 0 , extraDigits);
544-
545- // Try JUST outside.
546- generateAndOutputMapcodes (minLat - d, minLon - d, 0 , extraDigits);
547- generateAndOutputMapcodes (minLat - d, maxLon + d, 0 , extraDigits);
548- generateAndOutputMapcodes (maxLat + d, minLon - d, 0 , extraDigits);
549- generateAndOutputMapcodes (maxLat + d, maxLon + d, 0 , extraDigits);
550- factor = factor * 10.0 ;
551- }
544+ const double d = 0.000001 ;
545+ generateAndOutputMapcodes (minLat + d, minLon + d, 0 , extraDigits, useXYZ);
546+ generateAndOutputMapcodes (minLat + d, maxLon - d, 0 , extraDigits, useXYZ);
547+ generateAndOutputMapcodes (maxLat - d, minLon + d, 0 , extraDigits, useXYZ);
548+ generateAndOutputMapcodes (maxLat - d, maxLon - d, 0 , extraDigits, useXYZ);
549+
550+ // Try JUST outside.
551+ generateAndOutputMapcodes (minLat - d, minLon - d, 0 , extraDigits, useXYZ);
552+ generateAndOutputMapcodes (minLat - d, maxLon + d, 0 , extraDigits, useXYZ);
553+ generateAndOutputMapcodes (maxLat + d, minLon - d, 0 , extraDigits, useXYZ);
554+ generateAndOutputMapcodes (maxLat + d, maxLon + d, 0 , extraDigits, useXYZ);
552555
553556 if ((i % SHOW_PROGRESS) == 0 ) {
554557 showProgress (i);
555558 }
556559 }
557560 outputStatistics ();
558561 }
559- else if ((strcmp (cmd, " -g" ) == 0 ) || (strcmp (cmd, " --grid" ) == 0 ) ||
560- (strcmp (cmd, " -r" ) == 0 ) || (strcmp (cmd, " --random" ) == 0 )) {
562+ else if ((strcmp (cmd, " -g" ) == 0 ) || (strcmp (cmd, " -gXYZ" ) == 0 ) ||
563+ (strcmp (cmd, " --grid" ) == 0 ) || (strcmp (cmd, " --gridXYZ" ) == 0 ) ||
564+ (strcmp (cmd, " -r" ) == 0 ) || (strcmp (cmd, " -rXYZ" ) == 0 ) ||
565+ (strcmp (cmd, " --random" ) == 0 ) || (strcmp (cmd, " --randomXYZ" ) == 0 )) {
561566
562567 // ------------------------------------------------------------------
563568 // Generate grid test set: [-g | --grid] <nrOfPoints> [<extradigits>]
@@ -592,6 +597,7 @@ int main(const int argc, const char** argv)
592597 extraDigits = atoi (argv[3 ]);
593598 }
594599 }
600+ useXYZ = (strstr (cmd, " XYZ" ) != 0 );
595601
596602 // Statistics.
597603 resetStatistics (nrOfPoints);
@@ -624,7 +630,7 @@ int main(const int argc, const char** argv)
624630 }
625631
626632 unitToLatLonDeg (unit1, unit2, &lat, &lon);
627- generateAndOutputMapcodes (lat, lon, 1 , extraDigits);
633+ generateAndOutputMapcodes (lat, lon, 1 , extraDigits, useXYZ );
628634
629635 if ((i % SHOW_PROGRESS) == 0 ) {
630636 showProgress (i);
0 commit comments