#[cfg(feature = "dioxus")]
use dioxus::prelude::Store;
#[cfg_attr(feature = "dioxus", derive(Store))]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Spring {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
pub velocity: f32,
}
impl Default for Spring {
fn default() -> Self {
Self {
stiffness: 100.0,
damping: 10.0,
mass: 1.0,
velocity: 0.0,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum SpringState {
Active,
Completed,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spring_default() {
let spring = Spring::default();
assert_eq!(spring.stiffness, 100.0);
assert_eq!(spring.damping, 10.0);
assert_eq!(spring.mass, 1.0);
assert_eq!(spring.velocity, 0.0);
}
#[test]
fn test_spring_custom() {
let spring = Spring {
stiffness: 200.0,
damping: 20.0,
mass: 2.0,
velocity: 5.0,
};
assert_eq!(spring.stiffness, 200.0);
assert_eq!(spring.damping, 20.0);
assert_eq!(spring.mass, 2.0);
assert_eq!(spring.velocity, 5.0);
}
}