autd3_core/geometry/
transducer.rs

1use super::Point3;
2
3/// A ultrasound transducer.
4#[derive(Clone, Debug, PartialEq)]
5pub struct Transducer {
6    pub(crate) idx: u8,
7    pub(crate) dev_idx: u16,
8    position: Point3,
9}
10
11impl Transducer {
12    /// Creates a new [`Transducer`].
13    #[must_use]
14    pub const fn new(position: Point3) -> Self {
15        Self {
16            idx: 0,
17            dev_idx: 0,
18            position,
19        }
20    }
21
22    /// Gets the local index of the transducer.
23    #[must_use]
24    pub const fn idx(&self) -> usize {
25        self.idx as _
26    }
27
28    /// Gets the index of the device to which this transducer belongs.
29    #[must_use]
30    pub const fn dev_idx(&self) -> usize {
31        self.dev_idx as _
32    }
33
34    /// Gets the position of the transducer.
35    #[must_use]
36    pub const fn position(&self) -> Point3 {
37        self.position
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn idx() {
47        let tr = Transducer::new(Point3::origin());
48        assert_eq!(0, tr.idx());
49        assert_eq!(0, tr.dev_idx());
50    }
51}