Program: 69329
Project: 69329
Buggy source:
/** 
 * @param dBlockX
 * @param dBlockWidth
 * @param aax
 * @param axPV
 * @param scX
 * @param iXLabelLocation
 * @param iYLabelLocation
 * @param iYTitleLocation
 * @param laXAxisLabels
 * @param iv
 * @param bTicksLeft
 * @param bTicksRight
 * @param dYAxisLabelsThickness
 * @param dDecorationThickness
 * @param dYAxisTitleThickness
 * @param dX
 * @param dX1
 * @param dX2
 * @param dWTotal
 * @return
 * @throws ChartException
 */
private double adjustHorizontalWithValueOrigin(double dBlockX,double dBlockWidth,AllAxes aax,final OneAxis axPV,final AutoScale scX,final int iXLabelLocation,final int iYLabelLocation,final int iYTitleLocation,final Label laXAxisLabels,final IntersectionValue iv,final boolean bTicksLeft,final boolean bTicksRight,double dYAxisLabelsThickness,double[] dDecorationThickness,double dYAxisTitleThickness,double dX,double dX1,double dX2,double dWTotal) throws ChartException {
  double dStart;
  double dEnd;
  double dDeltaX1=0, dDeltaX2=0;
  if (iYTitleLocation == RIGHT) {
    dX2+=dYAxisTitleThickness;
  }
 else   if (iYTitleLocation == LEFT) {
    dX1-=dYAxisTitleThickness;
  }
  double dW1=0, dW2=0;
  if (iYLabelLocation == LEFT) {
    dW1=(bTicksLeft ? getTickSize() : 0) + Math.max(dYAxisLabelsThickness,dDecorationThickness[0]);
    dW2=(bTicksRight ? getTickSize() : 0);
    if (dW1 + dW2 <= dWTotal) {
      dX1-=dW1;
      dX2+=dW2;
      dWTotal-=(dW1 + dW2);
    }
 else {
      axPV.setShowLabels(false);
    }
    dDeltaX1=dX - dX1;
    dDeltaX2=dX2 - dX;
    if (dX1 < dBlockX) {
      final Object[] oaMinMax=scX.getMinMax();
      boolean bForceBreak=false;
      do {
        scX.setEndPoints(scX.getStart() - scX.getStartShift(),scX.getEnd() + scX.getEndShift());
        scX.resetShifts();
        double[] da=scX.getEndPoints();
        double dT_RI=dBlockX - dX1;
        if (scX.getDirection() == BACKWARD) {
          double dAMin_AMax=da[0] - da[1];
          double dAMax_RI=Math.abs(da[0] - dX);
          double dDelta=(dT_RI / dAMax_RI) * dAMin_AMax;
          dEnd=da[1] + dDelta;
          dStart=da[0];
          if (dEnd < dBlockX) {
            dEnd=dBlockX;
            bForceBreak=true;
          }
        }
 else {
          double dAMin_AMax=da[1] - da[0];
          double dAMax_RI=Math.abs(da[1] - dX);
          double dDelta=(dT_RI / dAMax_RI) * dAMin_AMax;
          dStart=da[0] + dDelta;
          dEnd=da[1];
          if (dStart < dBlockX) {
            dStart=dBlockX;
            bForceBreak=true;
          }
        }
        scX.setEndPoints(dStart,dEnd);
        scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            bForceBreak=true;
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            bForceBreak=true;
            break;
          }
        }
        dX=getLocation(scX,iv);
        dX1=dX - dDeltaX1;
      }
 while (Math.abs(dX1 - dBlockX) > 1 && !bForceBreak);
    }
 else {
      dStart=scX.getStart();
      dEnd=scX.getEnd();
      scX.setEndPoints(dStart,dEnd);
      scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
      if (!scX.isStepFixed()) {
        final Object[] oaMinMax=scX.getMinMax();
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            break;
          }
        }
      }
      dX=getLocation(scX,iv);
    }
    dX1=dX - dDeltaX1;
    dX2=dX + dDeltaX2;
  }
 else   if (iYLabelLocation == RIGHT) {
    dW1=(bTicksLeft ? getTickSize() : 0);
    dW2=(bTicksRight ? getTickSize() : 0) + Math.max(dYAxisLabelsThickness,dDecorationThickness[1]);
    if (dW1 + dW2 <= dWTotal) {
      dX1-=dW1;
      dX2+=dW2;
      dWTotal-=(dW1 + dW2);
    }
    dDeltaX1=dX - dX1;
    dDeltaX2=dX2 - dX;
    if (dX2 > dBlockX + dBlockWidth) {
      final Object[] oaMinMax=scX.getMinMax();
      boolean bForceBreak=false;
      do {
        scX.setEndPoints(scX.getStart() - scX.getStartShift(),scX.getEnd() + scX.getEndShift());
        scX.resetShifts();
        double[] da=scX.getEndPoints();
        double dT_RI=dX2 - (dBlockX + dBlockWidth);
        if (scX.getDirection() == BACKWARD) {
          double dAMin_AMax=da[0] - da[1];
          double dAMin_RI=Math.abs(dX - da[1]);
          double dDelta=Math.abs(dT_RI / dAMin_RI) * dAMin_AMax;
          dStart=da[0] - dDelta;
          dEnd=da[1];
          if (dStart > dBlockX + dBlockWidth) {
            dStart=dBlockX + dBlockWidth;
            bForceBreak=true;
          }
        }
 else {
          double dAMin_AMax=da[1] - da[0];
          double dAMin_RI=Math.abs(dX - da[0]);
          double dDelta=(dT_RI / dAMin_RI) * dAMin_AMax;
          dEnd=da[1] - dDelta;
          dStart=da[0];
          if (dEnd > dBlockX + dBlockWidth) {
            dEnd=dBlockX + dBlockWidth;
            bForceBreak=true;
          }
        }
        scX.setEndPoints(dStart,dEnd);
        scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
        if (!scX.isStepFixed()) {
          while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
            if (!scX.zoomOut()) {
              bForceBreak=true;
              break;
            }
            scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
            int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
            if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
              bForceBreak=true;
              break;
            }
          }
        }
        dX=getLocation(scX,iv);
        dX2=dX + dDeltaX2;
      }
 while (Math.abs(dX2 - (dBlockX + dBlockWidth)) > 1 && !bForceBreak);
    }
 else {
      dStart=scX.getStart();
      dEnd=scX.getEnd();
      scX.setEndPoints(dStart,dEnd);
      scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
      if (!scX.isStepFixed()) {
        final Object[] oaMinMax=scX.getMinMax();
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            break;
          }
        }
      }
      dX=getLocation(scX,iv);
    }
    dX2=dX + dDeltaX2;
    dX1=dX - dDeltaX1;
  }
  axPV.setTitleCoordinate((iYTitleLocation == LEFT) ? dX1 - 1 : dX2 + 1 - dYAxisTitleThickness);
  return dX;
}

Fixed version (ground truth):
/** 
 * @param dBlockX
 * @param dBlockWidth
 * @param aax
 * @param axPV
 * @param scX
 * @param iXLabelLocation
 * @param iYLabelLocation
 * @param iYTitleLocation
 * @param laXAxisLabels
 * @param iv
 * @param bTicksLeft
 * @param bTicksRight
 * @param dYAxisLabelsThickness
 * @param dDecorationThickness
 * @param dYAxisTitleThickness
 * @param dX
 * @param dX1
 * @param dX2
 * @param dWTotal
 * @return
 * @throws ChartException
 */
private double adjustHorizontalWithValueOrigin(double dBlockX,double dBlockWidth,AllAxes aax,final OneAxis axPV,final AutoScale scX,final int iXLabelLocation,final int iYLabelLocation,final int iYTitleLocation,final Label laXAxisLabels,final IntersectionValue iv,final boolean bTicksLeft,final boolean bTicksRight,double dYAxisLabelsThickness,double[] dDecorationThickness,double dYAxisTitleThickness,double dX,double dX1,double dX2,double dWTotal) throws ChartException {
  double dStart;
  double dEnd;
  double dDeltaX1=0, dDeltaX2=0;
  if (iYTitleLocation == RIGHT) {
    dX2+=dYAxisTitleThickness;
  }
 else   if (iYTitleLocation == LEFT) {
    dX1-=dYAxisTitleThickness;
  }
  double dW1=0, dW2=0;
  if (iYLabelLocation == LEFT) {
    dW1=(bTicksLeft ? getTickSize() : 0) + Math.max(dYAxisLabelsThickness,dDecorationThickness[0]);
    dW2=(bTicksRight ? getTickSize() : 0);
    if (dW1 + dW2 <= dWTotal) {
      dX1-=dW1;
      dX2+=dW2;
    }
 else {
      axPV.setShowLabels(false);
    }
    dDeltaX1=dX - dX1;
    dDeltaX2=dX2 - dX;
    if (dX1 < dBlockX) {
      final Object[] oaMinMax=scX.getMinMax();
      boolean bForceBreak=false;
      do {
        scX.setEndPoints(scX.getStart() - scX.getStartShift(),scX.getEnd() + scX.getEndShift());
        scX.resetShifts();
        double[] da=scX.getEndPoints();
        double dT_RI=dBlockX - dX1;
        if (scX.getDirection() == BACKWARD) {
          double dAMin_AMax=da[0] - da[1];
          double dAMax_RI=Math.abs(da[0] - dX);
          double dDelta=(dT_RI / dAMax_RI) * dAMin_AMax;
          dEnd=da[1] + dDelta;
          dStart=da[0];
          if (dEnd < dBlockX) {
            dEnd=dBlockX;
            bForceBreak=true;
          }
        }
 else {
          double dAMin_AMax=da[1] - da[0];
          double dAMax_RI=Math.abs(da[1] - dX);
          double dDelta=(dT_RI / dAMax_RI) * dAMin_AMax;
          dStart=da[0] + dDelta;
          dEnd=da[1];
          if (dStart < dBlockX) {
            dStart=dBlockX;
            bForceBreak=true;
          }
        }
        scX.setEndPoints(dStart,dEnd);
        scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            bForceBreak=true;
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            bForceBreak=true;
            break;
          }
        }
        dX=getLocation(scX,iv);
        dX1=dX - dDeltaX1;
      }
 while (Math.abs(dX1 - dBlockX) > 1 && !bForceBreak);
    }
 else {
      dStart=scX.getStart();
      dEnd=scX.getEnd();
      scX.setEndPoints(dStart,dEnd);
      scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
      if (!scX.isStepFixed()) {
        final Object[] oaMinMax=scX.getMinMax();
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            break;
          }
        }
      }
      dX=getLocation(scX,iv);
    }
    dX1=dX - dDeltaX1;
    dX2=dX + dDeltaX2;
  }
 else   if (iYLabelLocation == RIGHT) {
    dW1=(bTicksLeft ? getTickSize() : 0);
    dW2=(bTicksRight ? getTickSize() : 0) + Math.max(dYAxisLabelsThickness,dDecorationThickness[1]);
    if (dW1 + dW2 <= dWTotal) {
      dX1-=dW1;
      dX2+=dW2;
    }
    dDeltaX1=dX - dX1;
    dDeltaX2=dX2 - dX;
    if (dX2 > dBlockX + dBlockWidth) {
      final Object[] oaMinMax=scX.getMinMax();
      boolean bForceBreak=false;
      do {
        scX.setEndPoints(scX.getStart() - scX.getStartShift(),scX.getEnd() + scX.getEndShift());
        scX.resetShifts();
        double[] da=scX.getEndPoints();
        double dT_RI=dX2 - (dBlockX + dBlockWidth);
        if (scX.getDirection() == BACKWARD) {
          double dAMin_AMax=da[0] - da[1];
          double dAMin_RI=Math.abs(dX - da[1]);
          double dDelta=Math.abs(dT_RI / dAMin_RI) * dAMin_AMax;
          dStart=da[0] - dDelta;
          dEnd=da[1];
          if (dStart > dBlockX + dBlockWidth) {
            dStart=dBlockX + dBlockWidth;
            bForceBreak=true;
          }
        }
 else {
          double dAMin_AMax=da[1] - da[0];
          double dAMin_RI=Math.abs(dX - da[0]);
          double dDelta=(dT_RI / dAMin_RI) * dAMin_AMax;
          dEnd=da[1] - dDelta;
          dStart=da[0];
          if (dEnd > dBlockX + dBlockWidth) {
            dEnd=dBlockX + dBlockWidth;
            bForceBreak=true;
          }
        }
        scX.setEndPoints(dStart,dEnd);
        scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
        if (!scX.isStepFixed()) {
          while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
            if (!scX.zoomOut()) {
              bForceBreak=true;
              break;
            }
            scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
            int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
            if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
              bForceBreak=true;
              break;
            }
          }
        }
        dX=getLocation(scX,iv);
        dX2=dX + dDeltaX2;
      }
 while (Math.abs(dX2 - (dBlockX + dBlockWidth)) > 1 && !bForceBreak);
    }
 else {
      dStart=scX.getStart();
      dEnd=scX.getEnd();
      scX.setEndPoints(dStart,dEnd);
      scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
      if (!scX.isStepFixed()) {
        final Object[] oaMinMax=scX.getMinMax();
        while (!scX.checkFit(ids,laXAxisLabels,iXLabelLocation)) {
          if (!scX.zoomOut()) {
            break;
          }
          scX.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
          int tickCount=scX.computeTicks(ids,laXAxisLabels,iXLabelLocation,HORIZONTAL,dStart,dEnd,true,aax);
          if (scX.getUnit() != null && asInteger(scX.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
            break;
          }
        }
      }
      dX=getLocation(scX,iv);
    }
    dX2=dX + dDeltaX2;
    dX1=dX - dDeltaX1;
  }
  axPV.setTitleCoordinate((iYTitleLocation == LEFT) ? dX1 - 1 : dX2 + 1 - dYAxisTitleThickness);
  return dX;
}