use core::ops::{Deref, DerefMut};
use geo_types::{CoordNum, Point as GtPoint};
use geometry_coords::CoordinateScalar;
use geometry_cs::Cartesian;
use geometry_tag::PointTag;
use geometry_trait::{Geometry, Point, PointMut};
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[repr(transparent)]
pub struct GeoPoint<T: CoordNum>(pub GtPoint<T>);
impl<T: CoordNum> GeoPoint<T> {
#[inline]
#[must_use]
pub const fn new(inner: GtPoint<T>) -> Self {
Self(inner)
}
#[inline]
#[must_use]
pub fn into_inner(self) -> GtPoint<T> {
self.0
}
}
impl<T: CoordNum> Deref for GeoPoint<T> {
type Target = GtPoint<T>;
#[inline]
fn deref(&self) -> &GtPoint<T> {
&self.0
}
}
impl<T: CoordNum> DerefMut for GeoPoint<T> {
#[inline]
fn deref_mut(&mut self) -> &mut GtPoint<T> {
&mut self.0
}
}
impl<T: CoordNum> From<GtPoint<T>> for GeoPoint<T> {
#[inline]
fn from(inner: GtPoint<T>) -> Self {
Self(inner)
}
}
impl<T: CoordNum> From<GeoPoint<T>> for GtPoint<T> {
#[inline]
fn from(wrapper: GeoPoint<T>) -> Self {
wrapper.0
}
}
impl<T: CoordinateScalar + CoordNum> Geometry for GeoPoint<T> {
type Kind = PointTag;
type Point = Self;
}
impl<T: CoordinateScalar + CoordNum> Point for GeoPoint<T> {
type Scalar = T;
type Cs = Cartesian;
const DIM: usize = 2;
#[inline]
fn get<const D: usize>(&self) -> T {
if D == 0 { self.0.0.x } else { self.0.0.y }
}
}
impl<T: CoordinateScalar + CoordNum> PointMut for GeoPoint<T> {
#[inline]
fn set<const D: usize>(&mut self, value: T) {
if D == 0 {
self.0.0.x = value;
} else {
self.0.0.y = value;
}
}
}