54 if ( plsc->level < 3 )
56 plabort(
"plgradient: Please set up window first" );
61 plabort(
"plgradient: Not enough vertices in polygon" );
65 if ( !plsc->dev_gradient )
69 plwarn(
"Driver does not support native gradients, switching to software fallback gradient.\n" );
87 double cosangle = cos(
PI * angle / 180. );
88 double sinangle = sin(
PI * angle / 180. );
89 xrot = x[0] * cosangle + y[0] * sinangle;
93 for ( i = 1; i < n; i++ )
95 xrot = x[i] * cosangle + y[i] * sinangle;
96 if ( xrot < xrot_min )
101 else if ( xrot > xrot_max )
112 dxgrad[0] = x[irot_min];
113 dxgrad[1] = dxgrad[0] + ( xrot_max - xrot_min ) * cosangle;
114 dygrad[0] = y[irot_min];
115 dygrad[1] = dygrad[0] + ( xrot_max - xrot_min ) * sinangle;
116 for ( i = 0; i <
NGRAD; i++ )
122 difilt( xgrad, ygrad, NGRAD, &clpxmi, &clpxma, &clpymi, &clpyma );
123 plsc->xgradient = xgrad;
124 plsc->ygradient = ygrad;
125 plsc->ngradient =
NGRAD;
130 xpoly = (
PLINT *) malloc( (
size_t) ( n + 1 ) *
sizeof (
PLINT ) );
131 ypoly = (
PLINT *) malloc( (
size_t) ( n + 1 ) *
sizeof (
PLINT ) );
133 if ( ( xpoly == NULL ) || ( ypoly == NULL ) )
135 plexit(
"plgradient: Insufficient memory for large polygon" );
144 for ( i = 0; i < n; i++ )
149 if ( x[0] != x[n - 1] || y[0] != y[n - 1] )
155 plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
180 PLFLT xrot, xrot_min, xrot_max, cosangle, sinangle;
181 PLFLT xmin, xmax, ymin, ymax;
182 PLFLT **z, *edge, xcoord, ycoord;
187 plabort(
"plgradient_soft: Not enough vertices in polygon" );
204 cosangle = cos(
PI / 180. * angle );
205 sinangle = sin(
PI / 180. * angle );
206 xrot = x[0] * cosangle + y[0] * sinangle;
209 for ( i = 1; i < n; i++ )
213 else if ( x[i] > xmax )
218 else if ( y[i] > ymax )
221 xrot = x[i] * cosangle + y[i] * sinangle;
222 if ( xrot < xrot_min )
224 else if ( xrot > xrot_max )
234 for ( i = 0; i <
NX; i++ )
236 xcoord = xmin + ( (
PLFLT) i ) * ( xmax - xmin ) / (
PLFLT) ( NX - 1 );
237 for ( j = 0; j <
NY; j++ )
239 ycoord = ymin + ( (
PLFLT) j ) * ( ymax - ymin ) / (
PLFLT) ( NY - 1 );
240 xrot = xcoord * cosangle + ycoord * sinangle;
241 z[i][j] = ( xrot - xrot_min ) / ( xrot_max - xrot_min );
249 plexit(
"plgradient_soft: Insufficient memory for large polygon"
251 for ( i = 0; i <
NEDGE; i++ )
255 edge, NEDGE, 0, 0, 0,
plfill, 1, NULL, NULL );
256 free( (
void *) edge );
void plexit(PLCHAR_VECTOR errormsg)
static PLINT gradient_defined(PLFLT x, PLFLT y)
const PLFLT *const * PLFLT_MATRIX
void plabort(PLCHAR_VECTOR errormsg)
void plFree2dGrid(PLFLT **f, PLINT nx, PLINT PL_UNUSED(ny))
void difilt(PLINT *xsc, PLINT *ysc, PLINT npts, PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
void c_plgradient(PLINT n, PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT angle)
void plP_gradient(short *x, short *y, PLINT npts)
void plAlloc2dGrid(PLFLT ***f, PLINT nx, PLINT ny)
void plP_plfclp(PLINT *x, PLINT *y, PLINT npts, PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax, void(*draw)(short *, short *, PLINT))
int plP_pointinpolygon(PLINT n, PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT xp, PLFLT yp)
void plwarn(PLCHAR_VECTOR errormsg)
static void plgradient_soft(PLINT n, PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT angle)
const PLFLT * PLFLT_VECTOR