[][src]Struct euclid::Length

#[repr(C)]pub struct Length<T, Unit>(pub T, _);

A one-dimensional distance, with value represented by T and unit of measurement Unit.

T can be any numeric type, for example a primitive type like u64 or f32.

Unit is not used in the representation of a Length value. It is used only at compile time to ensure that a Length stored with one unit is converted explicitly before being used in an expression that requires a different unit. It may be a type without values, such as an empty enum.

You can multiply a Length by a scale::Scale to convert it from one unit to another. See the Scale docs for an example.

Implementations

impl<T, U> Length<T, U>[src]

pub const fn new(x: T) -> Self[src]

Associate a value with a unit of measure.

impl<T: Clone, U> Length<T, U>[src]

pub fn get(&self) -> T[src]

Unpack the underlying value from the wrapper, cloning it.

pub fn cast_unit<V>(&self) -> Length<T, V>[src]

Cast the unit

pub fn lerp(&self, other: Self, t: T) -> Self where
    T: One + Sub<Output = T> + Mul<Output = T> + Add<Output = T>, 
[src]

Linearly interpolate between this length and another length.

Example

use euclid::default::Length;

let from = Length::new(0.0);
let to = Length::new(8.0);

assert_eq!(from.lerp(to, -1.0), Length::new(-8.0));
assert_eq!(from.lerp(to,  0.0), Length::new( 0.0));
assert_eq!(from.lerp(to,  0.5), Length::new( 4.0));
assert_eq!(from.lerp(to,  1.0), Length::new( 8.0));
assert_eq!(from.lerp(to,  2.0), Length::new(16.0));

impl<T: NumCast + Clone, U> Length<T, U>[src]

pub fn cast<NewT: NumCast>(&self) -> Length<NewT, U>[src]

Cast from one numeric representation to another, preserving the units.

pub fn try_cast<NewT: NumCast>(&self) -> Option<Length<NewT, U>>[src]

Fallible cast from one numeric representation to another, preserving the units.

Trait Implementations

impl<T: Add, U> Add<Length<T, U>> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the + operator.

impl<T: AddAssign, U> AddAssign<Length<T, U>> for Length<T, U>[src]

impl<U, T: ApproxEq<T>> ApproxEq<T> for Length<T, U>[src]

impl<T: Clone, U> Clone for Length<T, U>[src]

impl<T: Copy, U> Copy for Length<T, U>[src]

impl<T: Debug, U> Debug for Length<T, U>[src]

impl<T: Default, U> Default for Length<T, U>[src]

impl<T: Display, U> Display for Length<T, U>[src]

impl<Src, Dst, T: Div> Div<Length<T, Src>> for Length<T, Dst>[src]

type Output = Scale<T::Output, Src, Dst>

The resulting type after applying the / operator.

impl<Src, Dst, T: Div> Div<Scale<T, Src, Dst>> for Length<T, Dst>[src]

type Output = Length<T::Output, Src>

The resulting type after applying the / operator.

impl<T: Div, U> Div<T> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the / operator.

impl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>[src]

impl<T: Eq, U> Eq for Length<T, U>[src]

impl<T: Hash, U> Hash for Length<T, U>[src]

impl<Src, Dst, T: Mul> Mul<Scale<T, Src, Dst>> for Length<T, Src>[src]

type Output = Length<T::Output, Dst>

The resulting type after applying the * operator.

impl<T: Mul, U> Mul<T> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the * operator.

impl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>[src]

impl<U, T: Neg> Neg for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the - operator.

impl<T: Ord, U> Ord for Length<T, U>[src]

impl<T: PartialEq, U> PartialEq<Length<T, U>> for Length<T, U>[src]

impl<T: PartialOrd, U> PartialOrd<Length<T, U>> for Length<T, U>[src]

impl<T: Saturating, U> Saturating for Length<T, U>[src]

impl<T: Sub, U> Sub<Length<T, U>> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the - operator.

impl<T: SubAssign, U> SubAssign<Length<T, U>> for Length<T, U>[src]

impl<T: Zero, U> Zero for Length<T, U>[src]

Auto Trait Implementations

impl<T, Unit> RefUnwindSafe for Length<T, Unit> where
    T: RefUnwindSafe,
    Unit: RefUnwindSafe

impl<T, Unit> Send for Length<T, Unit> where
    T: Send,
    Unit: Send

impl<T, Unit> Sync for Length<T, Unit> where
    T: Sync,
    Unit: Sync

impl<T, Unit> Unpin for Length<T, Unit> where
    T: Unpin,
    Unit: Unpin

impl<T, Unit> UnwindSafe for Length<T, Unit> where
    T: UnwindSafe,
    Unit: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Zero for T where
    T: Zero
[src]