#endif
static void
-selfBottom (edge_t* edges[], int ind, int cnt, int stepy, splineInfo* sinfo)
+selfBottom (edge_t* edges[], int ind, int cnt, int sizex, int stepy, splineInfo* sinfo)
{
int sgn, hy, ty;
point tp, hp;
e = edges[ind];
n = e->tail;
- /* stepx = (ND_rw_i(n)) / cnt; */
- stepx = stepy;
+ stepy /= 2;
+ stepy = MAX(stepy, 2);
+ stepx = sizex / cnt;
+ stepx = MAX(stepx, 2);
pointn = 0;
np = ND_coord_i(n);
tp = ED_tail_port(e).p;
}
static void
-selfTop (edge_t* edges[], int ind, int cnt, int stepy, splineInfo* sinfo)
+selfTop (edge_t* edges[], int ind, int cnt, int sizex, int stepy,
+ splineInfo* sinfo)
{
int sgn, hy, ty;
point tp, hp;
e = edges[ind];
n = e->tail;
- /* stepx = (ND_rw_i(n)) / cnt; */
- stepx = stepy;
+ stepy /= 2;
+ stepy = MAX(stepy, 2);
+ stepx = sizex / cnt;
+ stepx = MAX(stepx, 2);
pointn = 0;
np = ND_coord_i(n);
tp = ED_tail_port(e).p;
}
static void
-selfRight (edge_t* edges[], int ind, int cnt, int stepx, splineInfo* sinfo)
+selfRight (edge_t* edges[], int ind, int cnt, int stepx, int sizey,
+ splineInfo* sinfo)
{
int hx, tx, sgn;
point tp, hp;
e = edges[ind];
n = e->tail;
- stepy = (ND_ht_i(n) / 2) / cnt;
+ stepy = (sizey / 2) / cnt;
+ stepy = MAX(stepy, 2);
pointn = 0;
np = ND_coord_i(n);
tp = ED_tail_port(e).p;
}
static void
-selfLeft (edge_t* edges[], int ind, int cnt, int stepx, splineInfo* sinfo)
+selfLeft (edge_t* edges[], int ind, int cnt, int stepx, int sizey,
+ splineInfo* sinfo)
{
int hx, tx, sgn;
point tp, hp;
e = edges[ind];
n = e->tail;
- stepy = (ND_ht_i(n) / 2) / cnt;
+ stepy = (sizey / 2) / cnt;
+ stepy = MAX(stepy,2);
pointn = 0;
np = ND_coord_i(n);
tp = ED_tail_port(e).p;
* Assume e is self-edge.
* Return extra space necessary on the right for this edge.
* If the edge does not go on the right, return 0.
+ * NOTE: the actual space is determined dynamically by GD_nodesep,
+ * 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)
* Perhaps for self-edges, the label should be centered.
*/
void
-makeSelfEdge(path * P, edge_t * edges[], int ind, int cnt, int stepx,
- splineInfo * sinfo)
+makeSelfEdge(path * P, edge_t * edges[], int ind, int cnt, int sizex,
+ int sizey, splineInfo * sinfo)
{
edge_t *e;
#ifdef OLD
!(ED_head_port(e).side & LEFT) &&
((ED_tail_port(e).side != ED_head_port(e).side) ||
(!(ED_tail_port(e).side & (TOP|BOTTOM)))))) {
- selfRight(edges, ind, cnt, stepx, sinfo);
+ selfRight(edges, ind, cnt, sizex, sizey, sinfo);
}
/* self edge with port on left side */
/* handle L-R specially */
if ((ED_tail_port(e).side & RIGHT) || (ED_head_port(e).side & RIGHT)) {
- selfTop(edges, ind, cnt, stepx, sinfo);
+ selfTop(edges, ind, cnt, sizex, sizey, sinfo);
}
else {
- selfLeft(edges, ind, cnt, stepx, sinfo);
+ selfLeft(edges, ind, cnt, sizex, sizey, sinfo);
}
}
/* self edge with both ports on top side */
else if (ED_tail_port(e).side & TOP) {
- selfTop(edges, ind, cnt, stepx, sinfo);
+ selfTop(edges, ind, cnt, sizex, sizey, sinfo);
}
else if (ED_tail_port(e).side & BOTTOM) {
- selfBottom(edges, ind, cnt, stepx, sinfo);
+ selfBottom(edges, ind, cnt, sizex, sizey, sinfo);
}
else assert(0);
if (ED_tree_index(edges[i]) & MAINGRAPH) /* Aha! -C is on */
break;
}
- if (e0->tail == e0->head)
- makeSelfEdge(P, edges, ind, cnt, Multisep, &sinfo);
+ if (e0->tail == e0->head) {
+ int sizey, r;
+ n = e0->tail;
+ r = ND_rank(n);
+ if (r == GD_maxrank(g)) {
+ sizey = ND_coord_i(GD_rank(g)[r-1].v[0]).y - ND_coord_i(n).y;
+ }
+ else if (r == GD_minrank(g)) {
+ sizey = ND_coord_i(n).y - ND_coord_i(GD_rank(g)[r+1].v[0]).y;
+ }
+ else {
+ int upy = ND_coord_i(GD_rank(g)[r-1].v[0]).y - ND_coord_i(n).y;
+ int dwny = ND_coord_i(n).y - ND_coord_i(GD_rank(g)[r+1].v[0]).y;
+ sizey = MIN(upy, dwny);
+ }
+ makeSelfEdge(P, edges, ind, cnt, Multisep, sizey, &sinfo);
+ }
else if (ND_rank(e0->tail) == ND_rank(e0->head)) {
make_flat_edge(P, edges, ind, cnt);
}