From eb95edd858b58465ae5bc718a26f58b702206c61 Mon Sep 17 00:00:00 2001 From: ellson Date: Thu, 16 Mar 2006 16:52:38 +0000 Subject: [PATCH] improved egg and distorted ellipse shapes by passing FP to renderers --- lib/common/shapes.c | 15 +++++++++-- lib/gvc/gvcproc.h | 8 +++--- lib/gvc/gvrender.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 4224bf6cc..a510ce467 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -1197,6 +1197,7 @@ static void poly_gencode(GVJ_t * job, node_t * n) int i, j, peripheries, sides, style; pointf P, *vertices; static point *A; + static pointf *AF; static int A_size; bool filled; char *color; @@ -1208,6 +1209,7 @@ static void poly_gencode(GVJ_t * job, node_t * n) if (A_size < sides) { A_size = sides + 5; A = ALLOC(A_size, A, point); + AF = ALLOC(A_size, AF, pointf); } ND_label(n)->p = ND_coord_i(n); @@ -1297,6 +1299,12 @@ static void poly_gencode(GVJ_t * job, node_t * n) for (j = 0; j < peripheries; j++) { for (i = 0; i < sides; i++) { P = vertices[i + j * sides]; + AF[i].x = P.x * xsize / 16.; + AF[i].y = P.y * ysize / 16.; + if (sides > 2) { + AF[i].x += ND_coord_i(n).x; + AF[i].y += ND_coord_i(n).y; + } /* simple rounding produces random results around .5 * this trick should clip off the random part. * (note xsize/ysize prescaled by 16.0 above) */ @@ -1308,14 +1316,17 @@ static void poly_gencode(GVJ_t * job, node_t * n) } } if (sides <= 2) { - gvrender_ellipse(job, ND_coord_i(n), A[0].x, A[0].y, filled); + pointf PF; + + P2PF(ND_coord_i(n), PF); + gvrender_ellipsef(job, PF, AF[0].x, AF[0].y, filled); if (style & DIAGONALS) { Mcircle_hack(job, n); } } else if (style & (ROUNDED | DIAGONALS)) { node_round_corners(job, n, A, sides, style); } else { - gvrender_polygon(job, A, sides, filled); + gvrender_polygonf(job, AF, sides, filled); } /* fill innermost periphery only */ filled = FALSE; diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index 8f44bbd49..2c07f2c92 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -107,10 +107,10 @@ extern "C" { extern void gvrender_set_pencolor(GVJ_t * job, char *name); 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, point p, int rx, int ry, - int filled); - extern void gvrender_polygon(GVJ_t * job, point * A, int n, - int filled); + extern void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled); + extern void gvrender_ellipsef(GVJ_t * job, pointf p, double rx, double ry, int filled); + extern void gvrender_polygon(GVJ_t * job, point * A, int n, int filled); + extern void gvrender_polygonf(GVJ_t * job, pointf * AF, int n, int filled); extern void gvrender_beziercurve(GVJ_t * job, pointf * AF, int n, int arrow_at_start, int arrow_at_end, int); extern void gvrender_polyline(GVJ_t * job, point * A, int n); diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 4bf7a7155..91daac29b 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -778,6 +778,39 @@ void gvrender_set_style(GVJ_t * job, char **s) #endif } +void gvrender_ellipsef(GVJ_t * job, pointf pf, double rx, double ry, int filled) +{ + gvrender_engine_t *gvre = job->render.engine; + + if (gvre && gvre->ellipse) { + if (job->style->pen != PEN_NONE) { + pointf af[2]; + + /* center */ + af[0] = pf; + /* corner */ + af[1].x = pf.x + rx; + af[1].y = pf.y + ry; + /* scale */ + af[0] = gvrender_ptf(job, af[0]); + af[1] = gvrender_ptf(job, af[1]); + gvre->ellipse(job, af, filled); + } + } +#ifndef DISABLE_CODEGENS + else { + codegen_t *cg = job->codegen; + + if (cg && cg->ellipse) { + point p; + + PF2P(pf, p); + cg->ellipse(p, ROUND(rx), ROUND(ry), filled); + } + } +#endif +} + void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled) { gvrender_engine_t *gvre = job->render.engine; @@ -810,6 +843,38 @@ void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled) #endif } +void gvrender_polygonf(GVJ_t * job, pointf * af, int n, int filled) +{ + int i; + gvrender_engine_t *gvre = job->render.engine; + + if (gvre && gvre->polygon) { + if (job->style->pen != PEN_NONE) { + if (sizeAF < n) { + sizeAF = n+10; + AF = grealloc(AF, sizeAF * sizeof(pointf)); + } + for (i = 0; i < n; i++) + AF[i] = gvrender_ptf(job, af[i]); + gvre->polygon(job, AF, n, filled); + } + } +#ifndef DISABLE_CODEGENS + else { + codegen_t *cg = job->codegen; + + if (sizeA < n) { + sizeA = n+10; + A = grealloc(A, sizeA * sizeof(point)); + } + for (i = 0; i < n; i++) + PF2P(af[i], A[i]); + if (cg && cg->polygon) + cg->polygon(A, n, filled); + } +#endif +} + void gvrender_polygon(GVJ_t * job, point * A, int n, int filled) { gvrender_engine_t *gvre = job->render.engine; -- 2.40.0