erfa/
ellipsoid.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5//! Ellipsoid code.
6
7/// Available ellipsoid models. If in doubt, use `WGS84`.
8#[derive(Clone, Copy, Debug)]
9pub enum Ellipsoid {
10    /// [World Geodetic System 1984
11    /// ensemble](https://en.wikipedia.org/wiki/World_Geodetic_System)
12    WGS84 = 1,
13    /// [Geodetic Reference System
14    /// 1980](https://en.wikipedia.org/wiki/Geodetic_Reference_System_1980)
15    GRS80 = 2,
16    /// [World Geodetic System 1972
17    /// ensemble](https://en.wikipedia.org/wiki/World_Geodetic_System)
18    WGS72 = 3,
19}
20
21impl Default for Ellipsoid {
22    fn default() -> Self {
23        Self::WGS84
24    }
25}
26
27impl Ellipsoid {
28    /// Get the parameters of the supplied [`Ellipsoid`] in the form of
29    /// equatorial radius in meters (`a`) and flattening (`f`).  The latter is a
30    /// number around 0.00335, i.e. around 1/298.
31    ///
32    /// # References:
33    ///
34    /// * Department of Defense World Geodetic System 1984, National Imagery and
35    ///   Mapping Agency Technical Report 8350.2, Third Edition, p3-2.
36    ///
37    /// * Moritz, H., Bull. Geodesique 66-2, 187 (1992).
38    ///
39    /// * The Department of Defense World Geodetic System 1972, World Geodetic
40    ///   System Committee, May 1974.
41    ///
42    /// * Explanatory Supplement to the Astronomical Almanac, P. Kenneth
43    ///   Seidelmann (ed), University Science Books (1992), p220.
44    ///
45    pub fn get_params(self) -> (f64, f64) {
46        match self {
47            Ellipsoid::WGS84 => (6378137.0, 1.0 / 298.257223563),
48            Ellipsoid::GRS80 => (6378137.0, 1.0 / 298.257222101),
49            Ellipsoid::WGS72 => (6378135.0, 1.0 / 298.26),
50        }
51    }
52}