From 00f44ca8383b54c6630f822cf38886b29d37054c Mon Sep 17 00:00:00 2001 From: Karryanna Date: Mon, 29 Jun 2015 17:41:20 +0200 Subject: [PATCH] Labeller: Use hypot for eucleidian distance consistently --- labeller.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/labeller.c b/labeller.c index 9030974..3a608d4 100644 --- a/labeller.c +++ b/labeller.c @@ -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; -- 2.39.2