Struct euclid::scale_factor::ScaleFactor
[−]
[src]
pub struct ScaleFactor<Src, Dst, T>(pub T, _);
A scaling factor between two different units of measurement.
This is effectively a type-safe float, intended to be used in combination with other types like
length::Length
to enforce conversion between systems of measurement at compile time.
Src
and Dst
represent the units before and after multiplying a value by a ScaleFactor. They
may be types without values, such as empty enums. For example:
use euclid::scale_factor::ScaleFactor; use euclid::length::Length; enum Mm {}; enum Inch {}; let mm_per_inch: ScaleFactor<Inch, Mm, f32> = ScaleFactor::new(25.4); let one_foot: Length<Inch, f32> = Length::new(12.0); let one_foot_in_mm: Length<Mm, f32> = one_foot * mm_per_inch;
Methods
impl<Src, Dst, T> ScaleFactor<Src, Dst, T>
fn new(x: T) -> ScaleFactor<Src, Dst, T>
impl<Src, Dst, T: Clone> ScaleFactor<Src, Dst, T>
fn get(&self) -> T
impl<Src, Dst, T: Clone + One + Div<T, Output=T>> ScaleFactor<Src, Dst, T>
fn inv(&self) -> ScaleFactor<Dst, Src, T>
The inverse ScaleFactor (1.0 / self).
impl<Src, Dst, T0: NumCast + Clone> ScaleFactor<Src, Dst, T0>
fn cast<T1: NumCast + Clone>(&self) -> Option<ScaleFactor<Src, Dst, T1>>
Cast from one numeric representation to another, preserving the units.