pub fn to_words(lat: f64, lng: f64) -> Result<[&'static str; 5], Error<'static>> {
    if (-90f64..=90f64).contains(&lat) == false || (-180f64..=180f64).contains(&lng) == false {
        return Err(Error::CoordinatesOutOfRange)
    }

    let mut lat = lat + 90f64;
    let mut lng = ((lng - 180f64) % 360f64) + 360f64;

    let mut code = [""; 5];

    for (idx, code_word) in code.iter_mut().enumerate() {
        let lat_idx_f64 = (lat / TILES_SIZES[idx]).floor();
        let lng_idx_f64 = (lng / TILES_SIZES[idx]).floor();

        lat -= lat_idx_f64 * TILES_SIZES[idx];
        lng -= lng_idx_f64 * TILES_SIZES[idx];

        let word_idx = (lat_idx_f64 as usize) * RASTER_SIZE[idx].1 + (lng_idx_f64 as usize);
        *code_word = WORDLIST[word_idx];
    }

    Ok(code)
}
/// Encode coordinates represented as a latitude (in range -90..=+90) and a longitude (in range
/// -180..=+180) to five words. You may shorten the array to four elements according to the original
/// implementation.
///
/// # Example:
/// ```
/// use where39::to_words;
///
/// let code = to_words(51.02561728383f64, 13.72333333297f64).unwrap();
/// let expected = &["slush", "battle", "damage", "dentist"][..];
/// assert_eq!(expected, &code[..4]);
/// ```
Encode coordinates represented as a latitude (in range -90..=+90) and a longitude (in range
180..=+180) to five words. You may shorten the array to four elements according to the original
implementation.
Encode coordinates represented as a latitude ( in range - 90 .. = + 90 ) and a longitude ( in range 180 .. = + 180 ) to five words . You may shorten the array to four elements according to the original implementation .
pub fn to_words(lat: f64, lng: f64) -> Result<[&'static str; 5], Error<'static>> {
    if (-90f64..=90f64).contains(&lat) == false || (-180f64..=180f64).contains(&lng) == false {
        return Err(Error::CoordinatesOutOfRange)
    }
    let mut lat = lat + 90f64;
    let mut lng = ((lng - 180f64) % 360f64) + 360f64;
    let mut code = [""; 5];
    for (idx, code_word) in code.iter_mut().enumerate() {
        let lat_idx_f64 = (lat / TILES_SIZES[idx]).floor();
        let lng_idx_f64 = (lng / TILES_SIZES[idx]).floor();
        lat -= lat_idx_f64 * TILES_SIZES[idx];
        lng -= lng_idx_f64 * TILES_SIZES[idx];
        let word_idx = (lat_idx_f64 as usize) * RASTER_SIZE[idx].1 + (lng_idx_f64 as usize);
        *code_word = WORDLIST[word_idx];
    }
    Ok(code)
}
pub fn to_words ( lat : f64 , lng : f64 ) -> Result < [ & ' static str ; 5 ] , Error < ' static > > { if ( - 90f64 ..= 90f64 ) . contains ( & lat ) == false || ( - 180f64 ..= 180f64 ) . contains ( & lng ) == false { return Err ( Error :: CoordinatesOutOfRange ) } let mut lat = lat + 90f64 ; let mut lng = ( ( lng - 180f64 ) % 360f64 ) + 360f64 ; let mut code = [ " " ; 5 ] ; for ( idx , code_word ) in code . iter_mut ( ) . enumerate ( ) { let lat_idx_f64 = ( lat / TILES_SIZES [ idx ] ) . floor ( ) ; let lng_idx_f64 = ( lng / TILES_SIZES [ idx ] ) . floor ( ) ; lat -= lat_idx_f64 * TILES_SIZES [ idx ] ; lng -= lng_idx_f64 * TILES_SIZES [ idx ] ; let word_idx = ( lat_idx_f64 as usize ) * RASTER_SIZE [ idx ] . 1 + ( lng_idx_f64 as usize ) ; * code_word = WORDLIST [ word_idx ] ; } Ok ( code ) }
Encode coordinates represented as a latitude (in range -90..=+90) and a longitude (in range
180..=+180) to five words.
Encode coordinates represented as a latitude ( in range - 90 .. = + 90 ) and a longitude ( in range 180 .. = + 180 ) to five words .
lat
f64
lng
f64
example:
None