Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/emath/src/numeric.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

/// Implemented for all builtin numeric types
pub trait Numeric: Clone + Copy + PartialEq + PartialOrd + 'static {
/// Is this an integer type?
Expand Down Expand Up @@ -98,3 +100,17 @@ impl_numeric_non_zero_unsigned!(std::num::NonZeroU32);
impl_numeric_non_zero_unsigned!(std::num::NonZeroU64);
impl_numeric_non_zero_unsigned!(std::num::NonZeroU128);
impl_numeric_non_zero_unsigned!(std::num::NonZeroUsize);

impl eframe::emath::Numeric for Duration {
const INTEGRAL: bool = false;
const MIN: Self = Self(Duration::ZERO);
const MAX: Self = Self(Duration::MAX);

fn to_f64(self) -> f64 {
self.0.as_secs_f64()
}

fn from_f64(num: f64) -> Self {
Self(Duration::try_from_secs_f64(num).unwrap_or_default())
}
}
Loading