From 572d585bc69479347cb19f6f9a47f87f7e958a46 Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 10 Sep 2008 02:51:34 +0000 Subject: [PATCH] path boxes to fp --- lib/common/render.h | 2 +- lib/common/routespl.c | 14 +- lib/common/shapes.c | 21 +- lib/common/splines.c | 210 +------------------ lib/common/types.h | 12 +- lib/dotgen/dotsplines.c | 399 ++++-------------------------------- lib/fdpgen/clusteredges.c | 2 +- lib/neatogen/neatosplines.c | 2 +- 8 files changed, 70 insertions(+), 592 deletions(-) diff --git a/lib/common/render.h b/lib/common/render.h index 76c025a47..d1c16c4c1 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -63,7 +63,7 @@ extern "C" { typedef void (*nodesizefn_t) (Agnode_t *, boolean); - extern void add_box(path *, box); + extern void add_box(path *, boxf); extern void arrow_flags(Agedge_t * e, int *sflag, int *eflag); extern boxf arrow_bb(pointf p, pointf u, double arrowsize, int flag); extern void arrow_gen(GVJ_t * job, emit_state_t emit_state, pointf p, pointf u, diff --git a/lib/common/routespl.c b/lib/common/routespl.c index d278802ca..477692225 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -42,7 +42,7 @@ static int polypointn; /* size of polypoints[] */ static Pedge_t *edges; /* polygon edges passed to Proutespline */ static int edgen; /* size of edges[] */ -static void checkpath(int, box*, path*); +static void checkpath(int, boxf*, path*); static void mkspacep(int size); static void printpath(path * pp); #ifdef OBSOLETE @@ -298,7 +298,7 @@ static pointf *_routesplines(path * pp, int *npoints, int polyline) point sp[4]; int pi, bi, si; double t; - box *boxes; + boxf *boxes; int boxn; edge_t* realedge; int flip; @@ -611,9 +611,9 @@ static int overlap(int i0, int i1, int j0, int j1) * fixing all the bugs, at least try to engineer around them! * in postmodern CS, we could call this "self-healing code." */ -static void checkpath(int boxn, box* boxes, path* thepath) +static void checkpath(int boxn, boxf* boxes, path* thepath) { - box *ba, *bb; + boxf *ba, *bb; int bi, i, errs, l, r, d, u; int xoverlap, yoverlap; @@ -945,9 +945,9 @@ static void printpath(path * pp) #endif fprintf(stderr, "%d boxes:\n", pp->nbox); for (bi = 0; bi < pp->nbox; bi++) - fprintf(stderr, "%d (%d, %d), (%d, %d)\n", bi, pp->boxes[bi].LL.x, - pp->boxes[bi].LL.y, pp->boxes[bi].UR.x, - pp->boxes[bi].UR.y); + fprintf(stderr, "%d (%.3g, %.3g), (%.3g, %.3g)\n", bi, + pp->boxes[bi].LL.x, pp->boxes[bi].LL.y, + pp->boxes[bi].UR.x, pp->boxes[bi].UR.y); fprintf(stderr, "start port: (%d, %d), tangent angle: %.3f, %s\n", pp->start.p.x, pp->start.p.y, pp->start.theta, pp->start.constrained ? "constrained" : "not constrained"); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 2d20a72b3..ea4a3fc74 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -42,14 +42,14 @@ 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 int poly_path(node_t* n, port* p, int side, box rv[], int *kptr); +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 int record_path(node_t* n, port* p, int side, box rv[], int *kptr); +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); @@ -119,7 +119,7 @@ static polygon_t p_Mcircle = * assumed convex. * the point is relative to the node center. the edge * is passed in case the port affects spline clipping. - * int SHAPE_path(node *n, edge_t *e, int pt, box path[], int *nbox) + * int SHAPE_path(node *n, edge_t *e, int pt, boxf path[], int *nbox) * create a path for the port of e that touches n, * return side * void SHAPE_gencode(GVJ_t *job, node_t *n) @@ -1153,7 +1153,7 @@ static boolean poly_inside(inside_t * inside_context, pointf p) * side gives preferred side of bounding box for last node. * Return actual side. Returning 0 indicates nothing done. */ -static int poly_path(node_t* n, port* p, int side, box rv[], int *kptr) +static int poly_path(node_t* n, port* p, int side, boxf rv[], int *kptr) { side = 0; @@ -2085,7 +2085,7 @@ static void indent(int l) static void prbox(boxf b) { - fprintf(stderr, "((%f,%f),(%f,%f))\n", b.LL.x, b.LL.y, b.UR.x, b.UR.y); + fprintf(stderr, "((%.3g,%.3g),(%.3g,%.3g))\n", b.LL.x, b.LL.y, b.UR.x, b.UR.y); } static void dumpL(field_t * info, int level) @@ -2243,15 +2243,14 @@ record_inside(inside_t * inside_context, pointf p) * Generate box path from port to border. * See poly_path for constraints. */ -static int record_path(node_t* n, port* prt, int side, box rv[], int *kptr) +static int record_path(node_t* n, port* prt, int side, boxf rv[], int *kptr) { int i, ls, rs; - point p; + pointf p, np; field_t *info; - box B; if (!prt->defined) return 0; - p = prt->p; + P2PF(prt->p, p); info = (field_t *) ND_shape_info(n); for (i = 0; i < info->n_flds; i++) { @@ -2265,8 +2264,8 @@ static int record_path(node_t* n, port* prt, int side, box rv[], int *kptr) if (BETWEEN(ls, p.x, rs)) { /* FIXME: I don't understand this code */ if (GD_flip(n->graph)) { - BF2B(info->fld[i]->b, B); - rv[0] = flip_rec_box(B, ND_coord_i(n)); + P2PF(ND_coord_i(n), np); + rv[0] = flip_rec_boxf(info->fld[i]->b, np); } else { rv[0].LL.x = ND_coord_i(n).x + ls; rv[0].LL.y = ND_coord_i(n).y - ND_ht_i(n) / 2.; diff --git a/lib/common/splines.c b/lib/common/splines.c index b5df95698..fee3f1d6d 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -31,7 +31,7 @@ static int debugleveln(edge_t* e, int i) ND_showboxes(e->tail) == i); } -static void showPoints(point ps[], int pn) +static void showPoints(pointf ps[], int pn) { char buf[BUFSIZ]; int newcnt = Show_cnt + pn + 3; @@ -42,7 +42,7 @@ static void showPoints(point ps[], int pn) Show_boxes[li++] = strdup ("%% self list"); Show_boxes[li++] = strdup ("dbgstart"); for (bi = 0; bi < pn; bi++) { - sprintf(buf, "%d %d point", ps[bi].x, ps[bi].y); + sprintf(buf, "%.3g %.3g point", ps[bi].x, ps[bi].y); Show_boxes[li++] = strdup (buf); } Show_boxes[li++] = strdup ("grestore"); @@ -343,7 +343,7 @@ conc_slope(node_t* n) return ((m_in + m_out) / 2.0); } -void add_box(path * P, box b) +void add_box(path * P, boxf b) { if (b.LL.x < b.UR.x && b.LL.y < b.UR.y) P->boxes[P->nbox++] = b; @@ -386,7 +386,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) { int side, mask; node_t *n; - int (*pboxfn) (node_t*, port*, int, box*, int*); + int (*pboxfn) (node_t*, port*, int, boxf*, int*); n = e->tail; @@ -397,9 +397,6 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) else pboxfn = NULL; P->start.p = add_points(ND_coord_i(n), ED_tail_port(e).p); -#ifdef P_TANGENTS - P->ulpp = P->urpp = P->llpp = P->lrpp = NULL; -#endif if (merge) { /*P->start.theta = - M_PI / 2; */ P->start.theta = conc_slope(e->tail); @@ -416,7 +413,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) endp->np = P->start.p; if ((et == REGULAREDGE) && (ND_node_type(n) == NORMAL) && ((side = ED_tail_port(e).side))) { edge_t* orig; - box b0, b = endp->nb; + boxf b0, b = endp->nb; if (side & TOP) { endp->sidemask = TOP; if (P->start.p.x < ND_coord_i(n).x) { /* go left */ @@ -481,7 +478,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) return; } if ((et == FLATEDGE) && ((side = ED_tail_port(e).side))) { - box b0, b = endp->nb; + boxf b0, b = endp->nb; edge_t* orig; if (side & TOP) { b.LL.y = MIN(b.LL.y,P->end.p.y); @@ -580,7 +577,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) { int side, mask; node_t *n; - int (*pboxfn) (node_t* n, port*, int, box*, int*); + int (*pboxfn) (node_t* n, port*, int, boxf*, int*); n = e->head; @@ -606,7 +603,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) endp->np = P->end.p; if ((et == REGULAREDGE) && (ND_node_type(n) == NORMAL) && ((side = ED_head_port(e).side))) { edge_t* orig; - box b0, b = endp->nb; + boxf b0, b = endp->nb; if (side & TOP) { endp->sidemask = TOP; b.LL.y = MIN(b.LL.y,P->end.p.y); @@ -674,7 +671,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) if ((et == FLATEDGE) && ((side = ED_head_port(e).side))) { edge_t* orig; - box b0, b = endp->nb; + boxf b0, b = endp->nb; switch (side) { case LEFT: b.UR.x = P->end.p.x; @@ -769,193 +766,8 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) } } -#ifdef OLD -/* self edges */ -#define ANYW 0 /* could go either way */ - -static int selfsidemap[16][3] = { - {BOTTOM, BOTTOM, ANYW}, - {TOP, TOP, ANYW}, - {RIGHT, RIGHT, ANYW}, - {LEFT, LEFT, ANYW}, - {BOTTOM, LEFT, CCW}, - {LEFT, BOTTOM, CW}, - {TOP, RIGHT, CW}, - {RIGHT, TOP, CCW}, - {TOP, LEFT, CCW}, - {LEFT, TOP, CW}, - {BOTTOM, RIGHT, CCW}, - {RIGHT, BOTTOM, CW}, - {BOTTOM, TOP, CCW}, - {TOP, BOTTOM, CW}, - {LEFT, RIGHT, CCW}, - {RIGHT, LEFT, CW}, -}; - -static void -chooseselfsides(pathend_t * tendp, pathend_t * hendp, - int *tsidep, int *hsidep, int *dirp) -{ - int i; - - for (i = 0; i < 16; i++) - if ((selfsidemap[i][0] & tendp->sidemask) && - (selfsidemap[i][1] & hendp->sidemask)) - break; - if (i == 16) - abort(); - *tsidep = selfsidemap[i][0], *hsidep = selfsidemap[i][1]; - *dirp = selfsidemap[i][2]; - if (*dirp == ANYW) { /* ANYW can appear when tside == hside */ - switch (*tsidep) { - case BOTTOM: - *dirp = (tendp->np.x < hendp->np.x) ? CCW : CW; - break; - case RIGHT: - *dirp = (tendp->np.y < hendp->np.y) ? CCW : CW; - break; - case TOP: - *dirp = (tendp->np.x > hendp->np.x) ? CCW : CW; - break; - case LEFT: - *dirp = (tendp->np.y > hendp->np.y) ? CCW : CW; - break; - } - } -} - -static box makeselfend(box b, int side, int dir, int dx, int dy) -{ - box eb = { {0, 0}, {0, 0} }; - - switch (side) { - case BOTTOM: - eb = boxof(b.LL.x, b.LL.y - dy, b.UR.x, b.LL.y); - (dir == CCW) ? (eb.UR.x += dx / 2) : (eb.LL.x -= dx / 2); - break; - case RIGHT: - eb = boxof(b.UR.x, b.LL.y, b.UR.x + dx, b.UR.y); - (dir == CCW) ? (eb.UR.y += dy / 2) : (eb.LL.y -= dy / 2); - break; - case TOP: - eb = boxof(b.LL.x, b.UR.y, b.UR.x, b.UR.y + dy); - (dir == CCW) ? (eb.LL.x -= dx / 2) : (eb.UR.x += dx / 2); - break; - case LEFT: - eb = boxof(b.LL.x - dx, b.LL.y, b.LL.x, b.UR.y); - (dir == CCW) ? (eb.LL.y -= dy / 2) : (eb.UR.y += dy / 2); - break; - } - return eb; -} - -static box -makeselfcomponent(box nb, int side, int dx, int dy, int w, int h) -{ - box b = { {0, 0}, {0, 0} }; - - switch (side) { - case BOTTOM: - b.LL.x = nb.LL.x - dx - w, b.LL.y = nb.LL.y - dy - h; - b.UR.x = nb.UR.x + dx + w, b.UR.y = b.LL.y + h; - break; - case RIGHT: - b.LL.x = nb.UR.x + dx, b.LL.y = nb.LL.y - dy; - b.UR.x = b.LL.x + w, b.UR.y = nb.UR.y + dy; - break; - case TOP: - b.LL.x = nb.LL.x - dx - w, b.LL.y = nb.UR.y + dy; - b.UR.x = nb.UR.x + dx + w, b.UR.y = b.LL.y + h; - break; - case LEFT: - b.LL.x = nb.LL.x - dx - w, b.LL.y = nb.LL.y - dy; - b.UR.x = b.LL.x + w, b.UR.y = nb.UR.y + dy; - break; - } - return b; -} - -static void -adjustselfends(box * tbp, box * hbp, point p, int side, int dir) -{ - switch (side) { - case BOTTOM: - if (dir == CCW) { - tbp->LL.x -= (tbp->UR.x - p.x), tbp->UR.x = p.x; - hbp->UR.x += (p.x - hbp->LL.x), hbp->LL.x = p.x; - } else { - tbp->UR.x -= (tbp->LL.x - p.x), tbp->LL.x = p.x; - hbp->LL.x += (p.x - hbp->UR.x), hbp->UR.x = p.x; - } - break; - case RIGHT: - if (dir == CCW) { - tbp->LL.y -= (tbp->UR.y - p.y), tbp->UR.y = p.y; - hbp->UR.y += (p.y - hbp->LL.y), hbp->LL.y = p.y; - } else { - tbp->UR.y -= (tbp->LL.y - p.y), tbp->LL.y = p.y; - hbp->LL.y += (p.y - hbp->UR.y), hbp->UR.y = p.y; - } - break; - case TOP: - if (dir == CW) { - tbp->LL.x -= (tbp->UR.x - p.x), tbp->UR.x = p.x; - hbp->UR.x += (p.x - hbp->LL.x), hbp->LL.x = p.x; - } else { - tbp->UR.x -= (tbp->LL.x - p.x), tbp->LL.x = p.x; - hbp->LL.x += (p.x - hbp->UR.x), hbp->UR.x = p.x; - } - break; - case LEFT: - if (dir == CW) { - tbp->LL.y -= (tbp->UR.y - p.y), tbp->UR.y = p.y; - hbp->UR.y += (p.y - hbp->LL.y), hbp->LL.y = p.y; - } else { - tbp->UR.y -= (tbp->LL.y - p.y), tbp->LL.y = p.y; - hbp->LL.y += (p.y - hbp->UR.y), hbp->UR.y = p.y; - } - break; - } -} - -static void -completeselfpath(path * P, pathend_t * tendp, pathend_t * hendp, - int tside, int hside, int dir, int dx, int dy, int w, - int h) -{ - int i, side; - box boxes[4]; /* can't have more than 6 boxes */ - box tb, hb; - int boxn; - - tb = makeselfend(tendp->boxes[tendp->boxn - 1], tside, dir, dx, dy); - hb = makeselfend(hendp->boxes[hendp->boxn - 1], - hside, OTHERDIR(dir), dx, dy); - - if (tside == hside && tendp->np.x == hendp->np.x && - tendp->np.y == hendp->np.y) - adjustselfends(&tb, &hb, tendp->np, tside, dir); - - boxn = 0; - for (side = tside;; side = NEXTSIDE(side, dir)) { - boxes[boxn++] = makeselfcomponent(tendp->nb, side, dx, dy, w, h); - if (side == hside) - break; - } - for (i = 0; i < tendp->boxn; i++) - add_box(P, tendp->boxes[i]); - add_box(P, tb); - for (i = 0; i < boxn; i++) - add_box(P, boxes[i]); - add_box(P, hb); - for (i = hendp->boxn - 1; i >= 0; i--) - add_box(P, hendp->boxes[i]); -} -#endif - -static void -selfBottom (edge_t* edges[], int ind, int cnt, double sizex, double stepy, - splineInfo* sinfo) +static void selfBottom (edge_t* edges[], int ind, int cnt, + double sizex, double stepy, splineInfo* sinfo) { pointf tp, hp, np; node_t *n; diff --git a/lib/common/types.h b/lib/common/types.h index a29b8ddc6..e45939786 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -87,21 +87,17 @@ extern "C" { } splineInfo; typedef struct pathend_t { - box nb; /* the node box */ + boxf nb; /* the node box */ point np; /* node port */ int sidemask; int boxn; - box boxes[20]; + boxf boxes[20]; } pathend_t; typedef struct path { /* internal specification for an edge spline */ port start, end; -#ifdef P_TANGENTS -/* FIXME not used by anything */ - pointf *ulpp, *urpp, *llpp, *lrpp; /* tangents of near splines */ -#endif int nbox; /* number of subdivisions */ - box *boxes; /* rectangular regions of subdivision */ + boxf *boxes; /* rectangular regions of subdivision */ void *data; } path; @@ -175,7 +171,7 @@ extern "C" { 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 */ - int (*pboxfn)(node_t* n, port* p, int side, box rv[], int *kptr); /* finds box path to reach port */ + 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; diff --git a/lib/dotgen/dotsplines.c b/lib/dotgen/dotsplines.c index e4533ebb4..2e90afbda 100644 --- a/lib/dotgen/dotsplines.c +++ b/lib/dotgen/dotsplines.c @@ -51,59 +51,29 @@ } #define P2PF(p, pf) (pf.x = p.x, pf.y = p.y) - -#ifdef OBSOLETE -static int flatsidemap[16][6] = { - {BOTTOM, BOTTOM, BOTTOM, CCW, CCW, FALSE}, - {TOP, TOP, TOP, CW, CW, FALSE}, - {RIGHT, LEFT, BOTTOM, CW, CW, TRUE}, - {BOTTOM, TOP, RIGHT, CCW, CW, TRUE}, - {TOP, BOTTOM, RIGHT, CW, CCW, TRUE}, - {RIGHT, TOP, RIGHT, CCW, CW, TRUE}, - {RIGHT, BOTTOM, RIGHT, CW, CCW, TRUE}, - {TOP, LEFT, TOP, CW, CCW, TRUE}, - {BOTTOM, LEFT, BOTTOM, CCW, CW, TRUE}, - {RIGHT, RIGHT, BOTTOM, CW, CCW, TRUE}, - {LEFT, LEFT, BOTTOM, CCW, CW, TRUE}, - {LEFT, BOTTOM, BOTTOM, CCW, CCW, FALSE}, - {TOP, RIGHT, TOP, CW, CW, FALSE}, - {LEFT, TOP, TOP, CW, CW, FALSE}, - {BOTTOM, RIGHT, BOTTOM, CCW, CCW, FALSE}, - {LEFT, RIGHT, BOTTOM, CCW, CCW, FALSE}, -}; -#endif - #define AVG(a, b) ((a + b) / 2) -static box boxes[1000]; +static boxf boxes[1000]; typedef struct { int LeftBound, RightBound, Splinesep, Multisep; - box* Rank_box; + boxf* Rank_box; } spline_info_t; static void adjustregularpath(path *, int, int); static Agedge_t *bot_bound(Agedge_t *, int); static boolean pathscross(Agnode_t *, Agnode_t *, Agedge_t *, Agedge_t *); -#ifdef OBSOLETE -static void chooseflatsides(pathend_t *, pathend_t *, int *, int *, int *, - int *, int *, int *); -static void completeflatpath(path *, pathend_t *, pathend_t *, - box *, box *, int, int); -static box makeflatend(box, int, int, box); -static box makeflatcomponent(box, box, int, int, int, int, int); -#endif static Agraph_t *cl_bound(Agnode_t *, Agnode_t *); static int cl_vninside(Agraph_t *, Agnode_t *); static void completeregularpath(path *, Agedge_t *, Agedge_t *, - pathend_t *, pathend_t *, box *, int, int); + pathend_t *, pathend_t *, boxf *, int, int); static int edgecmp(Agedge_t **, Agedge_t **); static void make_flat_edge(spline_info_t*, path *, Agedge_t **, int, int, int); static void make_regular_edge(spline_info_t*, path *, Agedge_t **, int, int, int); -static box makeregularend(box, int, int); -static box maximal_bbox(spline_info_t*, Agnode_t *, Agedge_t *, Agedge_t *); +static boxf makeregularend(boxf, int, int); +static boxf maximal_bbox(spline_info_t*, Agnode_t *, Agedge_t *, Agedge_t *); static Agnode_t *neighbor(Agnode_t *, Agedge_t *, Agedge_t *, int); static void place_vnlabel(Agnode_t *); -static box rank_box(spline_info_t* sp, Agraph_t *, int); +static boxf rank_box(spline_info_t* sp, Agraph_t *, int); static void recover_slack(Agedge_t *, path *); static void resize_vn(Agnode_t *, int, int, int); static void setflags(Agedge_t *, int, int, int); @@ -332,8 +302,8 @@ static void _dot_splines(graph_t * g, int normalize) (qsort_cmpf) edgecmp); /* FIXME: just how many boxes can there be? */ - P->boxes = N_NEW(n_nodes + 20 * 2 * NSUB, box); - sd.Rank_box = N_NEW(i, box); + P->boxes = N_NEW(n_nodes + 20 * 2 * NSUB, boxf); + sd.Rank_box = N_NEW(i, boxf); if (et == ET_LINE) { /* place regular edge labels */ @@ -577,92 +547,6 @@ static int edgecmp(edge_t** ptr0, edge_t** ptr1) return (e0->id - e1->id); } -#if 0 -/* fledgecmp: - * Sort edges by mid y value of ports. - * If this is the same, and all y values are the same, - * check if one segment lies within the other. - */ -static int -fledgecmp(edge_t** ptr0, edge_t** ptr1) -{ - edge_t *e0, *e1; - point tp0, tp1, hp0, hp1; - int y0, y1; - - e0 = *ptr0; - e1 = *ptr1; - tp0 = ED_tail_port(e0).p; - hp0 = ED_head_port(e0).p; - tp1 = ED_tail_port(e1).p; - hp1 = ED_head_port(e1).p; - y0 = (tp0.y + hp0.y)/2; - y1 = (tp1.y + hp1.y)/2; - if (y0 != y1) return (y0-y1); - if ((tp0.y == hp0.y) && (tp1.y == hp1.y)) { - if ((tp0.x <= tp1.x) && (hp0.x >= hp1.x)) { - if (tp0.y <= 0) return -1; - else return 1; - } - else if ((tp0.x >= tp1.x) && (hp0.x <= hp1.x)) { - if (tp0.y <= 0) return 1; - else return -1; - } - } - return (e0->id - e1->id); - -} - -#define LABEL_SPACE 8 - -/* setFlatAdjPos: - * Create middle boxes for routing using ordered list of edges going from - * bottom to top. - * Also, set label positions. - */ -static void -setFlatAdjPos (edge_t** edges, int n_edges, int flip, box* boxes, edge_t* e0) -{ - int r, i, x, boxw, availht; - edge_t* e; - double y, wd, ht, totalht = 0; - textlabel_t* lbl; - node_t *tn, *hn; - graph_t* g; - -assert(0); - tn = e0->tail, hn = e0->head; - g = tn->graph; - x = (ND_coord_i(tn).x + ND_coord_i(hn).x)/2; - y = ND_coord_i(tn).y; - r = ND_rank(tn); - availht = GD_rank(g)[r].ht2 + GD_rank(g)[r].ht1 + GD_ranksep(g); - boxw = (ND_coord_i(hn).x - ND_coord_i(tn).x - ND_rw_i(tn) - ND_lw_i(hn))/3; - for (i = 0; i < n_edges; i++) { - if (!((lbl = ED_label(e)))) continue; - if (flip) { - ht = lbl->dimen.x; - wd = lbl->dimen.y; - } - else { - ht = lbl->dimen.y; - wd = lbl->dimen.x; - } - totalht += ht; - boxw = MAX(boxw, wd); - } - for (i = 0; i < n_edges; i++) { - e = edges[i]; - lbl = ED_label(e); - if (GD_flip(g)) ht = lbl->dimen.x; - else ht = lbl->dimen.y; - lbl->p.x = x; - lbl->p.y = ROUND(y - ht/2); - y -= ht + LABEL_SPACE; - } -} -#endif - /* cloneGraph: */ static struct { @@ -993,7 +877,7 @@ static void makeFlatEnd (spline_info_t* sp, path* P, node_t* n, edge_t* e, pathend_t* endp, boolean isBegin) { - box b; + boxf b; graph_t* g = n->graph; b = endp->nb = maximal_bbox(sp, n, NULL, e); @@ -1012,7 +896,7 @@ static void makeBottomFlatEnd (spline_info_t* sp, path* P, node_t* n, edge_t* e, pathend_t* endp, boolean isBegin) { - box b; + boxf b; graph_t* g = n->graph; b = endp->nb = maximal_bbox(sp, n, NULL, e); @@ -1141,7 +1025,7 @@ make_flat_bottom_edges(spline_info_t* sp, path * P, edge_t ** edges, int for (i = 0; i < cnt; i++) { int boxn; - box b; + boxf b; e = edges[ind + i]; boxn = 0; @@ -1246,7 +1130,7 @@ make_flat_edge(spline_info_t* sp, path * P, edge_t ** edges, int ind, int cnt, i for (i = 0; i < cnt; i++) { int boxn; - box b; + boxf b; e = edges[ind + i]; boxn = 0; @@ -1391,7 +1275,7 @@ make_regular_edge(spline_info_t* sp, path * P, edge_t ** edges, int ind, int cnt edge_t fwdedgea, fwdedgeb, fwdedge, *e, *fe, *le, *segfirst; pointf *ps; pathend_t tend, hend; - box b; + boxf b; int boxn, sl, si, smode, i, j, dx, pn, hackflag, longedge; pointf pointfs[1000], pointfs2[1000]; int pointn; @@ -1561,202 +1445,13 @@ make_regular_edge(spline_info_t* sp, path * P, edge_t ** edges, int ind, int cnt } } -/* flat edges */ - -#ifdef OBSOLETE -static void -chooseflatsides(pathend_t* tendp, pathend_t *hendp, - int* tsidep, int* hsidep, int* msidep, int* tdirp, - int* hdirp, int* crossp) -{ - int i; - - for (i = 0; i < 16; i++) - if ((flatsidemap[i][0] & tendp->sidemask) && - (flatsidemap[i][1] & hendp->sidemask)) - break; - if (i == 16) - abort(); - *tsidep = flatsidemap[i][0], *hsidep = flatsidemap[i][1]; - *msidep = flatsidemap[i][2]; - *tdirp = flatsidemap[i][3], *hdirp = flatsidemap[i][4]; - *crossp = flatsidemap[i][5]; -} - -static void -completeflatpath(path * P, - pathend_t * tendp, pathend_t * hendp, - int tside, int hside, int mside, int tdir, int hdir, - box * arg_lb, box * arg_rb, int w, int h) -{ - int i, side, boxn; - box boxes[8]; - box tb, hb; - box lb, rb; - lb = *arg_lb; - rb = *arg_rb; - - tb = makeflatend(tendp->boxes[tendp->boxn - 1], tside, tdir, lb); - hb = makeflatend(hendp->boxes[hendp->boxn - 1], hside, OTHERDIR(hdir), - rb); - - boxn = 0; - for (side = tside;; side = NEXTSIDE(side, tdir)) { - boxes[boxn++] = makeflatcomponent(lb, rb, side, - (side == mside) ? 0 : -1, tdir, - w, h); - if (side == mside) - break; - } - if (mside == RIGHT) - mside = LEFT; - if (mside != hside) { - for (side = NEXTSIDE(mside, hdir);; side = NEXTSIDE(side, hdir)) { - boxes[boxn++] = makeflatcomponent(lb, rb, side, 1, hdir, w, h); - if (side == hside) - break; - } - } - - for (i = 0; i < tendp->boxn; i++) - add_box(P, tendp->boxes[i]); - if (tb.LL.x != tb.UR.x && tb.LL.y != tb.UR.y) - add_box(P, tb); - for (i = 0; i < boxn; i++) - add_box(P, boxes[i]); - if (hb.LL.x != hb.UR.x && hb.LL.y != hb.UR.y) - add_box(P, hb); - for (i = hendp->boxn - 1; i >= 0; i--) - add_box(P, hendp->boxes[i]); -} - -static box -makeflatend(box b, int side, int dir, box bb) -{ - box eb = { {0, 0}, {0, 0} }; - - switch (side) { - case BOTTOM: - eb = boxof(b.LL.x, bb.LL.y, b.UR.x, b.LL.y); - if (dir == CCW) - eb.UR.x += (bb.UR.x - b.UR.x) / 2; - else - eb.LL.x -= (b.LL.x - bb.LL.x) / 2; - break; - case RIGHT: - eb = boxof(b.UR.x, b.LL.y, bb.UR.x, b.UR.y); - if (dir == CCW) - eb.UR.y += (bb.UR.y - b.UR.y) / 2; - else - eb.LL.y -= (b.LL.y - bb.LL.y) / 2; - break; - case TOP: - eb = boxof(b.LL.x, b.UR.y, b.UR.x, bb.UR.y); - if (dir == CCW) - eb.LL.x -= (b.LL.x - bb.LL.x) / 2; - else - eb.UR.x += (bb.UR.x - b.UR.x) / 2; - break; - case LEFT: - eb = boxof(bb.LL.x, b.LL.y, b.LL.x, b.UR.y); - if (dir == CCW) - eb.LL.y -= (bb.UR.y - b.UR.y) / 2; - else - eb.UR.y += (b.LL.y - bb.LL.y) / 2; - break; - } - return eb; -} - -static box makeflatcomponent(lb, rb, side, mode, dir, w, h) -box lb, rb; -int side, mode, dir, w, h; -{ - box b = { {0, 0}, {0, 0} }; - - /* mode == -1 means use left box, 1 means use right box - and 0 means use mostly the left box */ - - switch (side) { - case BOTTOM: - b.LL.x = lb.LL.x - w, b.UR.x = rb.UR.x + w; - if (mode <= 0) - b.LL.y = lb.LL.y - h, b.UR.y = lb.LL.y; - else - b.LL.y = rb.LL.y - h, b.UR.y = rb.LL.y; - break; - case RIGHT: - if (mode == -1) { - b.LL.x = lb.UR.x, b.UR.x = lb.UR.x + w; - b.LL.y = lb.LL.y, b.UR.y = lb.UR.y; - } else if (mode == 0) { - b.LL.x = lb.UR.x, b.UR.x = lb.UR.x + w; - if (dir == CCW) - b.LL.y = lb.LL.y, b.UR.y = rb.UR.y; - else - b.LL.y = rb.LL.y, b.UR.y = lb.UR.y; - } else { - b.LL.x = rb.UR.x, b.UR.x = rb.UR.x + w; - b.LL.y = rb.LL.y, b.UR.y = rb.UR.y; - } - break; - case TOP: - b.LL.x = lb.LL.x - w, b.UR.x = rb.UR.x + w; - if (mode <= 0) - b.LL.y = lb.UR.y, b.UR.y = lb.UR.y + h; - else - b.LL.y = rb.UR.y, b.UR.y = rb.UR.y + h; - break; - case LEFT: - if (mode == -1) { - b.LL.x = lb.LL.x - w, b.UR.x = lb.LL.x; - b.LL.y = lb.LL.y, b.UR.y = lb.UR.y; - } else if (mode == 0) { - b.LL.x = lb.LL.x - w, b.UR.x = lb.LL.x; - if (dir == CCW) - b.LL.y = lb.LL.y, b.UR.y = rb.UR.y; - else - b.LL.y = rb.LL.y, b.UR.y = lb.UR.y; - } else { - b.LL.x = rb.LL.x - w, b.UR.x = rb.LL.x; - b.LL.y = rb.LL.y, b.UR.y = rb.UR.y; - } - break; - } - return b; -} -static void -completeflatpath(path* P, pathend_t* tendp, pathend_t* hendp, - box* lbp, box* rbp, int w, int h) -{ - int i; - box wbox; - box tb, hb; - box lb, rb; - lb = *lbp; - rb = *rbp; - - tb = makeflatend(tendp->boxes[tendp->boxn - 1], TOP, CW, lb); - hb = makeflatend(hendp->boxes[hendp->boxn - 1], TOP, CCW, rb); - - wbox = makeflatcomponent(lb, rb, TOP, 0, CW, w, h); - - for (i = 0; i < tendp->boxn; i++) - add_box(P, tendp->boxes[i]); - add_box(P, tb); - add_box(P, wbox); - for (i = hendp->boxn - 1; i >= 0; i--) - add_box(P, hendp->boxes[i]); -} -#endif - /* regular edges */ #define DONT_WANT_ANY_ENDPOINT_PATH_REFINEMENT #ifdef DONT_WANT_ANY_ENDPOINT_PATH_REFINEMENT static void completeregularpath(path * P, edge_t * first, edge_t * last, - pathend_t * tendp, pathend_t * hendp, box * boxes, + pathend_t * tendp, pathend_t * hendp, boxf * boxes, int boxn, int flag) { edge_t *uleft, *uright, *lleft, *lright; @@ -1770,35 +1465,25 @@ completeregularpath(path * P, edge_t * first, edge_t * last, uleft = top_bound(first, -1), uright = top_bound(first, 1); if (uleft) { spl = getsplinepoints(uleft); - pp = spl->list[0].list, pn = spl->list[0].size; -#ifdef P_TANGENTS - P->ulpp = &pp[0]; -#endif + pp = spl->list[0].list; + pn = spl->list[0].size; } if (uright) { spl = getsplinepoints(uright); - pp = spl->list[0].list, pn = spl->list[0].size; -#ifdef P_TANGENTS - P->urpp = &pp[0]; -#endif + pp = spl->list[0].list; + pn = spl->list[0].size; } lleft = lright = NULL; lleft = bot_bound(last, -1), lright = bot_bound(last, 1); if (lleft) { spl = getsplinepoints(lleft); - pp = spl->list[spl->size - 1].list, pn = - spl->list[spl->size - 1].size; -#ifdef P_TANGENTS - P->llpp = &pp[pn - 1]; -#endif + pp = spl->list[spl->size - 1].list; + pn = spl->list[spl->size - 1].size; } if (lright) { spl = getsplinepoints(lright); - pp = spl->list[spl->size - 1].list, pn = - spl->list[spl->size - 1].size; -#ifdef P_TANGENTS - P->lrpp = &pp[pn - 1]; -#endif + pp = spl->list[spl->size - 1].list; + pn = spl->list[spl->size - 1].size; } for (i = 0; i < tendp->boxn; i++) add_box(P, tendp->boxes[i]); @@ -1812,17 +1497,17 @@ completeregularpath(path * P, edge_t * first, edge_t * last, } #else void refineregularends(edge_t * left, edge_t * right, pathend_t * endp, - int dir, box b, box * boxes, int *boxnp); + int dir, boxf b, boxf * boxes, int *boxnp); /* box subdivision is obsolete, I think... ek */ static void completeregularpath(path * P, edge_t * first, edge_t * last, - pathend_t * tendp, pathend_t * hendp, box * boxes, + pathend_t * tendp, pathend_t * hendp, boxf * boxes, int boxn, int flag) { edge_t *uleft, *uright, *lleft, *lright; - box uboxes[NSUB], lboxes[NSUB]; - box b; + boxf uboxes[NSUB], lboxes[NSUB]; + boxf b; int uboxn, lboxn, i, y, fb, lb; fb = lb = -1; @@ -1884,15 +1569,15 @@ completeregularpath(path * P, edge_t * first, edge_t * last, * nodes in a given rank can differ in height. * for now, regular edges always go from top to bottom */ -static box makeregularend(box b, int side, int y) +static boxf makeregularend(boxf b, int side, int y) { - box newb; + boxf newb; switch (side) { case BOTTOM: - newb = boxof(b.LL.x, y, b.UR.x, b.LL.y); + newb = boxfof(b.LL.x, y, b.UR.x, b.LL.y); break; case TOP: - newb = boxof(b.LL.x, b.UR.y, b.UR.x, y); + newb = boxfof(b.LL.x, b.UR.y, b.UR.x, y); break; } return newb; @@ -2016,7 +1701,7 @@ int *boxnp; */ static void adjustregularpath(path * P, int fb, int lb) { - box *bp1, *bp2; + boxf *bp1, *bp2; int i, x; for (i = fb-1; i < lb+1; i++) { @@ -2046,26 +1731,12 @@ static void adjustregularpath(path * P, int fb, int lb) if (bp1->UR.x - MINW < bp2->LL.x) bp1->UR.x = bp2->LL.x + MINW; } -#ifdef OLD - else { - if (bp1->LL.x + MINW > bp2->UR.x) { - x = (bp1->LL.x + bp2->UR.x) / 2; - bp1->LL.x = x - HALFMINW; - bp2->UR.x = x + HALFMINW; - } - if (bp1->UR.x - MINW < bp2->LL.x) { - x = (bp1->UR.x + bp2->LL.x) / 2; - bp1->UR.x = x + HALFMINW; - bp2->LL.x = x - HALFMINW; - } - } -#endif } } -static box rank_box(spline_info_t* sp, graph_t * g, int r) +static boxf rank_box(spline_info_t* sp, graph_t * g, int r) { - box b; + boxf b; node_t /* *right0, *right1, */ * left0, *left1; b = sp->Rank_box[r]; @@ -2306,12 +1977,12 @@ node_t *n, *adj; */ #define FUDGE 4 -static box maximal_bbox(spline_info_t* sp, node_t* vn, edge_t* ie, edge_t* oe) +static boxf maximal_bbox(spline_info_t* sp, node_t* vn, edge_t* ie, edge_t* oe) { double b, nb; graph_t *g = vn->graph, *left_cl, *right_cl; node_t *left, *right; - box rv; + boxf rv; left_cl = right_cl = NULL; diff --git a/lib/fdpgen/clusteredges.c b/lib/fdpgen/clusteredges.c index b59b2093a..033a73a7b 100644 --- a/lib/fdpgen/clusteredges.c +++ b/lib/fdpgen/clusteredges.c @@ -273,7 +273,7 @@ int compoundEdges(graph_t * g, expand_t* pm, int edgetype) if ((n == head) && ED_count(e)) { /* self arc */ if (!P) { P = NEW(path); - P->boxes = N_NEW(agnnodes(g) + 20 * 2 * 9, box); + P->boxes = N_NEW(agnnodes(g) + 20 * 2 * 9, boxf); } makeSelfArcs(P, e, GD_nodesep(g)); } else if (ED_count(e)) { diff --git a/lib/neatogen/neatosplines.c b/lib/neatogen/neatosplines.c index 7e0844aac..e0f2b7192 100644 --- a/lib/neatogen/neatosplines.c +++ b/lib/neatogen/neatosplines.c @@ -841,7 +841,7 @@ static int _spline_edges(graph_t * g, expand_t* pmargin, int edgetype) else if (n == head) { /* self arc */ if (!P) { P = NEW(path); - P->boxes = N_NEW(agnnodes(g) + 20 * 2 * 9, box); + P->boxes = N_NEW(agnnodes(g) + 20 * 2 * 9, boxf); } makeSelfArcs(P, e, GD_nodesep(g)); } else if (vconfig) { /* ET_SPLINE or ET_POLYLINE */ -- 2.40.0