@@ -3,14 +3,14 @@ use geo::Point;
33use codearea:: CodeArea ;
44
55use consts:: {
6- SEPARATOR , SEPARATOR_POSITION , PADDING_CHAR , PADDING_CHAR_STR , CODE_ALPHABET , ENCODING_BASE ,
7- LATITUDE_MAX , LONGITUDE_MAX , PAIR_CODE_LENGTH , MAX_CODE_LENGTH , PAIR_RESOLUTIONS , GRID_COLUMNS , GRID_ROWS ,
8- MIN_TRIMMABLE_CODE_LEN ,
6+ CODE_ALPHABET , ENCODING_BASE , GRID_COLUMNS , GRID_ROWS , LATITUDE_MAX , LONGITUDE_MAX ,
7+ MAX_CODE_LENGTH , MIN_TRIMMABLE_CODE_LEN , PADDING_CHAR , PADDING_CHAR_STR , PAIR_CODE_LENGTH ,
8+ PAIR_RESOLUTIONS , SEPARATOR , SEPARATOR_POSITION ,
99} ;
1010
1111use private:: {
12- code_value , normalize_longitude , clip_latitude , compute_latitude_precision , prefix_by_reference ,
13- narrow_region ,
12+ clip_latitude , code_value , compute_latitude_precision , narrow_region , normalize_longitude ,
13+ prefix_by_reference ,
1414} ;
1515
1616/// Determines if a code is a valid Open Location Code.
@@ -62,7 +62,7 @@ pub fn is_valid(_code: &str) -> bool {
6262 return false ;
6363 }
6464 // Extract the padding from the code (mutates code)
65- let padding: String = code. drain ( ppos..eppos+ 1 ) . collect ( ) ;
65+ let padding: String = code. drain ( ppos..eppos + 1 ) . collect ( ) ;
6666 if padding. chars ( ) . any ( |c| c != PADDING_CHAR ) {
6767 // Padding must be one, contiguous block of padding chars
6868 return false ;
@@ -80,8 +80,7 @@ pub fn is_valid(_code: &str) -> bool {
8080/// A short Open Location Code is a sequence created by removing four or more
8181/// digits from an Open Location Code. It must include a separator character.
8282pub fn is_short ( _code : & str ) -> bool {
83- is_valid ( _code) &&
84- _code. find ( SEPARATOR ) . unwrap ( ) < SEPARATOR_POSITION
83+ is_valid ( _code) && _code. find ( SEPARATOR ) . unwrap ( ) < SEPARATOR_POSITION
8584}
8685
8786/// Determines if a code is a valid full Open Location Code.
@@ -143,9 +142,7 @@ pub fn encode(pt: Point<f64>, code_length: usize) -> String {
143142 }
144143 }
145144 if digit < SEPARATOR_POSITION {
146- code. push_str (
147- PADDING_CHAR_STR . repeat ( SEPARATOR_POSITION - digit) . as_str ( )
148- ) ;
145+ code. push_str ( PADDING_CHAR_STR . repeat ( SEPARATOR_POSITION - digit) . as_str ( ) ) ;
149146 code. push ( SEPARATOR ) ;
150147 }
151148 code
@@ -159,7 +156,8 @@ pub fn decode(_code: &str) -> Result<CodeArea, String> {
159156 if !is_full ( _code) {
160157 return Err ( format ! ( "Code must be a valid full code: {}" , _code) ) ;
161158 }
162- let mut code = _code. to_string ( )
159+ let mut code = _code
160+ . to_string ( )
163161 . replace ( SEPARATOR , "" )
164162 . replace ( PADDING_CHAR_STR , "" )
165163 . to_uppercase ( ) ;
@@ -189,7 +187,13 @@ pub fn decode(_code: &str) -> Result<CodeArea, String> {
189187 lng += lng_res * ( code_value ( chr) as f64 % GRID_COLUMNS ) ;
190188 }
191189 }
192- Ok ( CodeArea :: new ( lat, lng, lat + lat_res, lng + lng_res, code. len ( ) ) )
190+ Ok ( CodeArea :: new (
191+ lat,
192+ lng,
193+ lat + lat_res,
194+ lng + lng_res,
195+ code. len ( ) ,
196+ ) )
193197}
194198
195199/// Remove characters from the start of an OLC code.
@@ -218,13 +222,16 @@ pub fn shorten(_code: &str, ref_pt: Point<f64>) -> Result<String, String> {
218222
219223 let codearea: CodeArea = decode ( _code) . unwrap ( ) ;
220224 if codearea. code_length < MIN_TRIMMABLE_CODE_LEN {
221- return Err ( format ! ( "Code length must be at least {}" , MIN_TRIMMABLE_CODE_LEN ) ) ;
225+ return Err ( format ! (
226+ "Code length must be at least {}" ,
227+ MIN_TRIMMABLE_CODE_LEN
228+ ) ) ;
222229 }
223230
224231 // How close are the latitude and longitude to the code center.
225- let range = ( codearea. center . lat ( ) - clip_latitude ( ref_pt. lat ( ) ) ) . abs ( ) . max (
226- ( codearea . center . lng ( ) - normalize_longitude ( ref_pt . lng ( ) ) ) . abs ( )
227- ) ;
232+ let range = ( codearea. center . lat ( ) - clip_latitude ( ref_pt. lat ( ) ) )
233+ . abs ( )
234+ . max ( ( codearea . center . lng ( ) - normalize_longitude ( ref_pt . lng ( ) ) ) . abs ( ) ) ;
228235
229236 for i in 0 ..PAIR_RESOLUTIONS . len ( ) - 2 {
230237 // Check if we're close enough to shorten. The range must be less than 1/2
@@ -299,6 +306,8 @@ pub fn recover_nearest(_code: &str, ref_pt: Point<f64>) -> Result<String, String
299306 } else if ref_lng - half_res > longitude {
300307 longitude += resolution;
301308 }
302- Ok ( encode ( Point :: new ( longitude, latitude) , code_area. code_length ) )
309+ Ok ( encode (
310+ Point :: new ( longitude, latitude) ,
311+ code_area. code_length ,
312+ ) )
303313}
304-
0 commit comments