• 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

82.43
/operators/src/processing/circle_merging_quadtree/circle_radius_model.rs
1
use std::num::NonZeroUsize;
2

3
use snafu::ensure;
4

5
use crate::error;
6
use crate::util::Result;
7

8
/// A radius model that is based on the number of points in the circle.
9
pub trait CircleRadiusModel {
10
    fn with_scaled_radii(&self, resolution: f64) -> Result<Self>
11
    where
12
        Self: Sized;
13

14
    fn min_radius(&self) -> f64;
15
    fn calculate_radius(&self, number_of_points: NonZeroUsize) -> f64;
16
    fn delta(&self) -> f64;
17
}
18

19
/// A radius model that scales circles based on the logarithm of the number of points.
20
#[derive(Clone, Debug, Copy)]
×
21
pub struct LogScaledRadius {
22
    min_radius: f64,
23
    delta: f64,
24
    resolution: f64,
25
}
26

27
impl LogScaledRadius {
28
    pub fn new(min_radius_px: f64, delta_px: f64) -> Result<Self> {
17✔
29
        ensure!(
17✔
30
            min_radius_px > 0.,
17✔
31
            error::InputMustBeGreaterThanZero {
×
32
                scope: "CircleRadiusModel",
×
33
                name: "min_radius"
×
34
            }
×
35
        );
36
        ensure!(
17✔
37
            delta_px >= 0.,
17✔
38
            error::InputMustBeZeroOrPositive {
×
39
                scope: "CircleRadiusModel",
×
40
                name: "delta_px"
×
41
            }
×
42
        );
43

44
        Ok(LogScaledRadius {
17✔
45
            min_radius: min_radius_px,
17✔
46
            delta: delta_px,
17✔
47
            resolution: 1.,
17✔
48
        })
17✔
49
    }
17✔
50
}
51

52
impl CircleRadiusModel for LogScaledRadius {
53
    fn with_scaled_radii(&self, resolution: f64) -> Result<Self>
5✔
54
    where
5✔
55
        Self: Sized,
5✔
56
    {
5✔
57
        ensure!(
5✔
58
            resolution > 0.,
5✔
59
            error::InputMustBeGreaterThanZero {
×
60
                scope: "CircleRadiusModel",
×
61
                name: "resolution"
×
62
            }
×
63
        );
64

65
        Ok(Self {
5✔
66
            min_radius: self.min_radius * resolution,
5✔
67
            delta: self.delta * resolution,
5✔
68
            resolution,
5✔
69
        })
5✔
70
    }
5✔
71

72
    fn min_radius(&self) -> f64 {
49✔
73
        self.min_radius
49✔
74
    }
49✔
75

76
    fn calculate_radius(&self, number_of_points: NonZeroUsize) -> f64 {
38✔
77
        self.min_radius + (number_of_points.get() as f64).ln() * self.resolution
38✔
78
    }
38✔
79

80
    fn delta(&self) -> f64 {
34✔
81
        self.delta
34✔
82
    }
34✔
83
}
84

85
#[cfg(test)]
86
mod tests {
87
    use super::*;
88

89
    #[test]
1✔
90
    #[allow(clippy::float_cmp)]
91
    fn test_radius_calculation() {
1✔
92
        let radius_model = LogScaledRadius::new(8., 1.0).unwrap();
1✔
93

1✔
94
        assert_eq!(
1✔
95
            radius_model.calculate_radius(NonZeroUsize::new(1).unwrap()),
1✔
96
            8.
1✔
97
        );
1✔
98
        assert_eq!(
1✔
99
            radius_model.calculate_radius(NonZeroUsize::new(2).unwrap()),
1✔
100
            8. + 2.0_f64.ln()
1✔
101
        );
1✔
102
    }
1✔
103

104
    #[test]
1✔
105
    #[allow(clippy::float_cmp)]
106
    fn test_scaled_radius_calculation() {
1✔
107
        let radius_model = LogScaledRadius::new(8., 1.0)
1✔
108
            .unwrap()
1✔
109
            .with_scaled_radii(0.5)
1✔
110
            .unwrap();
1✔
111

1✔
112
        assert_eq!(
1✔
113
            radius_model.calculate_radius(NonZeroUsize::new(1).unwrap()),
1✔
114
            (8. / 2.)
1✔
115
        );
1✔
116
        assert_eq!(
1✔
117
            radius_model.calculate_radius(NonZeroUsize::new(2).unwrap()),
1✔
118
            (8. / 2.) + (2.0_f64.ln() / 2.)
1✔
119
        );
1✔
120
    }
1✔
121
}
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