|
6 | 6 | #include "PolyUtil.hpp"
|
7 | 7 |
|
8 | 8 | void usage() {
|
9 |
| - std::cout << "Usage:\n\n\tdistance latP lngP latA lngA [latB lngB]\n\n\tprint the sperical distance of point P from point A or of P from the great circle between A and B\n"; |
| 9 | + std::cout << "Usage:\n\n\tdistance latP lngP latA lngA latB lngB absoluteDelta relativeDelta\n\n\tcheck if a point P is within the given thresholdsa (in meters or percentage of the distance A-B) of the great circle route between A and B.\n"; |
10 | 10 | }
|
11 | 11 |
|
12 | 12 | int main(int argc, char** argv) {
|
13 |
| - if (argc != 5 && argc != 7) { |
| 13 | + if (argc != 9) { |
14 | 14 | usage();
|
15 | 15 | exit(1);
|
16 | 16 | }
|
17 |
| - std::string pLat = argv[1]; |
18 |
| - std::string pLng = argv[2]; |
19 |
| - std::string aLat = argv[3]; |
20 |
| - std::string aLng = argv[4]; |
21 |
| - |
22 |
| - LatLng p = { std::stod(pLat), std::stod(pLng) }; |
23 |
| - LatLng a = { std::stod(aLat), std::stod(aLng) }; |
24 |
| - |
25 |
| - std::string bLat, bLng; |
26 |
| - LatLng b = { 0.0, 0.0 }; |
| 17 | + LatLng p = { std::stod(argv[1]), std::stod(argv[2]) }; |
| 18 | + LatLng a = { std::stod(argv[3]), std::stod(argv[4]) }; |
| 19 | + LatLng b = { std::stod(argv[5]), std::stod(argv[6]) }; |
| 20 | + double distThreshold = std::stod(argv[7]) * 1852; |
| 21 | + double distPercentage = std::stod(argv[8]); |
27 | 22 |
|
28 | 23 | double distPA = SphericalUtil::computeDistanceBetween(p, a);
|
| 24 | + double distPB = SphericalUtil::computeDistanceBetween(p, b); |
| 25 | + double distAB = SphericalUtil::computeDistanceBetween(a, b); |
29 | 26 |
|
30 |
| - std::cout << "{\"distPA\": " << distPA / 1852.0; |
31 |
| - |
32 |
| - if (argc ==7) { |
33 |
| - std::string bLat = argv[5]; |
34 |
| - std::string bLng = argv[6]; |
35 |
| - LatLng b = { std::stod(bLat), std::stod(bLng) }; |
| 27 | + // calculate if the point is within the given tolerance of the route |
| 28 | + std::vector<LatLng> route = { a, b}; |
| 29 | + double threshold = std::max(distThreshold, distPercentage * distAB / 100.0); |
| 30 | + bool withinThreshold = PolyUtil::isLocationOnPath(p, route, threshold); |
36 | 31 |
|
37 |
| - double distPB = SphericalUtil::computeDistanceBetween(p, b); |
38 |
| - std::cout << ",\"distPB\": " << distPB / 1852.0; |
39 |
| - |
40 |
| - double distAB = SphericalUtil::computeDistanceBetween(a, b); |
41 |
| - std::cout << ",\"distAB\": " << distAB / 1852.0; |
42 |
| - |
43 |
| - double distPAB = PolyUtil::distanceToLine(p, a, b); |
44 |
| - std::cout << ",\"distPAB\": " << distPAB / 1852.0; |
45 |
| - } |
46 |
| - std::cout << "}"; |
| 32 | + std::cout << "{\"distPA\": " << distPA / 1852.0; |
| 33 | + std::cout << ",\"distPB\": " << distPB / 1852.0; |
| 34 | + std::cout << ",\"distAB\": " << distAB / 1852.0; |
| 35 | + std::cout << ",\"withinThreshold\": " << withinThreshold << "}"; |
47 | 36 |
|
48 | 37 | return 0;
|
49 | 38 | }
|
0 commit comments