From e18777e32448f465748535690666055c179d5d5f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 28 Mar 2021 12:58:58 +0530 Subject: add better brush drawing feedback --- src/bitmap.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/bitmap.rs') diff --git a/src/bitmap.rs b/src/bitmap.rs index 41af745..dc66d73 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -76,6 +76,14 @@ pub enum Axis { Y, } +#[derive(Debug, Copy, Clone)] +pub enum Quadrant { + I, + II, + III, + IV, +} + impl MapPoint { #[inline] pub fn scale(self, c: u32) -> MapPoint { @@ -98,6 +106,17 @@ impl MapPoint { pub fn reflect(self, around: MapPoint) -> MapPoint { around.scale(2) - self } + + #[inline] + pub fn quadrant(self, origin: MapPoint) -> Quadrant { + match (self, origin) { + _ if self.x >= origin.x && self.y >= origin.y => Quadrant::I, + _ if self.x < origin.x && self.y >= origin.y => Quadrant::II, + _ if self.x < origin.x && self.y < origin.y => Quadrant::III, + _ if self.x >= origin.x && self.y < origin.y => Quadrant::IV, + _ => unreachable!("unexpected quadrant!"), + } + } } impl Pixmap @@ -278,3 +297,12 @@ pub fn mirror_figure(figure: &[MapPoint], line: u32, axis: Axis) -> Vec Vec { figure.iter().map(|pt| pt.reflect(around)).collect() } + +pub fn positive_angle_with_x(start: MapPoint, end: MapPoint) -> u32 { + if end.x == start.x { + return 90; + } + let numer = (end.y as f64 - start.y as f64).abs(); + let denum = (end.x as f64 - start.x as f64).abs(); + (numer / denum).atan().to_degrees() as u32 +} -- cgit v1.2.3