From 470266f54069a1c9b6147026d018b437b6457f7b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Nov 2019 03:16:46 +0100 Subject: Add horizontal offset to `Primitive::Clip` --- core/src/vector.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'core/src') diff --git a/core/src/vector.rs b/core/src/vector.rs index f45daab9..92bf64ff 100644 --- a/core/src/vector.rs +++ b/core/src/vector.rs @@ -1,15 +1,26 @@ /// A 2D vector. #[derive(Debug, Clone, Copy, PartialEq)] -pub struct Vector { - pub x: f32, - pub y: f32, +pub struct Vector { + pub x: T, + pub y: T, } -impl Vector { +impl Vector { /// 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 std::ops::Add for Vector +where + T: std::ops::Add, +{ + type Output = Self; + + fn add(self, b: Self) -> Self { + Self::new(self.x + b.x, self.y + b.y) + } +} -- cgit