]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: Degree/radian conversions have functions
authorKarryanna <karry@karryanna.cz>
Tue, 30 Jun 2015 14:27:04 +0000 (16:27 +0200)
committerKarryanna <karry@karryanna.cz>
Tue, 30 Jun 2015 14:27:04 +0000 (16:27 +0200)
labeller.c

index 016742d9a780084c685fdd01492dcc9a43766295..4a5e26dc745d19253f6697a16ee3af8e89353a70 100644 (file)
@@ -126,6 +126,9 @@ static struct cf_section evolution_cf = {
   }
 };
 
+double convert_to_deg(double rotate_rad);
+double convert_to_rad(double rotate_deg);
+
 void compute_sizes(void);
 
 void make_population(void);
@@ -241,6 +244,16 @@ int min4(int a, int b, int c, int d)
   return min2(min2(a, b), min2(c, d));
 }
 
+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);
+}
+
 void dump_label(struct symbol *sym)
 {
   switch (sym->type)
@@ -312,7 +325,7 @@ void make_bitmap_label(struct variant *v, struct sym_text *text)
   int tw = ceil(text->tw);
   int th = ceil(text->th);
 
-  double rotate_rad = text->rotate / (-180 / M_PI);
+  double rotate_rad = convert_to_rad(text->rotate);
 
   // Initially, ll = [0; 0], lr = [tw, 0], ul = [0, th], ur = [tw, th]
   // They could be declared before but should not be initialized in code
@@ -878,7 +891,7 @@ void make_segments(void)
       rs->y2 = e->n2->o->y;
 
       rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
-      ((struct sym_text *) rs->label)->rotate = atan(rs->slope) * (-180 / M_PI);
+      ((struct sym_text *) rs->label)->rotate = convert_to_deg(atan(rs->slope));
       struct variant *v = GARY_PUSH(rs->request.variants);
       make_bitmap(v, rs->label);
 
@@ -1634,8 +1647,8 @@ double get_distance(struct placement *p)
       struct sym_text *st = (struct sym_text *) rs->label;
 
       double width = p->request->variants[p->variant_used].width;
-      double rotated_x = p->x + width * sin(st->rotate / (-180 / M_PI));
-      double rotated_y = p->y + width * cos(st->rotate / (-180 / M_PI));
+      double rotated_x = p->x + width * sin(convert_to_rad(st->rotate));
+      double rotated_y = p->y + width * cos(convert_to_rad(st->rotate));
 
       if (rs->x1 < rs->x2)
       {