From 89614e02c20c4e59fadded32d74fb888c755c1d7 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 19 Oct 2022 17:31:07 -0700 Subject: [PATCH] remove 'pointfof' and replace with aggregate initialization Now that Graphviz is compiled with C99, there does not seem to be much advantage in retaining this helper function. We have initialization syntax that is the same number of characters and can be understood locally without having to lookup the definition of `pointfof`. --- lib/common/emit.c | 4 ++-- lib/common/geomprocs.h | 9 --------- lib/common/postproc.c | 18 +++++++++--------- lib/common/shapes.c | 14 +++++++------- lib/common/splines.c | 40 ++++++++++++++++++++-------------------- lib/common/utils.c | 8 ++++---- lib/dotgen/dotsplines.c | 16 ++++++++-------- lib/label/nrtmain.c | 13 ++----------- lib/neatogen/neatoinit.c | 4 ++-- lib/osage/osageinit.c | 4 ++-- 10 files changed, 56 insertions(+), 74 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index 5f9a5ea8d..351f50eae 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -2007,8 +2007,8 @@ static void emit_attachment(GVJ_t * job, textlabel_t * lp, splines * spl) return; sz = lp->dimen; - AF[0] = pointfof(lp->pos.x + sz.x / 2., lp->pos.y - sz.y / 2.); - AF[1] = pointfof(AF[0].x - sz.x, AF[0].y); + AF[0] = (pointf){lp->pos.x + sz.x / 2., lp->pos.y - sz.y / 2.}; + AF[1] = (pointf){AF[0].x - sz.x, AF[0].y}; AF[2] = dotneato_closest(spl, lp->pos); /* Don't use edge style to draw attachment */ gvrender_set_style(job, job->gvc->defaultlinestyle); diff --git a/lib/common/geomprocs.h b/lib/common/geomprocs.h index 93f92904f..360e352c6 100644 --- a/lib/common/geomprocs.h +++ b/lib/common/geomprocs.h @@ -52,15 +52,6 @@ GEOMPROCS_API void rect2poly(pointf *p); GEOMPROCS_API int line_intersect (pointf a, pointf b, pointf c, pointf d, pointf* p); -static inline pointf pointfof(double x, double y) -{ - pointf r; - - r.x = x; - r.y = y; - return r; -} - static inline box boxof(int llx, int lly, int urx, int ury) { box b; diff --git a/lib/common/postproc.c b/lib/common/postproc.c index 205a404ae..1faa09c22 100644 --- a/lib/common/postproc.c +++ b/lib/common/postproc.c @@ -124,11 +124,11 @@ void translate_bb(graph_t * g, int rankdir) bb = GD_bb(g); if (rankdir == RANKDIR_LR || rankdir == RANKDIR_BT) { - new_bb.LL = map_point(pointfof(bb.LL.x, bb.UR.y)); - new_bb.UR = map_point(pointfof(bb.UR.x, bb.LL.y)); + new_bb.LL = map_point((pointf){bb.LL.x, bb.UR.y}); + new_bb.UR = map_point((pointf){bb.UR.x, bb.LL.y}); } else { - new_bb.LL = map_point(pointfof(bb.LL.x, bb.LL.y)); - new_bb.UR = map_point(pointfof(bb.UR.x, bb.UR.y)); + new_bb.LL = map_point((pointf){bb.LL.x, bb.LL.y}); + new_bb.UR = map_point((pointf){bb.UR.x, bb.UR.y}); } GD_bb(g) = new_bb; if (GD_label(g)) { @@ -476,8 +476,8 @@ static void addXLabels(Agraph_t * gp) n_objs = agnnodes(gp) + n_set_lbls + n_clbls + n_elbls; objp = objs = N_NEW(n_objs, object_t); xlp = lbls = N_NEW(n_lbls, xlabel_t); - bb.LL = pointfof(INT_MAX, INT_MAX); - bb.UR = pointfof(-INT_MAX, -INT_MAX); + bb.LL = (pointf){INT_MAX, INT_MAX}; + bb.UR = (pointf){-INT_MAX, -INT_MAX}; for (np = agfstnode(gp); np; np = agnxtnode(gp, np)) { @@ -663,13 +663,13 @@ void gv_postprocess(Agraph_t * g, int allowTranslation) Offset = GD_bb(g).LL; break; case RANKDIR_LR: - Offset = pointfof(-GD_bb(g).UR.y, GD_bb(g).LL.x); + Offset = (pointf){-GD_bb(g).UR.y, GD_bb(g).LL.x}; break; case RANKDIR_BT: - Offset = pointfof(GD_bb(g).LL.x, -GD_bb(g).UR.y); + Offset = (pointf){GD_bb(g).LL.x, -GD_bb(g).UR.y}; break; case RANKDIR_RL: - Offset = pointfof(GD_bb(g).LL.y, GD_bb(g).LL.x); + Offset = (pointf){GD_bb(g).LL.y, GD_bb(g).LL.x}; break; default: UNREACHABLE(); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index d7ebb6825..86368ca19 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -2601,7 +2601,7 @@ compassPort(node_t * n, boxf * bp, port * pp, char *compass, int sides, if (bp) { b = *bp; - p = pointfof((b.LL.x + b.UR.x) / 2, (b.LL.y + b.UR.y) / 2); + p = (pointf){(b.LL.x + b.UR.x) / 2, (b.LL.y + b.UR.y) / 2}; defined = true; } else { p.x = p.y = 0.; @@ -3506,9 +3506,9 @@ static void resize_reclbl(field_t * f, pointf sz, int nojustify_p) sf = f->fld[i]; amt = (int)((i + 1) * inc) - (int)(i * inc); if (f->LR) - newsz = pointfof(sf->size.x + amt, sz.y); + newsz = (pointf){sf->size.x + amt, sz.y}; else - newsz = pointfof(sz.x, sf->size.y + amt); + newsz = (pointf){sz.x, sf->size.y + amt}; resize_reclbl(sf, newsz, nojustify_p); } } @@ -3524,8 +3524,8 @@ static void pos_reclbl(field_t *f, pointf ul, unsigned char sides) { unsigned char mask; f->sides = sides; - f->b.LL = pointfof(ul.x, ul.y - f->size.y); - f->b.UR = pointfof(ul.x + f->size.x, ul.y); + f->b.LL = (pointf){ul.x, ul.y - f->size.y}; + f->b.UR = (pointf){ul.x + f->size.x, ul.y}; last = f->n_flds - 1; for (i = 0; i <= last; i++) { if (sides) { @@ -3596,7 +3596,7 @@ static void dumpL(field_t * info, int level) static void record_init(node_t * n) { field_t *info; - pointf ul, sz; + pointf sz; int flip; size_t len; char *textbuf; /* temp buffer for storing labels */ @@ -3633,7 +3633,7 @@ static void record_init(node_t * n) } resize_reclbl(info, sz, mapbool(late_string(n, N_nojustify, "false")) ? TRUE : FALSE); - ul = pointfof(-sz.x / 2., sz.y / 2.); /* FIXME - is this still true: suspected to introduce ronding error - see Kluge below */ + pointf ul = {-sz.x / 2., sz.y / 2.}; /* FIXME - is this still true: suspected to introduce ronding error - see Kluge below */ pos_reclbl(info, ul, sides); ND_width(n) = PS2INCH(info->size.x); ND_height(n) = PS2INCH(info->size.y + 1); /* Kluge!! +1 to fix rounding diff between layout and rendering diff --git a/lib/common/splines.c b/lib/common/splines.c index 1b94d8a6f..ce3c3ee28 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -867,11 +867,11 @@ static void selfBottom (edge_t* edges[], int ind, int cnt, dx += sgn * stepx; pointn = 0; points[pointn++] = tp; - points[pointn++] = pointfof(tp.x + dx, tp.y - ty / 3); - points[pointn++] = pointfof(tp.x + dx, np.y - dy); - points[pointn++] = pointfof((tp.x+hp.x)/2, np.y - dy); - points[pointn++] = pointfof(hp.x - dx, np.y - dy); - points[pointn++] = pointfof(hp.x - dx, hp.y - hy / 3); + points[pointn++] = (pointf){tp.x + dx, tp.y - ty / 3}; + points[pointn++] = (pointf){tp.x + dx, np.y - dy}; + points[pointn++] = (pointf){(tp.x + hp.x) / 2, np.y - dy}; + points[pointn++] = (pointf){hp.x - dx, np.y - dy}; + points[pointn++] = (pointf){hp.x - dx, hp.y - hy / 3}; points[pointn++] = hp; if (ED_label(e)) { if (GD_flip(agraphof(agtail(e)))) { @@ -977,11 +977,11 @@ selfTop (edge_t* edges[], int ind, int cnt, double sizex, double stepy, dx += sgn * stepx; pointn = 0; points[pointn++] = tp; - points[pointn++] = pointfof(tp.x + dx, tp.y + ty / 3); - points[pointn++] = pointfof(tp.x + dx, np.y + dy); - points[pointn++] = pointfof((tp.x+hp.x)/2, np.y + dy); - points[pointn++] = pointfof(hp.x - dx, np.y + dy); - points[pointn++] = pointfof(hp.x - dx, hp.y + hy / 3); + points[pointn++] = (pointf){tp.x + dx, tp.y + ty / 3}; + points[pointn++] = (pointf){tp.x + dx, np.y + dy}; + points[pointn++] = (pointf){(tp.x + hp.x) / 2, np.y + dy}; + points[pointn++] = (pointf){hp.x - dx, np.y + dy}; + points[pointn++] = (pointf){hp.x - dx, hp.y + hy / 3}; points[pointn++] = hp; if (ED_label(e)) { if (GD_flip(agraphof(agtail(e)))) { @@ -1051,11 +1051,11 @@ selfRight (edge_t* edges[], int ind, int cnt, double stepx, double sizey, dy += sgn * stepy; pointn = 0; points[pointn++] = tp; - points[pointn++] = pointfof(tp.x + tx / 3, tp.y + dy); - points[pointn++] = pointfof(np.x + dx, tp.y + dy); - points[pointn++] = pointfof(np.x + dx, (tp.y+hp.y)/2); - points[pointn++] = pointfof(np.x + dx, hp.y - dy); - points[pointn++] = pointfof(hp.x + hx / 3, hp.y - dy); + points[pointn++] = (pointf){tp.x + tx / 3, tp.y + dy}; + points[pointn++] = (pointf){np.x + dx, tp.y + dy}; + points[pointn++] = (pointf){np.x + dx, (tp.y + hp.y) / 2}; + points[pointn++] = (pointf){np.x + dx, hp.y - dy}; + points[pointn++] = (pointf){hp.x + hx / 3, hp.y - dy}; points[pointn++] = hp; if (ED_label(e)) { if (GD_flip(agraphof(agtail(e)))) { @@ -1128,11 +1128,11 @@ selfLeft (edge_t* edges[], int ind, int cnt, double stepx, double sizey, dy += sgn * stepy; pointn = 0; points[pointn++] = tp; - points[pointn++] = pointfof(tp.x - tx / 3, tp.y + dy); - points[pointn++] = pointfof(np.x - dx, tp.y + dy); - points[pointn++] = pointfof(np.x - dx, (tp.y+hp.y)/2); - points[pointn++] = pointfof(np.x - dx, hp.y - dy); - points[pointn++] = pointfof(hp.x - hx / 3, hp.y - dy); + points[pointn++] = (pointf){tp.x - tx / 3, tp.y + dy}; + points[pointn++] = (pointf){np.x - dx, tp.y + dy}; + points[pointn++] = (pointf){np.x - dx, (tp.y + hp.y) / 2}; + points[pointn++] = (pointf){np.x - dx, hp.y - dy}; + points[pointn++] = (pointf){hp.x - hx / 3, hp.y - dy}; points[pointn++] = hp; if (ED_label(e)) { diff --git a/lib/common/utils.c b/lib/common/utils.c index ba1f38955..52f3cb19c 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -781,13 +781,13 @@ void compute_bb(graph_t * g) int i, j; if ((agnnodes(g) == 0) && (GD_n_cluster(g) ==0)) { - bb.LL = pointfof(0, 0); - bb.UR = pointfof(0, 0); + bb.LL = (pointf){0}; + bb.UR = (pointf){0}; return; } - bb.LL = pointfof(INT_MAX, INT_MAX); - bb.UR = pointfof(-INT_MAX, -INT_MAX); + bb.LL = (pointf){INT_MAX, INT_MAX}; + bb.UR = (pointf){-INT_MAX, -INT_MAX}; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { ptf = coord(n); s2.x = ND_xsize(n) / 2.0; diff --git a/lib/dotgen/dotsplines.c b/lib/dotgen/dotsplines.c index a32ea004f..25de5d47d 100644 --- a/lib/dotgen/dotsplines.c +++ b/lib/dotgen/dotsplines.c @@ -1238,19 +1238,19 @@ makeSimpleFlat (node_t* tn, node_t* hn, edge_t** edges, int ind, int cnt, int et pointn = 0; if (et == EDGETYPE_SPLINE || et == EDGETYPE_LINE) { points[pointn++] = tp; - points[pointn++] = pointfof((2 * tp.x + hp.x) / 3, dy); - points[pointn++] = pointfof((2 * hp.x + tp.x) / 3, dy); + points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy}; points[pointn++] = hp; } else { /* EDGETYPE_PLINE */ points[pointn++] = tp; points[pointn++] = tp; - points[pointn++] = pointfof((2 * tp.x + hp.x) / 3, dy); - points[pointn++] = pointfof((2 * tp.x + hp.x) / 3, dy); - points[pointn++] = pointfof((2 * tp.x + hp.x) / 3, dy); - points[pointn++] = pointfof((2 * hp.x + tp.x) / 3, dy); - points[pointn++] = pointfof((2 * hp.x + tp.x) / 3, dy); - points[pointn++] = pointfof((2 * hp.x + tp.x) / 3, dy); + points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy}; + points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy}; points[pointn++] = hp; points[pointn++] = hp; } diff --git a/lib/label/nrtmain.c b/lib/label/nrtmain.c index d19d96061..dc8f00443 100644 --- a/lib/label/nrtmain.c +++ b/lib/label/nrtmain.c @@ -20,15 +20,6 @@ static char *progname; static int Verbose; extern pointf edgeMidpoint(graph_t * g, edge_t * e); -static inline pointf pointfof(double x, double y) -{ - pointf r; - - r.x = x; - r.y = y; - return r; -} - typedef struct { GVC_t *gvc; char *infname; @@ -129,8 +120,8 @@ int doxlabel(opts_t * opts) n_lbls = n_nlbls + n_elbls; objp = objs = gv_calloc(n_objs, sizeof(object_t)); xlp = lbls = gv_calloc(n_lbls, sizeof(xlabel_t)); - bb.LL = pointfof(INT_MAX, INT_MAX); - bb.UR = pointfof(-INT_MAX, -INT_MAX); + bb.LL = (pointf){INT_MAX, INT_MAX}; + bb.UR = (pointf){-INT_MAX, -INT_MAX}; for (np = agfstnode(gp); np; np = agnxtnode(gp, np)) { /* Add an obstacle per node */ diff --git a/lib/neatogen/neatoinit.c b/lib/neatogen/neatoinit.c index 5a6f3f903..470c940e7 100644 --- a/lib/neatogen/neatoinit.c +++ b/lib/neatogen/neatoinit.c @@ -174,7 +174,7 @@ static void set_label(void* obj, textlabel_t * l, char *name) char *lp; lp = agget(obj, name); if (lp && sscanf(lp, "%lf,%lf", &x, &y) == 2) { - l->pos = pointfof(x, y); + l->pos = (pointf){x, y}; l->set = true; } } @@ -494,7 +494,7 @@ nop_init_graphs(Agraph_t * g, attrsym_t * G_lp, attrsym_t * G_bb) if (GD_label(g) && G_lp) { s = agxget(g, G_lp); if (sscanf(s, "%lf,%lf", &x, &y) == 2) { - GD_label(g)->pos = pointfof(x, y); + GD_label(g)->pos = (pointf){x, y}; GD_label(g)->set = true; } } diff --git a/lib/osage/osageinit.c b/lib/osage/osageinit.c index 3e8191a6a..b41396708 100644 --- a/lib/osage/osageinit.c +++ b/lib/osage/osageinit.c @@ -165,8 +165,8 @@ layout (Agraph_t* g, int depth) pts = putRects (total, gs, &pinfo); free (pinfo.vals); - rootbb.LL = pointfof(INT_MAX, INT_MAX); - rootbb.UR = pointfof(-INT_MAX, -INT_MAX); + rootbb.LL = (pointf){INT_MAX, INT_MAX}; + rootbb.UR = (pointf){-INT_MAX, -INT_MAX}; /* reposition children relative to GD_bb(g) */ for (j = 0; j < total; j++) { -- 2.50.1