From 02c8475c9dd8ac589054a39d5ae01b565062dbe6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 19 May 2021 09:38:28 +0530 Subject: report manhattan dist. in line brush --- src/app.rs | 6 ++++-- src/bitmap.rs | 7 +++++++ src/lisp/eval.rs | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 68d687f..3e7ac0f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,5 +1,5 @@ use crate::{ - bitmap::{abs_difference, positive_angle_with_x, Axis, MapPoint, Pixmap}, + bitmap::{abs_difference, manhattan, positive_angle_with_x, Axis, MapPoint, Pixmap}, brush::{Brush, CircleBrush, LineBrush, RectSelectBrush}, cache::Cache, command::CommandBox, @@ -481,8 +481,9 @@ impl<'ctx> AppState<'ctx> { &mut self.canvas, self.ttf_context, format!( - "{:.width$}°", + "{:.width$}°, {}", angle, + manhattan(from, to.into()), width = if (angle - ANGLE).abs() < 1e-3 { 3 } else { 0 } ), PINK, @@ -1082,6 +1083,7 @@ impl<'ctx> AppState<'ctx> { } } } + self.cache(); self.redraw(); } } diff --git a/src/bitmap.rs b/src/bitmap.rs index 0b1754a..ff41cb8 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -333,3 +333,10 @@ pub fn positive_angle_with_x(start: MapPoint, end: MapPoint) -> f64 { let denum = (end.x as f64 - start.x as f64).abs(); (numer / denum).atan().to_degrees() } + +pub fn manhattan( + MapPoint { x: sx, y: sy }: MapPoint, + MapPoint { x: ex, y: ey, .. }: MapPoint, +) -> u32 { + abs_difference(sx, ex) + abs_difference(sy, ey) +} diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs index c5e4ed0..1b277f9 100644 --- a/src/lisp/eval.rs +++ b/src/lisp/eval.rs @@ -336,9 +336,9 @@ pub fn lookup(env_list: &[Environment], key: &str) -> Result( +pub fn lookup_mut<'a>( env_list: &'a mut [Environment], - key: &'b str, + key: &'_ str, ) -> Result<&'a mut LispExpr, LispError> { Ok(env_list .iter_mut() -- cgit v1.2.3