use crate::core::geo::geo_utils::GeoUtils;
use crate::core::geo::geometry::Geometry;
use crate::core::geo::lat_lon_geometry::LatLonGeometry;
use crate::core::geo::point2d;
use crate::core::geo::point2d::Point2D;
use crate::core::util::bit_util::BitUtil;
use crate::core::util::core_helper::CoreHelper;
use crate::core::util::error::lucene_error::Result;
#[derive(Clone, Copy, Debug)]
pub struct Point {
lat: f64,
lon: f64,
}
impl Point {
pub fn new(lat: f64, lon: f64) -> Result<Self> {
GeoUtils::check_latitude(lat)?;
GeoUtils::check_longitude(lon)?;
Ok(Self { lat, lon })
}
pub fn get_lat(&self) -> f64 {
self.lat
}
pub fn get_lon(&self) -> f64 {
self.lon
}
}
impl Geometry for Point {
type Component2D = Point2D;
fn to_component2d(&self) -> Result<Self::Component2D> {
point2d::create_from_point(self)
}
}
impl LatLonGeometry for Point {}
impl PartialEq for Point {
fn eq(&self, other: &Self) -> bool {
CoreHelper::compare_f64(self.lat, other.lat).is_eq()
&& CoreHelper::compare_f64(self.lon, other.lon).is_eq()
}
}
impl Eq for Point {}
impl std::hash::Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
(BitUtil::double_to_long_bits(self.lat) as u64).hash(state);
(BitUtil::double_to_long_bits(self.lon) as u64).hash(state);
}
}
impl std::fmt::Display for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Point({},{})", self.lon, self.lat)
}
}