Skip to content

Commit

Permalink
Replaced haversine crate with haversine-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrasingh committed Aug 10, 2024
1 parent 8ab84ed commit 04e6941
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion geoprox-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Marked `cache::build_search_space` as `inline`
- Replaced the [`haversine`](https://crates.io/crates/haversine) crate with [`haversine-rs`](https://crates.io/crates/haversine-rs) after noticing it performed better in benchmarks.

## 0.4.1

Expand Down
2 changes: 1 addition & 1 deletion geoprox-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0"
ahash = "0.8.11"
geohash = "0.13.1"
hashbrown = { version = "0.14.5", features = ["serde", "rayon"] }
haversine = "0.2.1"
haversine-rs = "0.3.0"
itertools = "0.13.0"
kiddo = { git = "https://github.com/sdd/kiddo.git", version = "4.2.0", rev = "cc62c6d76accdeba75c0f55db80c28eab8a21ae7", features = [
"serialize",
Expand Down
2 changes: 1 addition & 1 deletion geoprox-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn build_search_space(

for (ghash, members) in prefix_tree.iter_prefix(subregion_hash) {
if let Ok((position, _, _)) = geohash::decode(&ghash) {
members.iter().for_each(|id: &ObjectIdentifier| {
members.into_iter().for_each(|id: &ObjectIdentifier| {
debug!("adding object to kd-tree: id={} geohash={}", id, ghash);
// ? geohash position uses (lng, lat)
search_tree.add(&[position.y, position.x], *id);
Expand Down
13 changes: 8 additions & 5 deletions geoprox-core/src/metric.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
use haversine::Units;
use haversine_rs::point::Point;
use haversine_rs::units::Unit;
use kiddo::distance_metric::DistanceMetric;

pub struct HaversineDistance;

impl DistanceMetric<f64, 2> for HaversineDistance {
/// Computes the Haversine distance between two 2D points given latitude and longitude.
#[inline]
fn dist(a: &[f64; 2], b: &[f64; 2]) -> f64 {
haversine::distance(
haversine::Location {
haversine_rs::distance(
Point {
latitude: a[0],
longitude: a[1],
},
haversine::Location {
Point {
latitude: b[0],
longitude: b[1],
},
Units::Kilometers,
Unit::Kilometers,
)
}

/// Computes the absolute difference between two values along a single axis (latitude or longitude).
#[inline]
fn dist1(a: f64, b: f64) -> f64 {
(a - b).abs()
}
Expand Down

0 comments on commit 04e6941

Please sign in to comment.