### Eclipse Workspace Patch 1.0 #P org.eclipse.gef Index: src/org/eclipse/gef/SnapToGrid.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/src/org/eclipse/gef/SnapToGrid.java,v retrieving revision 1.31 diff -u -r1.31 SnapToGrid.java --- src/org/eclipse/gef/SnapToGrid.java 24 Jun 2005 22:05:46 -0000 1.31 +++ src/org/eclipse/gef/SnapToGrid.java 18 Jul 2006 18:36:19 -0000 @@ -133,9 +133,20 @@ if ((snapLocations & (WEST | HORIZONTAL)) != 0 && gridX > 0) { double leftCorrection = Math.IEEEremainder(rect.preciseX - origin.x, gridX); - correction.preciseX -= leftCorrection; + double rightCorrection = Math.IEEEremainder(rect.preciseRight() - origin.x, + gridX); + + double horizontalCorrection = 0; + + if (Math.abs(leftCorrection) > Math.abs(rightCorrection)) { + horizontalCorrection = rightCorrection; + } else { + horizontalCorrection = leftCorrection; + } + + correction.preciseX -= horizontalCorrection; if ((snapLocations & HORIZONTAL) == 0) - correction.preciseWidth += leftCorrection; + correction.preciseWidth += horizontalCorrection; snapLocations &= ~(WEST | HORIZONTAL); } @@ -148,9 +159,22 @@ if ((snapLocations & (NORTH | VERTICAL)) != 0 && gridY > 0) { double topCorrection = Math.IEEEremainder( rect.preciseY - origin.y, gridY); - correction.preciseY -= topCorrection; + + double bottomCorrection = Math.IEEEremainder(rect.preciseBottom() - origin.y, + gridY); + + double verticalCorrection = 0; + + if (Math.abs(topCorrection) > Math.abs(bottomCorrection)) { + verticalCorrection = bottomCorrection; + } else { + verticalCorrection = topCorrection; + } + + + correction.preciseY -= verticalCorrection; if ((snapLocations & VERTICAL) == 0) - correction.preciseHeight += topCorrection; + correction.preciseHeight += verticalCorrection; snapLocations &= ~(NORTH | VERTICAL); } @@ -161,7 +185,6 @@ result.preciseWidth += correction.preciseWidth; result.preciseHeight += correction.preciseHeight; result.updateInts(); - return snapLocations; }