autd3_core/geometry/
transducer.rs

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