Skip to content

Commit

Permalink
Auto merge of #222 - kvark:area, r=nical
Browse files Browse the repository at this point in the history
Fixed Size2D area

r? @nical

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/222)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Aug 22, 2017
2 parents c40f6b0 + 74936f7 commit 11bdb0b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl<T: Copy + Sub<T, Output=T>, U> Sub for TypedSize2D<T, U> {
}
}

impl<T: Copy + Clone + Mul<T, Output=U>, U> TypedSize2D<T, U> {
pub fn area(&self) -> U { self.width * self.height }
impl<T: Copy + Clone + Mul<T>, U> TypedSize2D<T, U> {
pub fn area(&self) -> T::Output { self.width * self.height }
}

impl<T, U> TypedSize2D<T, U>
Expand Down Expand Up @@ -291,4 +291,10 @@ mod size2d {
let p2 = Size2D::new(0.0, 0.0);
assert_eq!(p1 - p2, Size2D::new(0.0, 0.0));
}

#[test]
pub fn test_area() {
let p = Size2D::new(1.5, 2.0);
assert_eq!(p.area(), 3.0);
}
}

0 comments on commit 11bdb0b

Please sign in to comment.