use std::marker::PhantomData;
use super::*;
pub struct Scalar<A>
where
A: Axis,
{
value: f64,
axis: PhantomData<A>,
}
impl<A> std::fmt::Debug for Scalar<A>
where
A: Axis,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Scalar").field("value", &self.value).finish()
}
}
impl<A> Copy for Scalar<A> where A: Axis {}
impl<A> Clone for Scalar<A>
where
A: Axis,
{
fn clone(&self) -> Self {
*self
}
}
impl<A> Scalar<A>
where
A: Axis,
{
pub fn new(value: f64) -> Self {
assert!(value.is_finite(), "Scalar must be finite, got {value}");
Self {
value,
axis: PhantomData,
}
}
pub fn value(&self) -> f64 {
self.value
}
}
#[cfg(test)]
mod tests {
use super::*;
struct T;
impl Axis for T {}
#[test]
#[should_panic(expected = "Scalar must be finite")]
fn rejects_nan() {
let _ = Scalar::<T>::new(f64::NAN);
}
#[test]
#[should_panic(expected = "Scalar must be finite")]
fn rejects_infinity() {
let _ = Scalar::<T>::new(f64::INFINITY);
}
}