use core::ptr::NonNull;
use lwgeom_sys::*;
use crate::{LWGeom, LWGeomError, Result};
pub struct LWPoly {
inner: NonNull<LWPOLY>,
}
impl LWPoly {
fn new_from_raw(p_poly: *mut LWPOLY) -> Result<Self> {
Ok(Self {
inner: NonNull::new(p_poly).ok_or(LWGeomError::NullPtrError)?,
})
}
fn inner_ptr(&self) -> *mut LWPOLY {
self.inner.as_ptr()
}
pub fn into_lwgeom(self) -> Result<LWGeom> {
let p_geom = unsafe { lwpoly_as_lwgeom(self.inner_ptr()) };
LWGeom::new_from_raw(p_geom)
}
pub fn construct_envelope(srid: i32, x1: f64, y1: f64, x2: f64, y2: f64) -> Result<Self> {
let p_poly = unsafe { lwpoly_construct_envelope(srid, x1, y1, x2, y2) };
Self::new_from_raw(p_poly)
}
}
unsafe impl Send for LWPoly {}
unsafe impl Sync for LWPoly {}