Add XY::sum and XY::product

This commit is contained in:
Alexandre Bury 2019-10-07 08:43:03 -07:00
parent d6f5c0e0fa
commit a9cbcad4d4

View File

@ -269,6 +269,20 @@ impl<T: Ord + Add<Output = T> + Clone> XY<T> {
}
}
impl<T: Add> XY<T> {
/// Returns `self.x + self.y`.
pub fn sum(self) -> T::Output {
self.fold(std::ops::Add::add)
}
}
impl<T: Mul> XY<T> {
/// Returns `self.x * self.y`
pub fn product(self) -> T::Output {
self.fold(std::ops::Mul::mul)
}
}
impl<T: Zero + Clone> XY<T> {
/// Returns a vector with the X component of self, and y=0.
///