#[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
to convert it from one unit to
another. See the Scale
docs for an example.
Tuple Fields§
§0: T
Implementations§
Source§impl<T, U> Length<T, U>where
T: Clone,
impl<T, U> Length<T, U>where
T: Clone,
Sourcepub fn lerp(self, other: Length<T, U>, t: T) -> Length<T, U>
pub fn lerp(self, other: Length<T, U>, t: T) -> Length<T, U>
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));
Source§impl<T, U> Length<T, U>where
T: PartialOrd,
impl<T, U> Length<T, U>where
T: PartialOrd,
Trait Implementations§
Source§impl<T, U> AddAssign for Length<T, U>where
T: AddAssign,
impl<T, U> AddAssign for Length<T, U>where
T: AddAssign,
Source§fn add_assign(&mut self, other: Length<T, U>)
fn add_assign(&mut self, other: Length<T, U>)
Performs the
+=
operation. Read moreSource§impl<U, T> ApproxEq<T> for Length<T, U>where
T: ApproxEq<T>,
impl<U, T> ApproxEq<T> for Length<T, U>where
T: ApproxEq<T>,
Source§fn approx_epsilon() -> T
fn approx_epsilon() -> T
Default epsilon value
Source§fn approx_eq_eps(&self, other: &Length<T, U>, approx_epsilon: &T) -> bool
fn approx_eq_eps(&self, other: &Length<T, U>, approx_epsilon: &T) -> bool
Returns
true
if this object is approximately equal to the other one, using
a provided epsilon value.Source§fn approx_eq(&self, other: &Self) -> bool
fn approx_eq(&self, other: &Self) -> bool
Returns
true
if this object is approximately equal to the other one, using
the approx_epsilon
epsilon value.Source§impl<T, U> DivAssign<T> for Length<T, U>
impl<T, U> DivAssign<T> for Length<T, U>
Source§fn div_assign(&mut self, scale: T)
fn div_assign(&mut self, scale: T)
Performs the
/=
operation. Read moreSource§impl<T, U> MulAssign<T> for Length<T, U>
impl<T, U> MulAssign<T> for Length<T, U>
Source§fn mul_assign(&mut self, scale: T)
fn mul_assign(&mut self, scale: T)
Performs the
*=
operation. Read moreSource§impl<T, U> Ord for Length<T, U>where
T: Ord,
impl<T, U> Ord for Length<T, U>where
T: Ord,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T, U> PartialOrd for Length<T, U>where
T: PartialOrd,
impl<T, U> PartialOrd for Length<T, U>where
T: PartialOrd,
Source§impl<T, U> Saturating for Length<T, U>where
T: Saturating,
impl<T, U> Saturating for Length<T, U>where
T: Saturating,
Source§fn saturating_add(self, other: Length<T, U>) -> Length<T, U>
fn saturating_add(self, other: Length<T, U>) -> Length<T, U>
Saturating addition operator.
Returns a+b, saturating at the numeric bounds instead of overflowing.
Source§fn saturating_sub(self, other: Length<T, U>) -> Length<T, U>
fn saturating_sub(self, other: Length<T, U>) -> Length<T, U>
Saturating subtraction operator.
Returns a-b, saturating at the numeric bounds instead of overflowing.
Source§impl<T, U> SubAssign for Length<T, U>where
T: SubAssign,
impl<T, U> SubAssign for Length<T, U>where
T: SubAssign,
Source§fn sub_assign(&mut self, other: Length<T, U>)
fn sub_assign(&mut self, other: Length<T, U>)
Performs the
-=
operation. Read moreimpl<T, U> Copy for Length<T, U>where
T: Copy,
impl<T, U> Eq for Length<T, U>where
T: Eq,
Auto Trait Implementations§
impl<T, Unit> Freeze for Length<T, Unit>where
T: Freeze,
impl<T, Unit> RefUnwindSafe for Length<T, Unit>where
T: RefUnwindSafe,
Unit: RefUnwindSafe,
impl<T, Unit> Send for Length<T, Unit>
impl<T, Unit> Sync for Length<T, Unit>
impl<T, Unit> Unpin for Length<T, Unit>
impl<T, Unit> UnwindSafe for Length<T, Unit>where
T: UnwindSafe,
Unit: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.