Skip to content

Commit 3930e94

Browse files
committed
Added changes required by PG
1 parent 182a0af commit 3930e94

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include <stdio.h>
27+
#include <time.h>
2728
#include <math.h>
2829
#include "../mapcodelib/mapcoder.c"
2930

@@ -144,8 +145,8 @@ static void unitToLatLonDeg(
144145
const double lonRad = atan2(y, x);
145146

146147
// Convert radians to degrees.
147-
*latDeg = isnan(latRad) ? 90.0 : radToDeg(latRad);
148-
*lonDeg = isnan(lonRad) ? 180.0 : radToDeg(lonRad);
148+
*latDeg = (latRad == NAN) ? 90.0 : radToDeg(latRad);
149+
*lonDeg = (lonRad == NAN) ? 180.0 : radToDeg(lonRad);
149150
}
150151

151152

@@ -398,7 +399,7 @@ int main(const int argc, const char** argv)
398399

399400
// Get territory context.
400401
int context = 0;
401-
char* defaultTerritory = "AAA";
402+
const char* defaultTerritory = "AAA";
402403
if (argc == 5) {
403404
context = convertTerritoryIsoNameToCode(argv[4], 0);
404405
defaultTerritory = argv[4];
@@ -540,7 +541,7 @@ int main(const int argc, const char** argv)
540541

541542
int gridX = 0;
542543
int gridY = 0;
543-
int line = round(sqrt(totalNrOfPoints));
544+
int line = (int) (sqrt(totalNrOfPoints) + 0.5);
544545
for (int i = 0; i < totalNrOfPoints; ++i) {
545546
double lat;
546547
double lon;

mapcodelib/basics.h

100755100644
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
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-
171
#define UWORD unsigned short int // 2-byte unsigned integer
182

193
#define mapcode_cversion "1.33"
204
#define MAXWIDE 10
215
#define BASEX 31
226
#define MAXFITLONG 6
23-
#define XSIDE3 168
7+
#define XSIDE3 168
248
#define YSIDE3 176
259

2610
#define ALIASES "2UK=2UT,2CG=2CT,1GU=GUM,1UM=UMI,1VI=VIR,1PR=PRI,1AS=ASM,1MP=MNP,4JB=JBT,4QL=QLD,4TS=TAS,4CX=CXR,4CC=CCK,4NF=NFK,4HM=HMD,4NI=NFK,COL=5CL,5ME=5MX,MEX=5MX,5TM=TAM,5AG=AGU,5BC=BCN,5BS=BCS,5CM=CAM,5CS=CHP,5CH=CHH,5CO=COA,5DF=DIF,5DG=DUR,5GT=GUA,5GR=GRO,5HG=HID,5JA=JAL,5MI=MIC,5MO=MOR,5NA=NAY,5NL=NLE,5OA=OAX,5PB=PUE,5QE=QUE,5QR=ROO,5SL=SLP,5SI=SIN,5SO=SON,5TB=TAB,5TL=TLA,5VE=VER,5YU=YUC,5ZA=ZAC,811=8BJ,812=8TJ,813=8HE,814=8SX,815=8NM,821=8LN,822=8JL,823=8HL,831=8SH,832=8JS,833=8ZJ,834=8AH,835=8FJ,836=8JX,837=8SD,841=8HA,842=8HB,843=8HN,844=8GD,845=8GX,846=8HI,850=8CQ,851=8SC,852=8GZ,853=8YN,854=8XZ,861=8SN,862=8GS,863=8QH,864=8NX,865=8XJ,871=TWN,891=HKG,892=MAC,8TW=TWN,8HK=HKG,8MC=MAC,BEL=7BE,KIR=7KI,PRI=7PO,CHE=7CH,KHM=7KM,PER=7PM,TAM=7TT,0US=USA,0AU=AUS,0RU=RUS,0CN=CHN,EAZ=TZA,SKM=2SK,TAA=SHN,ASC=SHN,DGA=IOT,WAK=MHL,JTN=UMI,MID=1HI,2OD=2OR,"
2711

28-
#define MAX_MAPCODE_TERRITORY_CODE 541 // total number of areas (i.e. recognised iso codes) in this database
12+
#define MAX_CCODE 541 // total number of areas (i.e. recognised iso codes) in this database
2913
static char *entity_iso = ""
3014
"VAT,MCO,GIB,TKL,CCK,BLM,NRU,TUV,MAC,SXM,"
3115
"MAF,NFK,PCN,BVT,BMU,IOT,SMR,GGY,AIA,MSR,"
@@ -168,7 +152,7 @@ static char encode_chars[31] = {
168152
};
169153

170154

171-
static UWORD data_start[MAX_MAPCODE_TERRITORY_CODE+1] = {
155+
static UWORD data_start[MAX_CCODE+1] = {
172156
0, 3, 6, 9, 13, 16, 18, 19, 30, 31,
173157
33, 35, 37, 42, 44, 47, 51, 54, 56, 58,
174158
60, 62, 64, 68, 71, 79, 81, 116, 121, 131,
@@ -226,13 +210,13 @@ static UWORD data_start[MAX_MAPCODE_TERRITORY_CODE+1] = {
226210
16130,16162
227211
};
228212

229-
#define NR_BOUNDARY_RECS 16162
213+
#define NR_RECS 16162
230214
#define WORST_RECS_PER_CCODE 195 // 8 Argentina @43
231215

232216
typedef struct { long minx; long miny; long maxx; long maxy; unsigned long flags; } mminforec;
233217

234218
#ifndef MAKE_SOURCE_DIGITAL
235-
static mminforec mminfo[NR_BOUNDARY_RECS+1] = {
219+
static mminforec mminfo[NR_RECS+1] = {
236220
{ 12433114, 41851944, 12548434, 41938434,0x001002b},
237221
{ 5850000, 35450000, 18560000, 55080000,0x50a0636},
238222
{ 12444000, 41899000, 12460000, 41908000,0x003063c},

mapcodelib/mapcoder.c

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,8 +2317,8 @@ void asdms1(unsigned char *r,double v,long max,unsigned char degsym) // worst ca
23172317
unsigned char *asdms(unsigned char *r,double lat,double lon,unsigned char degsym) // worst case EXcluding zts is 22 bytes: -##d##'##",-###d##'##"
23182318
{
23192319
asdms1(r,lat,90*3600,degsym);
2320-
strcat(r,",");
2321-
asdms1(r+strlen(r),lon,180*3600,degsym);
2320+
strcat((char*)r,",");
2321+
asdms1(r+strlen((char*)r),lon,180*3600,degsym);
23222322
return r;
23232323
}
23242324

@@ -2348,7 +2348,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
23482348
while ( expnow<4 && isdig(*i) )
23492349
{
23502350
// get value
2351-
double v=atof(i); skipfp(i); skipwhite(i);
2351+
double v=atof((char*)i); skipfp(i); skipwhite(i);
23522352
if ( *i && strchr("oOdD\x0F8\x0BA\x0B0\x0A7",*i) ) // degree symbol? $F8=248degree $BA=186 $B0=176 $A7=167
23532353
{
23542354
i++; skipwhite(i);

mapcodelib/mapcoder.h

100755100644
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define UWORD unsigned short int // 2-byte unsigned integer.
2020
#define SUPPORT_FOREIGN_ALPHABETS
2121

22-
#define MAX_NR_OF_MAPCODE_RESULTS 64 // Max. number of results returned by encoder.
22+
#define MAX_NR_OF_MAPCODE_RESULTS 48 // Max. number of results returned by encoder.
2323
#define MAX_MAPCODE_RESULT_LEN 24 // Max. number of characters in a single result.
2424
#define COMPARE_MAPCODE_MISSING_CHARACTERS -999 // Used for compareWithMapcodeFormat.
2525

@@ -203,3 +203,21 @@ const char* decodeToRoman(const UWORD* string);
203203
* de-allocated by the caller. It will be overwritten by a subsequent call to this method!
204204
*/
205205
const UWORD* encodeToAlphabet(const char* mapcode, int alphabet);
206+
207+
208+
/**
209+
* List of #defines to support legacy systems. These names are deprecated but supported for
210+
* existing systems. Please use the names above.
211+
*/
212+
#define coord2mc encodeLatLonToMapcodes
213+
#define coord2mc1 encodeLatLonToSingleMapcode
214+
#define mc2coord decodeMapcodeToLatLon
215+
#define lookslikemapcode compareWithMapcodeFormat
216+
#define text2tc convertTerritoryIsoNameToCode
217+
#define tc2text convertTerritoryCodeToIsoName
218+
#define tccontext getCountryOrParentCountry
219+
#define tcparent getParentCountryOfState
220+
#define decode_to_roman decodeToRoman
221+
#define encode_to_alphabet encodeToAlphabet
222+
#define MAX_MAPCODE_TERRITORY_CODE MAX_CCODE
223+
#define NR_BOUNDARY_RECS NR_RECS

0 commit comments

Comments
 (0)