Skip to content

Commit 29fcc8b

Browse files
committed
Added LIMIT_TO_MICRODEGREES
1 parent 0460d94 commit 29fcc8b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

utility/mapcode.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
#include <time.h>
4444
#include "../mapcodelib/mapcoder.c"
4545

46+
// Specific define to be able to limit output to microdegrees, for test files.
47+
#undef LIMIT_TO_MICRODEGREES
48+
4649
#define my_isnan(x) (false)
4750
#define my_round(x) ((long) (floor((x) + 0.5)))
4851

@@ -282,18 +285,28 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
282285
char* results[2 * MAX_NR_OF_MAPCODE_RESULTS];
283286
int context = 0;
284287

285-
while (lon > 180) {
286-
lon -= 360;
288+
while (lon > 180.0) {
289+
lon -= 360.0;
290+
}
291+
while (lon < -180.0) {
292+
lon += 360.0;
287293
}
288-
while (lon < -180) {
289-
lon += 360;
294+
while (lat > 90.0) {
295+
lat -= 180.0;
290296
}
291-
while (lat > 90) {
292-
lat -= 180;
297+
while (lat < -90.0) {
298+
lat += 180.0;
293299
}
294-
while (lat < -90) {
295-
lat += 180;
300+
301+
#ifdef LIMIT_TO_MICRODEGREES
302+
{
303+
// Need to truncate lat/lon to microdegrees.
304+
long lon32 = lon * 1000000.0;
305+
long lat32 = lat * 1000000.0;
306+
lon = (lon32 / 1000000.0);
307+
lat = (lat32 / 1000000.0);
296308
}
309+
#endif
297310

298311
const int nrResults = encodeLatLonToMapcodes_Deprecated(results, lat, lon, context, extraDigits);
299312
if (nrResults <= 0) {

0 commit comments

Comments
 (0)