From 3f5492b2bb67326be43cd7c5ba02ccf0ba1ae0e3 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Tue, 19 Apr 2022 21:27:56 +0200 Subject: Refile for merging repos --- 2019-worms/src/geometry/point.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 2019-worms/src/geometry/point.rs (limited to '2019-worms/src/geometry/point.rs') diff --git a/2019-worms/src/geometry/point.rs b/2019-worms/src/geometry/point.rs new file mode 100644 index 0000000..1ab9b36 --- /dev/null +++ b/2019-worms/src/geometry/point.rs @@ -0,0 +1,37 @@ +use crate::geometry::vec::*; + +use std::ops::*; + +#[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq)] +pub struct Point2d { + pub x: i8, + pub y: i8, +} + +impl Point2d { + pub fn new(x: i8, y: i8) -> Point2d { + Point2d { x, y } + } +} + +impl Add for Point2d { + type Output = Self; + + fn add(self, other: Vec2d) -> Self { + Point2d { + x: self.x.saturating_add(other.x), + y: self.y.saturating_add(other.y), + } + } +} + +impl Sub for Point2d { + type Output = Vec2d; + + fn sub(self, other: Self) -> Vec2d { + Vec2d { + x: self.x.saturating_sub(other.x), + y: self.y.saturating_sub(other.y), + } + } +} -- cgit v1.2.3