use std::ops::{Add, Div, Mul, Sub};
pub trait Sample:
Copy
+ Default
+ Send
+ Sync
+ 'static
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ PartialOrd
{
const ZERO: Self;
const ONE: Self;
fn from_f32(value: f32) -> Self;
fn to_f32(self) -> f32;
fn from_f64(value: f64) -> Self;
fn to_f64(self) -> f64;
fn abs(self) -> Self;
fn sqrt(self) -> Self;
fn sin(self) -> Self;
fn cos(self) -> Self;
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
fn clamp(self, min: Self, max: Self) -> Self {
self.max(min).min(max)
}
}
impl Sample for f32 {
const ZERO: Self = 0.0;
const ONE: Self = 1.0;
#[inline(always)]
fn from_f32(value: f32) -> Self {
value
}
#[inline(always)]
fn to_f32(self) -> f32 {
self
}
#[inline(always)]
fn from_f64(value: f64) -> Self {
value as f32
}
#[inline(always)]
fn to_f64(self) -> f64 {
self as f64
}
#[inline(always)]
fn abs(self) -> Self {
f32::abs(self)
}
#[inline(always)]
fn sqrt(self) -> Self {
f32::sqrt(self)
}
#[inline(always)]
fn sin(self) -> Self {
f32::sin(self)
}
#[inline(always)]
fn cos(self) -> Self {
f32::cos(self)
}
#[inline(always)]
fn min(self, other: Self) -> Self {
f32::min(self, other)
}
#[inline(always)]
fn max(self, other: Self) -> Self {
f32::max(self, other)
}
#[inline(always)]
fn clamp(self, min: Self, max: Self) -> Self {
f32::clamp(self, min, max)
}
}
impl Sample for f64 {
const ZERO: Self = 0.0;
const ONE: Self = 1.0;
#[inline(always)]
fn from_f32(value: f32) -> Self {
value as f64
}
#[inline(always)]
fn to_f32(self) -> f32 {
self as f32
}
#[inline(always)]
fn from_f64(value: f64) -> Self {
value
}
#[inline(always)]
fn to_f64(self) -> f64 {
self
}
#[inline(always)]
fn abs(self) -> Self {
f64::abs(self)
}
#[inline(always)]
fn sqrt(self) -> Self {
f64::sqrt(self)
}
#[inline(always)]
fn sin(self) -> Self {
f64::sin(self)
}
#[inline(always)]
fn cos(self) -> Self {
f64::cos(self)
}
#[inline(always)]
fn min(self, other: Self) -> Self {
f64::min(self, other)
}
#[inline(always)]
fn max(self, other: Self) -> Self {
f64::max(self, other)
}
#[inline(always)]
fn clamp(self, min: Self, max: Self) -> Self {
f64::clamp(self, min, max)
}
}