use core::ops::{Add, Div, Mul, Sub};
pub trait ChebyScalar:
Copy + Add<Output = Self> + Sub<Output = Self> + Mul<f64, Output = Self> + Div<f64, Output = Self>
{
fn zero() -> Self;
fn magnitude(self) -> f64;
}
impl ChebyScalar for f64 {
#[inline]
fn zero() -> Self {
0.0
}
#[inline]
fn magnitude(self) -> f64 {
self.abs()
}
}
impl<U> ChebyScalar for qtty::Quantity<U>
where
U: qtty::Unit,
{
#[inline]
fn zero() -> Self {
Self::new(0.0)
}
#[inline]
fn magnitude(self) -> f64 {
self.value().abs()
}
}
pub trait ChebyTime:
Copy
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<f64, Output = Self>
+ Div<Self, Output = f64>
+ PartialOrd
{
fn zero() -> Self;
fn is_finite(self) -> bool;
}
impl ChebyTime for f64 {
#[inline]
fn zero() -> Self {
0.0
}
#[inline]
fn is_finite(self) -> bool {
f64::is_finite(self)
}
}
impl<U> ChebyTime for qtty::Quantity<U>
where
U: qtty::Unit,
qtty::Quantity<U>: Div<qtty::Quantity<U>, Output = f64>,
{
#[inline]
fn zero() -> Self {
Self::new(0.0)
}
#[inline]
fn is_finite(self) -> bool {
self.value().is_finite()
}
}
pub trait DifferentiateWith<X>: Sized {
type Derivative;
fn scale_derivative(self, x: X) -> Self::Derivative;
}
impl<T, X> DifferentiateWith<X> for T
where
T: Div<X>,
{
type Derivative = <T as Div<X>>::Output;
#[inline]
fn scale_derivative(self, x: X) -> Self::Derivative {
self / x
}
}
pub trait IntegrateWith<X>: Sized {
type Integral;
fn scale_integral(self, x: X) -> Self::Integral;
}
impl<T, X> IntegrateWith<X> for T
where
T: Mul<X>,
{
type Integral = <T as Mul<X>>::Output;
#[inline]
fn scale_integral(self, x: X) -> Self::Integral {
self * x
}
}