diff --git a/src/length.rs b/src/length.rs index 6ce99fa..1185fb0 100644 --- a/src/length.rs +++ b/src/length.rs @@ -64,6 +64,14 @@ impl> Div, Length> Neg> for Length { + #[inline] + fn neg(&self) -> Length { + Length(-self.get()) + } +} + impl Length { /// Cast from one numeric representation to another, preserving the units. pub fn cast(&self) -> Option> { @@ -151,5 +159,15 @@ mod tests { let int_foot: Length = one_foot.cast().unwrap(); assert_eq!(int_foot.get(), 12); + + let negative_one_foot = -one_foot; + assert_eq!(negative_one_foot.get(), -12.0); + + let negative_two_feet = -two_feet; + assert_eq!(negative_two_feet.get(), -24.0); + + let zero_feet: Length = Length(0.0); + let negative_zero_feet = -zero_feet; + assert_eq!(negative_zero_feet.get(), 0.0); } } diff --git a/src/point.rs b/src/point.rs index 8d4213c..67730a6 100644 --- a/src/point.rs +++ b/src/point.rs @@ -58,6 +58,13 @@ impl> Sub, Point2D> for Point2D { } } +impl > Neg> for Point2D { + #[inline] + fn neg(&self) -> Point2D { + Point2D(-self.x, -self.y) + } +} + impl, T1: Clone> Mul> for Point2D { #[inline] fn mul(&self, scale: &Scale) -> Point2D {