From 195a690463742e60aa789d91ceb6b7cd4618a141 Mon Sep 17 00:00:00 2001
From: Matthew Fernandez <matthew.fernandez@gmail.com>
Date: Mon, 14 Mar 2022 08:09:29 -0700
Subject: [PATCH] selfRightSpace: consistently use a double for calculating
 self width

This avoids going backwards and forwards between double and int, which was
causing some compiler warnings and unnecessary loss of precision.
---
 lib/common/render.h   | 2 +-
 lib/common/splines.c  | 6 ++----
 lib/dotgen/position.c | 3 +--
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/common/render.h b/lib/common/render.h
index 83703e7f0..4e622a411 100644
--- a/lib/common/render.h
+++ b/lib/common/render.h
@@ -137,7 +137,7 @@ extern "C" {
     RENDER_API void routesplinesterm(void);
     RENDER_API pointf* simpleSplineRoute (pointf, pointf, Ppoly_t, int*, int);
     RENDER_API pointf *routepolylines(path* pp, int* npoints);
-    RENDER_API int selfRightSpace (edge_t* e);
+    RENDER_API double selfRightSpace(edge_t *e);
     RENDER_API shape_kind shapeOf(node_t *);
     RENDER_API void shape_clip(node_t * n, pointf curve[4]);
     RENDER_API void make_simple_label (GVC_t * gvc, textlabel_t* rv);
diff --git a/lib/common/splines.c b/lib/common/splines.c
index bc07b2fa6..15fa081e7 100644
--- a/lib/common/splines.c
+++ b/lib/common/splines.c
@@ -1158,10 +1158,8 @@ selfLeft (edge_t* edges[], int ind, int cnt, double stepx, double sizey,
  * so using the constant SELF_EDGE_SIZE is going to be wrong.
  * Fortunately, the default nodesep is the same as SELF_EDGE_SIZE.
  */
-int
-selfRightSpace (edge_t* e)
-{
-    int sw;
+double selfRightSpace(edge_t *e) {
+    double sw;
     double label_width;
     textlabel_t* l = ED_label(e);
 
diff --git a/lib/dotgen/position.c b/lib/dotgen/position.c
index 287407ad9..1a3578d98 100644
--- a/lib/dotgen/position.c
+++ b/lib/dotgen/position.c
@@ -211,7 +211,6 @@ static void
 make_LR_constraints(graph_t * g)
 {
     int i, j, k;
-    int sw;			/* self width */
     int m0, m1;
     double width;
     int sep[2];
@@ -245,7 +244,7 @@ make_LR_constraints(graph_t * g)
                  * Note that this would not only affect left and right
                  * positioning but may also affect interrank spacing.
                  */
-		sw = 0;
+		double sw = 0; // self width
 		for (k = 0; (e = ND_other(u).list[k]); k++) {
 		    if (agtail(e) == aghead(e)) {
 			sw += selfRightSpace (e);
-- 
2.40.0