1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{Angle, NVector, Speed};
/// The state of a vehicle: its horizontal position and velocity (bearing and speed).
#[derive(PartialEq, Clone, Copy, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] // codecov:ignore:this
pub struct Vehicle {
position: NVector,
bearing: Angle,
speed: Speed,
}
impl Vehicle {
/// Creates a [Vehicle] from given horizontal position and velocity (bearing and speed).
pub fn new(position: NVector, bearing: Angle, speed: Speed) -> Self {
Self {
position,
bearing,
speed,
}
}
/// Returns the horizontal position of this vehicle.
#[inline]
pub fn position(&self) -> NVector {
self.position
}
/// Returns the bearing of this vehicle.
#[inline]
pub fn bearing(&self) -> Angle {
self.bearing
}
/// Returns the speed of this vehicle.
#[inline]
pub fn speed(&self) -> Speed {
self.speed
}
}