]> granicus.if.org Git - graphviz/commitdiff
simplify generation of ellipses a little
authorellson <devnull@localhost>
Tue, 2 Oct 2007 18:40:04 +0000 (18:40 +0000)
committerellson <devnull@localhost>
Tue, 2 Oct 2007 18:40:04 +0000 (18:40 +0000)
lib/common/arrows.c
lib/common/shapes.c
lib/gvc/gvcproc.h
lib/gvc/gvrender.c

index 6bb35d99a1a0931297975c1f82a782b99ea759ff..40751a6cd8be59f58f10d91bc1c79dfa3ee646e5 100644 (file)
@@ -448,11 +448,14 @@ static void arrow_type_diamond(GVJ_t * job, pointf p, pointf u, int flag)
 static void arrow_type_dot(GVJ_t * job, pointf p, pointf u, int flag)
 {
     double r;
+    pointf AF[2];
 
     r = sqrt(u.x * u.x + u.y * u.y) / 2.;
-    p.x += u.x / 2.;
-    p.y += u.y / 2.;
-    gvrender_ellipse(job, p, r, r, !(flag & ARR_MOD_OPEN));
+    AF[0].x = p.x + u.x / 2. - r;
+    AF[0].y = p.y + u.y / 2. - r;
+    AF[1].x = p.x + u.x / 2. + r;
+    AF[1].y = p.y + u.y / 2. + r;
+    gvrender_ellipse(job, AF, 2, !(flag & ARR_MOD_OPEN));
 }
 
 static pointf arrow_gen_type(GVJ_t * job, pointf p, pointf u, int flag)
index 50094d3de310331126274e2af01ec3311b1ba028..7da2dbc04212c23ed239051972cdcfff4f6a5c94 100644 (file)
@@ -630,7 +630,7 @@ static void poly_init(node_t * n)
     point imagesize;
     pointf P, Q, R;
     pointf *vertices;
-    char *p;
+    char *p, *sfile;
     double temp, alpha, beta, gamma, delta;
     double orientation, distortion, skew;
     double sectorangle, sidelength, skewdist, gdistortion, gskew;
@@ -706,7 +706,7 @@ static void poly_init(node_t * n)
              * function.
              */
        if (streq(ND_shape(n)->name, "custom")) {
-           char *sfile = agget(n, "shapefile");
+           sfile = agget(n, "shapefile");
            imagesize = gvusershape_size(n->graph, sfile);
            if ((imagesize.x == -1) && (imagesize.y == -1)) {
                agerr(AGWARN,
@@ -719,8 +719,7 @@ static void poly_init(node_t * n)
            }
        }
     }
-    else {
-       char *sfile = agget(n, "image");
+    else  if ((sfile = agget(n, "image"))) {
        imagesize = gvusershape_size(n->graph, sfile);
        if ((imagesize.x == -1) && (imagesize.y == -1)) {
             agerr(AGWARN,
@@ -805,11 +804,13 @@ static void poly_init(node_t * n)
     if (peripheries < 1)
        outp = 1;
     if (sides < 3) {           /* ellipses */
-       sides = 1;
-       vertices = N_NEW(outp, pointf);
+       sides = 2;
+       vertices = N_NEW(outp * sides, pointf);
        P.x = bb.x / 2.;
        P.y = bb.y / 2.;
-       vertices[0] = P;
+       vertices[1] = P;
+       vertices[0].x = -P.x;
+       vertices[0].y = -P.y;
        if (peripheries > 1) {
            for (j = 1; j < peripheries; j++) {
                P.x += GAP;
@@ -1459,20 +1460,13 @@ static void poly_gencode(GVJ_t * job, node_t * n)
        /* get coords of innermost periphery */
        for (i = 0; i < sides; i++) {
            P = vertices[i];
-           AF[i].x = P.x * xsize;
-           AF[i].y = P.y * ysize;
-           if (sides > 2) {
-               AF[i].x += (double)ND_coord_i(n).x;
-               AF[i].y += (double)ND_coord_i(n).y;
-           }
+           AF[i].x = P.x * xsize + (double)ND_coord_i(n).x;
+           AF[i].y = P.y * ysize + (double)ND_coord_i(n).y;
        }
        /* lay down fill first */
        if (filled && pfilled) {
            if (sides <= 2) {
-               pointf PF;
-
-               P2PF(ND_coord_i(n), PF);
-               gvrender_ellipse(job, PF, AF[0].x, AF[0].y, filled);
+               gvrender_ellipse(job, AF, sides, filled);
                if (style & DIAGONALS) {
                    Mcircle_hack(job, n);
                }
@@ -1482,34 +1476,18 @@ static void poly_gencode(GVJ_t * job, node_t * n)
                gvrender_polygon(job, AF, sides, filled);
            }
        }
-       if (sides <=2) {
-           pointf PF;
-
-           P2PF(ND_coord_i(n), PF);
-           AF[1].x = PF.x - AF[0].x;
-           AF[1].y = PF.y - AF[0].y;
-           AF[0].x += PF.x;
-           AF[0].y += PF.y;
-       }
-       gvrender_usershape(job, name, AF, 2, filled, FALSE);
+       gvrender_usershape(job, name, AF, sides, filled, FALSE);
        filled = FALSE;  /* with user shapes, we have done the fill if needed */
     }
 
     for (j = 0; j < peripheries; j++) {
        for (i = 0; i < sides; i++) {
            P = vertices[i + j * sides];
-           AF[i].x = P.x * xsize;
-           AF[i].y = P.y * ysize;
-           if (sides > 2) {
-               AF[i].x += (double)ND_coord_i(n).x;
-               AF[i].y += (double)ND_coord_i(n).y;
-           }
+           AF[i].x = P.x * xsize + (double)ND_coord_i(n).x;
+           AF[i].y = P.y * ysize + (double)ND_coord_i(n).y;
        }
        if (sides <= 2) {
-           pointf PF;
-
-           P2PF(ND_coord_i(n), PF);
-           gvrender_ellipse(job, PF, AF[0].x, AF[0].y, filled);
+           gvrender_ellipse(job, AF, sides, filled);
            if (style & DIAGONALS) {
                Mcircle_hack(job, n);
            }
index e8fbf69105053ff40a3bf3df5fc5c7f83b6a4326..30dcb4bce93f8ca122893357e40a63e5d2e17b4b 100644 (file)
@@ -111,8 +111,7 @@ extern "C" {
     extern void gvrender_set_penwidth(GVJ_t * job, double penwidth);
     extern void gvrender_set_fillcolor(GVJ_t * job, char *name);
     extern void gvrender_set_style(GVJ_t * job, char **s);
-    extern void gvrender_ellipse(GVJ_t * job, pointf p,
-                       double rx, double ry, boolean filled);
+    extern void gvrender_ellipse(GVJ_t * job, pointf * AF, int n, boolean filled);
     extern void gvrender_polygon(GVJ_t * job, pointf * AF, int n, boolean filled);
     extern void gvrender_box(GVJ_t * job, boxf BF, boolean filled);
     extern void gvrender_beziercurve(GVJ_t * job, pointf * AF, int n,
index 23400769f199508e00ca5bd01c3bc94b50bb34f9..d7aa0f454909369e40a052112dec7691febda6b9 100644 (file)
@@ -741,7 +741,7 @@ void gvrender_set_style(GVJ_t * job, char **s)
 #endif
 }
 
-void gvrender_ellipse(GVJ_t * job, pointf pf, double rx, double ry, boolean filled)
+void gvrender_ellipse(GVJ_t * job, pointf * pf, int n, boolean filled)
 {
     gvrender_engine_t *gvre = job->render.engine;
 
@@ -750,10 +750,10 @@ void gvrender_ellipse(GVJ_t * job, pointf pf, double rx, double ry, boolean fill
            pointf af[2];
 
            /* center */
-           af[0] = pf;
+           af[0].x = (pf[0].x + pf[1].x)/2.;
+           af[0].y = (pf[0].y + pf[1].y)/2.;
            /* corner */
-           af[1].x = pf.x + rx;
-           af[1].y = pf.y + ry;
+           af[1] = pf[1];
 
            if (! (job->flags & GVRENDER_DOES_TRANSFORM))
                gvrender_ptf_A(job, af, af, 2);
@@ -765,10 +765,19 @@ void gvrender_ellipse(GVJ_t * job, pointf pf, double rx, double ry, boolean fill
        codegen_t *cg = job->codegen;
 
        if (cg && cg->ellipse) {
-           point p;
+           pointf af[2];
+           point p, r;
 
-           PF2P(pf, p);
-           cg->ellipse(p, ROUND(rx), ROUND(ry), filled);
+           /* center */
+           af[0].x = (pf[0].x + pf[1].x)/2.;
+           af[0].y = (pf[0].y + pf[1].y)/2.;
+           /* radius */
+           af[1].x = pf[1].x - af[0].x;
+           af[1].y = pf[1].y - af[0].y;
+
+           PF2P(af[0], p);
+           PF2P(af[1], r);
+           cg->ellipse(p, r.x, r.y, filled);
        }
     }
 #endif