]> mj.ucw.cz Git - leo.git/blob - lab-utils.c
Labelling: Bugfixes in get_closure
[leo.git] / lab-utils.c
1 #include <stdlib.h>
2 #include <math.h>
3
4 #include <ucw/lib.h>
5 #include <ucw/gary.h>
6
7 #include "leo.h"
8 #include "sym.h"
9 #include "labeller.h"
10 #include "lab-utils.h"
11
12
13 int max2(int a, int b)
14 {
15   return (a > b ? a : b);
16 }
17
18 int min2(int a, int b)
19 {
20   return (a < b ? a : b);
21 }
22
23 int max4(int a, int b, int c, int d)
24 {
25   return max2(max2(a, b), max2(c, d));
26 }
27
28 int min4(int a, int b, int c, int d)
29 {
30   return min2(min2(a, b), min2(c, d));
31 }
32
33 int randint(int min, int max)
34 {
35   if (min == max) return min;
36   int r = random();
37   return min + (r % (max - min));
38 }
39
40 double randdouble(void)
41 {
42   return ((double) rand() / (double) RAND_MAX);
43 }
44
45 int flip(int a, int b)
46 {
47   return (random() % 2 ? a : b);
48 }
49
50 double convert_to_deg(double rotate_rad)
51 {
52   return rotate_rad * (-180 / M_PI);
53 }
54
55 double convert_to_rad(double rotate_deg)
56 {
57   return rotate_deg / (-180 / M_PI);
58 }
59
60 struct placement **filter(struct placement **list, bool **pred_ptr)
61 {
62   bool *pred = *pred_ptr; // As GARY can't be passed directly
63   struct placement **filtered;
64   GARY_INIT(filtered, 0);
65
66   for (uns i=0; i<GARY_SIZE(list); i++)
67   {
68     if (pred[list[i]->request->ind])
69       continue;
70
71     struct placement **p = GARY_PUSH(filtered);
72     *p = list[i];
73   }
74
75   return filtered;
76 }