1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/// The meaning of GPS time in the point records.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum GpsTimeType {
    /// GPS Week Time (the same as previous versions of LAS).
    Week,
    /// Standard GPS Time minus 1e9.
    Standard,
}

impl GpsTimeType {
    /// Returns true if this time type is gps standard time.
    ///
    /// # Examples
    ///
    /// ```
    /// use las::GpsTimeType;
    /// assert!(!GpsTimeType::Week.is_standard());
    /// assert!(GpsTimeType::Standard.is_standard());
    /// ```
    pub fn is_standard(&self) -> bool {
        match *self {
            GpsTimeType::Week => false,
            GpsTimeType::Standard => true,
        }
    }
}

impl From<GpsTimeType> for u16 {
    fn from(gps_time_type: GpsTimeType) -> u16 {
        match gps_time_type {
            GpsTimeType::Week => 0,
            GpsTimeType::Standard => 1,
        }
    }
}

impl From<u16> for GpsTimeType {
    fn from(n: u16) -> GpsTimeType {
        match n & 1 {
            0 => GpsTimeType::Week,
            1 => GpsTimeType::Standard,
            _ => unreachable!(),
        }
    }
}

impl Default for GpsTimeType {
    fn default() -> GpsTimeType {
        GpsTimeType::Week
    }
}