Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * Project: PROJ |
3 | | * Purpose: Distance computation |
4 | | * |
5 | | * Author: Thomas Knudsen, thokn@sdfe.dk, 2016-06-09/2016-11-06 |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2016, 2017 Thomas Knudsen/SDFE |
9 | | * |
10 | | * Permission is hereby granted, free of charge, to any person obtaining a |
11 | | * copy of this software and associated documentation files (the "Software"), |
12 | | * to deal in the Software without restriction, including without limitation |
13 | | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 | | * and/or sell copies of the Software, and to permit persons to whom the |
15 | | * Software is furnished to do so, subject to the following conditions: |
16 | | * |
17 | | * The above copyright notice and this permission notice shall be included |
18 | | * in all copies or substantial portions of the Software. |
19 | | * |
20 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
21 | | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
23 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
24 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
25 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
26 | | * DEALINGS IN THE SOFTWARE. |
27 | | *****************************************************************************/ |
28 | | |
29 | | #define FROM_PROJ_CPP |
30 | | |
31 | | #include "geodesic.h" |
32 | | |
33 | | #include "proj.h" |
34 | | #include "proj_internal.h" |
35 | | #include <math.h> |
36 | | |
37 | | #include "proj/internal/io_internal.hpp" |
38 | | |
39 | | /* Geodesic distance (in meter) + fwd and rev azimuth between two points on the |
40 | | * ellipsoid */ |
41 | 0 | PJ_COORD proj_geod(const PJ *P, PJ_COORD a, PJ_COORD b) { |
42 | 0 | PJ_COORD c; |
43 | 0 | if (!P->geod) { |
44 | 0 | return proj_coord_error(); |
45 | 0 | } |
46 | | /* Note: the geodesic code takes arguments in degrees */ |
47 | 0 | geod_inverse(P->geod, PJ_TODEG(a.lpz.phi), PJ_TODEG(a.lpz.lam), |
48 | 0 | PJ_TODEG(b.lpz.phi), PJ_TODEG(b.lpz.lam), c.v, c.v + 1, |
49 | 0 | c.v + 2); |
50 | | |
51 | | // cppcheck-suppress uninitvar |
52 | 0 | return c; |
53 | 0 | } |
54 | | |
55 | | /* Geodesic distance (in meter) between two points with angular 2D coordinates |
56 | | */ |
57 | 0 | double proj_lp_dist(const PJ *P, PJ_COORD a, PJ_COORD b) { |
58 | 0 | double s12, azi1, azi2; |
59 | | /* Note: the geodesic code takes arguments in degrees */ |
60 | 0 | if (!P->geod) { |
61 | 0 | return HUGE_VAL; |
62 | 0 | } |
63 | 0 | geod_inverse(P->geod, PJ_TODEG(a.lpz.phi), PJ_TODEG(a.lpz.lam), |
64 | 0 | PJ_TODEG(b.lpz.phi), PJ_TODEG(b.lpz.lam), &s12, &azi1, &azi2); |
65 | 0 | return s12; |
66 | 0 | } |
67 | | |
68 | | /* The geodesic distance AND the vertical offset */ |
69 | 0 | double proj_lpz_dist(const PJ *P, PJ_COORD a, PJ_COORD b) { |
70 | 0 | if (HUGE_VAL == a.lpz.lam || HUGE_VAL == b.lpz.lam) |
71 | 0 | return HUGE_VAL; |
72 | 0 | return hypot(proj_lp_dist(P, a, b), a.lpz.z - b.lpz.z); |
73 | 0 | } |
74 | | |
75 | | /* Euclidean distance between two points with linear 2D coordinates */ |
76 | 0 | double proj_xy_dist(PJ_COORD a, PJ_COORD b) { |
77 | 0 | return hypot(a.xy.x - b.xy.x, a.xy.y - b.xy.y); |
78 | 0 | } |
79 | | |
80 | | /* Euclidean distance between two points with linear 3D coordinates */ |
81 | 0 | double proj_xyz_dist(PJ_COORD a, PJ_COORD b) { |
82 | 0 | return hypot(proj_xy_dist(a, b), a.xyz.z - b.xyz.z); |
83 | 0 | } |