22 static int debugleveln(
edge_t* e,
int i)
31 static void showPoints(
pointf ps[],
int pn)
41 for (bi = 0; bi < pn; bi++) {
42 sprintf(buf,
"%.5g %.5g point", ps[bi].x, ps[bi].y);
61 pointf * ps,
int *startp,
int *endp,
65 int i, j, sflag, eflag;
108 pointf * sp,
boolean left_inside)
111 double low, high, t, *idir, *odir;
133 t = (high + low) / 2.0;
134 pt =
Bezier(sp, 3, t, left, right);
135 if (inside(inside_context, pt)) {
138 for (i = 0; i < 4; i++)
143 }
while (
ABS(opt.
x - pt.
x) > .5 ||
ABS(opt.
y - pt.
y) > .5);
145 for (i = 0; i < 4; i++)
148 for (i = 0; i < 4; i++)
164 double save_real_size;
167 save_real_size =
ND_rw(n);
168 for (i = 0; i < 4; i++) {
176 for (i = 0; i < 4; i++) {
180 ND_rw(n) = save_real_size;
197 double save_real_size;
205 inside_context.
s.
n = n;
207 save_real_size =
ND_rw(n);
210 left_inside =
ND_shape(n)->fns->insidefn(&inside_context, c);
211 ND_rw(n) = save_real_size;
212 shape_clip0(&inside_context, n, curve, left_inside);
247 int start, end, i, clipTail, clipHead;
281 inside_context.
s.
n = tn;
282 inside_context.
s.
bp = tbox;
283 for (start = 0; start < pn - 4; start += 3) {
286 if (
ND_shape(tn)->fns->insidefn(&inside_context, p2) ==
FALSE)
289 shape_clip0(&inside_context, tn, &ps[start],
TRUE);
293 inside_context.
s.
n = hn;
294 inside_context.
s.
bp = hbox;
295 for (end = pn - 4; end > 0; end -= 3) {
298 if (
ND_shape(hn)->fns->insidefn(&inside_context, p2) ==
FALSE)
301 shape_clip0(&inside_context, hn, &ps[end],
FALSE);
304 for (; start < pn - 4; start += 3)
307 for (; end > 0; end -= 3)
310 arrow_clip(fe, hn, ps, &start, &end, newspl, info);
311 for (i = start; i < end + 4; ) {
313 newspl->
list[i - start] = ps[i];
318 newspl->
list[i - start] = ps[i];
321 newspl->
list[i - start] = ps[i];
327 newspl->
size = end - start + 4;
333 double s_in, s_out, m_in, m_out;
339 for (cnt_in = 0; (e =
ND_in(n).list[cnt_in]); cnt_in++)
341 for (cnt_out = 0; (e =
ND_out(n).list[cnt_out]); cnt_out++)
345 m_in = atan2(p.
y, p.
x);
348 m_out = atan2(p.
y, p.
x);
349 return ((m_in + m_out) / 2.0);
390 #define HT2(n) (ND_ht(n)/2)
420 P->
data = (
void *) e;
424 boxf b0, b = endp->
nb;
463 else if (side &
LEFT) {
489 boxf b0, b = endp->
nb;
518 else if (side &
LEFT) {
618 boxf b0, b = endp->
nb;
657 else if (side &
LEFT) {
685 boxf b0, b = endp->
nb;
714 else if (side &
LEFT) {
785 static int convert_sides_to_points(
int tail_side,
int head_side)
787 int vertices[] = {12,4,6,2,3,1,9,8};
788 int i, tail_i, head_i;
790 {11,12,13,14,15,16,17,18},
791 {21,22,23,24,25,26,27,28},
792 {31,32,33,34,35,36,37,38},
793 {41,42,43,44,45,46,47,48},
794 {51,52,53,54,55,56,57,58},
795 {61,62,63,64,65,66,67,68},
796 {71,72,73,74,75,76,77,78},
797 {81,82,83,84,85,86,87,88}
800 tail_i = head_i = -1;
802 if(head_side == vertices[i]){
808 if(tail_side == vertices[i]){
814 if( tail_i < 0 || head_i < 0)
817 return pair_a[tail_i][head_i];
821 static void selfBottom (
edge_t* edges[],
int ind,
int cnt,
822 double sizex,
double stepy,
splineInfo* sinfo)
827 int i, sgn, point_pair;
828 double hy, ty, stepx, dx, dy, width, height;
835 stepx = (sizex / 2.) / cnt;
836 stepx =
MAX(stepx,2.);
845 if (tp.
x >= hp.
x) sgn = 1;
847 dy =
ND_ht(n)/2., dx = 0.;
857 ty =
MIN(dy, 3*(tp.
y + dy - np.
y));
858 hy =
MIN(dy, 3*(hp.
y + dy - np.
y));
859 for (i = 0; i < cnt; i++) {
861 dy += stepy, ty += stepy, hy += stepy, dx += sgn*stepx;
863 points[pointn++] = tp;
864 points[pointn++] = pointfof(tp.
x + dx, tp.
y - ty / 3);
865 points[pointn++] = pointfof(tp.
x + dx, np.
y - dy);
866 points[pointn++] = pointfof((tp.
x+hp.
x)/2, np.
y - dy);
867 points[pointn++] = pointfof(hp.
x - dx, np.
y - dy);
868 points[pointn++] = pointfof(hp.
x - dx, hp.
y - hy / 3);
869 points[pointn++] = hp;
882 dy += height - stepy;
886 if (debugleveln(e,1))
887 showPoints (points, pointn);
894 selfTop (
edge_t* edges[],
int ind,
int cnt,
double sizex,
double stepy,
897 int i, sgn, point_pair;
898 double hy, ty, stepx, dx, dy, width, height;
908 stepx = (sizex / 2.) / cnt;
909 stepx =
MAX(stepx, 2.);
918 if (tp.
x >= hp.
x) sgn = 1;
920 dy =
ND_ht(n)/2., dx = 0.;
926 dx = sgn*(
ND_rw(n) - (hp.
x-np.
x) + stepx);
930 dx = sgn*(
ND_lw(n)-(np.
x-hp.
x) + stepx);
933 dx = sgn*(
ND_rw(n)-(tp.
x-np.
x) + stepx);
936 dx = sgn*(
ND_rw(n)-(tp.
x-np.
x) + stepx);
945 dx = sgn*((((
ND_lw(n)-(np.
x-tp.
x)) + (
ND_rw(n)-(hp.
x-np.
x)))/3.));
948 dx = sgn*(
ND_lw(n)-(np.
x-tp.
x) + stepx);
951 dx = sgn*(
ND_lw(n)-(np.
x-tp.
x));
954 dx = sgn*((((
ND_lw(n)-(np.
x-tp.
x)) + (
ND_rw(n)-(hp.
x-np.
x)))/2.) + stepx);
959 dx = sgn*((((
ND_lw(n)-(np.
x-tp.
x)) + (
ND_rw(n)-(hp.
x-np.
x)))/2.) + 2*stepx);
964 ty =
MIN(dy, 3*(np.
y + dy - tp.
y));
965 hy =
MIN(dy, 3*(np.
y + dy - hp.
y));
966 for (i = 0; i < cnt; i++) {
968 dy += stepy, ty += stepy, hy += stepy, dx += sgn*stepx;
970 points[pointn++] = tp;
971 points[pointn++] = pointfof(tp.
x + dx, tp.
y + ty / 3);
972 points[pointn++] = pointfof(tp.
x + dx, np.
y + dy);
973 points[pointn++] = pointfof((tp.
x+hp.
x)/2, np.
y + dy);
974 points[pointn++] = pointfof(hp.
x - dx, np.
y + dy);
975 points[pointn++] = pointfof(hp.
x - dx, hp.
y + hy / 3);
976 points[pointn++] = hp;
989 dy += height - stepy;
993 if (debugleveln(e,1))
994 showPoints (points, pointn);
1001 selfRight (
edge_t* edges[],
int ind,
int cnt,
double stepx,
double sizey,
1004 int i, sgn, point_pair;
1005 double hx, tx, stepy, dx, dy, width, height;
1015 stepy = (sizey / 2.) / cnt;
1016 stepy =
MAX(stepy, 2.);
1025 if (tp.
y >= hp.
y) sgn = 1;
1027 dx =
ND_rw(n), dy = 0;
1033 case 65:
if(tp.
y == hp.
y)
1039 tx =
MIN(dx, 3*(np.
x + dx - tp.
x));
1040 hx =
MIN(dx, 3*(np.
x + dx - hp.
x));
1041 for (i = 0; i < cnt; i++) {
1043 dx += stepx, tx += stepx, hx += stepx, dy += sgn*stepy;
1045 points[pointn++] = tp;
1046 points[pointn++] = pointfof(tp.
x + tx / 3, tp.
y + dy);
1047 points[pointn++] = pointfof(np.
x + dx, tp.
y + dy);
1048 points[pointn++] = pointfof(np.
x + dx, (tp.
y+hp.
y)/2);
1049 points[pointn++] = pointfof(np.
x + dx, hp.
y - dy);
1050 points[pointn++] = pointfof(hp.
x + hx / 3, hp.
y - dy);
1051 points[pointn++] = hp;
1064 dx += width - stepx;
1068 if (debugleveln(e,1))
1069 showPoints (points, pointn);
1076 selfLeft (
edge_t* edges[],
int ind,
int cnt,
double stepx,
double sizey,
1079 int i, sgn,point_pair;
1080 double hx, tx, stepy, dx, dy, width, height;
1090 stepy = (sizey / 2.) / cnt;
1091 stepy =
MAX(stepy,2.);
1102 if (tp.
y >= hp.
y) sgn = 1;
1104 dx =
ND_lw(n), dy = 0.;
1117 tx =
MIN(dx, 3*(tp.
x + dx - np.
x));
1118 hx =
MIN(dx, 3*(hp.
x + dx - np.
x));
1119 for (i = 0; i < cnt; i++) {
1121 dx += stepx, tx += stepx, hx += stepx, dy += sgn*stepy;
1123 points[pointn++] = tp;
1124 points[pointn++] = pointfof(tp.
x - tx / 3, tp.
y + dy);
1125 points[pointn++] = pointfof(np.
x - dx, tp.
y + dy);
1126 points[pointn++] = pointfof(np.
x - dx, (tp.
y+hp.
y)/2);
1127 points[pointn++] = pointfof(np.
x - dx, hp.
y - dy);
1128 points[pointn++] = pointfof(hp.
x - hx / 3, hp.
y - dy);
1130 points[pointn++] = hp;
1143 dx += width - stepx;
1148 if (debugleveln(e,1))
1149 showPoints (points, pointn);
1208 selfRight(edges, ind, cnt, sizex, sizey, sinfo);
1216 selfTop(edges, ind, cnt, sizex, sizey, sinfo);
1219 selfLeft(edges, ind, cnt, sizex, sizey, sinfo);
1225 selfTop(edges, ind, cnt, sizex, sizey, sinfo);
1228 selfBottom(edges, ind, cnt, sizex, sizey, sinfo);
1290 for (i = 0; i < spl->
size; i++) {
1292 for (j = 0, k=3; k < bz.
size; j+=3,k+=3) {
1295 dist +=
DIST(pf, qf);
1299 for (i = 0; i < spl->
size; i++) {
1301 for (j = 0, k=3; k < bz.
size; j+=3,k+=3) {
1308 mf.
x = ((qf.
x*
dist) + (pf.
x*(d-dist)))/d;
1309 mf.
y = ((qf.
y*
dist) + (pf.
y*(d-dist)))/d;
1326 endPoints(
ED_spl(e), &p, &q);
1331 d.
x = (q.
x + p.
x) / 2.;
1332 d.
y = (p.
y + q.
y) / 2.;
1336 spf = polylineMidpoint (
ED_spl(e), &p, &q);
1342 #define LEFTOF(a,b,c) (((a.y - b.y)*(c.x - b.x) - (c.y - b.y)*(a.x - b.x)) > 0)
1343 #define MAXLABELWD (POINTS_PER_INCH/2.0)
1364 double f, ht, wd,
dist2;
1368 endPoints(
ED_spl(e), &p, &q);
1375 d.
x = (q.
x + p.
x) / 2.;
1376 d.
y = (p.
y + q.
y) / 2.;
1380 spf = polylineMidpoint (
ED_spl(e), &p, &q);
1384 dist2 = del.
x*del.
x + del.
y*del.
y;
1385 ht = (
ED_label(e)->dimen.y + 2)/2.0;
1388 leftOf =
LEFTOF(p, q, spf);
1389 if ((leftOf && (del.
y >= 0)) || (!leftOf && (del.
y < 0))) {
1390 if (del.
x*del.
y >= 0)
1395 if (del.
x*del.
y < 0)
1398 f = (del.
y*wd - del.
x*ht)/dist2;
1416 #define AGXGET(o,a) agxget(o,a)
1447 bez = &spl->
list[0];
1453 for (i = 0; i < 4; i++)
1454 c[i] = bez->
list[i];
1464 for (i = 0; i < 4; i++)
1465 c[i] = bez->
list[bez->
size - 4 + i];
1469 angle = atan2(pf.
y - pe.
y, pf.
x - pe.
x) +
1472 l->
pos.
x = pe.
x + dist * cos(angle);
1473 l->
pos.
y = pe.
y + dist * sin(angle);
1486 agerr (
AGERR,
"getsplinepoints: no spline points available for edge (%s,%s)\n",
bezier * new_spline(edge_t *e, int sz)
pointf edgeMidpoint(graph_t *g, edge_t *e)
splines * getsplinepoints(edge_t *e)
#define ALLOC(size, ptr, type)
boolean(* swapEnds)(edge_t *e)
void beginpath(path *, Agedge_t *, int, pathend_t *, boolean)
EXTERN Agsym_t * E_labeldistance
EXTERN Agsym_t * E_labelangle
void endpath(path *, Agedge_t *, int, pathend_t *, boolean)
void clip_and_install(edge_t *fe, node_t *hn, pointf *ps, int pn, splineInfo *info)
#define APPROXEQPT(p, q, tol)
int agerr(agerrlevel_t level, const char *fmt,...)
void arrow_flags(Agedge_t *e, int *sflag, int *eflag)
int arrowEndClip(edge_t *e, pointf *ps, int startp, int endp, bezier *spl, int eflag)
void add_box(path *, boxf)
CGRAPH_API Agraph_t * agraphof(void *obj)
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
void addEdgeLabels(graph_t *g, edge_t *e, pointf rp, pointf rq)
int leftOf(Point a, Point b, Point c)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
int selfRightSpace(edge_t *e)
CGRAPH_API char * agnameof(void *)
void update_bb_bz(boxf *bb, pointf *cp)
void makePortLabels(edge_t *e)
COORD dist2(Ppoint_t, Ppoint_t)
pointf Bezier(pointf *V, int degree, double t, pointf *Left, pointf *Right)
void arrowOrthoClip(edge_t *e, pointf *ps, int startp, int endp, bezier *spl, int sflag, int eflag)
double late_double(void *obj, attrsym_t *attr, double def, double low)
void shape_clip(node_t *n, pointf curve[4])
void makeSelfEdge(path *P, edge_t *edges[], int ind, int cnt, double sizex, double sizey, splineInfo *sinfo)
#define PORT_LABEL_DISTANCE
boolean(* splineMerge)(node_t *n)
void updateBB(graph_t *g, textlabel_t *lp)
EXTERN char ** Show_boxes
port resolvePort(node_t *n, node_t *other, port *oldport)
void(* pf)(char *, void *)
int place_portlabel(edge_t *e, boolean head_p)
double dist(Site *s, Site *t)
pointf dotneato_closest(splines *spl, pointf pt)
void bezier_clip(inside_t *inside_context, boolean(*insidefn)(inside_t *inside_context, pointf p), pointf *sp, boolean left_inside)
int arrowStartClip(edge_t *e, pointf *ps, int startp, int endp, bezier *spl, int sflag)