#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Zoom {
pub value: f64,
}
impl Zoom {
#[must_use]
pub fn new(value: f64) -> Self {
Self { value }
}
#[must_use]
pub fn with_value(mut self, value: f64) -> Self {
self.value = value;
self
}
}
impl From<f64> for Zoom {
fn from(value: f64) -> Self {
Self::new(value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_zoom_new() {
let z = Zoom::new(100.0);
assert!((z.value - 100.0).abs() < f64::EPSILON);
}
#[test]
fn test_with_value_and_from() {
let z = Zoom::new(50.0).with_value(75.0);
assert!((z.value - 75.0).abs() < f64::EPSILON);
assert!((Zoom::from(120.0).value - 120.0).abs() < f64::EPSILON);
}
}