@@ -8,26 +8,19 @@ use interface::encode;
8
8
use geo:: Point ;
9
9
10
10
pub fn code_value ( chr : char ) -> usize {
11
- for ( i, c) in CODE_ALPHABET . iter ( ) . enumerate ( ) {
12
- if chr == * c {
13
- return i;
14
- }
15
- }
16
11
// We assume this function is only called by other functions that have
17
12
// already ensured that the characters in the passed-in code are all valid
18
13
// and have all been "treated" (upper-cased, padding and '+' stripped)
19
- //
20
- // If that is the case, we will always return above.
21
- unreachable ! ( ) ;
14
+ CODE_ALPHABET . iter ( ) . position ( |& x| x == char) . unwrap ( )
22
15
}
23
16
24
17
pub fn normalize_longitude ( value : f64 ) -> f64 {
25
18
let mut result: f64 = value;
26
19
while result >= LONGITUDE_MAX {
27
- result = result - LONGITUDE_MAX * 2f64 ;
20
+ result -= LONGITUDE_MAX * 2f64 ;
28
21
}
29
22
while result < -LONGITUDE_MAX {
30
- result = result + LONGITUDE_MAX * 2f64 ;
23
+ result += LONGITUDE_MAX * 2f64 ;
31
24
}
32
25
result
33
26
}
@@ -40,7 +33,7 @@ pub fn compute_latitude_precision(code_length: usize) -> f64 {
40
33
if code_length <= PAIR_CODE_LENGTH {
41
34
return ENCODING_BASE . powf ( ( code_length as f64 / -2f64 + 2f64 ) . floor ( ) )
42
35
}
43
- ENCODING_BASE . powf ( - 3f64 ) / GRID_ROWS . powf ( code_length as f64 - PAIR_CODE_LENGTH as f64 )
36
+ ENCODING_BASE . powi ( - 3i32 ) / GRID_ROWS . powf ( code_length as f64 - PAIR_CODE_LENGTH as f64 )
44
37
}
45
38
46
39
pub fn prefix_by_reference ( pt : Point < f64 > , code_length : usize ) -> String {
0 commit comments