"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "region.c" between
cfitsio-3.49.tar.gz and cfitsio-4.0.0.tar.gz

About: CFITSIO is a library of C and Fortran subroutines for reading and writing data files in the FITS (Flexible Image Transport System) data format.

region.c  (cfitsio-3.49):region.c  (cfitsio-4.0.0)
skipping to change at line 982 skipping to change at line 982
} }
result = result || comp_result; result = result || comp_result;
return( result ); return( result );
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void fits_free_region( SAORegion *Rgn ) void fits_free_region( SAORegion *Rgn )
/* Free up memory allocated to hold the region data. */ /* Free up memory allocated to hold the region data.
This is more complicated for the case of polygons, which may be sharing
points arrays due to shallow copying (in fits_set_region_components) of
'exluded' regions. We must ensure that these arrays are only freed once.
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
{ {
int i; int i,j;
int nFreedPoly=0;
int nPolyArraySize=10;
double **freedPolyPtrs=0;
double *ptsToFree=0;
int isAlreadyFreed=0;
freedPolyPtrs = (double**)malloc(nPolyArraySize*sizeof(double*));
for( i=0; i<Rgn->nShapes; i++ ) for( i=0; i<Rgn->nShapes; i++ )
if( Rgn->Shapes[i].shape == poly_rgn ) if( Rgn->Shapes[i].shape == poly_rgn )
free( Rgn->Shapes[i].param.poly.Pts ); {
/* No shared arrays for 'include' polygons */
if (Rgn->Shapes[i].sign)
free(Rgn->Shapes[i].param.poly.Pts);
else
{
ptsToFree = Rgn->Shapes[i].param.poly.Pts;
isAlreadyFreed = 0;
for (j=0; j<nFreedPoly && !isAlreadyFreed; j++)
{
if (freedPolyPtrs[j] == ptsToFree)
isAlreadyFreed = 1;
}
if (!isAlreadyFreed)
{
free(ptsToFree);
/* Now add pointer to array of freed points */
if (nFreedPoly == nPolyArraySize)
{
nPolyArraySize *= 2;
freedPolyPtrs = (double **)realloc(freedPolyPtrs,
nPolyArraySize*sizeof(double*));
}
freedPolyPtrs[nFreedPoly] = ptsToFree;
++nFreedPoly;
}
}
}
if( Rgn->Shapes ) if( Rgn->Shapes )
free( Rgn->Shapes ); free( Rgn->Shapes );
free( Rgn ); free( Rgn );
free(freedPolyPtrs);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int Pt_in_Poly( double x, static int Pt_in_Poly( double x,
double y, double y,
int nPts, int nPts,
double *Pts ) double *Pts )
/* Internal routine for testing whether the coordinate x,y is within the */ /* Internal routine for testing whether the coordinate x,y is within the */
/* polygon region traced out by the array Pts. */ /* polygon region traced out by the array Pts. */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
skipping to change at line 1108 skipping to change at line 1149
j--; j--;
/* and loop back through the regions */ /* and loop back through the regions */
while ( j >= 0 ) { while ( j >= 0 ) {
/* if this is an include region then insert a copy of the exclude /* if this is an include region then insert a copy of the exclude
region immediately after it */ region immediately after it */
/* Note that this makes shallow copies of a polygon's dynamically
allocated Pts array -- the memory is shared. This must be checked
when freeing in fits_free_region. */
if ( aRgn->Shapes[j].sign ) { if ( aRgn->Shapes[j].sign ) {
aRgn->Shapes = (RgnShape *) realloc (aRgn->Shapes,(1+aRgn->nShapes)*siz eof(RgnShape)); aRgn->Shapes = (RgnShape *) realloc (aRgn->Shapes,(1+aRgn->nShapes)*siz eof(RgnShape));
aRgn->nShapes++; aRgn->nShapes++;
for (k=aRgn->nShapes-1; k>j+1; k--) aRgn->Shapes[k] = aRgn->Shapes[k-1] ; for (k=aRgn->nShapes-1; k>j+1; k--) aRgn->Shapes[k] = aRgn->Shapes[k-1] ;
i++; i++;
aRgn->Shapes[j+1] = aRgn->Shapes[i]; aRgn->Shapes[j+1] = aRgn->Shapes[i];
} }
 End of changes. 5 change blocks. 
3 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)