From c0e63f72ff91a5b559c83aa63353661f4e0fb820 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Jan 2022 09:10:03 -0800 Subject: [PATCH] API BREAK: return a C99 bool from 'insidefn' instead of a boolean --- CHANGELOG.md | 3 +++ lib/common/arrows.c | 2 +- lib/common/render.h | 2 +- lib/common/shapes.c | 42 +++++++++++++++++++++--------------------- lib/common/splines.c | 4 ++-- lib/common/types.h | 3 ++- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45bf78676..acde87af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: Using Graphviz as a library on Windows now requires the `GVDLL` symbol to be set to ensure correct linking. +- **Breaking**: The `insidefn` member of the `shape_functions` struct must now + be a pointer to a function returning a C99 `bool` instead of a + Graphviz-specific `boolean`. - **Breaking**: Graphviz headers no longer define the constant `MAXSHORT`. A drop-in replacement is `SHRT_MAX` in the C standard library’s limits.h. - **Breaking**: Graphviz headers no lnger define `NIL` macros. A drop-in diff --git a/lib/common/arrows.c b/lib/common/arrows.c index 196228ba2..baa31c1e4 100644 --- a/lib/common/arrows.c +++ b/lib/common/arrows.c @@ -258,7 +258,7 @@ double arrow_length(edge_t * e, int flag) } /* inside function for calls to bezier_clip */ -static boolean inside(inside_t * inside_context, pointf p) +static bool inside(inside_t * inside_context, pointf p) { return DIST2(p, inside_context->a.p[0]) <= inside_context->a.r[0]; } diff --git a/lib/common/render.h b/lib/common/render.h index 8bb72a73f..fca6d8929 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -77,7 +77,7 @@ extern "C" { RENDER_API void arrowOrthoClip(edge_t*, pointf* ps, int, int, bezier*, int sflag, int eflag); RENDER_API void beginpath(path *, Agedge_t *, int, pathend_t *, bool); RENDER_API void bezier_clip(inside_t * inside_context, - boolean(*insidefn) (inside_t * inside_context, + bool(*insidefn) (inside_t * inside_context, pointf p), pointf * sp, bool left_inside); RENDER_API shape_desc *bind_shape(char *name, node_t *); RENDER_API void makeStraightEdge(graph_t * g, edge_t * e, int edgetype, splineInfo * info); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 15392b990..d09e6ccf2 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -42,28 +42,28 @@ static char *point_style[3] = { "invis\0", "filled\0", 0 }; static void poly_init(node_t * n); static void poly_free(node_t * n); static port poly_port(node_t * n, char *portname, char *); -static boolean poly_inside(inside_t * inside_context, pointf p); +static bool poly_inside(inside_t * inside_context, pointf p); static int poly_path(node_t * n, port * p, int side, boxf rv[], int *kptr); static void poly_gencode(GVJ_t * job, node_t * n); static void record_init(node_t * n); static void record_free(node_t * n); static port record_port(node_t * n, char *portname, char *); -static boolean record_inside(inside_t * inside_context, pointf p); +static bool record_inside(inside_t * inside_context, pointf p); static int record_path(node_t * n, port * p, int side, boxf rv[], int *kptr); static void record_gencode(GVJ_t * job, node_t * n); static void point_init(node_t * n); static void point_gencode(GVJ_t * job, node_t * n); -static boolean point_inside(inside_t * inside_context, pointf p); +static bool point_inside(inside_t * inside_context, pointf p); -static boolean epsf_inside(inside_t * inside_context, pointf p); +static bool epsf_inside(inside_t * inside_context, pointf p); static void epsf_gencode(GVJ_t * job, node_t * n); static pointf star_size (pointf); static void star_vertices (pointf*, pointf*); -static boolean star_inside(inside_t * inside_context, pointf p); +static bool star_inside(inside_t * inside_context, pointf p); static poly_desc_t star_gen = { star_size, star_vertices, @@ -2249,7 +2249,7 @@ static void poly_free(node_t * n) * coordinate system, it is reset as P in the unrotated coordinate system. Similarly, * the ND_rw, ND_lw and ND_ht values are rotated if the graph is flipped. */ -static boolean poly_inside(inside_t * inside_context, pointf p) +static bool poly_inside(inside_t * inside_context, pointf p) { static node_t *lastn; /* last node argument */ static polygon_t *poly; @@ -2265,7 +2265,7 @@ static boolean poly_inside(inside_t * inside_context, pointf p) if (!inside_context) { lastn = NULL; - return FALSE; + return false; } bp = inside_context->s.bp; @@ -2332,7 +2332,7 @@ static boolean poly_inside(inside_t * inside_context, pointf p) /* inside bounding box? */ if (fabs(P.x) > box_URx || fabs(P.y) > box_URy) - return FALSE; + return false; /* ellipses */ if (sides <= 2) @@ -2344,10 +2344,10 @@ static boolean poly_inside(inside_t * inside_context, pointf p) Q = vertex[i + outp]; R = vertex[i1 + outp]; if (!same_side(P, O, Q, R)) /* false if outside the segment's face */ - return FALSE; + return false; /* else inside the segment face... */ if ((s = same_side(P, Q, R, O)) && same_side(P, R, O, Q)) /* true if between the segment's sides */ - return TRUE; + return true; /* else maybe in another segment */ for (j = 1; j < sides; j++) { /* iterate over remaining segments */ if (s) { /* clockwise */ @@ -2359,12 +2359,12 @@ static boolean poly_inside(inside_t * inside_context, pointf p) } if (!same_side(P, O, vertex[i + outp], vertex[i1 + outp])) { /* false if outside any other segment's face */ last = i; - return FALSE; + return false; } } /* inside all segments' faces */ last = i; /* in case next edge is to same side */ - return TRUE; + return true; } /* poly_path: @@ -3035,7 +3035,7 @@ static void point_init(node_t * n) ND_shape_info(n) = (void *) poly; } -static boolean point_inside(inside_t * inside_context, pointf p) +static bool point_inside(inside_t * inside_context, pointf p) { static node_t *lastn; /* last node argument */ static double radius; @@ -3044,7 +3044,7 @@ static boolean point_inside(inside_t * inside_context, pointf p) if (!inside_context) { lastn = NULL; - return FALSE; + return false; } n = inside_context->s.n; @@ -3065,7 +3065,7 @@ static boolean point_inside(inside_t * inside_context, pointf p) /* inside bounding box? */ if (fabs(P.x) > radius || fabs(P.y) > radius) - return FALSE; + return false; return hypot(P.x, P.y) <= radius; } @@ -3614,7 +3614,7 @@ static port record_port(node_t * n, char *portname, char *compass) * Note that this does not handle Mrecords correctly. It assumes * everything is a rectangle. */ -static boolean record_inside(inside_t * inside_context, pointf p) +static bool record_inside(inside_t * inside_context, pointf p) { field_t *fld0; @@ -3839,7 +3839,7 @@ shape_desc *bind_shape(char *name, node_t * np) return rv; } -static boolean epsf_inside(inside_t * inside_context, pointf p) +static bool epsf_inside(inside_t * inside_context, pointf p) { pointf P; double x2; @@ -3936,7 +3936,7 @@ static void star_vertices (pointf* vertices, pointf* bb) *bb = sz; } -static boolean star_inside(inside_t * inside_context, pointf p) +static bool star_inside(inside_t * inside_context, pointf p) { static node_t *lastn; /* last node argument */ static polygon_t *poly; @@ -3946,7 +3946,7 @@ static boolean star_inside(inside_t * inside_context, pointf p) if (!inside_context) { lastn = NULL; - return FALSE; + return false; } boxf *bp = inside_context->s.bp; node_t *n = inside_context->s.n; @@ -3981,10 +3981,10 @@ static boolean star_inside(inside_t * inside_context, pointf p) outcnt++; } if (outcnt == 2) { - return FALSE; + return false; } } - return TRUE; + return true; } /* cylinder: diff --git a/lib/common/splines.c b/lib/common/splines.c index 636ee2ad4..6774bc71f 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -102,7 +102,7 @@ arrow_clip(edge_t * fe, node_t * hn, * The points p are in node coordinates. */ void bezier_clip(inside_t * inside_context, - boolean(*inside) (inside_t * inside_context, pointf p), + bool(*inside) (inside_t * inside_context, pointf p), pointf * sp, bool left_inside) { pointf seg[4], best[4], pt, opt, *left, *right; @@ -204,7 +204,7 @@ void shape_clip(node_t * n, pointf curve[4]) save_real_size = ND_rw(n); c.x = curve[0].x - ND_coord(n).x; c.y = curve[0].y - ND_coord(n).y; - left_inside = ND_shape(n)->fns->insidefn(&inside_context, c) != FALSE; + left_inside = ND_shape(n)->fns->insidefn(&inside_context, c); ND_rw(n) = save_real_size; shape_clip0(&inside_context, n, curve, left_inside); } diff --git a/lib/common/types.h b/lib/common/types.h index d7cf6c20d..9d9454b04 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -13,6 +13,7 @@ /* Define if you want CGRAPH */ #define WITH_CGRAPH 1 +#include #include #include #include @@ -171,7 +172,7 @@ extern "C" { void (*initfn) (node_t *); /* initializes shape from node u.shape_info structure */ void (*freefn) (node_t *); /* frees shape from node u.shape_info structure */ port(*portfn) (node_t *, char *, char *); /* finds aiming point and slope of port */ - boolean(*insidefn) (inside_t * inside_context, pointf); /* clips incident gvc->e spline on shape of gvc->n */ + bool(*insidefn) (inside_t * inside_context, pointf); /* clips incident gvc->e spline on shape of gvc->n */ int (*pboxfn)(node_t* n, port* p, int side, boxf rv[], int *kptr); /* finds box path to reach port */ void (*codefn) (GVJ_t * job, node_t * n); /* emits graphics code for node */ } shape_functions; -- 2.40.0