10 #include "lab-utils.h"
13 int max2(int a, int b)
15 return (a > b ? a : b);
18 int min2(int a, int b)
20 return (a < b ? a : b);
23 int max4(int a, int b, int c, int d)
25 return max2(max2(a, b), max2(c, d));
28 int min4(int a, int b, int c, int d)
30 return min2(min2(a, b), min2(c, d));
33 int randint(int min, int max)
35 if (min == max) return min;
37 return min + (r % (max - min));
40 double randdouble(void)
42 return ((double) rand() / (double) RAND_MAX);
45 int flip(int a, int b)
47 return (random() % 2 ? a : b);
50 double convert_to_deg(double rotate_rad)
52 return rotate_rad * (-180 / M_PI);
55 double convert_to_rad(double rotate_deg)
57 return rotate_deg / (-180 / M_PI);
60 struct placement **filter(struct placement **list, bool **pred_ptr)
62 bool *pred = *pred_ptr; // As GARY can't be passed directly
63 struct placement **filtered;
64 GARY_INIT(filtered, 0);
66 for (uns i=0; i<GARY_SIZE(list); i++)
68 if (pred[list[i]->request->ind])
71 struct placement **p = GARY_PUSH(filtered);