colinsheppard / insalmo

The Individual-Based Salmon Stream Model
GNU General Public License v2.0
2 stars 0 forks source link

Handle drawing redds and fish on cells with no pixels #88

Closed SFRailsback closed 11 years ago

SFRailsback commented 11 years ago

It's possible for small cells to have zero pixels when raster resolution is large. This caused a seg fault in [redd drawSelfOn] when myRasterX and myRasterY failed to be set in [fishCell addRedd]

My solution was to use this code in [fishCell addRedd]: if(pixelCount > 0) {

[aRedd setRasterX: polyCellPixels[aPixelNum]->pixelX];
[aRedd setRasterY: polyCellPixels[aPixelNum]->pixelY];

}

else { [aRedd setRasterX: -1]; [aRedd setRasterY: -1]; }

And this code in [redd drawSelfOn]: if (myRasterX >= 0) { [aRaster ellipseX0: myRasterX - 3 Y0: myRasterY - 2 X1: myRasterX + 3 Y1: myRasterY + 2 Width: 1 Color: myColor];
}