Add horizontal offset to Primitive::Clip

This commit is contained in:
Héctor Ramón Jiménez 2019-11-05 03:16:46 +01:00
parent ba470a2b2a
commit 470266f540
6 changed files with 40 additions and 25 deletions

View file

@ -1,15 +1,26 @@
/// A 2D vector.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vector {
pub x: f32,
pub y: f32,
pub struct Vector<T = f32> {
pub x: T,
pub y: T,
}
impl Vector {
impl<T> Vector<T> {
/// Creates a new [`Vector`] with the given components.
///
/// [`Vector`]: struct.Vector.html
pub fn new(x: f32, y: f32) -> Self {
pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
}
impl<T> std::ops::Add for Vector<T>
where
T: std::ops::Add<Output = T>,
{
type Output = Self;
fn add(self, b: Self) -> Self {
Self::new(self.x + b.x, self.y + b.y)
}
}