• 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

93.85
/datatypes/src/raster/empty_grid.rs
1
use super::{
2
    grid_traits::{ChangeGridBounds, GridShapeAccess},
3
    GridBoundingBox, GridBounds, GridIdx, GridShape, GridShape1D, GridShape2D, GridShape3D,
4
    GridSize, GridSpaceToLinearSpace,
5
};
6
use crate::util::{ByteSize, Result};
7
use serde::{Deserialize, Serialize};
8
use std::{marker::PhantomData, ops::Add};
9

UNCOV
10
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
×
11
#[serde(rename_all = "camelCase")]
12
pub struct EmptyGrid<D, T> {
13
    pub shape: D,
14
    pub phantom_data: PhantomData<T>,
15
}
16

17
pub type EmptyGrid1D<T> = EmptyGrid<GridShape1D, T>;
18
pub type EmptyGrid2D<T> = EmptyGrid<GridShape2D, T>;
19
pub type EmptyGrid3D<T> = EmptyGrid<GridShape3D, T>;
20

21
impl<D, T> EmptyGrid<D, T>
22
where
23
    D: GridSize,
24
{
25
    /// Creates a new `NoDataGrid`
26
    pub fn new(shape: D) -> Self {
67,841✔
27
        Self {
67,841✔
28
            shape,
67,841✔
29
            phantom_data: PhantomData,
67,841✔
30
        }
67,841✔
31
    }
67,841✔
32

33
    /// Converts the data type of the raster by converting it pixel-wise
34
    pub fn convert_dtype<To>(self) -> EmptyGrid<D, To>
66,297✔
35
    where
66,297✔
36
        T: 'static,
66,297✔
37
        To: 'static,
66,297✔
38
    {
66,297✔
39
        EmptyGrid::new(self.shape)
66,297✔
40
    }
66,297✔
41
}
42

43
impl<D, T> GridSize for EmptyGrid<D, T>
44
where
45
    D: GridSize + GridSpaceToLinearSpace,
46
{
47
    type ShapeArray = D::ShapeArray;
48

49
    const NDIM: usize = D::NDIM;
50

51
    fn axis_size(&self) -> Self::ShapeArray {
1✔
52
        self.shape.axis_size()
1✔
53
    }
1✔
54

55
    fn number_of_elements(&self) -> usize {
66,256✔
56
        self.shape.number_of_elements()
66,256✔
57
    }
66,256✔
58
}
59

60
impl<T, D> GridBounds for EmptyGrid<D, T>
61
where
62
    D: GridBounds,
63
{
64
    type IndexArray = D::IndexArray;
65

66
    fn min_index(&self) -> GridIdx<Self::IndexArray> {
134✔
67
        self.shape.min_index()
134✔
68
    }
134✔
69

70
    fn max_index(&self) -> GridIdx<Self::IndexArray> {
134✔
71
        self.shape.max_index()
134✔
72
    }
134✔
73
}
74

75
impl<D, T> GridShapeAccess for EmptyGrid<D, T>
76
where
77
    D: GridSize,
78
    D::ShapeArray: Into<GridShape<D::ShapeArray>>,
79
    T: Copy,
80
{
81
    type ShapeArray = D::ShapeArray;
82

83
    fn grid_shape_array(&self) -> Self::ShapeArray {
458✔
84
        self.shape.axis_size()
458✔
85
    }
458✔
86
}
87

88
impl<D, T, I> ChangeGridBounds<I> for EmptyGrid<D, T>
89
where
90
    I: AsRef<[isize]> + Clone,
91
    D: GridBounds<IndexArray = I> + Clone,
92
    T: Copy,
93
    GridBoundingBox<I>: GridSize,
94
    GridIdx<I>: Add<Output = GridIdx<I>> + From<I>,
95
{
96
    type Output = EmptyGrid<GridBoundingBox<I>, T>;
97

98
    fn shift_by_offset(self, offset: GridIdx<I>) -> Self::Output {
64✔
99
        EmptyGrid::new(self.shift_bounding_box(offset))
64✔
100
    }
64✔
101

102
    fn set_grid_bounds(self, bounds: GridBoundingBox<I>) -> Result<Self::Output> {
×
103
        Ok(EmptyGrid::new(bounds))
×
104
    }
×
105
}
106

107
impl<D, T> ByteSize for EmptyGrid<D, T> {}
108

109
#[cfg(test)]
110
mod tests {
111
    use crate::raster::BoundedGrid;
112
    use crate::raster::GridBoundingBox2D;
113

114
    use super::*;
115

116
    #[test]
117
    fn new() {
1✔
118
        let n: EmptyGrid2D<u8> = EmptyGrid2D::new([2, 2].into());
1✔
119
        let expected = EmptyGrid {
1✔
120
            shape: GridShape2D::from([2, 2]),
1✔
121
            phantom_data: PhantomData,
1✔
122
        };
1✔
123
        assert_eq!(n, expected);
1✔
124
    }
1✔
125

126
    #[test]
127
    fn ndim() {
1✔
128
        assert_eq!(EmptyGrid1D::<i32>::NDIM, 1);
1✔
129
        assert_eq!(EmptyGrid2D::<f64>::NDIM, 2);
1✔
130
        assert_eq!(EmptyGrid3D::<u16>::NDIM, 3);
1✔
131
    }
1✔
132

133
    #[test]
134
    fn axis_size() {
1✔
135
        let n: EmptyGrid2D<u8> = EmptyGrid2D::new([2, 2].into());
1✔
136
        assert_eq!(n.axis_size(), [2, 2]);
1✔
137
    }
1✔
138

139
    #[test]
140
    fn number_of_elements() {
1✔
141
        let n: EmptyGrid2D<u8> = EmptyGrid2D::new([2, 2].into());
1✔
142
        assert_eq!(n.number_of_elements(), 4);
1✔
143
    }
1✔
144

145
    #[test]
146
    fn grid_bounds_2d() {
1✔
147
        let dim: GridShape2D = [3, 2].into();
1✔
148
        let raster2d: EmptyGrid2D<u8> = EmptyGrid::new(dim);
1✔
149

1✔
150
        assert_eq!(raster2d.min_index(), GridIdx([0, 0]));
1✔
151
        assert_eq!(raster2d.max_index(), GridIdx([2, 1]));
1✔
152

153
        let exp_bbox = GridBoundingBox2D::new([0, 0], [2, 1]).unwrap();
1✔
154
        assert_eq!(raster2d.bounding_box(), exp_bbox);
1✔
155
    }
1✔
156
}
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