Program: 98677
Project: 98677
Buggy source:
/** 
 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) 
 */
@Override public void mouseDragged(MouseEvent e){
  if (start != null) {
    end=snap(e.getPoint());
    if (selected == null) {
      if (e.isShiftDown()) {
        int dx=end.x - start.x;
        int dy=end.y - start.y;
        end.y=start.y + (int)Math.copySign(dx,dy);
      }
    }
 else     if (selected != null && resize != null) {
      double w=resize.w;
      double h=resize.h;
      int dx=end.x - start.x;
      int dy=end.y - start.y;
      Point delta=new Point();
      Point inverseX=new Point();
      Point inverseY=new Point();
      AffineTransform reverse=new AffineTransform();
      reverse.rotate(-resize.r);
      reverse.transform(new Point(dx,dy),delta);
      try {
        reverse.inverseTransform(new Point(delta.x,0),inverseX);
        reverse.inverseTransform(new Point(0,delta.y),inverseY);
      }
 catch (      NoninvertibleTransformException e1) {
        Throwables.propagate(e1);
      }
      double x=resize.x;
      double y=resize.y;
      if (e.isShiftDown()) {
        double a=w / h;
switch (corner.getType()) {
case Cursor.NW_RESIZE_CURSOR:
          x+=((inverseX.y * a) + (inverseY.y * a));
        y+=(inverseX.y + inverseY.y);
      w-=delta.y * a;
    h-=delta.y;
  break;
case Cursor.NE_RESIZE_CURSOR:
x+=inverseY.x;
y+=inverseY.y;
w-=delta.y * a;
h-=delta.y;
break;
case Cursor.SW_RESIZE_CURSOR:
x-=((inverseX.y * a) + (inverseY.y * a));
y+=inverseX.y;
w+=delta.y * a;
h+=delta.y;
break;
case Cursor.SE_RESIZE_CURSOR:
w+=delta.y * a;
h+=delta.y;
break;
}
}
 else {
switch (corner.getType()) {
case Cursor.NW_RESIZE_CURSOR:
x+=(inverseX.x + inverseY.x);
y+=(inverseX.y + inverseY.y);
w-=delta.x;
h-=delta.y;
break;
case Cursor.NE_RESIZE_CURSOR:
x+=inverseY.x;
y+=inverseY.y;
w+=delta.x;
h-=delta.y;
break;
case Cursor.SW_RESIZE_CURSOR:
x+=(inverseX.x + inverseY.x);
y+=inverseX.y;
w-=delta.x;
h+=delta.y;
break;
case Cursor.SE_RESIZE_CURSOR:
w+=delta.x;
h+=delta.y;
break;
}
}
int grid=controller.getSnapGrid();
w=Math.max(grid,w);
h=Math.max(grid,h);
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
selected.x=x;
selected.y=y;
selected.w=w;
selected.h=h;
selected.r=resize.r;
selected.shx=resize.shx;
selected.shy=resize.shy;
}
 else if (selected != null && move != null) {
int dx=end.x - start.x;
int dy=end.y - start.y;
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
if (move.isMatrix()) {
AffineTransform moved=AffineTransform.getTranslateInstance(dx,dy);
moved.concatenate(move.getTransform());
double matrix[]=new double[6];
moved.getMatrix(matrix);
selected.setMatrix(matrix);
}
 else {
double x=move.x + dx;
double y=move.y + dy;
selected.x=x;
selected.y=y;
selected.w=move.w;
selected.h=move.h;
selected.r=move.r;
selected.shx=move.shx;
selected.shy=move.shy;
}
}
 else if (selected != null && rotate != null) {
Point origin=new Point();
rotate.getTransform().transform(new Point(0,0),origin);
int dx=end.x - origin.x;
int dy=end.y - origin.y;
double r=Math.atan2(dy,dx);
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
selected.x=rotate.x;
selected.y=rotate.y;
selected.w=rotate.w;
selected.h=rotate.h;
selected.r=r;
selected.shx=rotate.shx;
selected.shy=rotate.shy;
}
repaint();
}
}

Fixed version (ground truth):
/** 
 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) 
 */
@Override public void mouseDragged(MouseEvent e){
  if (start != null) {
    end=snap(e.getPoint());
    if (selected == null) {
      if (e.isShiftDown()) {
        int dx=end.x - start.x;
        int dy=end.y - start.y;
        end.y=start.y + (int)Math.copySign(dx,dy);
      }
    }
 else     if (selected != null && resize != null) {
      double w=resize.w;
      double h=resize.h;
      int dx=end.x - start.x;
      int dy=end.y - start.y;
      Point delta=new Point();
      Point inverseX=new Point();
      Point inverseY=new Point();
      AffineTransform reverse=new AffineTransform();
      reverse.rotate(-resize.r);
      reverse.transform(new Point(dx,dy),delta);
      try {
        reverse.inverseTransform(new Point(delta.x,0),inverseX);
        reverse.inverseTransform(new Point(0,delta.y),inverseY);
      }
 catch (      NoninvertibleTransformException e1) {
        Throwables.propagate(e1);
      }
      double x=resize.x;
      double y=resize.y;
      if (e.isShiftDown()) {
        double a=w / h;
switch (corner.getType()) {
case Cursor.NW_RESIZE_CURSOR:
          x+=((inverseX.y * a) + (inverseY.y * a));
        y+=(inverseX.y + inverseY.y);
      w-=delta.y * a;
    h-=delta.y;
  break;
case Cursor.NE_RESIZE_CURSOR:
x+=inverseY.x;
y+=inverseY.y;
w-=delta.y * a;
h-=delta.y;
break;
case Cursor.SW_RESIZE_CURSOR:
x-=((inverseX.y * a) + (inverseY.y * a));
y+=inverseX.y;
w+=delta.y * a;
h+=delta.y;
break;
case Cursor.SE_RESIZE_CURSOR:
w+=delta.y * a;
h+=delta.y;
break;
}
}
 else {
switch (corner.getType()) {
case Cursor.NW_RESIZE_CURSOR:
x+=(inverseX.x + inverseY.x);
y+=(inverseX.y + inverseY.y);
w-=delta.x;
h-=delta.y;
break;
case Cursor.NE_RESIZE_CURSOR:
x+=inverseY.x;
y+=inverseY.y;
w+=delta.x;
h-=delta.y;
break;
case Cursor.SW_RESIZE_CURSOR:
x+=(inverseX.x + inverseY.x);
y+=inverseX.y;
w-=delta.x;
h+=delta.y;
break;
case Cursor.SE_RESIZE_CURSOR:
w+=delta.x;
h+=delta.y;
break;
}
}
int grid=controller.getSnapGrid();
w=Math.max(grid,w);
h=Math.max(grid,h);
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
selected.x=x;
selected.y=y;
selected.w=w;
selected.h=h;
selected.r=resize.r;
selected.shx=resize.shx;
selected.shy=resize.shy;
}
 else if (selected != null && move != null) {
int dx=end.x - start.x;
int dy=end.y - start.y;
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
if (move.isMatrix()) {
AffineTransform moved=AffineTransform.getTranslateInstance(dx,dy);
moved.concatenate(move.getTransform());
double matrix[]=new double[6];
moved.getMatrix(matrix);
selected.setMatrix(matrix);
}
 else {
double x=move.x + dx;
double y=move.y + dy;
selected.x=x;
selected.y=y;
selected.w=move.w;
selected.h=move.h;
selected.r=move.r;
selected.shx=move.shx;
selected.shy=move.shy;
}
}
 else if (selected != null && rotate != null) {
Point origin=new Point();
rotate.getTransform().transform(new Point(0,0),origin);
int dx=end.x - origin.x;
int dy=end.y - origin.y;
double r=Math.atan2(dy - (selected.shy * dx),dx - (selected.shx * dy));
selected=new Transform(selected.getId(),selected.getZIndex(),getSize());
selected.x=rotate.x;
selected.y=rotate.y;
selected.w=rotate.w;
selected.h=rotate.h;
selected.r=r;
selected.shx=rotate.shx;
selected.shy=rotate.shy;
}
repaint();
}
}