Program: 11659
Project: 11659
Buggy source:
@Override public void paintTo(GlimpseContext context,GlimpseBounds bounds,Axis2D axis){
  GL gl=context.getGL();
  int width=bounds.getWidth();
  int height=bounds.getHeight();
  Axis1D axisX=axis.getAxisX();
  Axis1D axisY=axis.getAxisY();
  double[] xPositions=ticksX.getTickPositions(axis.getAxisX());
  double[] yPositions=ticksY.getTickPositions(axis.getAxisY());
  AxisUnitConverter convX=ticksX.getAxisUnitConverter();
  convX=convX == null ? new AxisUnitConverter(){
    public double toAxisUnits(    double value){
      return value;
    }
    public double fromAxisUnits(    double value){
      return value;
    }
  }
 : convX;
  AxisUnitConverter convY=ticksY.getAxisUnitConverter();
  convY=convY == null ? new AxisUnitConverter(){
    public double toAxisUnits(    double value){
      return value;
    }
    public double fromAxisUnits(    double value){
      return value;
    }
  }
 : convY;
  double onePixelX=0.5 / axisX.getPixelsPerValue();
  double onePixelY=0.5 / axisY.getPixelsPerValue();
  int originY=axisY.valueToScreenPixel(0.0);
  if (originY < 0 || lockBottom)   originY=0;
  if (originY > height || lockTop)   originY=height;
  int originX=axisX.valueToScreenPixel(0.0);
  if (originX < 0 || lockLeft)   originX=0;
  if (originX > width || lockRight)   originX=width;
  boolean rightCornerX=false;
  boolean leftCornerX=false;
  boolean topCornerY=false;
  boolean bottomCornerY=false;
  double doriginX=0.0;
  if (doriginX <= axisX.getMin() || lockLeft) {
    doriginX=axisX.getMin() + onePixelX;
    leftCornerX=true;
  }
  if (doriginX > axisX.getMax() || lockRight) {
    doriginX=axisX.getMax();
    rightCornerX=true;
  }
  double doriginY=0.0;
  if (doriginY <= axisY.getMin() || lockBottom) {
    doriginY=axisY.getMin() + onePixelY;
    topCornerY=true;
  }
  if (doriginY > axisY.getMax() || lockTop) {
    doriginY=axisY.getMax();
    bottomCornerY=true;
  }
  boolean labelRight=width - originX > rightBuffer;
  boolean labelTop=height - originY > topBuffer;
  GlimpseColor.setColor(textRenderer,textColor);
  textRenderer.beginRendering(width,height);
  try {
    if (showHorizontal) {
      String[] xLabels=ticksX.getTickLabels(axis.getAxisX(),xPositions);
      int offsetY;
      if (labelTop) {
        offsetY=tickWidth + labelBuffer;
      }
 else {
        Rectangle2D textBounds=textRenderer.getBounds(xLabels[0]);
        offsetY=(int)-(textBounds.getHeight() + tickWidth + labelBuffer);
      }
      for (int i=0; i < xPositions.length; i++) {
        String label=xLabels[i];
        double valueX=xPositions[i];
        if (valueX == 0.0 && !showZero)         continue;
        int posX=axisX.valueToScreenPixel(valueX);
        if (shouldPaintLabel(rightCornerX,leftCornerX,posX,width,rightBuffer))         textRenderer.draw(label,posX + labelBuffer,originY + offsetY);
      }
    }
    if (showVertical) {
      String[] yLabels=ticksY.getTickLabels(axis.getAxisY(),yPositions);
      for (int i=0; i < yPositions.length; i++) {
        String label=yLabels[i];
        Rectangle2D textBounds=textRenderer.getBounds(label);
        double valueY=yPositions[i];
        if (valueY == 0.0 && !showZero)         continue;
        int offsetX;
        if (labelRight) {
          offsetX=tickWidth + labelBuffer;
        }
 else {
          offsetX=(int)-(textBounds.getWidth() + tickWidth + labelBuffer);
        }
        int posY=axisY.valueToScreenPixel(valueY);
        if (shouldPaintLabel(bottomCornerY,topCornerY,posY,height,topBuffer))         textRenderer.draw(label,originX + offsetX,posY + labelBuffer);
      }
    }
  }
  finally {
    textRenderer.endRendering();
  }
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(-0.5,width - 1 + 0.5f,-0.5,height - 1 + 0.5f,-1,1);
  GlimpseColor.glColor(gl,lineColor);
  gl.glBegin(GL.GL_LINES);
  try {
    if (showHorizontal) {
      double tickWidthX=tickWidth / axisY.getPixelsPerValue();
      for (int i=0; i < xPositions.length; i++) {
        double valueX=xPositions[i];
        int tick=axisX.valueToScreenPixel(convX.fromAxisUnits(valueX));
        gl.glVertex2d(tick,axisY.valueToScreenPixelUnits(doriginY - tickWidthX));
        gl.glVertex2d(tick,axisY.valueToScreenPixelUnits(doriginY + tickWidthX));
        if (labelTop) {
          gl.glVertex2d(tick,axisY.valueToScreenPixelUnits(doriginY + tickWidthX));
          gl.glVertex2d(tick + labelBuffer - 1,axisY.valueToScreenPixelUnits(doriginY + tickWidthX) + labelBuffer - 1);
        }
 else {
          gl.glVertex2d(tick,axisY.valueToScreenPixelUnits(doriginY - tickWidthX));
          gl.glVertex2d(tick + labelBuffer - 1,axisY.valueToScreenPixelUnits(doriginY - tickWidthX) - labelBuffer + 1);
        }
      }
    }
    if (showVertical) {
      double tickWidthY=tickWidth / axisX.getPixelsPerValue();
      for (int i=0; i < yPositions.length; i++) {
        double valueY=yPositions[i];
        int tick=axisY.valueToScreenPixel(convY.fromAxisUnits(valueY));
        gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX - tickWidthY),tick);
        gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX + tickWidthY),tick);
        if (labelRight) {
          gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX + tickWidthY),tick);
          gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX + tickWidthY) + labelBuffer - 1,tick + labelBuffer - 1);
        }
 else {
          gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX - tickWidthY),tick);
          gl.glVertex2d(axisX.valueToScreenPixelUnits(doriginX - tickWidthY) - labelBuffer + 1,tick + labelBuffer - 1);
        }
      }
    }
    if (showHorizontal && showOrigin) {
      gl.glVertex2d(axisX.valueToScreenPixel(convX.fromAxisUnits(axis.getMinX())),axisY.valueToScreenPixel(convY.fromAxisUnits(doriginY)));
      gl.glVertex2d(axisX.valueToScreenPixel(convX.fromAxisUnits(axis.getMaxX())),axisY.valueToScreenPixel(convY.fromAxisUnits(doriginY)));
    }
    if (showVertical && showOrigin) {
      gl.glVertex2d(axisX.valueToScreenPixel(convX.fromAxisUnits(doriginX)),axisY.valueToScreenPixel(convY.fromAxisUnits(axis.getMinY())));
      gl.glVertex2d(axisX.valueToScreenPixel(convX.fromAxisUnits(doriginX)),axisY.valueToScreenPixel(convY.fromAxisUnits(axis.getMaxY())));
    }
  }
  finally {
    gl.glEnd();
  }
}

Fixed version (ground truth):
@Override public void paintTo(GlimpseContext context,GlimpseBounds bounds,Axis2D axis){
  GL gl=context.getGL();
  int width=bounds.getWidth();
  int height=bounds.getHeight();
  Axis1D axisX=axis.getAxisX();
  Axis1D axisY=axis.getAxisY();
  double[] positionsX=ticksX.getTickPositions(axis.getAxisX());
  double[] positionsY=ticksY.getTickPositions(axis.getAxisY());
  AxisUnitConverter convX=ticksX.getAxisUnitConverter();
  convX=convX == null ? AxisUnitConverters.identity : convX;
  AxisUnitConverter convY=ticksY.getAxisUnitConverter();
  convY=convY == null ? AxisUnitConverters.identity : convY;
  double onePixelX=0.5 / axisX.getPixelsPerValue();
  double onePixelY=0.5 / axisY.getPixelsPerValue();
  int originY=axisY.valueToScreenPixel(0.0);
  if (originY < 0 || lockBottom)   originY=0;
  if (originY > height || lockTop)   originY=height;
  int originX=axisX.valueToScreenPixel(0.0);
  if (originX < 0 || lockLeft)   originX=0;
  if (originX > width || lockRight)   originX=width;
  boolean rightCornerX=false;
  boolean leftCornerX=false;
  boolean topCornerY=false;
  boolean bottomCornerY=false;
  double doriginX=0.0;
  if (doriginX <= axisX.getMin() || lockLeft) {
    doriginX=axisX.getMin() + onePixelX;
    leftCornerX=true;
  }
  if (doriginX > axisX.getMax() || lockRight) {
    doriginX=axisX.getMax();
    rightCornerX=true;
  }
  double doriginY=0.0;
  if (doriginY <= axisY.getMin() || lockBottom) {
    doriginY=axisY.getMin() + onePixelY;
    topCornerY=true;
  }
  if (doriginY > axisY.getMax() || lockTop) {
    doriginY=axisY.getMax();
    bottomCornerY=true;
  }
  boolean labelRight=width - originX > rightBuffer;
  boolean labelTop=height - originY > topBuffer;
  boolean[] paintLabelsX=new boolean[positionsX.length];
  boolean[] paintLabelsY=new boolean[positionsY.length];
  GlimpseColor.setColor(textRenderer,textColor);
  textRenderer.beginRendering(width,height);
  try {
    if (showHorizontal) {
      String[] labelsX=ticksX.getTickLabels(axis.getAxisX(),positionsX);
      int offsetY;
      if (labelTop) {
        offsetY=tickWidth + labelBuffer;
      }
 else {
        Rectangle2D textBounds=textRenderer.getBounds(labelsX[0]);
        offsetY=(int)-(textBounds.getHeight() + tickWidth + labelBuffer);
      }
      for (int i=0; i < positionsX.length; i++) {
        String label=labelsX[i];
        double valueX=positionsX[i];
        if (valueX == 0.0 && !showZero)         continue;
        int posX=axisX.valueToScreenPixel(valueX);
        paintLabelsX[i]=shouldPaintLabel(rightCornerX,leftCornerX,posX,width,rightBuffer);
        if (paintLabelsX[i])         textRenderer.draw(label,posX + labelBuffer,originY + offsetY);
      }
    }
    if (showVertical) {
      String[] labelsY=ticksY.getTickLabels(axis.getAxisY(),positionsY);
      for (int i=0; i < positionsY.length; i++) {
        String label=labelsY[i];
        Rectangle2D textBounds=textRenderer.getBounds(label);
        double valueY=positionsY[i];
        if (valueY == 0.0 && !showZero)         continue;
        int offsetX;
        if (labelRight) {
          offsetX=tickWidth + labelBuffer;
        }
 else {
          offsetX=(int)-(textBounds.getWidth() + tickWidth + labelBuffer);
        }
        int posY=axisY.valueToScreenPixel(valueY);
        paintLabelsY[i]=shouldPaintLabel(bottomCornerY,topCornerY,posY,height,topBuffer);
        if (paintLabelsY[i])         textRenderer.draw(label,originX + offsetX,posY + labelBuffer);
      }
    }
  }
  finally {
    textRenderer.endRendering();
  }
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(axis.getMinX(),axis.getMaxX(),axis.getMinY(),axis.getMaxY(),-1,1);
  GlimpseColor.glColor(gl,lineColor);
  double labelBufferX=labelBuffer / axisX.getPixelsPerValue();
  double labelBufferY=labelBuffer / axisY.getPixelsPerValue();
  gl.glBegin(GL.GL_LINES);
  try {
    if (showHorizontal) {
      double tickWidthY=tickWidth / axisY.getPixelsPerValue();
      for (int i=0; i < positionsX.length; i++) {
        if (paintLabelsX[i]) {
          double valueX=convX.fromAxisUnits(positionsX[i]);
          gl.glVertex2d(valueX,doriginY - tickWidthY);
          gl.glVertex2d(valueX,doriginY + tickWidthY);
          if (labelTop) {
            gl.glVertex2d(valueX,doriginY + tickWidthY);
            gl.glVertex2d(valueX + labelBufferX,doriginY + tickWidthY + labelBufferY);
          }
 else {
            gl.glVertex2d(valueX,doriginY - tickWidthY);
            gl.glVertex2d(valueX + labelBufferX,doriginY - tickWidthY - labelBufferY);
          }
        }
      }
    }
    if (showVertical) {
      double tickWidthX=tickWidth / axisX.getPixelsPerValue();
      for (int i=0; i < positionsY.length; i++) {
        if (paintLabelsY[i]) {
          double valueY=convY.fromAxisUnits(positionsY[i]);
          gl.glVertex2d(doriginX - tickWidthX,valueY);
          gl.glVertex2d(doriginX + tickWidthX,valueY);
          if (labelRight) {
            gl.glVertex2d(doriginX + tickWidthX,valueY);
            gl.glVertex2d(doriginX + tickWidthX + labelBufferX,valueY + labelBufferY);
          }
 else {
            gl.glVertex2d(doriginX - tickWidthX,valueY);
            gl.glVertex2d(doriginX - tickWidthX - labelBufferX,valueY + labelBufferY);
          }
        }
      }
    }
    if (showHorizontal && showOrigin) {
      gl.glVertex2d(convX.fromAxisUnits(axis.getMinX()),convY.fromAxisUnits(doriginY));
      gl.glVertex2d(convX.fromAxisUnits(axis.getMaxX()),convY.fromAxisUnits(doriginY));
    }
    if (showVertical && showOrigin) {
      gl.glVertex2d(convX.fromAxisUnits(doriginX),convY.fromAxisUnits(axis.getMinY()));
      gl.glVertex2d(convX.fromAxisUnits(doriginX),convY.fromAxisUnits(axis.getMaxY()));
    }
  }
  finally {
    gl.glEnd();
  }
}