From f1f80f2870f893570e33ae3f16080a7077e1e4cc Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 28 Sep 2015 13:44:59 -0700 Subject: [PATCH] Add Length / Length -> ScaleFactor division --- src/length.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/length.rs b/src/length.rs index 9eac541..a782846 100644 --- a/src/length.rs +++ b/src/length.rs @@ -75,6 +75,15 @@ impl> Sub> for Length { } } +// length / length +impl> Div> for Length { + type Output = ScaleFactor; + #[inline] + fn div(self, other: Length) -> ScaleFactor { + ScaleFactor::new(self.get() / other.get()) + } +} + // length * scaleFactor impl> Mul> for Length { type Output = Length; @@ -145,9 +154,9 @@ mod tests { use super::Length; use scale_factor::ScaleFactor; - #[derive(Debug)] + #[derive(Debug, Copy, Clone)] enum Inch {} - #[derive(Debug)] + #[derive(Debug, Copy, Clone)] enum Mm {} #[test] @@ -175,9 +184,10 @@ mod tests { assert!(!(two_feet > two_feet)); assert!(!(two_feet < two_feet)); - let one_foot_in_mm: Length = one_foot.clone() * mm_per_inch.clone(); + let one_foot_in_mm: Length = one_foot * mm_per_inch; assert_eq!(one_foot_in_mm, Length::new(304.8)); + assert_eq!(one_foot_in_mm / one_foot, mm_per_inch); let back_to_inches: Length = one_foot_in_mm / mm_per_inch; assert_eq!(one_foot, back_to_inches);