Created
May 9, 2014 23:53
-
-
Save mbrubeck/74dd82ddb093dcda7f2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A scaling factor between two different length units. | |
/// | |
/// This is effectively a type-safe float, intended to be used in combination with the known-type | |
/// instances of Point2D, Rect, etc. | |
#[deriving(Clone, Decodable, Encodable, Eq)] | |
pub struct ScaleFactor<Src, Dst>(pub f32); | |
impl<Src, Dst> Deref<f32> for ScaleFactor<Src, Dst> { | |
fn deref<'a>(&'a self) -> &'a f32 { | |
let ScaleFactor(ref x) = *self; | |
x | |
} | |
} | |
impl<A,B,C> Mul<ScaleFactor<B, C>, ScaleFactor<A, C>> for ScaleFactor<A, B> { | |
#[inline] | |
fn mul(&self, other: &ScaleFactor<B, C>) -> ScaleFactor<A, C> { | |
ScaleFactor(**self * **other) | |
} | |
} | |
impl<Src, Dst> Mul<Src, Dst> for ScaleFactor<Src, Dst> { | |
#[inline] | |
fn mul(&self, other: &Src) -> Dst { | |
**self * *other | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment