1use derive_deref::Deref;
2use leap_sys::*;
3
4use crate::{BoneRef, DigitRef, PalmRef};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[doc = " The Hand chirality types."]
8#[doc = " Used in the LEAP_HAND struct."]
9#[doc = " @since 3.0.0"]
10pub enum HandType {
11 #[doc = " A left hand. @since 3.0.0"]
12 Left,
13 #[doc = " A right hand. @since 3.0.0"]
14 Right,
15}
16
17#[doc = " Describes a tracked hand. @since 3.0.0"]
18#[derive(Deref, Clone, Copy)]
19pub struct HandRef<'a>(pub(crate) &'a LEAP_HAND);
22
23impl<'a> HandRef<'a> {
24 #[doc = " Identifies the chirality of this hand. @since 3.0.0"]
25 pub fn hand_type(&self) -> HandType {
26 match self.type_ {
27 leap_sys::_eLeapHandType_eLeapHandType_Left => HandType::Left,
28 leap_sys::_eLeapHandType_eLeapHandType_Right => HandType::Right,
29 _ => unreachable!(),
30 }
31 }
32
33 #[doc = " Additional information associated with the palm. @since 3.0.0"]
34 pub fn palm(&self) -> PalmRef {
35 PalmRef(&self.palm)
36 }
37
38 #[doc = " The arm to which this hand is attached."]
39 #[doc = " An arm consists of a single LEAP_BONE struct."]
40 #[doc = " @since 3.0.0"]
41 pub fn arm(&self) -> BoneRef {
42 BoneRef(&self.arm)
43 }
44
45 #[doc = " The fingers of the hand as an array. @since 3.0.0"]
46 pub fn digits(&self) -> [DigitRef; 5] {
47 let digits;
48 unsafe {
49 digits = &self.__bindgen_anon_1.digits;
50 }
51 [
52 DigitRef(&digits[0]),
53 DigitRef(&digits[1]),
54 DigitRef(&digits[2]),
55 DigitRef(&digits[3]),
56 DigitRef(&digits[4]),
57 ]
58 }
59
60 #[doc = " The thumb. @since 3.0.0"]
61 pub fn thumb(&self) -> DigitRef {
62 unsafe { DigitRef(&self.__bindgen_anon_1.__bindgen_anon_1.thumb) }
63 }
64
65 #[doc = " The index finger. @since 3.0.0"]
66 pub fn index(&self) -> DigitRef {
67 unsafe { DigitRef(&self.__bindgen_anon_1.__bindgen_anon_1.index) }
68 }
69
70 #[doc = " The middle finger. @since 3.0.0"]
71 pub fn middle(&self) -> DigitRef {
72 unsafe { DigitRef(&self.__bindgen_anon_1.__bindgen_anon_1.middle) }
73 }
74
75 #[doc = " The ring finger. @since 3.0.0"]
76 pub fn ring(&self) -> DigitRef {
77 unsafe { DigitRef(&self.__bindgen_anon_1.__bindgen_anon_1.ring) }
78 }
79
80 #[doc = " The pinky finger. @since 3.0.0"]
81 pub fn pinky(&self) -> DigitRef {
82 unsafe { DigitRef(&self.__bindgen_anon_1.__bindgen_anon_1.pinky) }
83 }
84}
85
86#[cfg(test)]
87mod tests {
88 use crate::tests::*;
89 use crate::*;
90
91 #[test]
92 fn get_all_hand_bones() {
93 let mut connection = initialize_connection();
94 connection
95 .wait_for(|e| match e {
96 EventRef::Tracking(e) => {
97 let hands = e.hands();
98 if hands.is_empty() {
99 println!("Warning: Put hands in front of the sensor for this test.");
100 }
101
102 let digits_by_array = hands.iter().flat_map(|h| h.digits());
103
104 let digits_by_name = hands
105 .iter()
106 .flat_map(|h| [h.thumb(), h.index(), h.middle(), h.ring(), h.pinky()]);
107
108 for digit in digits_by_array.chain(digits_by_name) {
109 let bones_by_array = digit.bones();
110 let bones_by_name = [
111 digit.proximal(),
112 digit.intermediate(),
113 digit.proximal(),
114 digit.distal(),
115 ];
116
117 for bone in bones_by_array.iter().chain(bones_by_name.iter()) {
118 assert!(bone.width > 0.0);
119 }
120 }
121 Some(())
122 }
123 _ => None,
124 })
125 .expect("No hand in view");
126 }
127}