1
0
Fork 0

Extract common method Vec2::max

This commit is contained in:
Lars Martens 2023-12-11 13:05:31 +01:00
parent c6c6a234c0
commit 82e0348158
Signed by: haselkern
GPG key ID: B5CF1F363C179AD4
3 changed files with 22 additions and 12 deletions

View file

@ -121,6 +121,26 @@ impl<T> Vec2<T> {
}
}
impl<T> Vec2<T>
where
T: Ord,
{
/// Returns the component-wise maximum of this vector and the other.
///
/// ```rust
/// # use aoc2023::Vec2;
/// let a = Vec2::new(1, 5);
/// let b = Vec2::new(2, -5);
/// assert_eq!(a.max(b), Vec2::new(2, 5));
/// ```
pub fn max(self, other: Self) -> Self {
Self {
x: self.x.max(other.x),
y: self.y.max(other.y),
}
}
}
impl<T> Add for Vec2<T>
where
T: Add<Output = T>,