• 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

94.57
/operators/src/processing/expression/functions.rs
1
use proc_macro2::{Ident, TokenStream};
2
use quote::quote;
3
use std::{collections::HashMap, ops::RangeInclusive};
4

5
pub(super) struct Function {
6
    pub num_args: RangeInclusive<usize>,
7
    pub token_fn: fn(usize, Ident) -> TokenStream,
8
}
9

10
lazy_static::lazy_static! {
11
    pub(super) static ref FUNCTIONS: HashMap<&'static str, Function> = {
12
        let mut functions = HashMap::new();
13

14
        functions.insert("min", Function {
15
            num_args: 2..=3,
16
            token_fn: |num_args, fn_name| {
2✔
17
                match num_args {
2✔
18
                    2 => quote! {
1✔
19
                        fn #fn_name(a: Option<f64>, b: Option<f64>) -> Option<f64> {
1✔
20
                            apply(a, b, f64::min)
1✔
21
                        }
1✔
22
                    },
1✔
23
                    3 => quote! {
1✔
24
                        fn #fn_name(a: Option<f64>, b: Option<f64>, c: Option<f64>) -> Option<f64> {
1✔
25
                            match (a, b, c) {
1✔
26
                                (Some(a), Some(b), Some(c)) => Some(f64::min(a, f64::min(b, c))),
1✔
27
                                _ => None,
1✔
28
                            }
1✔
29
                        }
1✔
30
                    },
1✔
31
                    _ => TokenStream::new(),
×
32
                }
33
            }
2✔
34
        });
35

36
        functions.insert("max", Function {
37
            num_args: 2..=3,
38
            token_fn: |num_args, fn_name| {
3✔
39
                match num_args {
3✔
40
                    2 => quote! {
2✔
41
                        fn #fn_name(a: Option<f64>, b: Option<f64>) -> Option<f64> {
2✔
42
                            apply(a, b, f64::max)
2✔
43
                        }
2✔
44
                    },
2✔
45
                    3 => quote! {
1✔
46
                        fn #fn_name(a: Option<f64>, b: Option<f64>, c: Option<f64>) -> Option<f64> {
1✔
47
                            match (a, b, c) {
1✔
48
                                (Some(a), Some(b), Some(c)) => Some(f64::max(a, f64::max(b, c))),
1✔
49
                                _ => None,
1✔
50
                            }
1✔
51
                        }
1✔
52
                    },
1✔
53
                    _ => TokenStream::new(),
×
54
                }
55
            }
3✔
56
        });
57

58
        functions.insert("abs", Function {
59
            num_args: 1..=1,
60
            token_fn: |_, fn_name| quote! {
×
61
                fn #fn_name(a: Option<f64>) -> Option<f64> {
×
62
                    a.map(f64::abs)
×
63
                }
×
64
            },
×
65
        });
66

67
        functions.insert("pow", Function {
68
            num_args: 2..=2,
69
            token_fn: |_, fn_name| quote! {
2✔
70
                fn #fn_name(a: Option<f64>, b: Option<f64>) -> Option<f64> {
2✔
71
                    apply(a, b, f64::powf)
2✔
72
                }
2✔
73
            },
2✔
74
        });
75

76
        functions.insert("sqrt", Function {
77
            num_args: 1..=1,
78
            token_fn: |_, fn_name| quote! {
1✔
79
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
80
                    a.map(f64::sqrt)
1✔
81
                }
1✔
82
            },
1✔
83
        });
84

85
        functions.insert("cos", Function {
86
            num_args: 1..=1,
87
            token_fn: |_, fn_name| quote! {
1✔
88
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
89
                    a.map(f64::cos)
1✔
90
                }
1✔
91
            },
1✔
92
        });
93

94
        functions.insert("sin", Function {
95
            num_args: 1..=1,
96
            token_fn: |_, fn_name| quote! {
1✔
97
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
98
                    a.map(f64::sin)
1✔
99
                }
1✔
100
            },
1✔
101
        });
102

103
        functions.insert("tan", Function {
104
            num_args: 1..=1,
105
            token_fn: |_, fn_name| quote! {
1✔
106
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
107
                    a.map(f64::tan)
1✔
108
                }
1✔
109
            },
1✔
110
        });
111

112
        functions.insert("acos", Function {
113
            num_args: 1..=1,
114
            token_fn: |_, fn_name| quote! {
1✔
115
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
116
                    a.map(f64::acos)
1✔
117
                }
1✔
118
            },
1✔
119
        });
120

121
        functions.insert("asin", Function {
122
            num_args: 1..=1,
123
            token_fn: |_, fn_name| quote! {
1✔
124
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
125
                    a.map(f64::asin)
1✔
126
                }
1✔
127
            },
1✔
128
        });
129

130
        functions.insert("atan", Function {
131
            num_args: 1..=1,
132
            token_fn: |_, fn_name| quote! {
1✔
133
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
134
                    a.map(f64::atan)
1✔
135
                }
1✔
136
            },
1✔
137
        });
138

139
        functions.insert("log10", Function {
140
            num_args: 1..=1,
141
            token_fn: |_, fn_name| quote! {
1✔
142
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
143
                    a.map(f64::log10)
1✔
144
                }
1✔
145
            },
1✔
146
        });
147

148
        functions.insert("ln", Function {
149
            num_args: 1..=1,
150
            token_fn: |_, fn_name| quote! {
1✔
151
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
152
                    a.map(f64::ln)
1✔
153
                }
1✔
154
            },
1✔
155
        });
156

157
        functions.insert("pi", Function {
158
            num_args: 0..=0,
159
            token_fn: |_, fn_name| quote! {
2✔
160
                fn #fn_name() -> Option<f64> {
2✔
161
                    Some(std::f64::consts::PI)
2✔
162
                }
2✔
163
            },
2✔
164
        });
165

166
        functions.insert("e", Function {
167
            num_args: 0..=0,
168
            token_fn: |_, fn_name| quote! {
1✔
169
                fn #fn_name() -> Option<f64> {
1✔
170
                    Some(std::f64::consts::E)
1✔
171
                }
1✔
172
            },
1✔
173
        });
174

175
        functions.insert("round", Function {
176
            num_args: 1..=1,
177
            token_fn: |_, fn_name| quote! {
1✔
178
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
179
                    a.map(f64::round)
1✔
180
                }
1✔
181
            },
1✔
182
        });
183

184
        functions.insert("ceil", Function {
185
            num_args: 1..=1,
186
            token_fn: |_, fn_name| quote! {
1✔
187
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
188
                    a.map(f64::ceil)
1✔
189
                }
1✔
190
            },
1✔
191
        });
192

193
        functions.insert("floor", Function {
194
            num_args: 1..=1,
195
            token_fn: |_, fn_name| quote! {
1✔
196
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
197
                    a.map(f64::floor)
1✔
198
                }
1✔
199
            },
1✔
200
        });
201

202
        functions.insert("mod", Function {
203
            num_args: 2..=2,
204
            token_fn: |_, fn_name| quote! {
1✔
205
                fn #fn_name(a: Option<f64>, b: Option<f64>) -> Option<f64> {
1✔
206
                    apply(a, b, std::ops::Rem::rem)
1✔
207
                }
1✔
208
            },
1✔
209
        });
210

211
        functions.insert("to_radians", Function {
212
            num_args: 1..=1,
213
            token_fn: |_, fn_name| quote! {
1✔
214
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
215
                    a.map(f64::to_radians)
1✔
216
                }
1✔
217
            },
1✔
218
        });
219

220
        functions.insert("to_degrees", Function {
221
            num_args: 1..=1,
222
            token_fn: |_, fn_name| quote! {
1✔
223
                fn #fn_name(a: Option<f64>) -> Option<f64> {
1✔
224
                    a.map(f64::to_degrees)
1✔
225
                }
1✔
226
            },
1✔
227
        });
228

229
        functions
230
    };
231
}
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

© 2025 Coveralls, Inc