Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neighbor does not automatically adjust for coordinate bounds #48

Closed
russellsteadman opened this issue Mar 12, 2024 · 3 comments
Closed

Comments

@russellsteadman
Copy link
Contributor

The geohash::neighbor function does not adjust when a coordinate reaches the latitude/longitude boundaries, so calculating neighbors throws errors for some hashes.

fn main() {
    let geohash = "2hb";

    let decoded = geohash::decode(geohash).unwrap();
    println!("{:?}", decoded.0.x_y());

    let neighbor = geohash::neighbor(geohash, geohash::Direction::W).unwrap();
    println!("{:?}", neighbor);
}
(-179.296875, -17.578125)
thread 'main' panicked at src\main.rs:7:70:
called `Result::unwrap()` on an `Err` value: InvalidCoordinateRange(Coord { x: -180.703125, y: -17.578125 })

Latitudes y range from [-90.0, 90.0] and longitudes x range from [-180.0, 180.0] where any value exceeding the upper bound should be added to the lower bound and vice versa.

let mut longitude: f64 = -181.0;
longitude = (longitude + 180.0).rem_euclid(360.0) - 180.0;
println!("{:?}", longitude);

let mut latitude: f64 = 91.0;
latitude = ((latitude + 90.0).rem_euclid(180.0)) - 90.0;
println!("{:?}", latitude);
179.0
-89.0
@sunng87
Copy link
Member

sunng87 commented Mar 13, 2024

Fixed in #49

@sunng87 sunng87 closed this as completed Mar 13, 2024
@russellsteadman
Copy link
Contributor Author

Would it be possible to push this bug fix as 0.13.1? @sunng87

@sunng87
Copy link
Member

sunng87 commented Mar 13, 2024

Sure. 0.13.1 has been released to crates.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants