]> mj.ucw.cz Git - leo.git/commitdiff
Labeller: Use hypot for eucleidian distance consistently
authorKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:41:20 +0000 (17:41 +0200)
committerKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:41:20 +0000 (17:41 +0200)
labeller.c

index 90309743534add378158bfd5c4cce1710125f5fc..3a608d4cfe70e9a9d45146abacd776bb3dd932be 100644 (file)
@@ -793,7 +793,7 @@ void cut_edge(struct graph_edge *e, double dist)
   struct osm_node *n11 = xmalloc(sizeof(struct osm_node));
   struct graph_node *gn = xmalloc(sizeof(struct graph_node));
   gn->o = n11;
-  double vsize = sqrt(pow(n1->x - n2->x, 2) + pow(n1->y - n2->y, 2));
+  double vsize = hypot(n1->x - n2->x, n1->y - n2->y);
   n11->x = n1->x + (n2->x - n1->x) / vsize * dist;
   n11->y = n1->y + (n2->y - n1->y) / vsize * dist;
 
@@ -1627,7 +1627,7 @@ double get_distance(struct placement *p)
       struct request_point *rp = (struct request_point *) p->request;
       dx = rp->x + v->offset_x - p->x;
       dy = rp->y + v->offset_y - p->y;
-      distance = sqrt(dx*dx + dy*dy);
+      distance = hypot(dx, dy);
       if (dbg_rank >= VERBOSITY_PLACEMENT)
         printf("Point placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, rp->x, rp->y);
       break;
@@ -1674,13 +1674,13 @@ double get_distance(struct placement *p)
         }
       }
 
-      distance = sqrt(dx*dx + dy*dy);
+      distance = hypot(dx, dy);
       break;
     case REQUEST_AREA: ;
       struct request_area *ra = (struct request_area *) p->request;
       dx = ra->cx + v->offset_x - p->x;
       dy = ra->cy + v->offset_y - p->y;
-      distance = sqrt(dx*dx + dy*dy);
+      distance = hypot(dx, dy);
       if (dbg_rank >= VERBOSITY_PLACEMENT)
         printf("Area placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, ra->cx, ra->cy);
       break;