See More

/* * Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This application uses the Mapcode C library to encode and decode Mapcodes. * It also serves as an example of how to use this library in a C environment. * * It also offers additional options to generate "test sets" of coordinates * and Mapcodes to check other Mapcode implementations against reference data. * * These test sets consist of: * * - a number of "grid distributed" coordinates, which forms a set of coordinates * and their Mapcodes, wrapped as a grid around the Earth; * * - a number of "random uniformly distributed" coordinates, which forms a set of * random coordinates on the surface of Earth; or * * - a set which consists of typical Mapcode "boundaries" and "edge cases", based * on the internal implementation of the boundaries database of the Mapcode * implementation. * * If the executable is named mapcode_debug, the self-checking mechanism is * activated. Note, however, that the self checks may fail for certain decodes * even though the decodes are OK. */ #include #include #include #include "../mapcodelib/mapcoder.c" // Specific define to be able to limit output to microdegrees, for test files. #undef LIMIT_TO_MICRODEGREES #define my_isnan(x) (false) #define my_round(x) ((int) (floor((x) + 0.5))) static int selfCheckEnabled = 0; static const int NORMAL_ERROR = 1; static const int INTERNAL_ERROR = 2; /** * Some global constants to be used. */ static const double PI = 3.14159265358979323846; static const int SHOW_PROGRESS = 125; static const double DELTA = 0.001; /** * These statistics are stored globally so they can be updated easily by the * generateAndOutputMapcodes() method. */ static int totalNrOfPoints = 0; static int totalNrOfResults = 0; static int largestNrOfResults = 0; static double latLargestNrOfResults = 0.0; static double lonLargestNrOfResults = 0.0; /** * The usage() method explains how this application can be used. It is called * whenever a incorrect amount or combination of parameters is entered. */ static void usage(const char *appName) { printf("MAPCODE (version %s)\n", mapcode_cversion); printf("Copyright (C) 2014-2015 Stichting Mapcode Foundation\n"); printf("\n"); #ifndef SUPPORT_HIGH_PRECISION printf("Warning: High precision support is disabled in this build.)\n\n"); #endif #ifdef LIMIT_TO_MICRODEGREES printf("Warning: This build is limited to using microdegrees.\n\n"); #endif printf("Usage:\n"); printf(" %s [-d| --decode] [ ...]\n", appName); printf("\n"); printf(" Decode a mapcode to a lat/lon. The default territory code is used if\n"); printf(" the mapcode is a shorthand local code\n"); printf("\n"); printf(" %s [-e[0-8] | --encode[0-8]] <-90..90><-180..180>&&&&&&&foundLat&foundLon&x&y&z&lat&lon<-90..90><-180..180>&&&&&&&lat&lon