@@ -274,39 +274,6 @@ static void selfCheckMapcodeToLatLon(const char* territory, const char* mapcode,
274274 }
275275}
276276
277-
278-
279- /* *
280- * The method asCoordinate() generates and returns a printable coordinate
281- * precisely as it would be interpreted internally by mapcode encoding
282- * (i.e. correctly rounded to the nearest one-millionth of a degree).
283- * As target, pass a buffer for at least 12 characters (including zero termination).
284- * If target = 0, an internal scratch buffer is used (the THIRD call will
285- * overwrite the first call).
286- */
287- static char asCoordinateBuffer[24 ];
288- static int ascoptr;
289- static const char * asCoordinate (double coord, char * target)
290- {
291- long c = (long ) ((coord * 1000000 ) + ((coord < 0 ) ? -0.5 : 0.5 ));
292- int negative = (c < 0 );
293- if (negative) {
294- c = -c;
295- }
296- if (target == 0 ) {
297- ascoptr= ((ascoptr != 0 ) ? 0 : 12 );
298- target = &asCoordinateBuffer[ascoptr];
299- }
300- sprintf (target," %s%d.%06d" , (negative ? " -" : " " ), (int ) (c / 1000000 ), (int ) (c % 1000000 ));
301- return target;
302- }
303-
304-
305- /* *
306- * The method printMapcode() generates and outputs Mapcodes for a lat/lon pair.
307- * If iShowError != 0, then encoding errors are output to stderr, otherwise they
308- * are ignored.
309- */
310277static void generateAndOutputMapcodes (double lat, double lon, int iShowError, int extraDigits, int useXYZ) {
311278
312279 char * results[MAX_NR_OF_MAPCODE_RESULTS];
@@ -328,7 +295,7 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
328295 const int nrResults = encodeLatLonToMapcodes (results, lat, lon, context, extraDigits);
329296 if (nrResults <= 0 ) {
330297 if (iShowError) {
331- fprintf (stderr, " error: cannot encode lat=%s , lon=%s )\n " , asCoordinate ( lat, 0 ), asCoordinate ( lon, 0 ) );
298+ fprintf (stderr, " error: cannot encode lat=%.12g , lon=%.12g )\n " , lat, lon);
332299 exit (NORMAL_ERROR);
333300 }
334301 }
@@ -338,10 +305,10 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
338305 double y;
339306 double z;
340307 convertLatLonToXYZ (lat, lon, &x, &y, &z);
341- printf (" %d %s %s %lf %lf %lf \n " , nrResults, asCoordinate ( lat, 0 ), asCoordinate ( lon, 0 ) , x, y, z);
308+ printf (" %d %.12g %.12g %.12g %.12g %.12g \n " , nrResults, lat, lon, x, y, z);
342309 }
343310 else {
344- printf (" %d %s %s \n " , nrResults, asCoordinate ( lat, 0 ), asCoordinate ( lon, 0 ) );
311+ printf (" %d %.12g %.12g \n " , nrResults, lat, lon);
345312 }
346313 for (int j = 0 ; j < nrResults; ++j) {
347314 const char * foundMapcode = results[(j * 2 )];
0 commit comments