Axis

Trait Axis 

Source
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§

Source

const ZERO: Self

A zero value.

Source

const INFINITY: Self

A value which is larger than any finite value.

Source

const NEG_INFINITY: Self

A value which is smaller than any finite value.

Required Methods§

Source

fn is_finite(self) -> bool

Determine whether this value is finite or infinite.

Source

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.

Source

fn square(self) -> Self

Compute the square of this value.

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.

Implementations on Foreign Types§

Source§

impl Axis for f32

Source§

const ZERO: Self = 0f32

Source§

const INFINITY: Self = +Inf_f32

Source§

const NEG_INFINITY: Self = -Inf_f32

Source§

fn is_finite(self) -> bool

Source§

fn in_between(self, rhs: Self) -> Self

Source§

fn square(self) -> Self

Source§

impl Axis for f64

Source§

const ZERO: Self = 0f64

Source§

const INFINITY: Self = +Inf_f64

Source§

const NEG_INFINITY: Self = -Inf_f64

Source§

fn is_finite(self) -> bool

Source§

fn in_between(self, rhs: Self) -> Self

Source§

fn square(self) -> Self

Implementors§