Skip to main content

grib/grid/
flags.rs

1use crate::def::grib2::template::param_set;
2
3impl param_set::ScanningMode {
4    /// Returns `true` if points of the first row or column scan in the `+i`
5    /// (`+x`) direction.
6    ///
7    /// # Examples
8    ///
9    /// ```
10    /// assert_eq!(
11    ///     grib::def::grib2::template::param_set::ScanningMode(0b00000000).scans_positively_for_i(),
12    ///     true
13    /// );
14    /// ```
15    pub fn scans_positively_for_i(&self) -> bool {
16        self.0 & 0b10000000 == 0
17    }
18
19    /// Returns `true` if points of the first row or column scan in the `+j`
20    /// (`+y`) direction.
21    ///
22    /// # Examples
23    ///
24    /// ```
25    /// assert_eq!(
26    ///     grib::def::grib2::template::param_set::ScanningMode(0b00000000).scans_positively_for_j(),
27    ///     false
28    /// );
29    /// ```
30    pub fn scans_positively_for_j(&self) -> bool {
31        self.0 & 0b01000000 != 0
32    }
33
34    /// Returns `true` if adjacent points in `i` (`x`) direction are
35    /// consecutive.
36    ///
37    /// # Examples
38    ///
39    /// ```
40    /// assert_eq!(
41    ///     grib::def::grib2::template::param_set::ScanningMode(0b00000000).is_consecutive_for_i(),
42    ///     true
43    /// );
44    /// ```
45    pub fn is_consecutive_for_i(&self) -> bool {
46        self.0 & 0b00100000 == 0
47    }
48
49    /// Returns `true` if adjacent rows scans in the opposite direction.
50    ///
51    /// # Examples
52    ///
53    /// ```
54    /// assert_eq!(
55    ///     grib::def::grib2::template::param_set::ScanningMode(0b00000000).scans_alternating_rows(),
56    ///     false
57    /// );
58    /// ```
59    pub fn scans_alternating_rows(&self) -> bool {
60        self.0 & 0b00010000 != 0
61    }
62
63    pub(crate) fn has_unsupported_flags(&self) -> bool {
64        self.0 & 0b00001111 != 0
65    }
66}
67
68impl param_set::ProjectionCentreFlag {
69    /// Returns `true` if North Pole is on the projection plane. Otherwise (i.e.
70    /// if South Pole is on), returns `false`.
71    ///
72    /// # Examples
73    ///
74    /// ```
75    /// assert_eq!(
76    ///     grib::def::grib2::template::param_set::ProjectionCentreFlag(0b00000000)
77    ///         .contains_north_pole_on_projection_plane(),
78    ///     true
79    /// );
80    /// ```
81    pub fn contains_north_pole_on_projection_plane(&self) -> bool {
82        self.0 & 0b10000000 == 0
83    }
84
85    /// Returns `true` if projection is bipolar and symmetric. Otherwise (i.e.
86    /// if only one projection centre is used), returns `false`.
87    ///
88    /// # Examples
89    ///
90    /// ```
91    /// assert_eq!(
92    ///     grib::def::grib2::template::param_set::ProjectionCentreFlag(0b00000000).is_bipolar(),
93    ///     false
94    /// );
95    /// ```
96    pub fn is_bipolar(&self) -> bool {
97        self.0 & 0b01000000 != 0
98    }
99
100    #[allow(dead_code)]
101    pub(crate) fn has_unsupported_flags(&self) -> bool {
102        self.0 & 0b00111111 != 0
103    }
104}