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

geo-engine / geoengine / 3929938005

pending completion
3929938005

push

github

GitHub
Merge #713

84930 of 96741 relevant lines covered (87.79%)

79640.1 hits per line

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

95.71
/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::Result;
7
use serde::{Deserialize, Serialize};
8
use std::{marker::PhantomData, ops::Add};
9

10
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
505✔
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 {
55,040✔
27
        Self {
55,040✔
28
            shape,
55,040✔
29
            phantom_data: PhantomData,
55,040✔
30
        }
55,040✔
31
    }
55,040✔
32

33
    /// Converts the data type of the raster by converting it pixel-wise
34
    pub fn convert_dtype<To>(self) -> EmptyGrid<D, To>
54,009✔
35
    where
54,009✔
36
        T: 'static,
54,009✔
37
        To: 'static,
54,009✔
38
    {
54,009✔
39
        EmptyGrid::new(self.shape)
54,009✔
40
    }
54,009✔
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 {
53,996✔
56
        self.shape.number_of_elements()
53,996✔
57
    }
53,996✔
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> {
38✔
67
        self.shape.min_index()
38✔
68
    }
38✔
69

70
    fn max_index(&self) -> GridIdx<Self::IndexArray> {
38✔
71
        self.shape.max_index()
38✔
72
    }
38✔
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 {
280✔
84
        self.shape.axis_size()
280✔
85
    }
280✔
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 {
16✔
99
        EmptyGrid::new(self.shift_bounding_box(offset))
16✔
100
    }
16✔
101

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

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

112
    use super::*;
113

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

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

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

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

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

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

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