geoconv/
wgs72.rs

1// {{{ Copyright (c) Paul R. Tagliamonte <paultag@gmail.com>, 2023-2024
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE. }}}
20
21use crate::wgs::Wgs;
22
23/// [Wgs72] ("World Geodetic System 1972") is a standard published by the United
24/// States National Geospatial-Intelligence Agency.
25///
26/// This CoordinateSystem isn't used very much any more (if at all), but is
27/// implemented to assist with the conversion of old geospatial data
28/// to the Wgs84 system, what you actually want.
29#[derive(Debug, Copy, Clone, PartialEq)]
30pub struct Wgs72 {}
31
32impl Wgs for Wgs72 {
33    const A: f64 = 6378135.0;
34    const B: f64 = 6356750.52;
35}
36
37#[cfg(test)]
38mod tests {
39    use super::Wgs72;
40    use crate::{Degrees, Lle, Meters, Wgs84};
41
42    type Wgs72Lle = Lle<Wgs72, Degrees>;
43    type Wgs84Lle = Lle<Wgs84, Degrees>;
44
45    macro_rules! assert_in_eps {
46        ($x:expr, $y:expr, $d:expr) => {
47            if !($x - $y < $d && $y - $x < $d) {
48                panic!();
49            }
50        };
51    }
52
53    #[test]
54    fn round_trip_wgs72_to_wgs84() {
55        let origin = Wgs72Lle::new(Degrees::new(10.0), Degrees::new(-20.0), Meters::new(30.0));
56        let translated: Wgs84Lle = origin.translate();
57        let round_trip: Wgs72Lle = translated.translate();
58
59        assert_in_eps!(
60            origin.latitude.as_float(),
61            round_trip.latitude.as_float(),
62            1e-7
63        );
64
65        assert_in_eps!(
66            origin.longitude.as_float(),
67            round_trip.longitude.as_float(),
68            1e-7
69        );
70
71        assert_in_eps!(
72            origin.elevation.as_float(),
73            round_trip.elevation.as_float(),
74            1e-7
75        );
76    }
77}
78
79// vim: foldmethod=marker