pub trait Axis:
PartialOrd
+ Copy
+ Sub<Output = Self>
+ Add<Output = Self> {
const ZERO: Self;
const INFINITY: Self;
const NEG_INFINITY: Self;
// Required methods
fn is_finite(self) -> bool;
fn in_between(self, rhs: Self) -> Self;
fn square(self) -> Self;
}Expand description
A generic trait representing values which may be used as an “axis;” that is, elements of a vector representing a point.
An array of Axis values is a point which can be stored in a Capt.
Accordingly, this trait specifies nearly all the requirements for points that Capts require.
The only exception is that Axis values really ought to be Ord instead of PartialOrd;
however, due to the disaster that is IEE 754 floating point numbers, f32 and f64 are not
totally ordered. As a compromise, we relax the Ord requirement so that you can use floats in a
Capt.
§Examples
#[derive(Clone, Copy, PartialOrd, PartialEq)]
enum HyperInt {
MinusInf,
Real(i32),
PlusInf,
}
impl std::ops::Add for HyperInt {
// ...
}
impl std::ops::Sub for HyperInt {
// ...
}
impl capt::Axis for HyperInt {
const ZERO: Self = Self::Real(0);
const INFINITY: Self = Self::PlusInf;
const NEG_INFINITY: Self = Self::MinusInf;
fn is_finite(self) -> bool {
matches!(self, Self::Real(_))
}
fn in_between(self, rhs: Self) -> Self {
match (self, rhs) {
(Self::PlusInf, Self::MinusInf) | (Self::MinusInf, Self::PlusInf) => Self::Real(0),
(Self::MinusInf, _) | (_, Self::MinusInf) => Self::MinusInf,
(Self::PlusInf, _) | (_, Self::PlusInf) => Self::PlusInf,
(Self::Real(a), Self::Real(b)) => Self::Real((a + b) / 2)
}
}
fn square(self) -> Self {
match self {
Self::PlusInf | Self::MinusInf => Self::PlusInf,
Self::Real(a) => Self::Real(a * a),
}
}
}Required Associated Constants§
Sourceconst NEG_INFINITY: Self
const NEG_INFINITY: Self
A value which is smaller than any finite value.
Required Methods§
Sourcefn in_between(self, rhs: Self) -> Self
fn in_between(self, rhs: Self) -> Self
Compute a value of Self which is halfway between self and rhs.
If there are no legal values between self and rhs, it is acceptable to return self
instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.