use crate::physics::ColliderShape;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CharacterCapsule {
half_height: f32,
radius: f32,
}
impl CharacterCapsule {
pub fn new(half_height: f32, radius: f32) -> Self {
CharacterCapsule {
half_height,
radius,
}
}
pub fn resize(&mut self, half_height: f32, radius: f32) {
self.half_height = half_height;
self.radius = radius;
}
pub fn half_height(&self) -> f32 {
self.half_height
}
pub fn radius(&self) -> f32 {
self.radius
}
pub(crate) fn shape(&self) -> ColliderShape {
ColliderShape::Capsule {
half_height: self.half_height,
radius: self.radius,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_capsule_carries_the_dimensions_it_was_built_from() {
let capsule = CharacterCapsule::new(0.6, 0.3);
assert_eq!(capsule.half_height(), 0.6);
assert_eq!(capsule.radius(), 0.3);
assert_eq!(
capsule.shape(),
ColliderShape::Capsule {
half_height: 0.6,
radius: 0.3,
}
);
}
#[test]
fn resizing_replaces_both_dimensions() {
let mut capsule = CharacterCapsule::new(0.6, 0.3);
capsule.resize(0.6, 0.3);
assert_eq!(capsule, CharacterCapsule::new(0.6, 0.3));
capsule.resize(0.9, 0.4);
assert_eq!(capsule.half_height(), 0.9);
assert_eq!(capsule.radius(), 0.4);
}
}