From 42a5b16d0430a715af437c51f4e7b3a5a52238f0 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 26 Apr 2024 10:06:15 +0200 Subject: [PATCH] Refactor move_img function to comply with the Norm I think this is function would better be left alone but I have to comply. --- src/main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 28e26c0..2163fc9 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */ -/* Updated: 2024/04/26 09:41:56 by ljiriste ### ########.fr */ +/* Updated: 2024/04/26 09:59:47 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -138,6 +138,15 @@ void change_zoom(t_session *s, t_vect2 invariant, double d_zoom) return ; } +void move_pixel(t_img *img, t_vect2 old, t_vect2 new) +{ + *(double *)ft_mat_access(&img->base, new.y, new.x) + = *(double *)ft_mat_access(&img->base, old.y, old.x); + *(bool *)ft_mat_access(&img->calced, new.y, new.x) + = *(bool *)ft_mat_access(&img->calced, old.y, old.x); + return ; +} + void move_img(t_img *img, int delta_x, int delta_y) { int x; @@ -155,12 +164,8 @@ void move_img(t_img *img, int delta_x, int delta_y) { if (0 <= x - delta_x && x - delta_x < img->width && 0 <= y - delta_y && y - delta_y < img->height) - { - *(double *)ft_mat_access(&img->base, y - delta_y, x - delta_x) - = *(double *)ft_mat_access(&img->base, y, x); - *(bool *)ft_mat_access(&img->calced, y - delta_y, x - delta_x) = - *(bool *)ft_mat_access(&img->calced, y, x); - } + move_pixel(img, (t_vect2){.x = x, .y = y}, + (t_vect2){.x = x - delta_x, .y = y - delta_y}); if (!(0 <= x + delta_x && x + delta_x < img->width && 0 <= y + delta_y && y + delta_y < img->height)) *(bool *)ft_mat_access(&img->calced, y, x) = false; -- 2.30.2