commit 1187bd34f090f8fc5bb79ed7b06df12fbc785576
parent 1c53367304de13c236993a9f985a83f8d9806fae
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 30 Mar 2023 02:05:13 -0700
simplify code
Diffstat:
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs
@@ -400,23 +400,22 @@ impl From<(u32, u32)> for Point {
fn get_contour_red_pixels(top_left_pt: &Point, img: &DynamicImage) -> Vec<Point> {
let mut out = vec![];
- let bottom_right_pt = top_left_pt.add(Point::from(img.dimensions()));
for i in 0..img.width() {
if let Some(px_color) = get_pixel_in_bound(img, i, 0) {
if px_color == *RED_COLOR {
- out.push(Point::new(top_left_pt.x+i, 0));
+ out.push(top_left_pt.add(Point::new(i, 0)));
}
}
if let Some(px_color) = get_pixel_in_bound(img, i, img.height()-1) {
if px_color == *RED_COLOR {
- out.push(Point::new(top_left_pt.x+i, bottom_right_pt.y-1));
+ out.push(top_left_pt.add(Point::new(i, img.height()-1)));
}
}
}
for i in 1..img.height()-1 {
if let Some(px_color) = get_pixel_in_bound(img, 0, i) {
if px_color == *RED_COLOR {
- out.push(Point::new(top_left_pt.x, top_left_pt.y+i));
+ out.push(top_left_pt.add(Point::new(0, i)));
}
}
if img.width() < img.height() {
@@ -426,7 +425,7 @@ fn get_contour_red_pixels(top_left_pt: &Point, img: &DynamicImage) -> Vec<Point>
}
if let Some(px_color) = get_pixel_in_bound(img, img.width()-1, i) {
if px_color == *RED_COLOR {
- out.push(Point::new(bottom_right_pt.x-1, top_left_pt.y+i));
+ out.push(top_left_pt.add(Point::new(img.width()-1, i)));
}
}
}