Skip to content

Commit 28548ec

Browse files
committed
Prepared for 1.40 added extraDigits to --random; improved help text
1 parent 22cef2d commit 28548ec

File tree

5 files changed

+62
-19
lines changed

5 files changed

+62
-19
lines changed

README

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ of how to use the library.
4949
To build the original Mapcode tool, execute:
5050

5151
cd example
52-
gcc mapcode.c -o mapcode
52+
gcc mapcode.cpp -o mapcode
5353

5454
For help, simply execute the binary file 'mapcode' without no arguments.
5555
This tool provides a rather extensive command-line interface to encode and
@@ -61,34 +61,45 @@ MAPCODE LIBRARY - RELEASE NOTES
6161
-------------------------------------------------------------------------------
6262

6363
1.40
64+
6465
Added extraDigits parameter to allow high-precision mapcodes to be generated.
6566

6667
1.33
67-
Fix to not remove valid results just across the edge of a territory. Improved interface readability
68-
and renamed methods to more readable forms.
68+
69+
Fix to not remove valid results just across the edge of a territory.
70+
Improved interface readability and renamed methods to more readable forms.
6971

7072
1.32
71-
Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative is produced in edge cases; prevent FIJI failing to
72-
decode at exactly 180 degrees.
73+
74+
Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative
75+
is produced in edge cases; prevent FIJI failing to decode at exactly 180 degrees.
7376

7477
1.31
78+
7579
Added compareWithMapcodeFormat().
7680

7781
1.30
82+
7883
IUpdated the documentation and extended it with examples and suggestions.
7984

8085
1.29
86+
8187
Also generate country-wide alternative mapcodes for states.
8288

8389
1.28
84-
Bug fix for the needless generation of 7-letter alternatives to short mapcodes in large states in India.
90+
91+
Bug fix for the needless generation of 7-letter alternatives to short mapcodes
92+
in large states in India.
8593

8694
1.27
95+
8796
Improved (faster) implementation of the function isInArea.
8897

8998
1.26
99+
90100
Added alias OD ("Odisha") for indian state OR ("Orissa").
91101

92102
1.25
103+
93104
Initial release to the public domain.
94105

example/mapcode.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
/**
2-
* Copyright (C) 2014 Stichting Mapcode Foundation
3-
* For terms of use refer to http://www.mapcode.com/downloads.html
1+
/*
2+
* Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
415
*/
516

617
/**
@@ -31,7 +42,6 @@
3142
#define my_isnan(x) (false)
3243
#define my_round(x) ((long) (floor((x) + 0.5)))
3344

34-
static const char* VERSION = "1";
3545
static const int SELF_CHECK = 1;
3646
static const int SELF_CHECK_EXIT = 0;
3747

@@ -64,7 +74,7 @@ static double lonLargestNrOfResults = 0.0;
6474
* whenever a incorrect amount or combination of parameters is entered.
6575
*/
6676
static void usage(const char* appName) {
67-
printf("MAPCODE (version %s.%s%s)\n", mapcode_cversion, VERSION, SELF_CHECK ? ", self-checking" : "");
77+
printf("MAPCODE (version %s%s)\n", mapcode_cversion, SELF_CHECK ? ", self-checking" : "");
6878
printf("Copyright (C) 2014 Stichting Mapcode Foundation\n");
6979
printf("\n");
7080
printf("Usage:\n");
@@ -80,12 +90,16 @@ static void usage(const char* appName) {
8090
printf("\n");
8191
printf(" %s [-b | --boundaries]\n", appName);
8292
printf(" %s [-g | --grid] <nrOfPoints> [<extraDigits>]\n", appName);
83-
printf(" %s [-r | --random] <nrOfPoints> [<seed>]\n", appName);
93+
printf(" %s [-r | --random] <nrOfPoints> [<extraDigits>] [<seed>]\n", appName);
8494
printf("\n");
8595
printf(" Create a test set of lat/lon pairs based on the Mapcode boundaries database\n");
8696
printf(" as a fixed 3D grid or random uniformly distributed set of lat/lons with their\n");
8797
printf(" (x, y, z) coordinates and all Mapcode aliases.\n");
8898
printf("\n");
99+
printf(" <extraDigits> specifies additional accuracy, use 0 for standard.\n");
100+
printf(" <seed> is an optional random seed, use 0 for arbitrary>.\n");
101+
printf(" (You may wish to specify a specific seed to regenerate test cases).\n");
102+
printf("\n");
89103
printf(" The output format is:\n");
90104
printf(" <number-of-aliases> <lat-deg> <lon-deg> <x> <y> <z>\n");
91105
printf(" <territory> <mapcode> (repeated 'number-of-aliases' times)\n");
@@ -100,7 +114,7 @@ static void usage(const char* appName) {
100114
printf(" The (x, y, z) coordinates are primarily meant for visualization of the data set.\n");
101115
printf("\n");
102116
printf(" Notes on the use of stdout and stderr:\n");
103-
printf(" stdout: used for outputting 3D point data; stderr: used for statistics.");
117+
printf(" stdout: used for outputting 3D point data; stderr: used for statistics.\n");
104118
printf(" You can redirect stdout to a destination file, while stderr will show progress.\n");
105119
printf("\n");
106120
printf(" The result code is 0 when no error occurred, 1 if an input error occurred and 2\n");
@@ -552,7 +566,7 @@ int main(const int argc, const char** argv)
552566
// Generate grid test set: [-g | --grid] <nrOfPoints> [<extradigits>]
553567
// Generate uniform test set: [-r | --random] <nrOfPoints> [<seed>]
554568
// ------------------------------------------------------------------
555-
if ((argc < 3) || (argc > 4)) {
569+
if ((argc < 3) || (argc > 5)) {
556570
fprintf(stderr, "error: incorrect number of arguments\n\n");
557571
usage(appName);
558572
return NORMAL_ERROR;
@@ -565,8 +579,11 @@ int main(const int argc, const char** argv)
565579
}
566580
int random = (strcmp(cmd, "-r") == 0) || (strcmp(cmd, "--random") == 0);
567581
if (random) {
568-
if (argc == 4) {
569-
const int seed = atoi(argv[3]);
582+
if (argc >= 4) {
583+
extraDigits = atoi(argv[3]);
584+
}
585+
if (argc == 5) {
586+
const int seed = atoi(argv[4]);
570587
srand(seed);
571588
}
572589
else {

mapcodelib/basics.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#define UWORD unsigned short int // 2-byte unsigned integer
218

319
#define mapcode_cversion "1.40"

mapcodelib/mapcoder.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
23482348
char *p;
23492349
int sign=1;
23502350

2351-
while (*i && (p=strchr(winds,*i))!=NULL) { { if ( (p-winds) & 1 ) sign*=-1; } i++; }
2351+
while (*i && (p=(char*)strchr(winds,*i))!=NULL) { { if ( (p-(char*)winds) & 1 ) sign*=-1; } i++; }
23522352

23532353
// we are now at a lead digit, or there is an error
23542354
if (!isdig(*i))
@@ -2381,7 +2381,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
23812381
}
23822382

23832383
// allow all posisble final endsigns
2384-
{ while (*i && (p=strchr(winds,*i))!=NULL) { if ( (p-winds) & 1 ) sign*=-1; i++; } }
2384+
{ while (*i && (p=(char*)strchr(winds,*i))!=NULL) { if ( (p-(char*)winds) & 1 ) sign*=-1; i++; } }
23852385

23862386
// we now MUST be at the end of the string!
23872387
if (*i)

mapcodelib/mapcoder.h

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

17-
1817
#define RELEASENEAT // Use clean code (mapcoder.c).
1918
#define UWORD unsigned short int // 2-byte unsigned integer.
2019
#define SUPPORT_FOREIGN_ALPHABETS

0 commit comments

Comments
 (0)