]> mj.ucw.cz Git - leo.git/blobdiff - lab-utils.c
Labelling: Breaking labeller into more source files
[leo.git] / lab-utils.c
diff --git a/lab-utils.c b/lab-utils.c
new file mode 100644 (file)
index 0000000..9b3f8f3
--- /dev/null
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include <math.h>
+
+#include <ucw/lib.h>
+#include <ucw/gary.h>
+
+#include "leo.h"
+#include "sym.h"
+#include "labeller.h"
+#include "lab-utils.h"
+
+
+int max2(int a, int b)
+{
+  return (a > b ? a : b);
+}
+
+int min2(int a, int b)
+{
+  return (a < b ? a : b);
+}
+
+int max4(int a, int b, int c, int d)
+{
+  return max2(max2(a, b), max2(c, d));
+}
+
+int min4(int a, int b, int c, int d)
+{
+  return min2(min2(a, b), min2(c, d));
+}
+
+int randint(int min, int max)
+{
+  if (min == max) return min;
+  int r = random();
+  return min + (r % (max - min));
+}
+
+double randdouble(void)
+{
+  return ((double) rand() / (double) RAND_MAX);
+}
+
+int flip(int a, int b)
+{
+  return (random() % 2 ? a : b);
+}
+
+double convert_to_deg(double rotate_rad)
+{
+  return rotate_rad * (-180 / M_PI);
+}
+
+double convert_to_rad(double rotate_deg)
+{
+  return rotate_deg / (-180 / M_PI);
+}
+
+struct placement **filter(struct placement **list, bool **pred_ptr)
+{
+  bool *pred = *pred_ptr; // As GARY can't be passed directly
+  struct placement **filtered;
+  GARY_INIT(filtered, 0);
+
+  for (uns i=0; i<GARY_SIZE(list); i++)
+  {
+    if (pred[list[i]->request->ind])
+      continue;
+
+    struct placement **p = GARY_PUSH(filtered);
+    *p = list[i];
+  }
+
+  return filtered;
+}