arci/traits/
move_base.rs

1use auto_impl::auto_impl;
2
3use crate::error::Error;
4
5#[derive(Clone, Debug, Default, Copy)]
6pub struct BaseVelocity {
7    pub x: f64,
8    pub y: f64,
9    pub theta: f64,
10}
11
12impl BaseVelocity {
13    pub fn new(x: f64, y: f64, theta: f64) -> Self {
14        Self { x, y, theta }
15    }
16}
17
18/// Multiply scalar value for velocity
19///
20/// # Example
21///
22/// ```
23/// use assert_approx_eq::assert_approx_eq;
24/// use arci::BaseVelocity;
25///
26/// let vel = BaseVelocity::new(0.1, -0.2, 1.0);
27/// let twice = vel * 2.0;
28/// assert_approx_eq!(twice.x, 0.2);
29/// assert_approx_eq!(twice.y, -0.4);
30/// assert_approx_eq!(twice.theta, 2.0);
31/// ```
32impl std::ops::Mul<f64> for BaseVelocity {
33    type Output = Self;
34
35    fn mul(self, rhs: f64) -> Self::Output {
36        Self {
37            x: self.x * rhs,
38            y: self.y * rhs,
39            theta: self.theta * rhs,
40        }
41    }
42}
43
44/// Multiply scalar value for velocity
45///
46/// # Example
47///
48/// ```
49/// use assert_approx_eq::assert_approx_eq;
50/// use arci::BaseVelocity;
51///
52/// let mut vel = BaseVelocity::new(0.1, -0.2, 1.0);
53/// vel *= 2.0;
54/// assert_approx_eq!(vel.x, 0.2);
55/// assert_approx_eq!(vel.y, -0.4);
56/// assert_approx_eq!(vel.theta, 2.0);
57/// ```
58impl std::ops::MulAssign<f64> for BaseVelocity {
59    fn mul_assign(&mut self, rhs: f64) {
60        self.x *= rhs;
61        self.y *= rhs;
62        self.theta *= rhs;
63    }
64}
65
66#[auto_impl(Box, Arc)]
67pub trait MoveBase: Send + Sync {
68    fn send_velocity(&self, velocity: &BaseVelocity) -> Result<(), Error>;
69    fn current_velocity(&self) -> Result<BaseVelocity, Error>;
70}