bhcli

A TUI for chatting on LE PHP Chats (onion)
git clone https://git.dasho.dev/n0tr1v/bhcli.git
Log | Files | Refs | README

commit d9f8ac41db83f83e493f6cd2e217d792ced37d96
parent 74f51db1dfdf9da92986944617db1207e37a6800
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 30 Mar 2023 13:49:00 -0700

simplify code

Diffstat:
Msrc/lechatphp/mod.rs | 27+++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs @@ -382,34 +382,25 @@ impl Point { fn get_contour_red_pixels(top_left_pt: &Point, img: &DynamicImage) -> Vec<Point> { let (img_width, img_height) = img.dimensions(); let mut out = vec![]; - for x in 0..img_width { - if let Some(px_color) = get_pixel_in_bound(img, x, 0) { - if px_color == *RED_COLOR { - out.push(top_left_pt.add(Point::new(x, 0))); - } - } - if let Some(px_color) = get_pixel_in_bound(img, x, img_height-1) { + let mut add_px = |x, y| { + if let Some(px_color) = get_pixel_in_bound(img, x, y) { if px_color == *RED_COLOR { - out.push(top_left_pt.add(Point::new(x, img_height-1))); + out.push(top_left_pt.add(Point::new(x, y))); } } + }; + for x in 0..img_width { + add_px(x, 0); + add_px(x, img_height-1); } for y in 1..img_height-1 { - if let Some(px_color) = get_pixel_in_bound(img, 0, y) { - if px_color == *RED_COLOR { - out.push(top_left_pt.add(Point::new(0, y))); - } - } + add_px(0, y); if img_width < img_height { if img_width == 150 { continue; } } - if let Some(px_color) = get_pixel_in_bound(img, img_width-1, y) { - if px_color == *RED_COLOR { - out.push(top_left_pt.add(Point::new(img_width-1, y))); - } - } + add_px(img_width-1, y); } out }