diff options
author | 2020-03-10 06:12:06 +0100 | |
---|---|---|
committer | 2020-03-10 06:12:06 +0100 | |
commit | e4fbca59b4b9478c9c5fa5eec9ebe31dc93412ad (patch) | |
tree | 237d2e5dd29c2d0f05f2b68f829425bb480b8ce7 /core | |
parent | 6151c528241d0a6ece88e6e664df1b50f8174ecb (diff) | |
parent | 5a91b52ef4066701d82a897b44a3f90412f210d2 (diff) | |
download | iced-e4fbca59b4b9478c9c5fa5eec9ebe31dc93412ad.tar.gz iced-e4fbca59b4b9478c9c5fa5eec9ebe31dc93412ad.tar.bz2 iced-e4fbca59b4b9478c9c5fa5eec9ebe31dc93412ad.zip |
Merge branch 'master' into feature/panes-widget
Diffstat (limited to '')
-rw-r--r-- | core/src/point.rs | 11 | ||||
-rw-r--r-- | core/src/vector.rs | 13 |
2 files changed, 23 insertions, 1 deletions
diff --git a/core/src/point.rs b/core/src/point.rs index b9a8149c..b55f5099 100644 --- a/core/src/point.rs +++ b/core/src/point.rs @@ -46,3 +46,14 @@ impl std::ops::Add<Vector> for Point { } } } + +impl std::ops::Sub<Vector> for Point { + type Output = Self; + + fn sub(self, vector: Vector) -> Self { + Self { + x: self.x - vector.x, + y: self.y - vector.y, + } + } +} diff --git a/core/src/vector.rs b/core/src/vector.rs index 1c09ee3e..a75053a0 100644 --- a/core/src/vector.rs +++ b/core/src/vector.rs @@ -16,7 +16,7 @@ impl<T> Vector<T> { /// Creates a new [`Vector`] with the given components. /// /// [`Vector`]: struct.Vector.html - pub fn new(x: T, y: T) -> Self { + pub const fn new(x: T, y: T) -> Self { Self { x, y } } } @@ -32,6 +32,17 @@ where } } +impl<T> std::ops::Sub for Vector<T> +where + T: std::ops::Sub<Output = T>, +{ + type Output = Self; + + fn sub(self, b: Self) -> Self { + Self::new(self.x - b.x, self.y - b.y) + } +} + impl<T> Default for Vector<T> where T: Default, |