aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 8c3b144..0825c8c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,6 +1,7 @@
1use crate::{ 1use crate::{
2 app::AppState, 2 app::AppState,
3 consts::FONT_PATH, 3 consts::FONT_PATH,
4 bitmap::{abs_difference, MapPoint},
4 lisp::{ 5 lisp::{
5 error::{EvalError, LispError, ParseError}, 6 error::{EvalError, LispError, ParseError},
6 eval::Evaluator, 7 eval::Evaluator,
@@ -132,6 +133,21 @@ pub fn compress<T: PartialEq + Clone>(scanline: &[T]) -> Vec<(T, usize)> {
132 runs 133 runs
133} 134}
134 135
136pub fn rect_coords(s: MapPoint, e: MapPoint) -> (MapPoint, MapPoint) {
137 let (width, height) = (abs_difference(s.x, e.x), abs_difference(s.y, e.y));
138 let start_loc = if e.x >= s.x && e.y >= s.y {
139 (s.x, s.y)
140 } else if e.x >= s.x && e.y < s.y {
141 (s.x, e.y)
142 } else if e.x < s.x && e.y >= s.y {
143 (e.x, s.y)
144 } else {
145 (e.x, e.y)
146 }.into();
147 let end_loc = start_loc + (width, height).into();
148 (start_loc, end_loc)
149}
150
135#[cfg(test)] 151#[cfg(test)]
136mod tests { 152mod tests {
137 use super::compress; 153 use super::compress;