This is an automated email from the git hooks/post-receive script. sf pushed a commit to annotated tag v1.33 in repository mapcode.
commit e0bb80c218d61d27cc9953d13bd0f86ee24f9644 Author: Rijn Buve <[email protected]> Date: Wed Sep 3 19:36:54 2014 +0200 Added PGs changes to printing lat/lon --- LICENSE | 0 NOTICE | 0 RELEASE_NOTES | 0 example/mapcode.cpp | 43 ++++++++++++++++++++++++++++++++++++------- mapcodelib/basics.h | 0 mapcodelib/mapcoder.c | 18 +++++++++++++----- mapcodelib/mapcoder.h | 27 +++++++++++++-------------- 7 files changed, 62 insertions(+), 26 deletions(-) diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/NOTICE b/NOTICE old mode 100644 new mode 100755 diff --git a/RELEASE_NOTES b/RELEASE_NOTES old mode 100644 new mode 100755 diff --git a/example/mapcode.cpp b/example/mapcode.cpp old mode 100644 new mode 100755 index 20bd7b8..13b067c --- a/example/mapcode.cpp +++ b/example/mapcode.cpp @@ -24,10 +24,14 @@ */ #include <stdio.h> -#include <time.h> #include <math.h> +#include <time.h> #include "../mapcodelib/mapcoder.c" +#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; @@ -145,8 +149,8 @@ static void unitToLatLonDeg( const double lonRad = atan2(y, x); // Convert radians to degrees. - *latDeg = (latRad == NAN) ? 90.0 : radToDeg(latRad); - *lonDeg = (lonRad == NAN) ? 180.0 : radToDeg(lonRad); + *latDeg = my_isnan(latRad) ? 90.0 : radToDeg(latRad); + *lonDeg = my_isnan(lonRad) ? 180.0 : radToDeg(lonRad); } @@ -159,7 +163,6 @@ static void convertLatLonToXYZ(double latDeg, double lonDeg, double* x, double* double latRad = degToRad(latDeg); double lonRad = degToRad(lonDeg); *x = cos(latRad) * cos(lonRad); - *y = cos(latRad) * sin(lonRad); *z = sin(latRad); } @@ -240,6 +243,32 @@ 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 + * (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 + * overwrite the first call). + */ +static char asCoordinateBuffer[24]; +static int ascoptr; +static const char* asCoordinate(double coord, char* target) +{ + long c = (long) ((coord * 1000000) + ((coord < 0) ? -0.5 : 0.5)); + int negative = (c < 0); + if (negative) { + c = -c; + } + if (target == 0) { + target = &asCoordinateBuffer[ascoptr]; + ascoptr= ((ascoptr != 0) ? 0 : 12); + } + sprintf(target,"%s%d.%06d", (negative ? "-" : ""), c / 1000000, c % 1000000); + return target; +} + + +/** * The method printMapcode() generates and outputs Mapcodes for a lat/lon pair. * If iShowError != 0, then encoding errors are output to stderr, otherwise they * are ignored. @@ -251,7 +280,7 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError) { const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context); if (nrResults <= 0) { if (iShowError) { - fprintf(stderr, "error: cannot encode lat=%f, lon=%f)\n", lat, lon); + fprintf(stderr, "error: cannot encode lat=%s, lon=%s)\n", asCoordinate(lat, 0), asCoordinate(lon, 0)); exit(NORMAL_ERROR); } } @@ -260,7 +289,7 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError) { double y; double z; convertLatLonToXYZ(lat, lon, &x, &y, &z); - printf("%d %lf %lf %lf %lf %lf\n", nrResults, lat, lon, x, y, z); + printf("%d %s %s %lf %lf %lf\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0), x, y, z); for (int j = 0; j < nrResults; ++j) { const char* foundMapcode = results[(j * 2)]; const char* foundTerritory = results[(j * 2) + 1]; @@ -541,7 +570,7 @@ int main(const int argc, const char** argv) int gridX = 0; int gridY = 0; - int line = (int) (sqrt(totalNrOfPoints) + 0.5); + int line = my_round(sqrt(totalNrOfPoints)); for (int i = 0; i < totalNrOfPoints; ++i) { double lat; double lon; diff --git a/mapcodelib/basics.h b/mapcodelib/basics.h old mode 100644 new mode 100755 diff --git a/mapcodelib/mapcoder.c b/mapcodelib/mapcoder.c old mode 100644 new mode 100755 index 165b11a..aee1829 --- a/mapcodelib/mapcoder.c +++ b/mapcodelib/mapcoder.c @@ -42,7 +42,17 @@ int current_ccode=-1; // cache for setup_country #define MAXGLOBALRESULTS 32 // The worst actually seems to be 14, which is at 52.050500, 113.468600 #define WORSTCASE_MAPCODE_BYTES 16 // worst case is high-precision earth xxxxx.yyyy-zz, rounded upwords to multiple of 4 bytes (assuming latin-only results) -char global_buffer[MAXGLOBALRESULTS*2][WORSTCASE_MAPCODE_BYTES]; // cache for worst-case result +char global_storage[2048]; // cyclic cache for results +int storage_ptr; +char *addstorage(const char *str) +{ + int len=strlen(str)+1; // bytes needed; + storage_ptr &= (2048-1); + if (storage_ptr<0 || storage_ptr+len>2048-2) storage_ptr=0; + strcpy(global_storage+storage_ptr,str); + storage_ptr+=len; + return global_storage+storage_ptr-len; +} char **global_results; int nr_global_results; @@ -1090,10 +1100,8 @@ void addresult(char *resultbuffer, char *result, long x,long y, int ccode) if (result_override>=0) ccode=result_override; // 1.32 true recursive processing #endif if (*result && global_results && nr_global_results>=0 && nr_global_results+1<(2*MAXGLOBALRESULTS)) { - global_results[nr_global_results]=global_buffer[nr_global_results]; - strcpy(global_results[nr_global_results++],result); - global_results[nr_global_results]=global_buffer[nr_global_results]; - strcpy(global_results[nr_global_results++],makeiso(ccode,1)); + global_results[nr_global_results++] = addstorage(result); + global_results[nr_global_results++] = addstorage(makeiso(ccode,1)); } // add to buffer (if any) if (resultbuffer) diff --git a/mapcodelib/mapcoder.h b/mapcodelib/mapcoder.h old mode 100644 new mode 100755 index ab483bc..a889ba1 --- a/mapcodelib/mapcoder.h +++ b/mapcodelib/mapcoder.h @@ -206,18 +206,17 @@ const UWORD* encodeToAlphabet(const char* mapcode, int alphabet); /** - * List of #defines to support legacy systems. These names are deprecated but supported for - * existing systems. Please use the names above. + * list of #defines to support legacy systems */ -#define coord2mc encodeLatLonToMapcodes -#define coord2mc1 encodeLatLonToSingleMapcode -#define mc2coord decodeMapcodeToLatLon -#define lookslikemapcode compareWithMapcodeFormat -#define text2tc convertTerritoryIsoNameToCode -#define tc2text convertTerritoryCodeToIsoName -#define tccontext getCountryOrParentCountry -#define tcparent getParentCountryOfState -#define decode_to_roman decodeToRoman -#define encode_to_alphabet encodeToAlphabet -#define MAX_MAPCODE_TERRITORY_CODE MAX_CCODE -#define NR_BOUNDARY_RECS NR_RECS +#define coord2mc encodeLatLonToMapcodes +#define coord2mc1 encodeLatLonToSingleMapcode +#define mc2coord decodeMapcodeToLatLon +#define lookslikemapcode compareWithMapcodeFormat +#define text2tc convertTerritoryIsoNameToCode +#define tc2text convertTerritoryCodeToIsoName +#define tccontext getCountryOrParentCountry +#define tcparent getParentCountryOfState +#define decode_to_roman decodeToRoman +#define encode_to_alphabet encodeToAlphabet +#define MAX_MAPCODE_TERRITORY_CODE MAX_CCODE +#define NR_BOUNDARY_RECS NR_RECS -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git _______________________________________________ Pkg-grass-devel mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

