aboutsummaryrefslogtreecommitdiff
path: root/src/bitmap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitmap.rs')
-rw-r--r--src/bitmap.rs28
1 files changed, 28 insertions, 0 deletions
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 {
76 Y, 76 Y,
77} 77}
78 78
79#[derive(Debug, Copy, Clone)]
80pub enum Quadrant {
81 I,
82 II,
83 III,
84 IV,
85}
86
79impl MapPoint { 87impl MapPoint {
80 #[inline] 88 #[inline]
81 pub fn scale(self, c: u32) -> MapPoint { 89 pub fn scale(self, c: u32) -> MapPoint {
@@ -98,6 +106,17 @@ impl MapPoint {
98 pub fn reflect(self, around: MapPoint) -> MapPoint { 106 pub fn reflect(self, around: MapPoint) -> MapPoint {
99 around.scale(2) - self 107 around.scale(2) - self
100 } 108 }
109
110 #[inline]
111 pub fn quadrant(self, origin: MapPoint) -> Quadrant {
112 match (self, origin) {
113 _ if self.x >= origin.x && self.y >= origin.y => Quadrant::I,
114 _ if self.x < origin.x && self.y >= origin.y => Quadrant::II,
115 _ if self.x < origin.x && self.y < origin.y => Quadrant::III,
116 _ if self.x >= origin.x && self.y < origin.y => Quadrant::IV,
117 _ => unreachable!("unexpected quadrant!"),
118 }
119 }
101} 120}
102 121
103impl<T> Pixmap<T> 122impl<T> Pixmap<T>
@@ -278,3 +297,12 @@ pub fn mirror_figure(figure: &[MapPoint], line: u32, axis: Axis) -> Vec<MapPoint
278pub fn reflect_figure(figure: &[MapPoint], around: MapPoint) -> Vec<MapPoint> { 297pub fn reflect_figure(figure: &[MapPoint], around: MapPoint) -> Vec<MapPoint> {
279 figure.iter().map(|pt| pt.reflect(around)).collect() 298 figure.iter().map(|pt| pt.reflect(around)).collect()
280} 299}
300
301pub fn positive_angle_with_x(start: MapPoint, end: MapPoint) -> u32 {
302 if end.x == start.x {
303 return 90;
304 }
305 let numer = (end.y as f64 - start.y as f64).abs();
306 let denum = (end.x as f64 - start.x as f64).abs();
307 (numer / denum).atan().to_degrees() as u32
308}