mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
store the geopoint in three dimensions
This commit is contained in:
parent
11a056d116
commit
98a365aaae
5 changed files with 39 additions and 13 deletions
|
@ -54,7 +54,11 @@ pub type FieldId = u16;
|
|||
pub type Position = u32;
|
||||
pub type RelativePosition = u16;
|
||||
pub type FieldDistribution = BTreeMap<String, u64>;
|
||||
pub type GeoPoint = rstar::primitives::GeomWithData<[f64; 2], DocumentId>;
|
||||
|
||||
/// A GeoPoint is a point in cartesian plan, called xyz_point in the code. Its metadata
|
||||
/// is a tuple composed of 1. the DocumentId of the associated document and 2. the original point
|
||||
/// expressed in term of latitude and longitude.
|
||||
pub type GeoPoint = rstar::primitives::GeomWithData<[f64; 3], (DocumentId, [f64; 2])>;
|
||||
|
||||
pub const MAX_POSITION_PER_ATTRIBUTE: u32 = u16::MAX as u32 + 1;
|
||||
|
||||
|
@ -168,6 +172,17 @@ pub fn distance_between_two_points(a: &[f64; 2], b: &[f64; 2]) -> f64 {
|
|||
a.haversine_distance_to(&b).meters()
|
||||
}
|
||||
|
||||
/// Convert a point expressed in terms of latitude and longitude to a point in the
|
||||
/// cartesian coordinate expressed in terms of x, y and z.
|
||||
pub fn lat_lng_to_xyz(coord: &[f64; 2]) -> [f64; 3] {
|
||||
let [lat, lng] = coord.map(|f| f.to_radians());
|
||||
let x = lat.cos() * lng.cos();
|
||||
let y = lat.cos() * lng.sin();
|
||||
let z = lat.sin();
|
||||
|
||||
[x, y, z]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue