#[repr(C)]pub struct Length<T, Unit>(pub T, _);
Expand description
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.
Tuple Fields
0: T
Implementations
sourceimpl<T: Clone, U> Length<T, U>
impl<T: Clone, U> Length<T, U>
sourcepub fn lerp(self, other: Self, t: T) -> Self where
T: One + Sub<Output = T> + Mul<Output = T> + Add<Output = T>,
pub fn lerp(self, other: Self, t: T) -> Self where
T: One + Sub<Output = T> + Mul<Output = T> + Add<Output = T>,
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));
sourceimpl<T: PartialOrd, U> Length<T, U>
impl<T: PartialOrd, U> Length<T, U>
Trait Implementations
sourceimpl<T: AddAssign, U> AddAssign<Length<T, U>> for Length<T, U>
impl<T: AddAssign, U> AddAssign<Length<T, U>> for Length<T, U>
sourcefn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the +=
operation. Read more
sourceimpl<U, T: ApproxEq<T>> ApproxEq<T> for Length<T, U>
impl<U, T: ApproxEq<T>> ApproxEq<T> for Length<T, U>
sourcefn approx_epsilon() -> T
fn approx_epsilon() -> T
Default epsilon value
sourceimpl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>
impl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>
sourcefn div_assign(&mut self, scale: T)
fn div_assign(&mut self, scale: T)
Performs the /=
operation. Read more
sourceimpl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>
impl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>
sourcefn mul_assign(&mut self, scale: T)
fn mul_assign(&mut self, scale: T)
Performs the *=
operation. Read more
sourceimpl<T: Ord, U> Ord for Length<T, U>
impl<T: Ord, U> Ord for Length<T, U>
sourceimpl<T: PartialOrd, U> PartialOrd<Length<T, U>> for Length<T, U>
impl<T: PartialOrd, U> PartialOrd<Length<T, U>> for Length<T, U>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T: Saturating, U> Saturating for Length<T, U>
impl<T: Saturating, U> Saturating for Length<T, U>
sourcefn saturating_add(self, other: Self) -> Self
fn saturating_add(self, other: Self) -> Self
Saturating addition operator. Returns a+b, saturating at the numeric bounds instead of overflowing. Read more
sourcefn saturating_sub(self, other: Self) -> Self
fn saturating_sub(self, other: Self) -> Self
Saturating subtraction operator. Returns a-b, saturating at the numeric bounds instead of overflowing. Read more
sourceimpl<T: SubAssign, U> SubAssign<Length<T, U>> for Length<T, U>
impl<T: SubAssign, U> SubAssign<Length<T, U>> for Length<T, U>
sourcefn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the -=
operation. Read more
impl<T: Copy, U> Copy for Length<T, U>
impl<T: Eq, U> Eq for Length<T, U>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more