From: Arjen M. <arj...@us...> - 2005-04-28 08:35:00
|
Update of /cvsroot/plplot/plplot/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1694 Modified Files: plline.c Log Message: Fixed a few bugs regarding pointinpolygon() and added dynamic array management to cater for polygons with many vertices Index: plline.c =================================================================== RCS file: /cvsroot/plplot/plplot/src/plline.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- plline.c 27 Apr 2005 06:44:24 -0000 1.35 +++ plline.c 28 Apr 2005 08:34:51 -0000 1.36 @@ -505,9 +505,19 @@ { PLINT x1, x2, y1, y2; PLINT i, iclp = 0; - short xclp[PL_MAXPOLY], yclp[PL_MAXPOLY]; + + short _xclp[PL_MAXPOLY], _yclp[PL_MAXPOLY]; + short *xclp, *yclp; int drawable; + if ( npts < PL_MAXPOLY ) { + xclp = _xclp; + yclp = _yclp; + } else { + xclp = (short *) malloc( npts*sizeof(short) ) ; + yclp = (short *) malloc( npts*sizeof(short) ) ; + } + for (i = 0; i < npts - 1; i++) { x1 = x[i]; x2 = x[i + 1]; @@ -561,6 +571,11 @@ plsc->currx = x[npts-1]; plsc->curry = y[npts-1]; + + if ( xclp != _xclp ) { + free( xclp ); + free( yclp ); + } } /*----------------------------------------------------------------------*\ @@ -624,7 +639,8 @@ { PLINT i, x1, x2, y1, y2; int iclp = 0, iout = 2; - short xclp[2*PL_MAXPOLY+2], yclp[2*PL_MAXPOLY+2]; + short _xclp[2*PL_MAXPOLY+2], _yclp[2*PL_MAXPOLY+2]; + short *xclp, *yclp; int drawable; int crossed_xmin1 = 0, crossed_xmax1 = 0; int crossed_ymin1 = 0, crossed_ymax1 = 0; @@ -636,6 +652,14 @@ /* Must have at least 3 points and draw() specified */ if (npts < 3 || !draw) return; + if ( npts < PL_MAXPOLY ) { + xclp = _xclp; + yclp = _yclp; + } else { + xclp = (short *) malloc( (2*npts+2)*sizeof(short) ) ; + yclp = (short *) malloc( (2*npts+2)*sizeof(short) ) ; + } + for (i = 0; i < npts - 1; i++) { x1 = x[i]; x2 = x[i+1]; y1 = y[i]; y2 = y[i+1]; @@ -799,6 +823,13 @@ xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; (*draw)(xclp, yclp, iclp); + + if ( xclp != _xclp ) { + free( xclp ); + free( yclp ); + } + + return; } } @@ -1008,6 +1039,11 @@ /* Draw the sucker */ if (iclp >= 3) (*draw)(xclp, yclp, iclp); + + if ( xclp != _xclp ) { + free( xclp ); + free( yclp ); + } } /*----------------------------------------------------------------------*\ @@ -1304,10 +1340,10 @@ xvp = xpp - xout; yvp = ypp - yout; - for ( i = 0; i <= n; i ++ ) { + for ( i = 0; i < n; i ++ ) { x1 = (PLFLT) x[i] ; y1 = (PLFLT) y[i] ; - if ( i < n ) { + if ( i < n-1 ) { x2 = (PLFLT) x[i+1] ; y2 = (PLFLT) y[i+1] ; } else { @@ -1408,10 +1444,10 @@ xvp = xpp - xout; yvp = ypp - yout; - for ( i = 0; i <= n; i ++ ) { + for ( i = 0; i < n; i ++ ) { x1 = (PLFLT) x[i] ; y1 = (PLFLT) y[i] ; - if ( i < n ) { + if ( i < n-1 ) { x2 = (PLFLT) x[i+1] ; y2 = (PLFLT) y[i+1] ; } else { |