use std::ops::Deref;
use leap_sys::LEAP_POINT_MAPPING;
use crate::{sized_with_trailing_data::SizedWithTrailingData, LeapVectorRef};
pub struct PointMapping {
pub(crate) handle: Box<SizedWithTrailingData<LEAP_POINT_MAPPING>>,
}
impl Deref for PointMapping {
type Target = LEAP_POINT_MAPPING;
fn deref(&self) -> &Self::Target {
&self.handle.sized
}
}
impl PointMapping {
pub(crate) unsafe fn new_uninitialized(point_mapping_size: u64) -> Self {
let trailing_size = point_mapping_size as usize - std::mem::size_of::<LEAP_POINT_MAPPING>();
Self {
handle: SizedWithTrailingData::allocate(std::mem::zeroed(), trailing_size),
}
}
#[doc = " The 3D points being mapped. @since 4.0.0"]
pub fn points(&self) -> Vec<LeapVectorRef> {
unsafe {
(0..self.handle.sized.nPoints as isize)
.map(|i| &*self.handle.sized.pPoints.offset(i))
.map(LeapVectorRef)
.collect()
}
}
#[doc = " The IDs of the 3D points being mapped. @since 4.0.0"]
pub fn pids(&self) -> &[u32] {
unsafe {
std::slice::from_raw_parts(self.handle.sized.pIDs, self.handle.sized.nPoints as usize)
}
}
}