-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
32 lines (29 loc) · 1.44 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ansebast <ansebast@student.42luanda.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 17:54:08 by ansebast #+# #+# */
/* Updated: 2024/10/05 20:13:06 by ansebast ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void calculate_scale(t_vars *vars)
{
t_bounds bounds;
double scale_x;
double scale_y;
bounds = get_projected_bounds(vars);
scale_x = (double)WIN_WIDTH / ((bounds.max_x) - (bounds.min_x));
scale_y = (double)(WIN_HEIGHT - 220) / (bounds.max_y - bounds.min_y);
vars->scale = fmin(scale_x, scale_y);
if (vars->scale > 300)
vars->scale = 300;
bounds = get_projected_bounds(vars);
vars->x_offset = (WIN_WIDTH - (bounds.max_x - bounds.min_x)) / 2
- bounds.min_x;
vars->y_offset = (WIN_HEIGHT - (bounds.max_y - bounds.min_y)) / 2
- bounds.min_y;
}