• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 10178074589

31 Jul 2024 09:34AM UTC coverage: 91.068% (+0.4%) from 90.682%
10178074589

push

github

web-flow
Merge pull request #973 from geo-engine/remove-XGB-update-toolchain

Remove-XGB-update-toolchain

81 of 88 new or added lines in 29 files covered. (92.05%)

456 existing lines in 119 files now uncovered.

131088 of 143945 relevant lines covered (91.07%)

53581.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.17
/datatypes/src/primitives/query_rectangle.rs
1
use super::{
2
    AxisAlignedRectangle, BoundingBox2D, SpatialPartition2D, SpatialPartitioned, SpatialResolution,
3
    TimeInterval,
4
};
5
use crate::{
6
    error::{DuplicateBandInQueryBandSelection, QueryBandSelectionMustNotBeEmpty},
7
    util::Result,
8
};
9
use serde::{Deserialize, Serialize};
10
use snafu::ensure;
11

12
/// A spatio-temporal rectangle with a specified resolution and the selected bands
UNCOV
13
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
×
14
#[serde(rename_all = "camelCase")]
15
pub struct QueryRectangle<
16
    SpatialBounds: AxisAlignedRectangle,
17
    AttributeSelection: QueryAttributeSelection,
18
> {
19
    pub spatial_bounds: SpatialBounds,
20
    pub time_interval: TimeInterval,
21
    pub spatial_resolution: SpatialResolution,
22
    pub attributes: AttributeSelection,
23
}
24

25
pub trait QueryAttributeSelection: Clone + Send + Sync {}
26

27
#[derive(Clone, Debug, PartialEq, Serialize)]
28
pub struct BandSelection(Vec<u32>);
29

30
impl BandSelection {
31
    pub fn new(bands: Vec<u32>) -> Result<Self> {
13✔
32
        fn has_no_duplicates<T: std::hash::Hash + std::cmp::Eq>(vec: &[T]) -> bool {
13✔
33
            let set: std::collections::HashSet<_> = vec.iter().collect();
13✔
34
            set.len() == vec.len()
13✔
35
        }
13✔
36

13✔
37
        ensure!(has_no_duplicates(&bands), DuplicateBandInQueryBandSelection);
13✔
38
        ensure!(!bands.is_empty(), QueryBandSelectionMustNotBeEmpty);
13✔
39

40
        Ok(Self(bands))
13✔
41
    }
13✔
42

43
    pub fn new_unchecked(bands: Vec<u32>) -> Self {
228✔
44
        Self(bands)
228✔
45
    }
228✔
46

47
    pub fn first() -> Self {
216✔
48
        Self(vec![0])
216✔
49
    }
216✔
50

51
    pub fn first_n(n: u32) -> Self {
27✔
52
        Self((0..n).collect())
27✔
53
    }
27✔
54

55
    pub fn new_single(band: u32) -> Self {
21✔
56
        Self(vec![band])
21✔
57
    }
21✔
58

59
    pub fn count(&self) -> u32 {
198✔
60
        self.0.len() as u32
198✔
61
    }
198✔
62

63
    pub fn as_slice(&self) -> &[u32] {
1,176✔
64
        &self.0
1,176✔
65
    }
1,176✔
66

67
    pub fn as_vec(&self) -> Vec<u32> {
123✔
68
        self.0.clone()
123✔
69
    }
123✔
70
}
71

72
impl From<u32> for BandSelection {
73
    fn from(value: u32) -> Self {
209✔
74
        Self(vec![value])
209✔
75
    }
209✔
76
}
77

78
impl TryFrom<Vec<u32>> for BandSelection {
79
    type Error = crate::error::Error;
80

81
    fn try_from(value: Vec<u32>) -> Result<Self, Self::Error> {
×
82
        Self::new(value)
×
83
    }
×
84
}
85

86
impl<const N: usize> TryFrom<[u32; N]> for BandSelection {
87
    type Error = crate::error::Error;
88

89
    fn try_from(value: [u32; N]) -> Result<Self, Self::Error> {
11✔
90
        Self::new(value.to_vec())
11✔
91
    }
11✔
92
}
93

94
impl QueryAttributeSelection for BandSelection {}
95

UNCOV
96
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
×
97
pub struct ColumnSelection {}
98

99
impl ColumnSelection {
100
    pub fn all() -> Self {
169✔
101
        Self {}
169✔
102
    }
169✔
103
}
104

105
impl QueryAttributeSelection for ColumnSelection {}
106

UNCOV
107
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
×
108
pub struct PlotSeriesSelection {}
109

110
impl PlotSeriesSelection {
111
    pub fn all() -> Self {
54✔
112
        Self {}
54✔
113
    }
54✔
114
}
115

116
impl QueryAttributeSelection for PlotSeriesSelection {}
117

118
pub type VectorQueryRectangle = QueryRectangle<BoundingBox2D, ColumnSelection>;
119
pub type RasterQueryRectangle = QueryRectangle<SpatialPartition2D, BandSelection>;
120
pub type PlotQueryRectangle = QueryRectangle<BoundingBox2D, PlotSeriesSelection>;
121

122
impl RasterQueryRectangle {
123
    pub fn from_qrect_and_bands<A>(
44✔
124
        query: &QueryRectangle<BoundingBox2D, A>,
44✔
125
        bands: BandSelection,
44✔
126
    ) -> Self
44✔
127
    where
44✔
128
        A: QueryAttributeSelection,
44✔
129
        QueryRectangle<BoundingBox2D, A>: SpatialPartitioned,
44✔
130
    {
44✔
131
        Self {
44✔
132
            spatial_bounds: query.spatial_partition(),
44✔
133
            time_interval: query.time_interval,
44✔
134
            spatial_resolution: query.spatial_resolution,
44✔
135
            attributes: bands,
44✔
136
        }
44✔
137
    }
44✔
138

139
    #[must_use]
140
    pub fn select_bands(&self, bands: BandSelection) -> Self {
4✔
141
        Self {
4✔
142
            spatial_bounds: self.spatial_bounds,
4✔
143
            time_interval: self.time_interval,
4✔
144
            spatial_resolution: self.spatial_resolution,
4✔
145
            attributes: bands,
4✔
146
        }
4✔
147
    }
4✔
148
}
149

150
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, ColumnSelection> {
151
    fn spatial_partition(&self) -> SpatialPartition2D {
16✔
152
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
16✔
153
    }
16✔
154
}
155

156
impl SpatialPartitioned for QueryRectangle<BoundingBox2D, PlotSeriesSelection> {
157
    fn spatial_partition(&self) -> SpatialPartition2D {
28✔
158
        SpatialPartition2D::with_bbox_and_resolution(self.spatial_bounds, self.spatial_resolution)
28✔
159
    }
28✔
160
}
161

162
impl SpatialPartitioned for QueryRectangle<SpatialPartition2D, BandSelection> {
163
    fn spatial_partition(&self) -> SpatialPartition2D {
545✔
164
        self.spatial_bounds
545✔
165
    }
545✔
166
}
167

168
impl From<QueryRectangle<BoundingBox2D, ColumnSelection>>
169
    for QueryRectangle<BoundingBox2D, PlotSeriesSelection>
170
{
171
    fn from(value: QueryRectangle<BoundingBox2D, ColumnSelection>) -> Self {
2✔
172
        Self {
2✔
173
            spatial_bounds: value.spatial_bounds,
2✔
174
            time_interval: value.time_interval,
2✔
175
            spatial_resolution: value.spatial_resolution,
2✔
176
            attributes: value.attributes.into(),
2✔
177
        }
2✔
178
    }
2✔
179
}
180

181
impl From<QueryRectangle<BoundingBox2D, PlotSeriesSelection>>
182
    for QueryRectangle<BoundingBox2D, ColumnSelection>
183
{
184
    fn from(value: QueryRectangle<BoundingBox2D, PlotSeriesSelection>) -> Self {
34✔
185
        Self {
34✔
186
            spatial_bounds: value.spatial_bounds,
34✔
187
            time_interval: value.time_interval,
34✔
188
            spatial_resolution: value.spatial_resolution,
34✔
189
            attributes: value.attributes.into(),
34✔
190
        }
34✔
191
    }
34✔
192
}
193

194
impl From<ColumnSelection> for PlotSeriesSelection {
195
    fn from(_: ColumnSelection) -> Self {
2✔
196
        Self {}
2✔
197
    }
2✔
198
}
199

200
impl From<PlotSeriesSelection> for ColumnSelection {
201
    fn from(_: PlotSeriesSelection) -> Self {
34✔
202
        Self {}
34✔
203
    }
34✔
204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc