1use std::ops::Deref;
2
3use leap_sys::LEAP_POINT_MAPPING;
4
5use crate::{sized_with_trailing_data::SizedWithTrailingData, LeapVectorRef};
6
7pub struct PointMapping {
10 pub(crate) handle: Box<SizedWithTrailingData<LEAP_POINT_MAPPING>>,
13}
14
15impl Deref for PointMapping {
16 type Target = LEAP_POINT_MAPPING;
17
18 fn deref(&self) -> &Self::Target {
19 &self.handle.sized
20 }
21}
22
23impl PointMapping {
24 pub(crate) unsafe fn new_uninitialized(point_mapping_size: u64) -> Self {
27 let trailing_size = point_mapping_size as usize - std::mem::size_of::<LEAP_POINT_MAPPING>();
28 Self {
29 handle: SizedWithTrailingData::allocate(std::mem::zeroed(), trailing_size),
30 }
31 }
32
33 #[doc = " The 3D points being mapped. @since 4.0.0"]
34 pub fn points(&self) -> Vec<LeapVectorRef> {
35 unsafe {
36 (0..self.handle.sized.nPoints as isize)
37 .map(|i| &*self.handle.sized.pPoints.offset(i))
38 .map(LeapVectorRef)
39 .collect()
40 }
41 }
42
43 #[doc = " The IDs of the 3D points being mapped. @since 4.0.0"]
44 pub fn pids(&self) -> &[u32] {
45 unsafe {
46 std::slice::from_raw_parts(self.handle.sized.pIDs, self.handle.sized.nPoints as usize)
47 }
48 }
49}