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.

Trait Implementations

impl<A, B, C, T: Clone + Mul<T, Output=T>> Mul<ScaleFactor<B, C, T>> for ScaleFactor<A, B, T>

type Output = ScaleFactor<A, C, T>

fn mul(self, other: ScaleFactor<B, C, T>) -> ScaleFactor<A, C, T>

impl<Src, Dst, T: Clone + Add<T, Output=T>> Add for ScaleFactor<Src, Dst, T>

type Output = ScaleFactor<Src, Dst, T>

fn add(self, other: ScaleFactor<Src, Dst, T>) -> ScaleFactor<Src, Dst, T>

impl<Src, Dst, T: Clone + Sub<T, Output=T>> Sub for ScaleFactor<Src, Dst, T>

type Output = ScaleFactor<Src, Dst, T>

fn sub(self, other: ScaleFactor<Src, Dst, T>) -> ScaleFactor<Src, Dst, T>

impl<Src, Dst, T: Clone + PartialEq> PartialEq for ScaleFactor<Src, Dst, T>

fn eq(&self, other: &ScaleFactor<Src, Dst, T>) -> bool

1.0.0fn ne(&self, other: &Rhs) -> bool

impl<Src, Dst, T: Clone> Clone for ScaleFactor<Src, Dst, T>

fn clone(&self) -> ScaleFactor<Src, Dst, T>

1.0.0fn clone_from(&mut self, source: &Self)

Derived Implementations

impl<Src: Debug, Dst: Debug, T: Debug> Debug for ScaleFactor<Src, Dst, T>

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl<Src: Encodable, Dst: Encodable, T: Encodable> Encodable for ScaleFactor<Src, Dst, T>

fn encode<__SSrcDstT: Encoder>(&self, __arg_0: &mut __SSrcDstT) -> Result<(), __SSrcDstT::Error>

impl<Src: Decodable, Dst: Decodable, T: Decodable> Decodable for ScaleFactor<Src, Dst, T>

fn decode<__DSrcDstT: Decoder>(__arg_0: &mut __DSrcDstT) -> Result<ScaleFactor<Src, Dst, T>, __DSrcDstT::Error>

impl<Src: Copy, Dst: Copy, T: Copy> Copy for ScaleFactor<Src, Dst, T>