Program: 140984
Project: 140984
Buggy source:
/** 
 * Compute the gray value for the illuminated contour line image
 * @param elevation Elevation of the point.
 * @param aspect Aspect of the point
 * @param slope Slope of the point.
 * @param cellSize
 * @return Gray value between 0 and 255.
 */
public int computeGray(double elevation,double aspect,double slope,double cellSize){
  double illumination=90 - azimuth;
  double angleDiff=smallestAngleDiff(illumination,aspect);
  double w=(gridMax - elevation) / (gridMax - gridMin);
  double shadowWidth=shadowWidthLow * w + shadowWidthHigh * (1d - w);
  double illiminatedWidth=illuminatedWidthLow * w + illuminatedWidthHigh * (1d - w);
  double a;
  if (illuminated) {
    double trad=transitionAngle / 180. * Math.PI;
    double arad=angleDiff / 180. * Math.PI;
    if (angleDiff > transitionAngle) {
      a=shadowWidth * slope * cellSize;
      double m=(Math.PI / 2) / (Math.PI - trad);
      double c=(Math.PI / 2) - m * trad;
      arad=arad * m + c;
      a*=Math.abs(Math.cos(arad));
    }
 else {
      a=illiminatedWidth * slope * cellSize;
      arad=arad / trad * (Math.PI / 2);
      a*=Math.abs(Math.cos(arad));
    }
  }
 else {
    a=shadowWidth * slope * cellSize;
    a*=Math.abs(Math.sin(angleDiff / 180 * Math.PI / 2));
  }
  a=Math.max(minWidth * slope * cellSize,a);
  double dist=Math.abs(elevation) % interval;
  if (dist > a) {
    dist=interval - dist;
  }
  if (a > dist) {
    if (!illuminated || angleDiff >= (transitionAngle + gradientAngle)) {
      return 0;
    }
 else     if (angleDiff <= (transitionAngle - gradientAngle)) {
      return illuminated ? illluminatedGray : 0;
    }
 else {
      double d=transitionAngle + gradientAngle - angleDiff;
      return (int)(d / (2. * gradientAngle) * 255.);
    }
  }
  return CONTOURS_TRANSPARENT;
}

Fixed version (ground truth):
/** 
 * Compute the gray value for the illuminated contour line image
 * @param elevation Elevation of the point.
 * @param aspect Aspect of the point
 * @param slope Slope of the point.
 * @param cellSize
 * @return Gray value between 0 and 255.
 */
public int computeGray(double elevation,double aspect,double slope,double cellSize){
  double illumination=90 - azimuth;
  double angleDiff=smallestAngleDiff(illumination,aspect);
  double w=(gridMax - elevation) / (gridMax - gridMin);
  double shadowWidth=shadowWidthLow * w + shadowWidthHigh * (1d - w);
  double illiminatedWidth=illuminatedWidthLow * w + illuminatedWidthHigh * (1d - w);
  double a;
  if (illuminated) {
    double trad=transitionAngle / 180. * Math.PI;
    double arad=angleDiff / 180. * Math.PI;
    if (angleDiff > transitionAngle) {
      a=shadowWidth * slope * cellSize;
      double m=(Math.PI / 2) / (Math.PI - trad);
      double c=(Math.PI / 2) - m * trad;
      arad=arad * m + c;
      a*=Math.abs(Math.cos(arad));
    }
 else {
      a=illiminatedWidth * slope * cellSize;
      arad=arad / trad * (Math.PI / 2);
      a*=Math.abs(Math.cos(arad));
    }
  }
 else {
    a=shadowWidth * slope * cellSize;
    a*=Math.abs(Math.sin(angleDiff / 180 * Math.PI / 2));
  }
  a=Math.max(minWidth * slope * cellSize,a);
  double zDist=Math.abs(elevation) % interval;
  if (zDist > interval / 2) {
    zDist=interval - zDist;
  }
  if (a > zDist) {
    if (!illuminated || angleDiff >= (transitionAngle + gradientAngle)) {
      return 0;
    }
 else     if (angleDiff <= (transitionAngle - gradientAngle)) {
      return illuminated ? illluminatedGray : 0;
    }
 else {
      double d=transitionAngle + gradientAngle - angleDiff;
      return (int)(d / (2. * gradientAngle) * 255.);
    }
  }
  return CONTOURS_TRANSPARENT;
}