• 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.89
/datatypes/src/primitives/spatial_resolution.rs
1
use std::{convert::TryFrom, ops::Add, ops::Div, ops::Mul, ops::Sub};
2

3
use crate::primitives::error;
4
use crate::util::Result;
5
use serde::{Deserialize, Serialize};
6
use snafu::ensure;
7

8
/// The spatial resolution in SRS units
9
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)]
265✔
10
pub struct SpatialResolution {
11
    pub x: f64,
12
    pub y: f64,
13
}
14

15
impl SpatialResolution {
16
    /// Create a new `SpatialResolution` object
17
    pub fn new_unchecked(x: f64, y: f64) -> Self {
200✔
18
        SpatialResolution { x, y }
200✔
19
    }
200✔
20

21
    pub fn new(x: f64, y: f64) -> Result<Self> {
69✔
22
        ensure!(x > 0.0, error::InvalidSpatialResolution { value: x });
69✔
23
        ensure!(y > 0.0, error::InvalidSpatialResolution { value: y });
69✔
24
        Ok(Self::new_unchecked(x, y))
69✔
25
    }
69✔
26

27
    pub fn zero_point_one() -> Self {
41✔
28
        SpatialResolution { x: 0.1, y: 0.1 }
41✔
29
    }
41✔
30

31
    pub fn zero_point_five() -> Self {
1✔
32
        SpatialResolution { x: 0.5, y: 0.5 }
1✔
33
    }
1✔
34

35
    pub fn one() -> Self {
154✔
36
        SpatialResolution { x: 1., y: 1. }
154✔
37
    }
154✔
38
}
39

40
impl TryFrom<(f64, f64)> for SpatialResolution {
41
    type Error = crate::error::Error;
42

43
    fn try_from(value: (f64, f64)) -> Result<Self, Self::Error> {
×
44
        Self::new(value.0, value.1)
×
45
    }
×
46
}
47

48
impl Add for SpatialResolution {
49
    type Output = Self;
50

51
    fn add(self, rhs: Self) -> Self::Output {
1✔
52
        SpatialResolution {
1✔
53
            x: self.x + rhs.x,
1✔
54
            y: self.y + rhs.y,
1✔
55
        }
1✔
56
    }
1✔
57
}
58

59
impl Sub for SpatialResolution {
60
    type Output = Self;
61

62
    fn sub(self, rhs: Self) -> Self::Output {
1✔
63
        SpatialResolution {
1✔
64
            x: self.x - rhs.x,
1✔
65
            y: self.y - rhs.y,
1✔
66
        }
1✔
67
    }
1✔
68
}
69

70
impl Mul<f64> for SpatialResolution {
71
    type Output = Self;
72

73
    fn mul(self, rhs: f64) -> Self::Output {
1✔
74
        SpatialResolution {
1✔
75
            x: self.x * rhs,
1✔
76
            y: self.y * rhs,
1✔
77
        }
1✔
78
    }
1✔
79
}
80

81
impl Div<f64> for SpatialResolution {
82
    type Output = Self;
83

84
    fn div(self, rhs: f64) -> Self::Output {
1✔
85
        SpatialResolution {
1✔
86
            x: self.x / rhs,
1✔
87
            y: self.y / rhs,
1✔
88
        }
1✔
89
    }
1✔
90
}
91

92
#[cfg(test)]
93
mod test {
94
    use super::*;
95
    use std::mem;
96

97
    #[test]
1✔
98
    fn byte_size() {
1✔
99
        assert_eq!(
1✔
100
            mem::size_of::<SpatialResolution>(),
1✔
101
            2 * mem::size_of::<f64>()
1✔
102
        );
1✔
103
        assert_eq!(mem::size_of::<SpatialResolution>(), 2 * 8);
1✔
104
    }
1✔
105

106
    #[test]
1✔
107
    fn add() {
1✔
108
        let res = SpatialResolution { x: 4., y: 9. } + SpatialResolution { x: 1., y: 1. };
1✔
109
        assert_eq!(res, SpatialResolution { x: 5., y: 10. });
1✔
110
    }
1✔
111

112
    #[test]
1✔
113
    fn sub() {
1✔
114
        let res = SpatialResolution { x: 4., y: 9. } - SpatialResolution { x: 1., y: 1. };
1✔
115
        assert_eq!(res, SpatialResolution { x: 3., y: 8. });
1✔
116
    }
1✔
117

118
    #[test]
1✔
119
    fn mul_scalar() {
1✔
120
        let res = SpatialResolution { x: 4., y: 9. } * 2.;
1✔
121
        assert_eq!(res, SpatialResolution { x: 8., y: 18. });
1✔
122
    }
1✔
123

124
    #[test]
1✔
125
    fn div_scalar() {
1✔
126
        let res = SpatialResolution { x: 4., y: 8. } / 2.;
1✔
127
        assert_eq!(res, SpatialResolution { x: 2., y: 4. });
1✔
128
    }
1✔
129
}
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