-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_range.c
90 lines (82 loc) · 2.47 KB
/
check_range.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* :::::::: */
/* check_range.c :+: :+: */
/* +:+ */
/* By: dnoom <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/04/06 11:25:30 by dnoom #+# #+# */
/* Updated: 2022/04/06 11:25:30 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "miniRT.h"
void check_range_i(t_parse_line *line, int i, int min, int max)
{
if (i < min || i > max)
{
printf(
"Expected int between %d and %d at line %d, column %d, found %d",
min, max, line->line_nr, line->i + 1, i);
error("int not in range");
}
}
void check_range_f_exc(t_parse_line *line, float f, float min, float max)
{
if (f <= min || f >= max)
{
printf(
"Expected float between %f and %f (excluding endpoints) at line %d "
", column %d, found %f", min, max, line->line_nr, line->i + 1, f);
error("Float not in range");
}
}
void check_range_f(t_parse_line *line, float f, float min, float max)
{
if (f < min || f > max)
{
printf(
"Expected float between %f and %f at line %d, column %d, found %f",
min, max, line->line_nr, line->i + 1, f);
error("Float not in range");
}
}
void check_range_vec3i(t_parse_line *line, t_vec3i v, int min, int max)
{
int j;
int i;
i = 0;
while (i < 3)
{
j = *(&v.x + i);
if (j < min || j > max)
{
printf(
"Expected three ints between %d and %d at line %d, "
"before column %d, found %d for int number %d",
min, max, line->line_nr, line->i + 1, j, i);
error("Int not in range");
exit(1);
}
i++;
}
}
void check_range_vec3f(t_parse_line *line, t_vec3f v, float min, float max)
{
float f;
int i;
i = 0;
while (i < 3)
{
f = *(&v.x + i);
if (f < min || f > max)
{
printf(
"Expected three floats between %f and %f at line %d, "
"before column %d, found %f for float number %d",
min, max, line->line_nr, line->i + 1, f, i);
error("Float not in range");
exit(1);
}
i++;
}
}