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

geo-engine / geoengine / 12984670324

27 Jan 2025 08:16AM UTC coverage: 90.028% (-0.07%) from 90.097%
12984670324

Pull #1011

github

web-flow
Merge 175b09936 into ef1edce10
Pull Request #1011: update to rust 1.84

22 of 27 new or added lines in 13 files covered. (81.48%)

105 existing lines in 43 files now uncovered.

125583 of 139494 relevant lines covered (90.03%)

57703.3 hits per line

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

94.12
/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 postgres_types::{FromSql, ToSql};
6
use serde::{Deserialize, Serialize};
7
use snafu::ensure;
8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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