void c_plfill(PLINT n, PLFLT *x, PLFLT *y) { PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; PLINT i; if (plsc->level < 3) { plabort("plfill: Please set up window first"); return; } if (n < 3) { plabort("plfill: Not enough points in object"); return; } if (n > PL_MAXPOLY-1) { plwarn("plfill: too many points in polygon"); n = PL_MAXPOLY; } for (i = 0; i < n; i++) { xpoly[i] = plP_wcpcx(x[i]); ypoly[i] = plP_wcpcy(y[i]); } if (x[0] != x[n-1] || y[0] != y[n-1]) { n++; xpoly[n-1] = plP_wcpcx(x[0]); ypoly[n-1] = plP_wcpcy(y[0]); } plP_plfclp(xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, plsc->clpymi, plsc->clpyma, plP_fill); }
void c_plfill3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z) { PLFLT tx[PL_MAXPOLY], ty[PL_MAXPOLY], tz[PL_MAXPOLY]; PLFLT *V[3]; PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; PLINT i; PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale; if (plsc->level < 3) { plabort("plfill3: Please set up window first"); return; } if (n < 3) { plabort("plfill3: Not enough points in object"); return; } if (n > PL_MAXPOLY-1) { plwarn("plfill3: too many points in polygon"); n = PL_MAXPOLY; } plP_gdom(&xmin, &xmax, &ymin, &ymax); plP_grange(&zscale, &zmin, &zmax); /* copy the vertices so we can clip without corrupting the input */ for( i=0; i < n; i++ ) { tx[i] = x[i]; ty[i] = y[i]; tz[i] = z[i]; } if (tx[0] != tx[n-1] || ty[0] != ty[n-1] || tz[0] != tz[n-1]) { tx[n] = tx[0]; ty[n] = ty[0]; tz[n] = tz[0]; n++; } V[0] = tx; V[1] = ty; V[2] = tz; n = plP_clip_poly(n, V, 0, 1, -xmin); n = plP_clip_poly(n, V, 0, -1, xmax); n = plP_clip_poly(n, V, 1, 1, -ymin); n = plP_clip_poly(n, V, 1, -1, ymax); n = plP_clip_poly(n, V, 2, 1, -zmin); n = plP_clip_poly(n, V, 2, -1, zmax); for( i=0; i < n; i++ ) { xpoly[i] = plP_wcpcx(plP_w3wcx( tx[i], ty[i], tz[i] )); ypoly[i] = plP_wcpcy(plP_w3wcy( tx[i], ty[i], tz[i] )); } /* AWI: in the past we have used * plP_fill(xpoly, ypoly, n); * here, but our educated guess is this fill should be done via the clipping * interface instead as below. * No example tests this code so one of our users will end up inadvertently * testing this for us. * * jc: I have checked, and both versions does give the same result, i.e., clipping * to the window boundaries. The reason is that the above plP_clip_poly() does * the clipping. To check this, is enough to diminish the x/y/z min/max arguments in * plw3d() in x08c. But let's keep it, although 10% slower... */ plP_plfclp(xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, plsc->clpymi, plsc->clpyma, plP_fill); }
/* * Plot an individual vector */ static void plP_plotvect(PLFLT x, PLFLT y, PLFLT u, PLFLT v, PLFLT scale) { PLFLT uu, vv, px0, py0, dpx, dpy; PLINT *a_x, *a_y; int j; uu = scale*u; vv = scale*v; if(uu == 0.0 && vv == 0.0) return; if (((a_x = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL)|| ((a_y = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL)) { plexit("plP_plotvect: Insufficient memory"); } px0 = plP_wcpcx(x); py0 = plP_wcpcy(y); pldebug("plP_plotvect", "%f %f %d %d\n",x,y,px0,py0); dpx = plP_wcpcx(x + 0.5*uu) - px0; dpy = plP_wcpcy(y + 0.5*vv) - py0; /* transform arrow -> a */ for (j = 0; j < plsc->arrow_npts; j++) { a_x[j] = (PLINT)(plsc->arrow_x[j] * dpx - plsc->arrow_y[j] * dpy + px0); a_y[j] = (PLINT)(plsc->arrow_x[j] * dpy + plsc->arrow_y[j] * dpx + py0); } /* draw the arrow */ plP_draphy_poly(a_x,a_y,plsc->arrow_npts); if (plsc->arrow_fill) { plP_plfclp(a_x, a_y, plsc->arrow_npts, plsc->clpxmi, plsc->clpxma, plsc->clpymi, plsc->clpyma, plP_fill); } free((void *)a_x); free((void *)a_y); }