diff options
Diffstat (limited to 'src/core/vector2.rs')
-rw-r--r-- | src/core/vector2.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/core/vector2.rs b/src/core/vector2.rs index 858068e..b3fa443 100644 --- a/src/core/vector2.rs +++ b/src/core/vector2.rs @@ -4,6 +4,7 @@ use crate::{Float, Number}; use std::ops::{Sub, Add}; use std::fmt; +use std::cmp::min; #[derive(Clone, Copy)] pub struct Vector2<T: Number> { @@ -84,6 +85,15 @@ impl From<Vector2f> for Vector2i { } } +impl Vector2i { + pub fn cap(&self, x: i32, y: i32) -> Self { + Self::new_xy( + min(self.x, x), + min(self.y, y), + ) + } +} + #[cfg(test)] mod tests { |