use serde::{Serialize,Deserialize};
#[derive(Copy,Clone,Debug,PartialEq,PartialOrd,Serialize,Deserialize)]
pub struct Volume(f64);
impl Volume {
#[inline]
pub fn new(float: f64) -> Option<Self> {
if float < 1.0 {
return None
} else if float > 100.0 {
return None
} else if float.is_nan() {
return None
}
Some(Self(float))
}
#[inline(always)]
pub unsafe fn new_unchecked(float: f64) -> Self {
Self(float)
}
#[inline(always)]
pub fn inner(&self) -> f64 {
self.0
}
#[inline(always)]
pub fn zero() -> Self {
Self(0.0)
}
#[inline(always)]
pub fn quarter() -> Self {
Self(25.0)
}
#[inline(always)]
pub fn half() -> Self {
Self(50.0)
}
#[inline(always)]
pub fn third() -> Self {
Self(75.0)
}
#[inline(always)]
pub fn max() -> Self {
Self(100.0)
}
}
impl std::fmt::Display for Volume {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}